Skip to content

Commit f68ee6e

Browse files
Ben L. TitzerCommit Bot
authored andcommitted
[typedarrays] Use Detach instead of Neuter
This is purely a renaming change. The ES spec uses the term 'detach' for the process of removing the backing store of a typed array, while V8 uses the historical term 'neuter'. Update our internal implementation, including method names and flag names, to match the spec. Note that some error messages still use the term 'neuter' since error messages are asserted by some embedder tests, like layout tests. R=bmeurer@chromium.org, yangguo@chromium.org, mstarzinger@chromium.org, mlippautz@chromium.org BUG=chromium:913887 Change-Id: I62f1c3ac9ae67ba01d612a5221afa3d92deae272 Reviewed-on: https://chromium-review.googlesource.com/c/1370036 Commit-Queue: Ben Titzer <titzer@chromium.org> Reviewed-by: Michael Starzinger <mstarzinger@chromium.org> Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Reviewed-by: Yang Guo <yangguo@chromium.org> Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Cr-Commit-Position: refs/heads/master@{#58149}
1 parent 7d3826e commit f68ee6e

File tree

81 files changed

+374
-377
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+374
-377
lines changed

include/v8.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4705,17 +4705,26 @@ class V8_EXPORT ArrayBuffer : public Object {
47054705
bool IsExternal() const;
47064706

47074707
/**
4708-
* Returns true if this ArrayBuffer may be neutered.
4708+
* Returns true if this ArrayBuffer may be detached.
47094709
*/
4710-
bool IsNeuterable() const;
4710+
bool IsDetachable() const;
4711+
4712+
// TODO(913887): fix the use of 'neuter' in the API.
4713+
V8_DEPRECATE_SOON("Use IsDetachable() instead.",
4714+
inline bool IsNeuterable() const) {
4715+
return IsDetachable();
4716+
}
47114717

47124718
/**
4713-
* Neuters this ArrayBuffer and all its views (typed arrays).
4714-
* Neutering sets the byte length of the buffer and all typed arrays to zero,
4719+
* Detaches this ArrayBuffer and all its views (typed arrays).
4720+
* Detaching sets the byte length of the buffer and all typed arrays to zero,
47154721
* preventing JavaScript from ever accessing underlying backing store.
4716-
* ArrayBuffer should have been externalized and must be neuterable.
4722+
* ArrayBuffer should have been externalized and must be detachable.
47174723
*/
4718-
void Neuter();
4724+
void Detach();
4725+
4726+
// TODO(913887): fix the use of 'neuter' in the API.
4727+
V8_DEPRECATE_SOON("Use Detach() instead.", inline void Neuter()) { Detach(); }
47194728

47204729
/**
47214730
* Make this ArrayBuffer external. The pointer to underlying memory block

src/api.cc

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7535,12 +7535,10 @@ bool v8::ArrayBuffer::IsExternal() const {
75357535
return Utils::OpenHandle(this)->is_external();
75367536
}
75377537

7538-
7539-
bool v8::ArrayBuffer::IsNeuterable() const {
7540-
return Utils::OpenHandle(this)->is_neuterable();
7538+
bool v8::ArrayBuffer::IsDetachable() const {
7539+
return Utils::OpenHandle(this)->is_detachable();
75417540
}
75427541

7543-
75447542
v8::ArrayBuffer::Contents v8::ArrayBuffer::Externalize() {
75457543
i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle(this);
75467544
i::Isolate* isolate = self->GetIsolate();
@@ -7597,21 +7595,18 @@ v8::ArrayBuffer::Contents v8::ArrayBuffer::GetContents() {
75977595
return contents;
75987596
}
75997597

7600-
7601-
void v8::ArrayBuffer::Neuter() {
7598+
void v8::ArrayBuffer::Detach() {
76027599
i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this);
76037600
i::Isolate* isolate = obj->GetIsolate();
7604-
Utils::ApiCheck(obj->is_external(),
7605-
"v8::ArrayBuffer::Neuter",
7606-
"Only externalized ArrayBuffers can be neutered");
7607-
Utils::ApiCheck(obj->is_neuterable(), "v8::ArrayBuffer::Neuter",
7608-
"Only neuterable ArrayBuffers can be neutered");
7609-
LOG_API(isolate, ArrayBuffer, Neuter);
7601+
Utils::ApiCheck(obj->is_external(), "v8::ArrayBuffer::Detach",
7602+
"Only externalized ArrayBuffers can be detached");
7603+
Utils::ApiCheck(obj->is_detachable(), "v8::ArrayBuffer::Detach",
7604+
"Only detachable ArrayBuffers can be detached");
7605+
LOG_API(isolate, ArrayBuffer, Detach);
76107606
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
7611-
obj->Neuter();
7607+
obj->Detach();
76127608
}
76137609

7614-
76157610
size_t v8::ArrayBuffer::ByteLength() const {
76167611
i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this);
76177612
return obj->byte_length();
@@ -7702,19 +7697,19 @@ bool v8::ArrayBufferView::HasBuffer() const {
77027697

77037698
size_t v8::ArrayBufferView::ByteOffset() {
77047699
i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
7705-
return obj->WasNeutered() ? 0 : obj->byte_offset();
7700+
return obj->WasDetached() ? 0 : obj->byte_offset();
77067701
}
77077702

77087703

77097704
size_t v8::ArrayBufferView::ByteLength() {
77107705
i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
7711-
return obj->WasNeutered() ? 0 : obj->byte_length();
7706+
return obj->WasDetached() ? 0 : obj->byte_length();
77127707
}
77137708

77147709

77157710
size_t v8::TypedArray::Length() {
77167711
i::Handle<i::JSTypedArray> obj = Utils::OpenHandle(this);
7717-
return obj->WasNeutered() ? 0 : obj->length_value();
7712+
return obj->WasDetached() ? 0 : obj->length_value();
77187713
}
77197714

77207715
static_assert(v8::TypedArray::kMaxLength == i::Smi::kMaxValue,

src/builtins/builtins-array-gen.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3201,7 +3201,7 @@ TF_BUILTIN(ArrayIteratorPrototypeNext, CodeStubAssembler) {
32013201
// If {array} is a JSTypedArray, the {index} must always be a Smi.
32023202
CSA_ASSERT(this, TaggedIsSmi(index));
32033203

3204-
// Check that the {array}s buffer wasn't neutered.
3204+
// Check that the {array}s buffer wasn't detached.
32053205
ThrowIfArrayBufferViewBufferIsDetached(context, CAST(array), method_name);
32063206

32073207
// If we go outside of the {length}, we don't need to update the

src/builtins/builtins-arraybuffer.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static Object* SliceHelper(BuiltinArguments args, Isolate* isolate,
137137
CHECK_SHARED(is_shared, array_buffer, kMethodName);
138138

139139
// * [AB] If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
140-
if (!is_shared && array_buffer->was_neutered()) {
140+
if (!is_shared && array_buffer->was_detached()) {
141141
THROW_NEW_ERROR_RETURN_FAILURE(
142142
isolate, NewTypeError(MessageTemplate::kDetachedOperation,
143143
isolate->factory()->NewStringFromAsciiChecked(
@@ -223,7 +223,7 @@ static Object* SliceHelper(BuiltinArguments args, Isolate* isolate,
223223
CHECK_SHARED(is_shared, new_array_buffer, kMethodName);
224224

225225
// * [AB] If IsDetachedBuffer(new) is true, throw a TypeError exception.
226-
if (!is_shared && new_array_buffer->was_neutered()) {
226+
if (!is_shared && new_array_buffer->was_detached()) {
227227
THROW_NEW_ERROR_RETURN_FAILURE(
228228
isolate, NewTypeError(MessageTemplate::kDetachedOperation,
229229
isolate->factory()->NewStringFromAsciiChecked(
@@ -254,7 +254,7 @@ static Object* SliceHelper(BuiltinArguments args, Isolate* isolate,
254254

255255
// * [AB] NOTE: Side-effects of the above steps may have detached O.
256256
// * [AB] If IsDetachedBuffer(O) is true, throw a TypeError exception.
257-
if (!is_shared && array_buffer->was_neutered()) {
257+
if (!is_shared && array_buffer->was_detached()) {
258258
THROW_NEW_ERROR_RETURN_FAILURE(
259259
isolate, NewTypeError(MessageTemplate::kDetachedOperation,
260260
isolate->factory()->NewStringFromAsciiChecked(

src/builtins/builtins-sharedarraybuffer-gen.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void SharedArrayBufferBuiltinsAssembler::DebugSanityCheckAtomicIndex(
134134
Node* array, Node* index_word, Node* context) {
135135
// In Debug mode, we re-validate the index as a sanity check because
136136
// ToInteger above calls out to JavaScript. A SharedArrayBuffer can't be
137-
// neutered and the TypedArray length can't change either, so skipping this
137+
// detached and the TypedArray length can't change either, so skipping this
138138
// check in Release mode is safe.
139139
CSA_ASSERT(this,
140140
Uint32LessThan(index_word,

src/builtins/builtins-sharedarraybuffer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ V8_WARN_UNUSED_RESULT Maybe<size_t> ValidateAtomicAccess(
7474

7575
size_t access_index;
7676
if (!TryNumberToSize(*access_index_obj, &access_index) ||
77-
typed_array->WasNeutered() ||
77+
typed_array->WasDetached() ||
7878
access_index >= typed_array->length_value()) {
7979
isolate->Throw(*isolate->factory()->NewRangeError(
8080
MessageTemplate::kInvalidAtomicAccessIndex));

src/builtins/builtins-typed-array-gen.cc

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ TF_BUILTIN(TypedArrayInitialize, TypedArrayBuiltinsAssembler) {
185185
empty_fixed_array);
186186
// Setup the ArrayBuffer.
187187
// - Set BitField to 0.
188-
// - Set IsExternal and IsNeuterable bits of BitFieldSlot.
188+
// - Set IsExternal and IsDetachable bits of BitFieldSlot.
189189
// - Set the byte_length field to byte_length.
190190
// - Set backing_store to null/Smi(0).
191191
// - Set all embedder fields to Smi(0).
@@ -196,7 +196,7 @@ TF_BUILTIN(TypedArrayInitialize, TypedArrayBuiltinsAssembler) {
196196
MachineRepresentation::kWord32);
197197
}
198198
int32_t bitfield_value = (1 << JSArrayBuffer::IsExternalBit::kShift) |
199-
(1 << JSArrayBuffer::IsNeuterableBit::kShift);
199+
(1 << JSArrayBuffer::IsDetachableBit::kShift);
200200
StoreObjectFieldNoWriteBarrier(buffer, JSArrayBuffer::kBitFieldOffset,
201201
Int32Constant(bitfield_value),
202202
MachineRepresentation::kWord32);
@@ -612,7 +612,7 @@ void TypedArrayBuiltinsAssembler::ConstructByArrayLike(
612612
Node* source_data_ptr = LoadDataPtr(array_like);
613613

614614
// Calculate the byte length. We shouldn't be trying to copy if the typed
615-
// array was neutered.
615+
// array was detached.
616616
CSA_ASSERT(this, SmiNotEqual(length, SmiConstant(0)));
617617
CSA_ASSERT(this, Word32Equal(IsDetachedBuffer(LoadObjectField(
618618
array_like, JSTypedArray::kBufferOffset)),
@@ -805,7 +805,7 @@ TF_BUILTIN(TypedArrayPrototypeByteLength, TypedArrayBuiltinsAssembler) {
805805
// Check if the {receiver} is actually a JSTypedArray.
806806
ThrowIfNotInstanceType(context, receiver, JS_TYPED_ARRAY_TYPE, kMethodName);
807807

808-
// Default to zero if the {receiver}s buffer was neutered.
808+
// Default to zero if the {receiver}s buffer was detached.
809809
TNode<JSArrayBuffer> receiver_buffer =
810810
LoadJSArrayBufferViewBuffer(CAST(receiver));
811811
TNode<UintPtrT> byte_length = Select<UintPtrT>(
@@ -823,7 +823,7 @@ TF_BUILTIN(TypedArrayPrototypeByteOffset, TypedArrayBuiltinsAssembler) {
823823
// Check if the {receiver} is actually a JSTypedArray.
824824
ThrowIfNotInstanceType(context, receiver, JS_TYPED_ARRAY_TYPE, kMethodName);
825825

826-
// Default to zero if the {receiver}s buffer was neutered.
826+
// Default to zero if the {receiver}s buffer was detached.
827827
TNode<JSArrayBuffer> receiver_buffer =
828828
LoadJSArrayBufferViewBuffer(CAST(receiver));
829829
TNode<UintPtrT> byte_offset = Select<UintPtrT>(
@@ -841,7 +841,7 @@ TF_BUILTIN(TypedArrayPrototypeLength, TypedArrayBuiltinsAssembler) {
841841
// Check if the {receiver} is actually a JSTypedArray.
842842
ThrowIfNotInstanceType(context, receiver, JS_TYPED_ARRAY_TYPE, kMethodName);
843843

844-
// Default to zero if the {receiver}s buffer was neutered.
844+
// Default to zero if the {receiver}s buffer was detached.
845845
TNode<JSArrayBuffer> receiver_buffer =
846846
LoadJSArrayBufferViewBuffer(CAST(receiver));
847847
TNode<Smi> length = Select<Smi>(
@@ -1260,7 +1260,7 @@ TF_BUILTIN(TypedArrayPrototypeSet, TypedArrayBuiltinsAssembler) {
12601260
GotoIfNot(TaggedIsPositiveSmi(offset_num), &if_offset_is_out_of_bounds);
12611261
TNode<Smi> offset_smi = CAST(offset_num);
12621262

1263-
// Check the receiver is not neutered.
1263+
// Check the receiver is not detached.
12641264
ThrowIfArrayBufferViewBufferIsDetached(context, CAST(receiver), method_name);
12651265

12661266
// Check the source argument is valid and whether a fast path can be taken.
@@ -1274,7 +1274,7 @@ TF_BUILTIN(TypedArrayPrototypeSet, TypedArrayBuiltinsAssembler) {
12741274
// Fast path for a typed array source argument.
12751275
BIND(&if_source_is_typed_array);
12761276
{
1277-
// Check the source argument is not neutered.
1277+
// Check the source argument is not detached.
12781278
ThrowIfArrayBufferViewBufferIsDetached(context, CAST(source), method_name);
12791279

12801280
SetTypedArraySource(context, CAST(source), CAST(receiver),
@@ -1348,8 +1348,8 @@ TF_BUILTIN(TypedArrayPrototypeSlice, TypedArrayBuiltinsAssembler) {
13481348
args.PopAndReturn(result_array);
13491349

13501350
BIND(&if_count_is_not_zero);
1351-
// Check the source array is neutered or not. We don't need to check if the
1352-
// result array is neutered or not since TypedArraySpeciesCreate checked it.
1351+
// Check the source array is detached or not. We don't need to check if the
1352+
// result array is detached or not since TypedArraySpeciesCreate checked it.
13531353
CSA_ASSERT(this, Word32BinaryNot(IsDetachedBuffer(LoadObjectField(
13541354
result_array, JSTypedArray::kBufferOffset))));
13551355
TNode<JSArrayBuffer> receiver_buffer =
@@ -1539,7 +1539,7 @@ void TypedArrayBuiltinsAssembler::GenerateTypedArrayPrototypeIterationMethod(
15391539
GotoIf(TaggedIsSmi(receiver), &throw_bad_receiver);
15401540
GotoIfNot(IsJSTypedArray(CAST(receiver)), &throw_bad_receiver);
15411541

1542-
// Check if the {receiver}'s JSArrayBuffer was neutered.
1542+
// Check if the {receiver}'s JSArrayBuffer was detached.
15431543
ThrowIfArrayBufferViewBufferIsDetached(context, CAST(receiver), method_name);
15441544

15451545
Return(CreateArrayIterator(context, receiver, kind));
@@ -1586,7 +1586,7 @@ TF_BUILTIN(TypedArrayOf, TypedArrayBuiltinsAssembler) {
15861586
CodeStubArguments::ReceiverMode::kHasReceiver);
15871587

15881588
Label if_not_constructor(this, Label::kDeferred),
1589-
if_neutered(this, Label::kDeferred);
1589+
if_detached(this, Label::kDeferred);
15901590

15911591
// 3. Let C be the this value.
15921592
// 4. If IsConstructor(C) is false, throw a TypeError exception.
@@ -1619,16 +1619,16 @@ TF_BUILTIN(TypedArrayOf, TypedArrayBuiltinsAssembler) {
16191619
if (kind == BIGINT64_ELEMENTS || kind == BIGUINT64_ELEMENTS) {
16201620
EmitBigTypedArrayElementStore(new_typed_array, elements,
16211621
intptr_index, item, context,
1622-
&if_neutered);
1622+
&if_detached);
16231623
} else {
16241624
Node* value =
16251625
PrepareValueForWriteToTypedArray(item, kind, context);
16261626

1627-
// ToNumber may execute JavaScript code, which could neuter
1627+
// ToNumber may execute JavaScript code, which could detach
16281628
// the array's buffer.
16291629
Node* buffer = LoadObjectField(new_typed_array,
16301630
JSTypedArray::kBufferOffset);
1631-
GotoIf(IsDetachedBuffer(buffer), &if_neutered);
1631+
GotoIf(IsDetachedBuffer(buffer), &if_detached);
16321632

16331633
// GC may move backing store in ToNumber, thus load backing
16341634
// store everytime in this loop.
@@ -1647,7 +1647,7 @@ TF_BUILTIN(TypedArrayOf, TypedArrayBuiltinsAssembler) {
16471647
BIND(&if_not_constructor);
16481648
ThrowTypeError(context, MessageTemplate::kNotConstructor, receiver);
16491649

1650-
BIND(&if_neutered);
1650+
BIND(&if_detached);
16511651
ThrowTypeError(context, MessageTemplate::kDetachedOperation,
16521652
"%TypedArray%.of");
16531653
}
@@ -1661,7 +1661,7 @@ TF_BUILTIN(TypedArrayFrom, TypedArrayBuiltinsAssembler) {
16611661
if_not_constructor(this, Label::kDeferred),
16621662
if_map_fn_not_callable(this, Label::kDeferred),
16631663
if_iterator_fn_not_callable(this, Label::kDeferred),
1664-
if_neutered(this, Label::kDeferred);
1664+
if_detached(this, Label::kDeferred);
16651665

16661666
CodeStubArguments args(
16671667
this,
@@ -1849,16 +1849,16 @@ TF_BUILTIN(TypedArrayFrom, TypedArrayBuiltinsAssembler) {
18491849
if (kind == BIGINT64_ELEMENTS || kind == BIGUINT64_ELEMENTS) {
18501850
EmitBigTypedArrayElementStore(target_obj.value(), elements,
18511851
intptr_index, mapped_value,
1852-
context, &if_neutered);
1852+
context, &if_detached);
18531853
} else {
18541854
Node* const final_value = PrepareValueForWriteToTypedArray(
18551855
mapped_value, kind, context);
18561856

1857-
// ToNumber may execute JavaScript code, which could neuter
1857+
// ToNumber may execute JavaScript code, which could detach
18581858
// the array's buffer.
18591859
Node* buffer = LoadObjectField(target_obj.value(),
18601860
JSTypedArray::kBufferOffset);
1861-
GotoIf(IsDetachedBuffer(buffer), &if_neutered);
1861+
GotoIf(IsDetachedBuffer(buffer), &if_detached);
18621862

18631863
// GC may move backing store in map_fn, thus load backing
18641864
// store in each iteration of this loop.
@@ -1882,7 +1882,7 @@ TF_BUILTIN(TypedArrayFrom, TypedArrayBuiltinsAssembler) {
18821882
BIND(&if_iterator_fn_not_callable);
18831883
ThrowTypeError(context, MessageTemplate::kIteratorSymbolNonCallable);
18841884

1885-
BIND(&if_neutered);
1885+
BIND(&if_detached);
18861886
ThrowTypeError(context, MessageTemplate::kDetachedOperation,
18871887
"%TypedArray%.from");
18881888
}

src/builtins/builtins-typed-array.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ BUILTIN(TypedArrayPrototypeCopyWithin) {
8686
// TODO(caitp): throw here, as though the full algorithm were performed (the
8787
// throw would have come from ecma262/#sec-integerindexedelementget)
8888
// (see )
89-
if (V8_UNLIKELY(array->WasNeutered())) return *array;
89+
if (V8_UNLIKELY(array->WasDetached())) return *array;
9090

9191
// Ensure processed indexes are within array bounds
9292
DCHECK_GE(from, 0);
@@ -149,7 +149,7 @@ BUILTIN(TypedArrayPrototypeFill) {
149149
int64_t count = end - start;
150150
if (count <= 0) return *array;
151151

152-
if (V8_UNLIKELY(array->WasNeutered())) return *array;
152+
if (V8_UNLIKELY(array->WasDetached())) return *array;
153153

154154
// Ensure processed indexes are within array bounds
155155
DCHECK_GE(start, 0);
@@ -185,7 +185,7 @@ BUILTIN(TypedArrayPrototypeIncludes) {
185185
}
186186

187187
// TODO(cwhan.tunz): throw. See the above comment in CopyWithin.
188-
if (V8_UNLIKELY(array->WasNeutered()))
188+
if (V8_UNLIKELY(array->WasDetached()))
189189
return ReadOnlyRoots(isolate).false_value();
190190

191191
Handle<Object> search_element = args.atOrUndefined(isolate, 1);
@@ -217,7 +217,7 @@ BUILTIN(TypedArrayPrototypeIndexOf) {
217217
}
218218

219219
// TODO(cwhan.tunz): throw. See the above comment in CopyWithin.
220-
if (V8_UNLIKELY(array->WasNeutered())) return Smi::FromInt(-1);
220+
if (V8_UNLIKELY(array->WasDetached())) return Smi::FromInt(-1);
221221

222222
Handle<Object> search_element = args.atOrUndefined(isolate, 1);
223223
ElementsAccessor* elements = array->GetElementsAccessor();
@@ -252,7 +252,7 @@ BUILTIN(TypedArrayPrototypeLastIndexOf) {
252252
if (index < 0) return Smi::FromInt(-1);
253253

254254
// TODO(cwhan.tunz): throw. See the above comment in CopyWithin.
255-
if (V8_UNLIKELY(array->WasNeutered())) return Smi::FromInt(-1);
255+
if (V8_UNLIKELY(array->WasDetached())) return Smi::FromInt(-1);
256256

257257
Handle<Object> search_element = args.atOrUndefined(isolate, 1);
258258
ElementsAccessor* elements = array->GetElementsAccessor();

0 commit comments

Comments
 (0)