Reviewers: ,
Message:
Basic work on an implementation of Reflect.apply() (x64 only) which shares
code
with FunctionApply.
Establishing this and ReflectConstruct should help simplify the
implementation
of spreadcalls, so I'd love to get these in
Description:
Implement ES6 Reflect.apply()
BUG=v8:3900
R=
LOG=Y
Please review this at https://codereview.chromium.org/913073003/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+78, -5 lines):
M BUILD.gn
M src/bootstrapper.cc
M src/builtins.h
M src/flag-definitions.h
A src/harmony-reflect.js
M src/x64/builtins-x64.cc
M tools/gyp/v8.gyp
Index: BUILD.gn
diff --git a/BUILD.gn b/BUILD.gn
index
2946d5ad21842befa888451940035eb5d9e5584e..a43413ad7fe9845b0bf7ce68e707f6b7858135ad
100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -237,6 +237,7 @@ action("js2c_experimental") {
"src/harmony-tostring.js",
"src/harmony-templates.js",
"src/harmony-regexp.js",
+ "src/harmony-reflect.js"
]
outputs = [
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index
31d6e3e00c2cc355bc8b2caaface11a6989d55bd..daba7fe7a9a924a14049c5aedf9b6d3bfc61bcac
100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -1615,6 +1615,7 @@ EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_unicode)
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_unicode_regexps)
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_computed_property_names)
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_rest_parameters)
+EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_reflect)
void Genesis::InstallNativeFunctions_harmony_proxies() {
@@ -1647,6 +1648,7 @@ EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_unicode)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_computed_property_names)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_rest_parameters)
+EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_reflect)
void Genesis::InitializeGlobal_harmony_regexps() {
Handle<JSObject> builtins(native_context()->builtins());
@@ -2030,6 +2032,26 @@ bool Genesis::InstallNatives() {
*generator_object_prototype_map);
}
+ // Install references to functions of the Reflect object
+ {
+ Handle<JSFunction> apply =
+ InstallFunction(builtins, "ReflectApply", JS_OBJECT_TYPE,
+ JSObject::kHeaderSize, MaybeHandle<JSObject>(),
+ Builtins::kReflectApply);
+ if (FLAG_vector_ics) {
+ // Apply embeds an IC, so we need a type vector of size 1 in the
shared
+ // function info.
+ FeedbackVectorSpec spec(0, 1);
+ spec.SetKind(0, Code::CALL_IC);
+ Handle<TypeFeedbackVector> feedback_vector =
+ factory()->NewTypeFeedbackVector(spec);
+ apply->shared()->set_feedback_vector(*feedback_vector);
+ }
+
+ apply->shared()->set_internal_formal_parameter_count(3);
+ apply->shared()->set_length(3);
+ }
+
if (FLAG_disable_native_files) {
PrintF("Warning: Running without installed natives!\n");
return true;
@@ -2230,6 +2252,8 @@ bool Genesis::InstallExperimentalNatives() {
static const char* harmony_unicode_regexps_natives[] = {NULL};
static const char* harmony_computed_property_names_natives[] = {NULL};
static const char* harmony_rest_parameters_natives[] = {NULL};
+ static const char* harmony_reflect_natives[] = {"native
harmony-reflect.js",
+ NULL};
for (int i = ExperimentalNatives::GetDebuggerCount();
i < ExperimentalNatives::GetBuiltinsCount(); i++) {
@@ -2825,6 +2849,19 @@ Genesis::Genesis(Isolate* isolate,
isolate->counters()->contexts_created_from_scratch()->Increment();
}
+ if (FLAG_harmony_reflect) {
+ // TODO(caitp): this should not be here, there's got to be a better
way.
+ // Shouldn't InitializeExperimentalGlobal() happen before
+ // InitializeExperimentalNatives()?
+ Handle<JSGlobalObject> global(JSGlobalObject::cast(
+ native_context()->global_object()));
+ Handle<String> reflect_string =
+ factory()->NewStringFromStaticChars("Reflect");
+ Handle<Object> reflect =
+ factory()->NewJSObject(isolate->object_function(), TENURED);
+ JSObject::AddProperty(global, reflect_string, reflect, DONT_ENUM);
+ }
+
// Install experimental natives.
if (!InstallExperimentalNatives()) return;
InitializeExperimentalGlobal();
Index: src/builtins.h
diff --git a/src/builtins.h b/src/builtins.h
index
cfbb77d7a3180c5c343adf6830c0343d39a3f4fb..f01d78c565931a4d3c062ece4d4f1f03466987dd
100644
--- a/src/builtins.h
+++ b/src/builtins.h
@@ -109,6 +109,7 @@ enum BuiltinExtraArguments {
/* Uses KeyedLoadIC_Initialize; must be after in list.
*/ \
V(FunctionCall, BUILTIN, UNINITIALIZED,
kNoExtraICState) \
V(FunctionApply, BUILTIN, UNINITIALIZED,
kNoExtraICState) \
+ V(ReflectApply, BUILTIN, UNINITIALIZED,
kNoExtraICState) \
\
V(InternalArrayCode, BUILTIN, UNINITIALIZED,
kNoExtraICState) \
V(ArrayCode, BUILTIN, UNINITIALIZED,
kNoExtraICState) \
@@ -316,6 +317,7 @@ class Builtins {
static void Generate_FunctionCall(MacroAssembler* masm);
static void Generate_FunctionApply(MacroAssembler* masm);
+ static void Generate_ReflectApply(MacroAssembler* masm);
static void Generate_InternalArrayCode(MacroAssembler* masm);
static void Generate_ArrayCode(MacroAssembler* masm);
Index: src/flag-definitions.h
diff --git a/src/flag-definitions.h b/src/flag-definitions.h
index
e43f565c3cff7b1ce0b228c2e605f0061b9a461e..e31b40b6ddb04abb659c9419c746e6133bf1af02
100644
--- a/src/flag-definitions.h
+++ b/src/flag-definitions.h
@@ -193,7 +193,8 @@ DEFINE_IMPLICATION(es_staging, harmony)
V(harmony_unicode, "harmony unicode escapes") \
V(harmony_unicode_regexps, "harmony unicode regexps") \
V(harmony_computed_property_names, "harmony computed property names") \
- V(harmony_rest_parameters, "harmony rest parameters")
+ V(harmony_rest_parameters, "harmony rest parameters") \
+ V(harmony_reflect, "harmony Reflect API")
// Features that are complete (but still behind --harmony/es-staging flag).
#define HARMONY_STAGED(V) \
Index: src/harmony-reflect.js
diff --git a/src/harmony-reflect.js b/src/harmony-reflect.js
new file mode 100644
index
0000000000000000000000000000000000000000..7285e78bf28fea54e543e76d2c33c5223194f910
--- /dev/null
+++ b/src/harmony-reflect.js
@@ -0,0 +1,17 @@
+// Copyright 2013 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+'use strict';
+
+var $Reflect = global.Reflect;
+
+function SetUpReflect() {
+ %CheckIsBootstrapping();
+
+ InstallFunctions($Reflect, DONT_ENUM, $Array(
+ "apply", ReflectApply
+ ));
+}
+
+SetUpReflect();
Index: src/x64/builtins-x64.cc
diff --git a/src/x64/builtins-x64.cc b/src/x64/builtins-x64.cc
index
60a291acf5a27c070349ffcdb3bd532d206911b8..7a2f5791dc7044bc62577b68da36eec6739086b6
100644
--- a/src/x64/builtins-x64.cc
+++ b/src/x64/builtins-x64.cc
@@ -1051,7 +1051,11 @@ void Builtins::Generate_FunctionCall(MacroAssembler*
masm) {
}
-void Builtins::Generate_FunctionApply(MacroAssembler* masm) {
+// Used by FunctionApply and ReflectApply
+static void Generate_ApplyHelper(MacroAssembler* masm, bool
targetIsArgument) {
+ const int kFormalParameters = targetIsArgument ? 3 : 2;
+ const int kStackSize = kFormalParameters + 1;
+
// Stack at entry:
// rsp : return address
// rsp[8] : arguments
@@ -1203,7 +1207,7 @@ void Builtins::Generate_FunctionApply(MacroAssembler*
masm) {
__ InvokeFunction(rdi, actual, CALL_FUNCTION, NullCallWrapper());
frame_scope.GenerateLeaveFrame();
- __ ret(3 * kPointerSize); // remove this, receiver, and arguments
+ __ ret(kStackSize * kPointerSize); // remove this, receiver, and
arguments
// Call the function proxy.
__ bind(&call_proxy);
@@ -1216,7 +1220,17 @@ void
Builtins::Generate_FunctionApply(MacroAssembler* masm) {
// Leave internal frame.
}
- __ ret(3 * kPointerSize); // remove this, receiver, and arguments
+ __ ret(kStackSize * kPointerSize); // remove this, receiver, and
arguments
+}
+
+
+void Builtins::Generate_FunctionApply(MacroAssembler* masm) {
+ Generate_ApplyHelper(masm, false);
+}
+
+
+void Builtins::Generate_ReflectApply(MacroAssembler* masm) {
+ Generate_ApplyHelper(masm, true);
}
Index: tools/gyp/v8.gyp
diff --git a/tools/gyp/v8.gyp b/tools/gyp/v8.gyp
index
7fa63e41e2062724057b9a2dad7542598499c95f..a5644595ca4869851eba391b039e56884527e38a
100644
--- a/tools/gyp/v8.gyp
+++ b/tools/gyp/v8.gyp
@@ -1704,7 +1704,8 @@
'../../src/harmony-tostring.js',
'../../src/harmony-typedarray.js',
'../../src/harmony-templates.js',
- '../../src/harmony-regexp.js'
+ '../../src/harmony-regexp.js',
+ '../../src/harmony-reflect.js'
],
'libraries_bin_file': '<(SHARED_INTERMEDIATE_DIR)/libraries.bin',
'libraries_experimental_bin_file':
'<(SHARED_INTERMEDIATE_DIR)/libraries-experimental.bin',
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.