Commit 096db4f0 authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[typedarray] Port the TypedArray constructor dispatcher to CSA.

Bug: v8:7102
Change-Id: Id37799cdf989558ca4f771d451f4b45cbf7123bf
Reviewed-on: https://chromium-review.googlesource.com/787434
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50744}
parent b0ac8a1a
......@@ -3109,21 +3109,6 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
TYPED_ARRAYS(INSTALL_TYPED_ARRAY)
#undef INSTALL_TYPED_ARRAY
// %typed_array_construct_by_length
Handle<JSFunction> construct_by_length = SimpleCreateFunction(
isolate,
factory->NewStringFromAsciiChecked("typedArrayConstructByLength"),
Builtins::kTypedArrayConstructByLength, 3, false);
native_context()->set_typed_array_construct_by_length(*construct_by_length);
// %typed_array_construct_by_array_buffer
Handle<JSFunction> construct_by_buffer = SimpleCreateFunction(
isolate,
factory->NewStringFromAsciiChecked("typedArrayConstructByArrayBuffer"),
Builtins::kTypedArrayConstructByArrayBuffer, 5, false);
native_context()->set_typed_array_construct_by_array_buffer(
*construct_by_buffer);
// %typed_array_construct_by_array_like
Handle<JSFunction> construct_by_array_like = SimpleCreateFunction(
isolate,
......@@ -3131,14 +3116,6 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Builtins::kTypedArrayConstructByArrayLike, 4, false);
native_context()->set_typed_array_construct_by_array_like(
*construct_by_array_like);
// %typed_array_construct_by_typed_array
Handle<JSFunction> construct_by_typed_array = SimpleCreateFunction(
isolate,
factory->NewStringFromAsciiChecked("typedArrayConstructByTypedArray"),
Builtins::kTypedArrayConstructByTypedArray, 3, false);
native_context()->set_typed_array_construct_by_typed_array(
*construct_by_typed_array);
}
{ // -- D a t a V i e w
......@@ -3696,9 +3673,14 @@ Handle<JSFunction> Genesis::InstallTypedArray(const char* name,
Handle<JSFunction> result = InstallFunction(
global, name, JS_TYPED_ARRAY_TYPE, JSTypedArray::kSizeWithEmbedderFields,
0, factory()->the_hole_value(), Builtins::kIllegal);
0, factory()->the_hole_value(), Builtins::kTypedArrayConstructor);
result->initial_map()->set_elements_kind(elements_kind);
result->shared()->DontAdaptArguments();
result->shared()->set_length(3);
result->shared()->SetConstructStub(
*BUILTIN_CODE(isolate_, TypedArrayConstructor_ConstructStub));
CHECK(JSObject::SetPrototype(result, typed_array_function, false, kDontThrow)
.FromJust());
......
......@@ -1065,14 +1065,11 @@ namespace internal {
TFS(TypedArrayInitialize, kHolder, kLength, kElementSize, kInitialize) \
TFS(TypedArrayInitializeWithBuffer, kHolder, kLength, kBuffer, kElementSize, \
kByteOffset) \
/* ES6 #sec-typedarray-buffer-byteoffset-length */ \
TFJ(TypedArrayConstructByArrayBuffer, 5, kHolder, kBuffer, kByteOffset, \
kLength, kElementSize) \
TFJ(TypedArrayConstructByArrayLike, 4, kHolder, kArrayLike, kLength, \
kElementSize) \
/* ES6 #sec-typedarray-length */ \
TFJ(TypedArrayConstructByLength, 3, kHolder, kLength, kElementSize) \
TFJ(TypedArrayConstructByTypedArray, 3, kHolder, kTypedArray, kElementSize) \
TFJ(TypedArrayConstructor, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
TFJ(TypedArrayConstructor_ConstructStub, \
SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
CPP(TypedArrayPrototypeBuffer) \
/* ES6 #sec-get-%typedarray%.prototype.bytelength */ \
TFJ(TypedArrayPrototypeByteLength, 0) \
......
This diff is collapsed.
......@@ -264,6 +264,7 @@ bool Builtins::IsLazy(int index) {
case kProxyConstructor_ConstructStub: // https://crbug.com/v8/6787.
case kNumberConstructor_ConstructStub: // https://crbug.com/v8/6787.
case kStringConstructor_ConstructStub: // https://crbug.com/v8/6787.
case kTypedArrayConstructor_ConstructStub: // https://crbug.com/v8/6787.
case kProxyConstructor: // https://crbug.com/v8/6787.
case kRecordWrite: // https://crbug.com/chromium/765301.
case kThrowWasmTrapDivByZero: // Required by wasm.
......
......@@ -63,14 +63,10 @@ enum ContextLookupFlags {
V(REFLECT_DELETE_PROPERTY_INDEX, JSFunction, reflect_delete_property) \
V(SPREAD_ARGUMENTS_INDEX, JSFunction, spread_arguments) \
V(SPREAD_ITERABLE_INDEX, JSFunction, spread_iterable) \
V(TYPED_ARRAY_CONSTRUCT_BY_ARRAY_BUFFER_INDEX, JSFunction, \
typed_array_construct_by_array_buffer) \
V(TYPED_ARRAY_CONSTRUCT_BY_ARRAY_LIKE_INDEX, JSFunction, \
typed_array_construct_by_array_like) \
V(TYPED_ARRAY_CONSTRUCT_BY_LENGTH_INDEX, JSFunction, \
typed_array_construct_by_length) \
V(TYPED_ARRAY_CONSTRUCT_BY_TYPED_ARRAY_INDEX, JSFunction, \
typed_array_construct_by_typed_array) \
V(TYPED_ARRAY_CONSTRUCT_BY_ITERABLE_INDEX, JSFunction, \
typed_array_construct_by_iterable) \
V(MATH_FLOOR_INDEX, JSFunction, math_floor) \
V(MATH_POW_INDEX, JSFunction, math_pow) \
V(NEW_PROMISE_CAPABILITY_INDEX, JSFunction, new_promise_capability) \
......
......@@ -42,14 +42,6 @@ endmacro
TYPED_ARRAYS(DECLARE_GLOBALS)
macro IS_ARRAYBUFFER(arg)
(%_ClassOf(arg) === 'ArrayBuffer')
endmacro
macro IS_SHAREDARRAYBUFFER(arg)
(%_ClassOf(arg) === 'SharedArrayBuffer')
endmacro
macro IS_TYPEDARRAY(arg)
(%_IsTypedArray(arg))
endmacro
......@@ -126,13 +118,12 @@ function TypedArraySpeciesCreate(exemplar, arg0, arg1, arg2) {
return TypedArrayCreate(constructor, arg0, arg1, arg2);
}
macro TYPED_ARRAY_CONSTRUCTOR(NAME, ELEMENT_SIZE)
function NAMEConstructByIterable(obj, iterable, iteratorFn) {
function TypedArrayConstructByIterable(obj, iterable, iteratorFn, elementSize) {
if (%IterableToListCanBeElided(iterable)) {
// This .length access is unobservable, because it being observable would
// mean that iteration has side effects, and we wouldn't reach this path.
%typed_array_construct_by_array_like(
obj, iterable, iterable.length, ELEMENT_SIZE);
obj, iterable, iterable.length, elementSize);
} else {
var list = new InternalArray();
// Reading the Symbol.iterator property of iterable twice would be
......@@ -150,33 +141,11 @@ function NAMEConstructByIterable(obj, iterable, iteratorFn) {
for (var value of newIterable) {
list.push(value);
}
%typed_array_construct_by_array_like(obj, list, list.length, ELEMENT_SIZE);
}
}
function NAMEConstructor(arg1, arg2, arg3) {
if (!IS_UNDEFINED(new.target)) {
if (IS_ARRAYBUFFER(arg1) || IS_SHAREDARRAYBUFFER(arg1)) {
%typed_array_construct_by_array_buffer(
this, arg1, arg2, arg3, ELEMENT_SIZE);
} else if (IS_TYPEDARRAY(arg1)) {
%typed_array_construct_by_typed_array(this, arg1, ELEMENT_SIZE);
} else if (IS_RECEIVER(arg1)) {
var iteratorFn = arg1[iteratorSymbol];
if (IS_UNDEFINED(iteratorFn)) {
%typed_array_construct_by_array_like(
this, arg1, arg1.length, ELEMENT_SIZE);
} else {
NAMEConstructByIterable(this, arg1, iteratorFn);
}
} else {
%typed_array_construct_by_length(this, arg1, ELEMENT_SIZE);
}
} else {
throw %make_type_error(kConstructorNotFunction, "NAME")
%typed_array_construct_by_array_like(obj, list, list.length, elementSize);
}
}
macro TYPED_ARRAY_CONSTRUCTOR(NAME, ELEMENT_SIZE)
function NAMESubArray(begin, end) {
var beginInt = TO_INTEGER(begin);
if (!IS_UNDEFINED(end)) {
......@@ -391,11 +360,8 @@ function TypedArrayConstructor() {
%AddNamedProperty(GlobalTypedArray.prototype, "toString", ArrayToString,
DONT_ENUM);
macro SETUP_TYPED_ARRAY(NAME, ELEMENT_SIZE)
%SetCode(GlobalNAME, NAMEConstructor);
endmacro
TYPED_ARRAYS(SETUP_TYPED_ARRAY)
%InstallToContext([
"typed_array_construct_by_iterable", TypedArrayConstructByIterable
]);
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment