Commit 66d26a35 authored by Adam Klein's avatar Adam Klein Committed by Commit Bot

[js] Move remaining Array setup code from prologue.js to bootstrapper

Also remove ImportNow() and helper runtime functions and Context methods
that are now unused.

Bug: v8:7624
Change-Id: I109b112d2147240e72eb0ed6112a267057de59cb
Reviewed-on: https://chromium-review.googlesource.com/c/1385224
Commit-Queue: Adam Klein <adamk@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58415}
parent caec42a8
......@@ -579,6 +579,14 @@ V8_NOINLINE void InstallConstant(Isolate* isolate, Handle<JSObject> holder,
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY));
}
V8_NOINLINE void InstallTrueValuedProperty(Isolate* isolate,
Handle<JSObject> holder,
const char* name) {
JSObject::AddProperty(isolate, holder,
isolate->factory()->InternalizeUtf8String(name),
isolate->factory()->true_value(), NONE);
}
V8_NOINLINE void InstallSpeciesGetter(Isolate* isolate,
Handle<JSFunction> constructor) {
Factory* factory = isolate->factory();
......@@ -1722,20 +1730,29 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
1, false);
SimpleInstallFunction(isolate_, proto, "join",
Builtins::kArrayPrototypeJoin, 1, false);
InstallFunctionWithBuiltinId(isolate_, proto, "keys",
Builtins::kArrayPrototypeKeys, 0, true,
BuiltinFunctionId::kArrayKeys);
InstallFunctionWithBuiltinId(isolate_, proto, "entries",
Builtins::kArrayPrototypeEntries, 0, true,
BuiltinFunctionId::kArrayEntries);
Handle<JSFunction> values_iterator = InstallFunctionWithBuiltinId(
isolate_, proto, "values", Builtins::kArrayPrototypeValues, 0, true,
BuiltinFunctionId::kArrayValues);
JSObject::AddProperty(isolate_, proto, factory->iterator_symbol(),
values_iterator, DONT_ENUM);
SimpleInstallFunction(isolate_, proto, "forEach", Builtins::kArrayForEach,
1, false);
{ // Set up iterator-related properties.
Handle<JSFunction> keys = InstallFunctionWithBuiltinId(
isolate_, proto, "keys", Builtins::kArrayPrototypeKeys, 0, true,
BuiltinFunctionId::kArrayKeys);
native_context()->set_array_keys_iterator(*keys);
Handle<JSFunction> entries = InstallFunctionWithBuiltinId(
isolate_, proto, "entries", Builtins::kArrayPrototypeEntries, 0, true,
BuiltinFunctionId::kArrayEntries);
native_context()->set_array_entries_iterator(*entries);
Handle<JSFunction> values = InstallFunctionWithBuiltinId(
isolate_, proto, "values", Builtins::kArrayPrototypeValues, 0, true,
BuiltinFunctionId::kArrayValues);
JSObject::AddProperty(isolate_, proto, factory->iterator_symbol(), values,
DONT_ENUM);
native_context()->set_array_values_iterator(*values);
}
Handle<JSFunction> for_each_fun = SimpleInstallFunction(
isolate_, proto, "forEach", Builtins::kArrayForEach, 1, false);
native_context()->set_array_for_each_iterator(*for_each_fun);
SimpleInstallFunction(isolate_, proto, "filter", Builtins::kArrayFilter, 1,
false);
SimpleInstallFunction(isolate_, proto, "map", Builtins::kArrayMap, 1,
......@@ -1754,6 +1771,20 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
SimpleInstallFunction(isolate_, proto, "toString",
Builtins::kArrayPrototypeToString, 0, false);
Handle<JSObject> unscopables = factory->NewJSObjectWithNullProto();
InstallTrueValuedProperty(isolate_, unscopables, "copyWithin");
InstallTrueValuedProperty(isolate_, unscopables, "entries");
InstallTrueValuedProperty(isolate_, unscopables, "fill");
InstallTrueValuedProperty(isolate_, unscopables, "find");
InstallTrueValuedProperty(isolate_, unscopables, "findIndex");
InstallTrueValuedProperty(isolate_, unscopables, "includes");
InstallTrueValuedProperty(isolate_, unscopables, "keys");
InstallTrueValuedProperty(isolate_, unscopables, "values");
JSObject::MigrateSlowToFast(unscopables, 0, "Bootstrapping");
JSObject::AddProperty(
isolate_, proto, factory->unscopables_symbol(), unscopables,
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
Handle<Map> map(proto->map(), isolate_);
Map::SetShouldBeFastPrototypeMap(map, true, isolate_);
}
......
......@@ -447,12 +447,6 @@ Handle<Object> Context::ErrorMessageForCodeGenerationFromStrings() {
#define COMPARE_NAME(index, type, name) \
if (string->IsOneByteEqualTo(STATIC_CHAR_VECTOR(#name))) return index;
int Context::ImportedFieldIndexForName(Handle<String> string) {
NATIVE_CONTEXT_IMPORTED_FIELDS(COMPARE_NAME)
return kNotFound;
}
int Context::IntrinsicIndexForName(Handle<String> string) {
NATIVE_CONTEXT_INTRINSIC_FUNCTIONS(COMPARE_NAME);
return kNotFound;
......
......@@ -69,6 +69,8 @@ enum ContextLookupFlags {
V(IS_PROMISE_INDEX, JSFunction, is_promise) \
V(PROMISE_THEN_INDEX, JSFunction, promise_then)
// TODO(adamk): This can be merged into NATIVE_CONTEXT_FIELDS; ideally we
// should prune unused fields as part of that merge.
#define NATIVE_CONTEXT_IMPORTED_FIELDS(V) \
V(ARRAY_ENTRIES_ITERATOR_INDEX, JSFunction, array_entries_iterator) \
V(ARRAY_FOR_EACH_ITERATOR_INDEX, JSFunction, array_for_each_iterator) \
......@@ -609,7 +611,6 @@ class Context : public HeapObject {
Handle<Object> ErrorMessageForCodeGenerationFromStrings();
static int ImportedFieldIndexForName(Handle<String> name);
static int IntrinsicIndexForName(Handle<String> name);
static int IntrinsicIndexForName(const unsigned char* name, int length);
......
......@@ -22,70 +22,19 @@ function Export(f) {
// Import from other scripts. The actual importing happens in PostNatives so
// that we can import from scripts executed later. However, that means that
// the import is not available until the very end. If the import needs to be
// available immediately, use ImportNow.
// the import is not available until the very end.
function Import(f) {
f.next = imports;
imports = f;
}
// Import immediately from exports of previous scripts. We need this for
// functions called during bootstrapping. Hooking up imports in PostNatives
// would be too late.
function ImportNow(name) {
return exports_container[name];
}
var GlobalArray = global.Array;
// -----------------------------------------------------------------------
// To be called by bootstrapper
function PostNatives(utils) {
%CheckIsBootstrapping();
// -------------------------------------------------------------------
// Array
var iteratorSymbol = ImportNow("iterator_symbol");
var unscopablesSymbol = ImportNow("unscopables_symbol");
// Set up unscopable properties on the Array.prototype object.
var unscopables = {
__proto__: null,
copyWithin: true,
entries: true,
fill: true,
find: true,
findIndex: true,
includes: true,
keys: true,
values: true,
};
%ToFastProperties(unscopables);
%AddNamedProperty(GlobalArray.prototype, unscopablesSymbol, unscopables,
DONT_ENUM | READ_ONLY);
// Array prototype functions that return iterators. They are exposed to the
// public API via Template::SetIntrinsicDataProperty().
var ArrayEntries = GlobalArray.prototype.entries;
var ArrayForEach = GlobalArray.prototype.forEach;
var ArrayKeys = GlobalArray.prototype.keys;
var ArrayValues = GlobalArray.prototype[iteratorSymbol];
%InstallToContext([
"array_entries_iterator", ArrayEntries,
"array_for_each_iterator", ArrayForEach,
"array_keys_iterator", ArrayKeys,
"array_values_iterator", ArrayValues,
]);
// -------------------------------------------------------------------
for ( ; !IS_UNDEFINED(imports); imports = imports.next) {
imports(exports_container);
}
......@@ -93,7 +42,6 @@ function PostNatives(utils) {
exports_container = UNDEFINED;
utils.Export = UNDEFINED;
utils.Import = UNDEFINED;
utils.ImportNow = UNDEFINED;
utils.PostNatives = UNDEFINED;
}
......@@ -102,7 +50,6 @@ function PostNatives(utils) {
%OptimizeObjectForAddingMultipleProperties(utils, 14);
utils.Import = Import;
utils.ImportNow = ImportNow;
utils.Export = Export;
utils.PostNatives = PostNatives;
......
......@@ -44,30 +44,6 @@ RUNTIME_FUNCTION(Runtime_ExportFromRuntime) {
return *container;
}
RUNTIME_FUNCTION(Runtime_InstallToContext) {
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0);
CHECK(array->HasFastElements());
CHECK(isolate->bootstrapper()->IsActive());
Handle<Context> native_context = isolate->native_context();
Handle<FixedArray> fixed_array(FixedArray::cast(array->elements()), isolate);
int length = Smi::ToInt(array->length());
for (int i = 0; i < length; i += 2) {
CHECK(fixed_array->get(i)->IsString());
Handle<String> name(String::cast(fixed_array->get(i)), isolate);
CHECK(fixed_array->get(i + 1)->IsJSObject());
Handle<JSObject> object(JSObject::cast(fixed_array->get(i + 1)), isolate);
int index = Context::ImportedFieldIndexForName(name);
if (index == Context::kNotFound) {
index = Context::IntrinsicIndexForName(name);
}
CHECK_NE(index, Context::kNotFound);
native_context->set(index, *object);
}
return ReadOnlyRoots(isolate).undefined_value();
}
RUNTIME_FUNCTION(Runtime_Throw) {
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());
......
......@@ -219,7 +219,6 @@ namespace internal {
F(ExportFromRuntime, 1, 1) \
F(GetAndResetRuntimeCallStats, -1 /* <= 2 */, 1) \
F(IncrementUseCounter, 1, 1) \
F(InstallToContext, 1, 1) \
F(Interrupt, 0, 1) \
F(NewReferenceError, 2, 1) \
F(NewSyntaxError, 2, 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