Commit 08ee2132 authored by yangguo's avatar yangguo Committed by Commit bot

Native context: install array methods via runtime import.

R=cbruni@chromium.org

Review URL: https://codereview.chromium.org/1324483002

Cr-Commit-Position: refs/heads/master@{#30446}
parent d80e062c
......@@ -11,6 +11,13 @@
// -------------------------------------------------------------------
// Imports
var ArrayConcatBuiltin = utils.ImportNow("array_concat");
var ArrayPopBuiltin = utils.ImportNow("array_pop");
var ArrayPushBuiltin = utils.ImportNow("array_push");
var ArrayShiftBuiltin = utils.ImportNow("array_shift");
var ArraySliceBuiltin = utils.ImportNow("array_slice");
var ArraySpliceBuiltin = utils.ImportNow("array_splice");
var ArrayUnshiftBuiltin = utils.ImportNow("array_unshift");
var Delete;
var GlobalArray = global.Array;
var InternalArray = utils.InternalArray;
......@@ -525,7 +532,7 @@ function ArrayPush() {
// Returns an array containing the array elements of the object followed
// by the array elements of each argument in order. See ECMA-262,
// section 15.4.4.7.
function ArrayConcatJS(arg1) { // length == 1
function ArrayConcat(arg1) { // length == 1
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.concat");
var array = TO_OBJECT(this);
......@@ -1619,45 +1626,43 @@ utils.InstallFunctions(GlobalArray, DONT_ENUM, [
"isArray", ArrayIsArray
]);
var specialFunctions = %SpecialArrayFunctions();
var getFunction = function(name, jsBuiltin, len) {
var f = jsBuiltin;
if (specialFunctions.hasOwnProperty(name)) {
f = specialFunctions[name];
}
if (!IS_UNDEFINED(len)) {
%FunctionSetLength(f, len);
}
return f;
};
%FunctionSetLength(ArrayEvery, 1);
%FunctionSetLength(ArrayFilter, 1);
%FunctionSetLength(ArrayForEach, 1);
%FunctionSetLength(ArrayIndexOf, 1);
%FunctionSetLength(ArrayLastIndexOf, 1);
%FunctionSetLength(ArrayMap, 1);
%FunctionSetLength(ArrayReduce, 1);
%FunctionSetLength(ArrayReduceRight, 1);
%FunctionSetLength(ArraySome, 1);
// Set up non-enumerable functions of the Array.prototype object and
// set their names.
// Manipulate the length of some of the functions to meet
// expectations set by ECMA-262 or Mozilla.
utils.InstallFunctions(GlobalArray.prototype, DONT_ENUM, [
"toString", getFunction("toString", ArrayToString),
"toLocaleString", getFunction("toLocaleString", ArrayToLocaleString),
"join", getFunction("join", ArrayJoin),
"pop", getFunction("pop", ArrayPop),
"push", getFunction("push", ArrayPush, 1),
"concat", getFunction("concat", ArrayConcatJS, 1),
"reverse", getFunction("reverse", ArrayReverse),
"shift", getFunction("shift", ArrayShift),
"unshift", getFunction("unshift", ArrayUnshift, 1),
"slice", getFunction("slice", ArraySlice, 2),
"splice", getFunction("splice", ArraySplice, 2),
"sort", getFunction("sort", ArraySort),
"filter", getFunction("filter", ArrayFilter, 1),
"forEach", getFunction("forEach", ArrayForEach, 1),
"some", getFunction("some", ArraySome, 1),
"every", getFunction("every", ArrayEvery, 1),
"map", getFunction("map", ArrayMap, 1),
"indexOf", getFunction("indexOf", ArrayIndexOf, 1),
"lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1),
"reduce", getFunction("reduce", ArrayReduce, 1),
"reduceRight", getFunction("reduceRight", ArrayReduceRight, 1)
"concat", ArrayConcatBuiltin,
"every", ArrayEvery,
"filter", ArrayFilter,
"forEach", ArrayForEach,
"indexOf", ArrayIndexOf,
"join", ArrayJoin,
"lastIndexOf", ArrayLastIndexOf,
"map", ArrayMap,
"pop", ArrayPopBuiltin,
"push", ArrayPushBuiltin,
"reduce", ArrayReduce,
"reduceRight", ArrayReduceRight,
"reverse", ArrayReverse,
"shift", ArrayShiftBuiltin,
"slice", ArraySliceBuiltin,
"some", ArraySome,
"sort", ArraySort,
"splice", ArraySpliceBuiltin,
"toLocaleString", ArrayToLocaleString,
"toString", ArrayToString,
"unshift", ArrayUnshiftBuiltin,
]);
%FinishArrayPrototypeSetup(GlobalArray.prototype);
......@@ -1666,20 +1671,20 @@ utils.InstallFunctions(GlobalArray.prototype, DONT_ENUM, [
// exposed to user code.
// Adding only the functions that are actually used.
utils.SetUpLockedPrototype(InternalArray, GlobalArray(), [
"concat", getFunction("concat", ArrayConcatJS),
"indexOf", getFunction("indexOf", ArrayIndexOf),
"join", getFunction("join", ArrayJoin),
"pop", getFunction("pop", ArrayPop),
"push", getFunction("push", ArrayPush),
"shift", getFunction("shift", ArrayShift),
"splice", getFunction("splice", ArraySplice)
"concat", ArrayConcatBuiltin,
"indexOf", ArrayIndexOf,
"join", ArrayJoin,
"pop", ArrayPopBuiltin,
"push", ArrayPushBuiltin,
"shift", ArrayShiftBuiltin,
"splice", ArraySpliceBuiltin,
]);
utils.SetUpLockedPrototype(InternalPackedArray, GlobalArray(), [
"join", getFunction("join", ArrayJoin),
"pop", getFunction("pop", ArrayPop),
"push", getFunction("push", ArrayPush),
"shift", getFunction("shift", ArrayShift)
"join", ArrayJoin,
"pop", ArrayPopBuiltin,
"push", ArrayPushBuiltin,
"shift", ArrayShiftBuiltin,
]);
// -------------------------------------------------------------------
......@@ -1706,7 +1711,7 @@ utils.Export(function(to) {
});
%InstallToContext([
"array_concat", ArrayConcatJS,
"array_concat", ArrayConcat,
"array_pop", ArrayPop,
"array_push", ArrayPush,
"array_shift", ArrayShift,
......
This diff is collapsed.
......@@ -28,35 +28,6 @@ RUNTIME_FUNCTION(Runtime_FinishArrayPrototypeSetup) {
}
static void InstallBuiltin(Isolate* isolate, Handle<JSObject> holder,
const char* name, Builtins::Name builtin_name) {
Handle<String> key = isolate->factory()->InternalizeUtf8String(name);
Handle<Code> code(isolate->builtins()->builtin(builtin_name));
Handle<JSFunction> optimized =
isolate->factory()->NewFunctionWithoutPrototype(key, code);
optimized->shared()->DontAdaptArguments();
JSObject::AddProperty(holder, key, optimized, NONE);
}
RUNTIME_FUNCTION(Runtime_SpecialArrayFunctions) {
HandleScope scope(isolate);
DCHECK(args.length() == 0);
Handle<JSObject> holder =
isolate->factory()->NewJSObject(isolate->object_function());
InstallBuiltin(isolate, holder, "pop", Builtins::kArrayPop);
InstallBuiltin(isolate, holder, "push", Builtins::kArrayPush);
InstallBuiltin(isolate, holder, "shift", Builtins::kArrayShift);
InstallBuiltin(isolate, holder, "unshift", Builtins::kArrayUnshift);
InstallBuiltin(isolate, holder, "slice", Builtins::kArraySlice);
InstallBuiltin(isolate, holder, "splice", Builtins::kArraySplice);
InstallBuiltin(isolate, holder, "concat", Builtins::kArrayConcat);
return *holder;
}
RUNTIME_FUNCTION(Runtime_FixedArrayGet) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 2);
......
......@@ -32,7 +32,6 @@ namespace internal {
#define FOR_EACH_INTRINSIC_ARRAY(F) \
F(FinishArrayPrototypeSetup, 1, 1) \
F(SpecialArrayFunctions, 0, 1) \
F(TransitionElementsKind, 2, 1) \
F(PushIfAbsent, 2, 1) \
F(ArrayConcat, 1, 1) \
......
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