Commit eb735f3d authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[runtime] Cleanup native methods creation in js/typedarray.js.

This CL replaces usages of utils.InstallFunctions and utils.InstallGetter()
with the DEFINE_METHOD* macros that ensure that the native function is
created in proper form from the beginning. Thus the function will not
require further reconfiguring like adding a computed name or removing of
'prototype' property.

This CL is one of a series of cleanup CL which are the preliminary steps for
improving function closures creation.

Bug: v8:6459
Change-Id: I8432be211adf104cacb74ba2431364bfd6614d18
Reviewed-on: https://chromium-review.googlesource.com/548177
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46297}
parent 80e223aa
...@@ -233,7 +233,9 @@ endmacro ...@@ -233,7 +233,9 @@ endmacro
TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR)
function TypedArraySubArray(begin, end) { DEFINE_METHOD(
GlobalTypedArray.prototype,
subarray(begin, end) {
switch (%_ClassOf(this)) { switch (%_ClassOf(this)) {
macro TYPED_ARRAY_SUBARRAY_CASE(NAME, ELEMENT_SIZE) macro TYPED_ARRAY_SUBARRAY_CASE(NAME, ELEMENT_SIZE)
case "NAME": case "NAME":
...@@ -243,8 +245,9 @@ TYPED_ARRAYS(TYPED_ARRAY_SUBARRAY_CASE) ...@@ -243,8 +245,9 @@ TYPED_ARRAYS(TYPED_ARRAY_SUBARRAY_CASE)
} }
throw %make_type_error(kIncompatibleMethodReceiver, throw %make_type_error(kIncompatibleMethodReceiver,
"get %TypedArray%.prototype.subarray", this); "get %TypedArray%.prototype.subarray", this);
} }
%SetForceInlineFlag(TypedArraySubArray); );
%SetForceInlineFlag(GlobalTypedArray.prototype.subarray);
...@@ -314,7 +317,9 @@ function TypedArraySetFromOverlappingTypedArray(target, source, offset) { ...@@ -314,7 +317,9 @@ function TypedArraySetFromOverlappingTypedArray(target, source, offset) {
} }
} }
function TypedArraySet(obj, offset) { DEFINE_METHOD_LEN(
GlobalTypedArray.prototype,
set(obj, offset) {
var intOffset = IS_UNDEFINED(offset) ? 0 : TO_INTEGER(offset); var intOffset = IS_UNDEFINED(offset) ? 0 : TO_INTEGER(offset);
if (intOffset < 0) throw %make_type_error(kTypedArraySetNegativeOffset); if (intOffset < 0) throw %make_type_error(kTypedArraySetNegativeOffset);
...@@ -356,15 +361,20 @@ function TypedArraySet(obj, offset) { ...@@ -356,15 +361,20 @@ function TypedArraySet(obj, offset) {
TypedArraySetFromArrayLike(this, obj, l, intOffset); TypedArraySetFromArrayLike(this, obj, l, intOffset);
return; return;
} }
} },
%FunctionSetLength(TypedArraySet, 1); 1 /* Set function length. */
);
function TypedArrayGetToStringTag() {
DEFINE_METHOD(
GlobalTypedArray.prototype,
get [toStringTagSymbol]() {
if (!IS_TYPEDARRAY(this)) return; if (!IS_TYPEDARRAY(this)) return;
var name = %_ClassOf(this); var name = %_ClassOf(this);
if (IS_UNDEFINED(name)) return; if (IS_UNDEFINED(name)) return;
return name; return name;
} }
);
// The following functions cannot be made efficient on sparse arrays while // The following functions cannot be made efficient on sparse arrays while
// preserving the semantics, since the calls to the receiver function can add // preserving the semantics, since the calls to the receiver function can add
...@@ -385,7 +395,9 @@ function InnerTypedArrayFilter(f, receiver, array, length, result) { ...@@ -385,7 +395,9 @@ function InnerTypedArrayFilter(f, receiver, array, length, result) {
// ES6 draft 07-15-13, section 22.2.3.9 // ES6 draft 07-15-13, section 22.2.3.9
function TypedArrayFilter(f, thisArg) { DEFINE_METHOD_LEN(
GlobalTypedArray.prototype,
filter(f, thisArg) {
ValidateTypedArray(this, "%TypeArray%.prototype.filter"); ValidateTypedArray(this, "%TypeArray%.prototype.filter");
var length = %_TypedArrayGetLength(this); var length = %_TypedArrayGetLength(this);
...@@ -398,34 +410,43 @@ function TypedArrayFilter(f, thisArg) { ...@@ -398,34 +410,43 @@ function TypedArrayFilter(f, thisArg) {
output[i] = result[i]; output[i] = result[i];
} }
return output; return output;
} },
%FunctionSetLength(TypedArrayFilter, 1); 1 /* Set function length. */
);
// ES6 draft 07-15-13, section 22.2.3.10 // ES6 draft 07-15-13, section 22.2.3.10
function TypedArrayFind(predicate, thisArg) { DEFINE_METHOD_LEN(
GlobalTypedArray.prototype,
find(predicate, thisArg) {
ValidateTypedArray(this, "%TypedArray%.prototype.find"); ValidateTypedArray(this, "%TypedArray%.prototype.find");
var length = %_TypedArrayGetLength(this); var length = %_TypedArrayGetLength(this);
return InnerArrayFind(predicate, thisArg, this, length); return InnerArrayFind(predicate, thisArg, this, length);
} },
%FunctionSetLength(TypedArrayFind, 1); 1 /* Set function length. */
);
// ES6 draft 07-15-13, section 22.2.3.11 // ES6 draft 07-15-13, section 22.2.3.11
function TypedArrayFindIndex(predicate, thisArg) { DEFINE_METHOD_LEN(
GlobalTypedArray.prototype,
findIndex(predicate, thisArg) {
ValidateTypedArray(this, "%TypedArray%.prototype.findIndex"); ValidateTypedArray(this, "%TypedArray%.prototype.findIndex");
var length = %_TypedArrayGetLength(this); var length = %_TypedArrayGetLength(this);
return InnerArrayFindIndex(predicate, thisArg, this, length); return InnerArrayFindIndex(predicate, thisArg, this, length);
} },
%FunctionSetLength(TypedArrayFindIndex, 1); 1 /* Set function length. */
);
// ES6 draft 05-18-15, section 22.2.3.25 // ES6 draft 05-18-15, section 22.2.3.25
function TypedArraySort(comparefn) { DEFINE_METHOD(
GlobalTypedArray.prototype,
sort(comparefn) {
ValidateTypedArray(this, "%TypedArray%.prototype.sort"); ValidateTypedArray(this, "%TypedArray%.prototype.sort");
var length = %_TypedArrayGetLength(this); var length = %_TypedArrayGetLength(this);
...@@ -435,38 +456,48 @@ function TypedArraySort(comparefn) { ...@@ -435,38 +456,48 @@ function TypedArraySort(comparefn) {
} }
return InnerArraySort(this, length, comparefn); return InnerArraySort(this, length, comparefn);
} }
);
// ES6 section 22.2.3.27 // ES6 section 22.2.3.27
function TypedArrayToLocaleString() { DEFINE_METHOD(
GlobalTypedArray.prototype,
toLocaleString() {
ValidateTypedArray(this, "%TypedArray%.prototype.toLocaleString"); ValidateTypedArray(this, "%TypedArray%.prototype.toLocaleString");
var length = %_TypedArrayGetLength(this); var length = %_TypedArrayGetLength(this);
return InnerArrayToLocaleString(this, length); return InnerArrayToLocaleString(this, length);
} }
);
// ES6 section 22.2.3.14 // ES6 section 22.2.3.14
function TypedArrayJoin(separator) { DEFINE_METHOD(
GlobalTypedArray.prototype,
join(separator) {
ValidateTypedArray(this, "%TypedArray%.prototype.join"); ValidateTypedArray(this, "%TypedArray%.prototype.join");
var length = %_TypedArrayGetLength(this); var length = %_TypedArrayGetLength(this);
return InnerArrayJoin(separator, this, length); return InnerArrayJoin(separator, this, length);
} }
);
// ES6 draft 08-24-14, section 22.2.2.2 // ES6 draft 08-24-14, section 22.2.2.2
function TypedArrayOf() { DEFINE_METHOD(
GlobalTypedArray,
of() {
var length = arguments.length; var length = arguments.length;
var array = TypedArrayCreate(this, length); var array = TypedArrayCreate(this, length);
for (var i = 0; i < length; i++) { for (var i = 0; i < length; i++) {
array[i] = arguments[i]; array[i] = arguments[i];
} }
return array; return array;
} }
);
// ES#sec-iterabletoarraylike Runtime Semantics: IterableToArrayLike( items ) // ES#sec-iterabletoarraylike Runtime Semantics: IterableToArrayLike( items )
...@@ -490,7 +521,9 @@ function IterableToArrayLike(items) { ...@@ -490,7 +521,9 @@ function IterableToArrayLike(items) {
// ES#sec-%typedarray%.from // ES#sec-%typedarray%.from
// %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) // %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
function TypedArrayFrom(source, mapfn, thisArg) { DEFINE_METHOD_LEN(
GlobalTypedArray,
'from'(source, mapfn, thisArg) {
if (!%IsConstructor(this)) throw %make_type_error(kNotConstructor, this); if (!%IsConstructor(this)) throw %make_type_error(kNotConstructor, this);
var mapping; var mapping;
if (!IS_UNDEFINED(mapfn)) { if (!IS_UNDEFINED(mapfn)) {
...@@ -513,8 +546,9 @@ function TypedArrayFrom(source, mapfn, thisArg) { ...@@ -513,8 +546,9 @@ function TypedArrayFrom(source, mapfn, thisArg) {
targetObject[i] = mappedValue; targetObject[i] = mappedValue;
} }
return targetObject; return targetObject;
} },
%FunctionSetLength(TypedArrayFrom, 1); 1 /* Set function length. */
);
// TODO(bmeurer): Migrate this to a proper builtin. // TODO(bmeurer): Migrate this to a proper builtin.
function TypedArrayConstructor() { function TypedArrayConstructor() {
...@@ -524,22 +558,7 @@ function TypedArrayConstructor() { ...@@ -524,22 +558,7 @@ function TypedArrayConstructor() {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
%SetCode(GlobalTypedArray, TypedArrayConstructor); %SetCode(GlobalTypedArray, TypedArrayConstructor);
utils.InstallFunctions(GlobalTypedArray, DONT_ENUM, [
"from", TypedArrayFrom,
"of", TypedArrayOf
]);
utils.InstallGetter(GlobalTypedArray.prototype, toStringTagSymbol,
TypedArrayGetToStringTag);
utils.InstallFunctions(GlobalTypedArray.prototype, DONT_ENUM, [
"subarray", TypedArraySubArray,
"set", TypedArraySet,
"filter", TypedArrayFilter,
"find", TypedArrayFind,
"findIndex", TypedArrayFindIndex,
"join", TypedArrayJoin,
"sort", TypedArraySort,
"toLocaleString", TypedArrayToLocaleString
]);
%AddNamedProperty(GlobalTypedArray.prototype, "toString", ArrayToString, %AddNamedProperty(GlobalTypedArray.prototype, "toString", ArrayToString,
DONT_ENUM); DONT_ENUM);
......
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