2014-03-31 12:01:02 +00:00
|
|
|
// Copyright 2014 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.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/bootstrapper.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/accessors.h"
|
2018-07-23 11:42:37 +00:00
|
|
|
#include "src/api-inl.h"
|
2015-02-04 13:01:34 +00:00
|
|
|
#include "src/api-natives.h"
|
2016-06-21 07:01:59 +00:00
|
|
|
#include "src/base/ieee754.h"
|
2014-06-20 08:40:11 +00:00
|
|
|
#include "src/code-stubs.h"
|
2016-08-23 12:35:20 +00:00
|
|
|
#include "src/compiler.h"
|
2017-02-23 11:46:29 +00:00
|
|
|
#include "src/debug/debug.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/extensions/externalize-string-extension.h"
|
|
|
|
#include "src/extensions/free-buffer-extension.h"
|
|
|
|
#include "src/extensions/gc-extension.h"
|
2016-04-27 11:10:41 +00:00
|
|
|
#include "src/extensions/ignition-statistics-extension.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/extensions/statistics-extension.h"
|
|
|
|
#include "src/extensions/trigger-failure-extension.h"
|
2015-08-21 06:44:17 +00:00
|
|
|
#include "src/heap/heap.h"
|
2015-09-01 09:25:19 +00:00
|
|
|
#include "src/isolate-inl.h"
|
2018-04-30 13:27:37 +00:00
|
|
|
#include "src/objects/api-callbacks.h"
|
2018-05-23 13:29:02 +00:00
|
|
|
#include "src/objects/arguments.h"
|
2018-07-10 12:52:05 +00:00
|
|
|
#include "src/objects/hash-table-inl.h"
|
2018-05-15 20:50:46 +00:00
|
|
|
#ifdef V8_INTL_SUPPORT
|
|
|
|
#include "src/objects/intl-objects.h"
|
2018-07-24 21:07:50 +00:00
|
|
|
#include "src/objects/js-list-format.h"
|
2018-05-15 20:50:46 +00:00
|
|
|
#include "src/objects/js-locale.h"
|
|
|
|
#endif // V8_INTL_SUPPORT
|
2018-07-25 14:11:56 +00:00
|
|
|
#include "src/objects/js-array-inl.h"
|
2018-05-23 13:29:02 +00:00
|
|
|
#include "src/objects/js-regexp-string-iterator.h"
|
2017-10-13 15:06:23 +00:00
|
|
|
#include "src/objects/js-regexp.h"
|
2018-07-10 12:52:05 +00:00
|
|
|
#ifdef V8_INTL_SUPPORT
|
|
|
|
#include "src/objects/js-relative-time-format.h"
|
|
|
|
#endif // V8_INTL_SUPPORT
|
2018-04-27 08:31:07 +00:00
|
|
|
#include "src/objects/templates.h"
|
2015-03-27 15:28:55 +00:00
|
|
|
#include "src/snapshot/natives.h"
|
|
|
|
#include "src/snapshot/snapshot.h"
|
2015-08-27 14:42:36 +00:00
|
|
|
#include "src/wasm/wasm-js.h"
|
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2017-09-13 10:56:20 +00:00
|
|
|
void SourceCodeCache::Initialize(Isolate* isolate, bool create_heap_objects) {
|
2018-07-04 09:10:05 +00:00
|
|
|
cache_ = create_heap_objects ? ReadOnlyRoots(isolate).empty_fixed_array()
|
|
|
|
: nullptr;
|
2017-09-13 10:56:20 +00:00
|
|
|
}
|
|
|
|
|
2018-06-20 10:10:43 +00:00
|
|
|
bool SourceCodeCache::Lookup(Isolate* isolate, Vector<const char> name,
|
2017-09-13 10:56:20 +00:00
|
|
|
Handle<SharedFunctionInfo>* handle) {
|
|
|
|
for (int i = 0; i < cache_->length(); i += 2) {
|
|
|
|
SeqOneByteString* str = SeqOneByteString::cast(cache_->get(i));
|
|
|
|
if (str->IsUtf8EqualTo(name)) {
|
|
|
|
*handle = Handle<SharedFunctionInfo>(
|
2018-06-20 10:10:43 +00:00
|
|
|
SharedFunctionInfo::cast(cache_->get(i + 1)), isolate);
|
2017-09-13 10:56:20 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
void SourceCodeCache::Add(Isolate* isolate, Vector<const char> name,
|
2017-09-13 10:56:20 +00:00
|
|
|
Handle<SharedFunctionInfo> shared) {
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
int length = cache_->length();
|
|
|
|
Handle<FixedArray> new_array = factory->NewFixedArray(length + 2, TENURED);
|
|
|
|
cache_->CopyTo(0, *new_array, 0, cache_->length());
|
|
|
|
cache_ = *new_array;
|
|
|
|
Handle<String> str =
|
|
|
|
factory->NewStringFromOneByte(Vector<const uint8_t>::cast(name), TENURED)
|
|
|
|
.ToHandleChecked();
|
|
|
|
DCHECK(!str.is_null());
|
|
|
|
cache_->set(length, *str);
|
|
|
|
cache_->set(length + 1, *shared);
|
|
|
|
Script::cast(shared->script())->set_type(type_);
|
|
|
|
}
|
|
|
|
|
2013-02-15 09:27:10 +00:00
|
|
|
Bootstrapper::Bootstrapper(Isolate* isolate)
|
|
|
|
: isolate_(isolate),
|
|
|
|
nesting_(0),
|
2015-02-09 09:04:45 +00:00
|
|
|
extensions_cache_(Script::TYPE_EXTENSION) {}
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2017-04-11 05:46:46 +00:00
|
|
|
Handle<String> Bootstrapper::GetNativeSource(NativeType type, int index) {
|
|
|
|
NativesExternalStringResource* resource =
|
|
|
|
new NativesExternalStringResource(type, index);
|
|
|
|
Handle<ExternalOneByteString> source_code =
|
|
|
|
isolate_->factory()->NewNativeSourceString(resource);
|
|
|
|
DCHECK(source_code->is_short());
|
|
|
|
return source_code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Bootstrapper::Initialize(bool create_heap_objects) {
|
2013-09-11 08:39:38 +00:00
|
|
|
extensions_cache_.Initialize(isolate_, create_heap_objects);
|
2013-05-21 12:03:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-17 10:52:00 +00:00
|
|
|
static const char* GCFunctionName() {
|
2017-10-13 16:33:03 +00:00
|
|
|
bool flag_given =
|
|
|
|
FLAG_expose_gc_as != nullptr && strlen(FLAG_expose_gc_as) != 0;
|
2014-01-17 10:52:00 +00:00
|
|
|
return flag_given ? FLAG_expose_gc_as : "gc";
|
|
|
|
}
|
|
|
|
|
2017-10-13 16:33:03 +00:00
|
|
|
v8::Extension* Bootstrapper::free_buffer_extension_ = nullptr;
|
|
|
|
v8::Extension* Bootstrapper::gc_extension_ = nullptr;
|
|
|
|
v8::Extension* Bootstrapper::externalize_string_extension_ = nullptr;
|
|
|
|
v8::Extension* Bootstrapper::statistics_extension_ = nullptr;
|
|
|
|
v8::Extension* Bootstrapper::trigger_failure_extension_ = nullptr;
|
|
|
|
v8::Extension* Bootstrapper::ignition_statistics_extension_ = nullptr;
|
2014-01-17 10:52:00 +00:00
|
|
|
|
2013-05-21 12:03:49 +00:00
|
|
|
void Bootstrapper::InitializeOncePerProcess() {
|
2014-01-17 10:52:00 +00:00
|
|
|
free_buffer_extension_ = new FreeBufferExtension;
|
|
|
|
v8::RegisterExtension(free_buffer_extension_);
|
|
|
|
gc_extension_ = new GCExtension(GCFunctionName());
|
|
|
|
v8::RegisterExtension(gc_extension_);
|
|
|
|
externalize_string_extension_ = new ExternalizeStringExtension;
|
|
|
|
v8::RegisterExtension(externalize_string_extension_);
|
|
|
|
statistics_extension_ = new StatisticsExtension;
|
|
|
|
v8::RegisterExtension(statistics_extension_);
|
|
|
|
trigger_failure_extension_ = new TriggerFailureExtension;
|
|
|
|
v8::RegisterExtension(trigger_failure_extension_);
|
2016-04-27 11:10:41 +00:00
|
|
|
ignition_statistics_extension_ = new IgnitionStatisticsExtension;
|
|
|
|
v8::RegisterExtension(ignition_statistics_extension_);
|
2014-01-17 10:52:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Bootstrapper::TearDownExtensions() {
|
|
|
|
delete free_buffer_extension_;
|
2017-10-13 16:33:03 +00:00
|
|
|
free_buffer_extension_ = nullptr;
|
2014-01-17 10:52:00 +00:00
|
|
|
delete gc_extension_;
|
2017-10-13 16:33:03 +00:00
|
|
|
gc_extension_ = nullptr;
|
2014-01-17 10:52:00 +00:00
|
|
|
delete externalize_string_extension_;
|
2017-10-13 16:33:03 +00:00
|
|
|
externalize_string_extension_ = nullptr;
|
2014-01-17 10:52:00 +00:00
|
|
|
delete statistics_extension_;
|
2017-10-13 16:33:03 +00:00
|
|
|
statistics_extension_ = nullptr;
|
2014-01-17 10:52:00 +00:00
|
|
|
delete trigger_failure_extension_;
|
2017-10-13 16:33:03 +00:00
|
|
|
trigger_failure_extension_ = nullptr;
|
2016-04-27 11:10:41 +00:00
|
|
|
delete ignition_statistics_extension_;
|
2017-10-13 16:33:03 +00:00
|
|
|
ignition_statistics_extension_ = nullptr;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2015-04-30 15:10:43 +00:00
|
|
|
void Bootstrapper::TearDown() {
|
2013-09-11 08:39:38 +00:00
|
|
|
extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Genesis BASE_EMBEDDED {
|
|
|
|
public:
|
2015-07-06 07:09:07 +00:00
|
|
|
Genesis(Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy,
|
|
|
|
v8::Local<v8::ObjectTemplate> global_proxy_template,
|
2017-01-09 10:12:04 +00:00
|
|
|
size_t context_snapshot_index,
|
2017-03-17 13:26:05 +00:00
|
|
|
v8::DeserializeEmbedderFieldsCallback embedder_fields_deserializer,
|
2017-01-09 10:12:04 +00:00
|
|
|
GlobalContextType context_type);
|
2016-07-07 19:37:05 +00:00
|
|
|
Genesis(Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy,
|
|
|
|
v8::Local<v8::ObjectTemplate> global_proxy_template);
|
2010-03-23 11:40:38 +00:00
|
|
|
~Genesis() { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-04-14 08:01:19 +00:00
|
|
|
Isolate* isolate() const { return isolate_; }
|
|
|
|
Factory* factory() const { return isolate_->factory(); }
|
2017-07-07 09:24:57 +00:00
|
|
|
Builtins* builtins() const { return isolate_->builtins(); }
|
2011-04-14 08:01:19 +00:00
|
|
|
Heap* heap() const { return isolate_->heap(); }
|
|
|
|
|
2013-03-18 17:36:47 +00:00
|
|
|
Handle<Context> result() { return result_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2016-07-07 19:37:05 +00:00
|
|
|
Handle<JSGlobalProxy> global_proxy() { return global_proxy_; }
|
|
|
|
|
2013-03-18 17:36:47 +00:00
|
|
|
private:
|
2012-08-17 09:03:08 +00:00
|
|
|
Handle<Context> native_context() { return native_context_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
// Creates some basic objects. Used for creating a context from scratch.
|
|
|
|
void CreateRoots();
|
|
|
|
// Creates the empty function. Used for creating a context from scratch.
|
2018-04-25 09:52:59 +00:00
|
|
|
Handle<JSFunction> CreateEmptyFunction();
|
2017-07-10 07:57:09 +00:00
|
|
|
// Returns the %ThrowTypeError% intrinsic function.
|
|
|
|
// See ES#sec-%throwtypeerror% for details.
|
|
|
|
Handle<JSFunction> GetThrowTypeErrorIntrinsic();
|
2011-03-17 20:28:17 +00:00
|
|
|
|
2017-07-03 13:40:13 +00:00
|
|
|
void CreateSloppyModeFunctionMaps(Handle<JSFunction> empty);
|
2011-03-17 20:28:17 +00:00
|
|
|
void CreateStrictModeFunctionMaps(Handle<JSFunction> empty);
|
2017-07-03 13:40:13 +00:00
|
|
|
void CreateObjectFunction(Handle<JSFunction> empty);
|
2016-04-06 08:37:09 +00:00
|
|
|
void CreateIteratorMaps(Handle<JSFunction> empty);
|
[async-iteration] implement AsyncGenerator
- Introduce new struct AsyncGeneratorRequest, which holds
information pertinent to resuming execution of an
AsyncGenerator, such as the Promise associated with the async
generator request. It is intended to be used as a singly
linked list, and holds a pointer to the next item in te queue.
- Introduce JSAsyncGeneratorObject (subclass of
JSGeneratorObject), which includes several new internal fields
(`queue` which contains a singly linked list of
AsyncGeneratorRequest objects, and `await_input` which
contains the sent value from an Await expression (This is
necessary to prevent function.sent (used by yield*) from
having the sent value observably overwritten during
execution).
- Modify SuspendGenerator to accept a set of Flags, which
indicate whether the suspend is for a Yield or Await, and
whether it takes place on an async generator or ES6
generator.
- Introduce interpreter intrinsics and TF intrinsic lowering for
accessing the await input of an async generator
- Modify the JSGeneratorStore operator to understand whether or
not it's suspending for a normal yield, or an AsyncGenerator
Await. This ensures appropriate registers are stored.
- Add versions of ResumeGeneratorTrampoline which store the
input value in a different field depending on wether it's an
AsyncGenerator Await resume, or an ordinary resume. Also modifies
whether debug code will assert that the generator object is a
JSGeneratorObject or a JSAsyncGeneratorObject depending on the
resume type.
BUG=v8:5855
R=bmeurer@chromium.org, rmcilroy@chromium.org, jgruber@chromium.org,
littledan@chromium.org, neis@chromium.org
TBR=marja@chromium.org
Change-Id: I9d58df1d344465fc937fe7eed322424204497187
Reviewed-on: https://chromium-review.googlesource.com/446961
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44240}
2017-03-29 13:41:45 +00:00
|
|
|
void CreateAsyncIteratorMaps(Handle<JSFunction> empty);
|
2016-05-17 00:26:53 +00:00
|
|
|
void CreateAsyncFunctionMaps(Handle<JSFunction> empty);
|
2016-03-21 19:39:16 +00:00
|
|
|
void CreateJSProxyMaps();
|
2012-02-20 08:42:18 +00:00
|
|
|
|
|
|
|
// Make the "arguments" and "caller" properties throw a TypeError on access.
|
2016-05-25 17:00:28 +00:00
|
|
|
void AddRestrictedFunctionProperties(Handle<JSFunction> empty);
|
2012-02-20 08:42:18 +00:00
|
|
|
|
2015-01-14 16:42:15 +00:00
|
|
|
// Creates the global objects using the global proxy and the template passed
|
|
|
|
// in through the API. We call this regardless of whether we are building a
|
2010-03-23 11:40:38 +00:00
|
|
|
// context from scratch or using a deserialized one from the partial snapshot
|
|
|
|
// but in the latter case we don't use the objects it produces directly, as
|
2016-12-13 11:24:24 +00:00
|
|
|
// we have to use the deserialized ones that are linked together with the
|
|
|
|
// rest of the context snapshot. At the end we link the global proxy and the
|
|
|
|
// context to each other.
|
2015-11-02 14:57:59 +00:00
|
|
|
Handle<JSGlobalObject> CreateNewGlobals(
|
2015-07-06 07:09:07 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> global_proxy_template,
|
2015-01-14 16:42:15 +00:00
|
|
|
Handle<JSGlobalProxy> global_proxy);
|
2014-07-01 12:12:34 +00:00
|
|
|
// Similarly, we want to use the global that has been created by the templates
|
|
|
|
// passed through the API. The global from the snapshot is detached from the
|
|
|
|
// other objects in the snapshot.
|
2015-12-01 23:35:57 +00:00
|
|
|
void HookUpGlobalObject(Handle<JSGlobalObject> global_object);
|
2016-12-13 11:24:24 +00:00
|
|
|
// Hooks the given global proxy into the context in the case we do not
|
|
|
|
// replace the global object from the deserialized native context.
|
|
|
|
void HookUpGlobalProxy(Handle<JSGlobalProxy> global_proxy);
|
2015-06-12 12:34:10 +00:00
|
|
|
// The native context has a ScriptContextTable that store declarative bindings
|
|
|
|
// made in script scopes. Add a "this" binding to that table pointing to the
|
|
|
|
// global proxy.
|
|
|
|
void InstallGlobalThisBinding();
|
2010-03-23 11:40:38 +00:00
|
|
|
// New context initialization. Used for creating a context from scratch.
|
2015-11-02 14:57:59 +00:00
|
|
|
void InitializeGlobal(Handle<JSGlobalObject> global_object,
|
2015-07-13 09:45:43 +00:00
|
|
|
Handle<JSFunction> empty_function,
|
2016-02-02 07:25:30 +00:00
|
|
|
GlobalContextType context_type);
|
2014-09-19 07:36:05 +00:00
|
|
|
void InitializeExperimentalGlobal();
|
2015-10-16 11:27:14 +00:00
|
|
|
// Depending on the situation, expose and/or get rid of the utils object.
|
2016-02-02 07:25:30 +00:00
|
|
|
void ConfigureUtilsObject(GlobalContextType context_type);
|
2014-10-20 13:33:34 +00:00
|
|
|
|
|
|
|
#define DECLARE_FEATURE_INITIALIZATION(id, descr) \
|
|
|
|
void InitializeGlobal_##id();
|
|
|
|
|
2014-11-04 16:05:27 +00:00
|
|
|
HARMONY_INPROGRESS(DECLARE_FEATURE_INITIALIZATION)
|
|
|
|
HARMONY_STAGED(DECLARE_FEATURE_INITIALIZATION)
|
|
|
|
HARMONY_SHIPPING(DECLARE_FEATURE_INITIALIZATION)
|
2014-10-20 13:33:34 +00:00
|
|
|
#undef DECLARE_FEATURE_INITIALIZATION
|
|
|
|
|
2018-01-10 23:52:53 +00:00
|
|
|
enum ArrayBufferKind {
|
|
|
|
ARRAY_BUFFER,
|
|
|
|
SHARED_ARRAY_BUFFER,
|
|
|
|
};
|
2017-06-13 23:17:05 +00:00
|
|
|
Handle<JSFunction> CreateArrayBuffer(Handle<String> name,
|
2018-01-10 23:52:53 +00:00
|
|
|
ArrayBufferKind array_buffer_kind);
|
2015-05-12 14:00:47 +00:00
|
|
|
Handle<JSFunction> InstallInternalArray(Handle<JSObject> target,
|
2013-02-15 15:20:05 +00:00
|
|
|
const char* name,
|
|
|
|
ElementsKind elements_kind);
|
2016-02-02 07:25:30 +00:00
|
|
|
bool InstallNatives(GlobalContextType context_type);
|
2013-04-16 14:16:30 +00:00
|
|
|
|
2017-11-28 08:35:49 +00:00
|
|
|
Handle<JSFunction> InstallTypedArray(const char* name,
|
|
|
|
ElementsKind elements_kind);
|
2015-05-08 08:44:47 +00:00
|
|
|
bool InstallExtraNatives();
|
2015-08-20 00:01:07 +00:00
|
|
|
bool InstallExperimentalExtraNatives();
|
2015-08-12 14:22:07 +00:00
|
|
|
bool InstallDebuggerNatives();
|
2010-12-14 18:53:48 +00:00
|
|
|
void InstallBuiltinFunctionIds();
|
2015-06-03 17:58:29 +00:00
|
|
|
void InstallExperimentalBuiltinFunctionIds();
|
2010-08-25 13:25:54 +00:00
|
|
|
void InitializeNormalizedMapCaches();
|
2011-11-15 23:26:22 +00:00
|
|
|
|
2011-11-15 22:48:55 +00:00
|
|
|
enum ExtensionTraversalState {
|
|
|
|
UNVISITED, VISITED, INSTALLED
|
|
|
|
};
|
|
|
|
|
|
|
|
class ExtensionStates {
|
2012-02-23 09:12:57 +00:00
|
|
|
public:
|
2011-11-15 22:48:55 +00:00
|
|
|
ExtensionStates();
|
|
|
|
ExtensionTraversalState get_state(RegisteredExtension* extension);
|
|
|
|
void set_state(RegisteredExtension* extension,
|
|
|
|
ExtensionTraversalState state);
|
2012-02-23 09:12:57 +00:00
|
|
|
private:
|
2016-06-09 17:58:10 +00:00
|
|
|
base::HashMap map_;
|
2011-11-15 23:26:22 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(ExtensionStates);
|
2011-11-15 22:48:55 +00:00
|
|
|
};
|
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
// Used both for deserialized and from-scratch contexts to add the extensions
|
|
|
|
// provided.
|
2018-05-31 14:14:48 +00:00
|
|
|
static bool InstallExtensions(Isolate* isolate,
|
|
|
|
Handle<Context> native_context,
|
2010-03-23 11:40:38 +00:00
|
|
|
v8::ExtensionConfiguration* extensions);
|
2014-01-16 13:18:28 +00:00
|
|
|
static bool InstallAutoExtensions(Isolate* isolate,
|
|
|
|
ExtensionStates* extension_states);
|
|
|
|
static bool InstallRequestedExtensions(Isolate* isolate,
|
|
|
|
v8::ExtensionConfiguration* extensions,
|
|
|
|
ExtensionStates* extension_states);
|
2013-02-15 09:27:10 +00:00
|
|
|
static bool InstallExtension(Isolate* isolate,
|
|
|
|
const char* name,
|
2011-11-15 22:48:55 +00:00
|
|
|
ExtensionStates* extension_states);
|
2013-02-15 09:27:10 +00:00
|
|
|
static bool InstallExtension(Isolate* isolate,
|
|
|
|
v8::RegisteredExtension* current,
|
2011-11-15 22:48:55 +00:00
|
|
|
ExtensionStates* extension_states);
|
2018-05-31 14:14:48 +00:00
|
|
|
static bool InstallSpecialObjects(Isolate* isolate,
|
|
|
|
Handle<Context> native_context);
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
bool ConfigureApiObject(Handle<JSObject> object,
|
|
|
|
Handle<ObjectTemplateInfo> object_template);
|
2014-07-01 12:12:34 +00:00
|
|
|
bool ConfigureGlobalObjects(
|
2015-07-06 07:09:07 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> global_proxy_template);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Migrates all properties from the 'from' object to the 'to'
|
|
|
|
// object and overrides the prototype in 'to' with the one from
|
|
|
|
// 'from'.
|
|
|
|
void TransferObject(Handle<JSObject> from, Handle<JSObject> to);
|
|
|
|
void TransferNamedProperties(Handle<JSObject> from, Handle<JSObject> to);
|
|
|
|
void TransferIndexedProperties(Handle<JSObject> from, Handle<JSObject> to);
|
|
|
|
|
2015-05-21 06:15:33 +00:00
|
|
|
static bool CallUtilsFunction(Isolate* isolate, const char* name);
|
|
|
|
|
2015-05-12 14:00:47 +00:00
|
|
|
static bool CompileExtension(Isolate* isolate, v8::Extension* extension);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-03-18 17:36:47 +00:00
|
|
|
Isolate* isolate_;
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<Context> result_;
|
2013-03-18 17:36:47 +00:00
|
|
|
Handle<Context> native_context_;
|
2016-07-07 19:37:05 +00:00
|
|
|
Handle<JSGlobalProxy> global_proxy_;
|
2011-03-17 20:28:17 +00:00
|
|
|
|
2017-07-13 09:33:22 +00:00
|
|
|
// Temporary function maps needed only during bootstrapping.
|
|
|
|
Handle<Map> strict_function_with_home_object_map_;
|
|
|
|
Handle<Map> strict_function_with_name_and_home_object_map_;
|
|
|
|
|
2017-07-10 07:57:09 +00:00
|
|
|
// %ThrowTypeError%. See ES#sec-%throwtypeerror% for details.
|
|
|
|
Handle<JSFunction> restricted_properties_thrower_;
|
2011-03-17 20:28:17 +00:00
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
BootstrapperActive active_;
|
|
|
|
friend class Bootstrapper;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
2017-04-25 13:32:18 +00:00
|
|
|
void Bootstrapper::Iterate(RootVisitor* v) {
|
2011-03-18 20:35:07 +00:00
|
|
|
extensions_cache_.Iterate(v);
|
2011-12-06 17:41:47 +00:00
|
|
|
v->Synchronize(VisitorSynchronization::kExtensions);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Handle<Context> Bootstrapper::CreateEnvironment(
|
2014-07-01 12:12:34 +00:00
|
|
|
MaybeHandle<JSGlobalProxy> maybe_global_proxy,
|
2015-07-06 07:09:07 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> global_proxy_template,
|
2016-06-15 15:38:40 +00:00
|
|
|
v8::ExtensionConfiguration* extensions, size_t context_snapshot_index,
|
2017-03-17 13:26:05 +00:00
|
|
|
v8::DeserializeEmbedderFieldsCallback embedder_fields_deserializer,
|
2016-06-15 15:38:40 +00:00
|
|
|
GlobalContextType context_type) {
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(isolate_);
|
2017-11-28 16:12:09 +00:00
|
|
|
Handle<Context> env;
|
|
|
|
{
|
|
|
|
Genesis genesis(isolate_, maybe_global_proxy, global_proxy_template,
|
|
|
|
context_snapshot_index, embedder_fields_deserializer,
|
|
|
|
context_type);
|
|
|
|
env = genesis.result();
|
|
|
|
if (env.is_null() || !InstallExtensions(env, extensions)) {
|
|
|
|
return Handle<Context>();
|
|
|
|
}
|
2010-03-23 11:40:38 +00:00
|
|
|
}
|
2017-11-28 16:12:09 +00:00
|
|
|
// Log all maps created during bootstrapping.
|
|
|
|
if (FLAG_trace_maps) LOG(isolate_, LogMaps());
|
2013-04-10 09:34:37 +00:00
|
|
|
return scope.CloseAndEscape(env);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 19:37:05 +00:00
|
|
|
Handle<JSGlobalProxy> Bootstrapper::NewRemoteContext(
|
|
|
|
MaybeHandle<JSGlobalProxy> maybe_global_proxy,
|
|
|
|
v8::Local<v8::ObjectTemplate> global_proxy_template) {
|
|
|
|
HandleScope scope(isolate_);
|
2017-11-28 16:12:09 +00:00
|
|
|
Handle<JSGlobalProxy> global_proxy;
|
|
|
|
{
|
|
|
|
Genesis genesis(isolate_, maybe_global_proxy, global_proxy_template);
|
|
|
|
global_proxy = genesis.global_proxy();
|
|
|
|
if (global_proxy.is_null()) return Handle<JSGlobalProxy>();
|
|
|
|
}
|
|
|
|
// Log all maps created during bootstrapping.
|
|
|
|
if (FLAG_trace_maps) LOG(isolate_, LogMaps());
|
2016-07-07 19:37:05 +00:00
|
|
|
return scope.CloseAndEscape(global_proxy);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
void Bootstrapper::DetachGlobal(Handle<Context> env) {
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_->counters()->errors_thrown_per_context()->AddSample(
|
2017-01-09 13:40:51 +00:00
|
|
|
env->GetErrorsThrown());
|
2015-11-06 08:07:52 +00:00
|
|
|
|
2018-07-04 09:10:05 +00:00
|
|
|
ReadOnlyRoots roots(isolate_);
|
2018-05-31 08:31:07 +00:00
|
|
|
Handle<JSGlobalProxy> global_proxy(JSGlobalProxy::cast(env->global_proxy()),
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_);
|
2018-07-04 09:10:05 +00:00
|
|
|
global_proxy->set_native_context(roots.null_value());
|
2018-05-31 14:14:48 +00:00
|
|
|
JSObject::ForceSetPrototype(global_proxy, isolate_->factory()->null_value());
|
2018-07-04 09:10:05 +00:00
|
|
|
global_proxy->map()->SetConstructor(roots.null_value());
|
2015-02-05 09:35:47 +00:00
|
|
|
if (FLAG_track_detached_contexts) {
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_->AddDetachedContext(env);
|
2015-02-05 09:35:47 +00:00
|
|
|
}
|
2010-03-24 13:24:46 +00:00
|
|
|
}
|
|
|
|
|
2015-08-31 12:52:59 +00:00
|
|
|
namespace {
|
|
|
|
|
2017-09-15 08:45:45 +00:00
|
|
|
V8_NOINLINE Handle<SharedFunctionInfo> SimpleCreateSharedFunctionInfo(
|
2018-04-11 15:07:23 +00:00
|
|
|
Isolate* isolate, Builtins::Name builtin_id, Handle<String> name, int len,
|
|
|
|
FunctionKind kind = FunctionKind::kNormalFunction) {
|
2018-03-22 16:09:55 +00:00
|
|
|
Handle<SharedFunctionInfo> shared =
|
2018-03-23 14:24:03 +00:00
|
|
|
isolate->factory()->NewSharedFunctionInfoForBuiltin(name, builtin_id,
|
2018-04-11 15:07:23 +00:00
|
|
|
kind);
|
2017-09-07 07:24:11 +00:00
|
|
|
shared->set_internal_formal_parameter_count(len);
|
|
|
|
shared->set_length(len);
|
|
|
|
return shared;
|
|
|
|
}
|
|
|
|
|
2018-03-23 14:24:03 +00:00
|
|
|
V8_NOINLINE Handle<SharedFunctionInfo> SimpleCreateBuiltinSharedFunctionInfo(
|
|
|
|
Isolate* isolate, Builtins::Name builtin_id, Handle<String> name, int len) {
|
2018-03-22 16:09:55 +00:00
|
|
|
Handle<SharedFunctionInfo> shared =
|
2018-03-23 14:24:03 +00:00
|
|
|
isolate->factory()->NewSharedFunctionInfoForBuiltin(name, builtin_id,
|
|
|
|
kNormalFunction);
|
2017-09-07 07:24:11 +00:00
|
|
|
shared->set_internal_formal_parameter_count(len);
|
|
|
|
shared->set_length(len);
|
|
|
|
return shared;
|
|
|
|
}
|
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
V8_NOINLINE void InstallFunction(Isolate* isolate, Handle<JSObject> target,
|
2017-09-15 08:45:45 +00:00
|
|
|
Handle<Name> property_name,
|
|
|
|
Handle<JSFunction> function,
|
|
|
|
Handle<String> function_name,
|
|
|
|
PropertyAttributes attributes = DONT_ENUM) {
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate, target, property_name, function, attributes);
|
2015-12-14 15:11:55 +00:00
|
|
|
}
|
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
V8_NOINLINE void InstallFunction(Isolate* isolate, Handle<JSObject> target,
|
2017-09-15 08:45:45 +00:00
|
|
|
Handle<JSFunction> function, Handle<Name> name,
|
|
|
|
PropertyAttributes attributes = DONT_ENUM) {
|
2018-07-13 09:32:35 +00:00
|
|
|
Handle<String> name_string =
|
|
|
|
Name::ToFunctionName(isolate, name).ToHandleChecked();
|
2018-06-19 09:00:37 +00:00
|
|
|
InstallFunction(isolate, target, name, function, name_string, attributes);
|
2015-12-14 15:11:55 +00:00
|
|
|
}
|
|
|
|
|
2017-09-15 08:45:45 +00:00
|
|
|
V8_NOINLINE Handle<JSFunction> CreateFunction(
|
|
|
|
Isolate* isolate, Handle<String> name, InstanceType type, int instance_size,
|
2017-10-18 20:14:09 +00:00
|
|
|
int inobject_properties, MaybeHandle<Object> maybe_prototype,
|
2017-11-08 12:56:08 +00:00
|
|
|
Builtins::Name builtin_id) {
|
2017-06-29 14:21:59 +00:00
|
|
|
Handle<Object> prototype;
|
2017-11-08 12:56:08 +00:00
|
|
|
Handle<JSFunction> result;
|
|
|
|
|
|
|
|
if (maybe_prototype.ToHandle(&prototype)) {
|
|
|
|
NewFunctionArgs args = NewFunctionArgs::ForBuiltinWithPrototype(
|
2018-03-22 16:09:55 +00:00
|
|
|
name, prototype, type, instance_size, inobject_properties, builtin_id,
|
|
|
|
IMMUTABLE);
|
2017-11-08 12:56:08 +00:00
|
|
|
|
|
|
|
result = isolate->factory()->NewFunction(args);
|
2017-11-28 08:35:49 +00:00
|
|
|
// Make the JSFunction's prototype object fast.
|
|
|
|
JSObject::MakePrototypesFast(handle(result->prototype(), isolate),
|
|
|
|
kStartAtReceiver, isolate);
|
2017-11-08 12:56:08 +00:00
|
|
|
} else {
|
|
|
|
NewFunctionArgs args = NewFunctionArgs::ForBuiltinWithoutPrototype(
|
2018-03-22 16:09:55 +00:00
|
|
|
name, builtin_id, LanguageMode::kStrict);
|
2017-11-08 12:56:08 +00:00
|
|
|
result = isolate->factory()->NewFunction(args);
|
2017-09-07 07:24:11 +00:00
|
|
|
}
|
2017-11-08 12:56:08 +00:00
|
|
|
|
2017-11-28 08:35:49 +00:00
|
|
|
// Make the resulting JSFunction object fast.
|
|
|
|
JSObject::MakePrototypesFast(result, kStartAtReceiver, isolate);
|
2017-02-01 14:02:59 +00:00
|
|
|
result->shared()->set_native(true);
|
|
|
|
return result;
|
2015-12-08 16:04:08 +00:00
|
|
|
}
|
|
|
|
|
2017-09-15 08:45:45 +00:00
|
|
|
V8_NOINLINE Handle<JSFunction> InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
Isolate* isolate, Handle<JSObject> target, Handle<Name> name,
|
|
|
|
InstanceType type, int instance_size, int inobject_properties,
|
2017-10-18 20:14:09 +00:00
|
|
|
MaybeHandle<Object> maybe_prototype, Builtins::Name call,
|
2017-09-15 08:45:45 +00:00
|
|
|
PropertyAttributes attributes) {
|
2018-07-13 09:32:35 +00:00
|
|
|
Handle<String> name_string =
|
|
|
|
Name::ToFunctionName(isolate, name).ToHandleChecked();
|
2015-08-31 10:09:52 +00:00
|
|
|
Handle<JSFunction> function =
|
2018-05-31 14:14:48 +00:00
|
|
|
CreateFunction(isolate, name_string, type, instance_size,
|
2017-10-18 20:14:09 +00:00
|
|
|
inobject_properties, maybe_prototype, call);
|
2018-06-19 09:00:37 +00:00
|
|
|
InstallFunction(isolate, target, name, function, name_string, attributes);
|
2015-12-14 15:11:55 +00:00
|
|
|
return function;
|
2015-08-31 12:52:59 +00:00
|
|
|
}
|
|
|
|
|
2017-09-15 08:45:45 +00:00
|
|
|
V8_NOINLINE Handle<JSFunction> InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
Isolate* isolate, Handle<JSObject> target, const char* name,
|
|
|
|
InstanceType type, int instance_size, int inobject_properties,
|
2017-10-18 20:14:09 +00:00
|
|
|
MaybeHandle<Object> maybe_prototype, Builtins::Name call) {
|
2015-11-02 13:04:20 +00:00
|
|
|
PropertyAttributes attributes = DONT_ENUM;
|
2018-05-31 14:14:48 +00:00
|
|
|
return InstallFunction(
|
|
|
|
isolate, target, isolate->factory()->InternalizeUtf8String(name), type,
|
|
|
|
instance_size, inobject_properties, maybe_prototype, call, attributes);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2017-09-15 08:45:45 +00:00
|
|
|
V8_NOINLINE Handle<JSFunction> SimpleCreateFunction(Isolate* isolate,
|
|
|
|
Handle<String> name,
|
|
|
|
Builtins::Name call,
|
|
|
|
int len, bool adapt) {
|
2016-04-06 08:37:09 +00:00
|
|
|
Handle<JSFunction> fun =
|
2017-10-18 20:14:09 +00:00
|
|
|
CreateFunction(isolate, name, JS_OBJECT_TYPE, JSObject::kHeaderSize, 0,
|
2016-04-06 08:37:09 +00:00
|
|
|
MaybeHandle<JSObject>(), call);
|
|
|
|
if (adapt) {
|
|
|
|
fun->shared()->set_internal_formal_parameter_count(len);
|
|
|
|
} else {
|
|
|
|
fun->shared()->DontAdaptArguments();
|
|
|
|
}
|
|
|
|
fun->shared()->set_length(len);
|
|
|
|
return fun;
|
|
|
|
}
|
2015-08-31 12:52:59 +00:00
|
|
|
|
2017-09-15 08:45:45 +00:00
|
|
|
V8_NOINLINE Handle<JSFunction> SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
Isolate* isolate, Handle<JSObject> base, Handle<Name> property_name,
|
2017-07-03 13:40:13 +00:00
|
|
|
Handle<String> function_name, Builtins::Name call, int len, bool adapt,
|
|
|
|
PropertyAttributes attrs = DONT_ENUM,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
BuiltinFunctionId id = BuiltinFunctionId::kInvalidBuiltinFunctionId) {
|
2016-04-06 08:37:09 +00:00
|
|
|
Handle<JSFunction> fun =
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleCreateFunction(isolate, function_name, call, len, adapt);
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
if (id != BuiltinFunctionId::kInvalidBuiltinFunctionId) {
|
2017-07-03 13:40:13 +00:00
|
|
|
fun->shared()->set_builtin_function_id(id);
|
|
|
|
}
|
2018-06-19 09:00:37 +00:00
|
|
|
InstallFunction(isolate, base, fun, property_name, attrs);
|
2017-06-26 10:03:43 +00:00
|
|
|
return fun;
|
|
|
|
}
|
|
|
|
|
2017-09-15 08:45:45 +00:00
|
|
|
V8_NOINLINE Handle<JSFunction> SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
Isolate* isolate, Handle<JSObject> base, Handle<String> name,
|
|
|
|
Builtins::Name call, int len, bool adapt,
|
|
|
|
PropertyAttributes attrs = DONT_ENUM,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
BuiltinFunctionId id = BuiltinFunctionId::kInvalidBuiltinFunctionId) {
|
2018-05-31 14:14:48 +00:00
|
|
|
return SimpleInstallFunction(isolate, base, name, name, call, len, adapt,
|
|
|
|
attrs, id);
|
2017-06-26 10:03:43 +00:00
|
|
|
}
|
|
|
|
|
2017-09-15 08:45:45 +00:00
|
|
|
V8_NOINLINE Handle<JSFunction> SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
Isolate* isolate, Handle<JSObject> base, Handle<Name> property_name,
|
2017-06-26 10:03:43 +00:00
|
|
|
const char* function_name, Builtins::Name call, int len, bool adapt,
|
|
|
|
PropertyAttributes attrs = DONT_ENUM,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
BuiltinFunctionId id = BuiltinFunctionId::kInvalidBuiltinFunctionId) {
|
2017-07-07 09:24:57 +00:00
|
|
|
// Function name does not have to be internalized.
|
|
|
|
return SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate, base, property_name,
|
|
|
|
isolate->factory()->NewStringFromAsciiChecked(function_name), call, len,
|
|
|
|
adapt, attrs, id);
|
2016-04-06 08:37:09 +00:00
|
|
|
}
|
|
|
|
|
2017-09-15 08:45:45 +00:00
|
|
|
V8_NOINLINE Handle<JSFunction> SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
Isolate* isolate, Handle<JSObject> base, const char* name,
|
|
|
|
Builtins::Name call, int len, bool adapt,
|
|
|
|
PropertyAttributes attrs = DONT_ENUM,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
BuiltinFunctionId id = BuiltinFunctionId::kInvalidBuiltinFunctionId) {
|
2017-07-07 09:24:57 +00:00
|
|
|
// Although function name does not have to be internalized the property name
|
|
|
|
// will be internalized during property addition anyway, so do it here now.
|
2018-05-31 14:14:48 +00:00
|
|
|
return SimpleInstallFunction(isolate, base,
|
|
|
|
isolate->factory()->InternalizeUtf8String(name),
|
|
|
|
call, len, adapt, attrs, id);
|
2016-04-06 08:37:09 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
V8_NOINLINE Handle<JSFunction> SimpleInstallFunction(
|
|
|
|
Isolate* isolate, Handle<JSObject> base, const char* name,
|
|
|
|
Builtins::Name call, int len, bool adapt, BuiltinFunctionId id) {
|
|
|
|
return SimpleInstallFunction(isolate, base, name, call, len, adapt, DONT_ENUM,
|
|
|
|
id);
|
2016-08-09 07:13:38 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
V8_NOINLINE void SimpleInstallGetterSetter(Isolate* isolate,
|
|
|
|
Handle<JSObject> base,
|
2017-09-15 08:45:45 +00:00
|
|
|
Handle<String> name,
|
|
|
|
Builtins::Name call_getter,
|
|
|
|
Builtins::Name call_setter,
|
|
|
|
PropertyAttributes attribs) {
|
2016-10-06 13:00:56 +00:00
|
|
|
Handle<String> getter_name =
|
2018-07-13 09:32:35 +00:00
|
|
|
Name::ToFunctionName(isolate, name, isolate->factory()->get_string())
|
2016-10-06 13:00:56 +00:00
|
|
|
.ToHandleChecked();
|
|
|
|
Handle<JSFunction> getter =
|
2016-10-14 11:24:44 +00:00
|
|
|
SimpleCreateFunction(isolate, getter_name, call_getter, 0, true);
|
2016-10-06 13:00:56 +00:00
|
|
|
|
|
|
|
Handle<String> setter_name =
|
2018-07-13 09:32:35 +00:00
|
|
|
Name::ToFunctionName(isolate, name, isolate->factory()->set_string())
|
2016-10-06 13:00:56 +00:00
|
|
|
.ToHandleChecked();
|
|
|
|
Handle<JSFunction> setter =
|
2016-10-14 11:24:44 +00:00
|
|
|
SimpleCreateFunction(isolate, setter_name, call_setter, 1, true);
|
2016-10-06 13:00:56 +00:00
|
|
|
|
|
|
|
JSObject::DefineAccessor(base, name, getter, setter, attribs).Check();
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
V8_NOINLINE Handle<JSFunction> SimpleInstallGetter(
|
|
|
|
Isolate* isolate, Handle<JSObject> base, Handle<Name> name,
|
|
|
|
Handle<Name> property_name, Builtins::Name call, bool adapt) {
|
2016-10-06 13:00:56 +00:00
|
|
|
Handle<String> getter_name =
|
2018-07-13 09:32:35 +00:00
|
|
|
Name::ToFunctionName(isolate, name, isolate->factory()->get_string())
|
2016-06-08 07:40:11 +00:00
|
|
|
.ToHandleChecked();
|
2016-10-06 13:00:56 +00:00
|
|
|
Handle<JSFunction> getter =
|
|
|
|
SimpleCreateFunction(isolate, getter_name, call, 0, adapt);
|
|
|
|
|
|
|
|
Handle<Object> setter = isolate->factory()->undefined_value();
|
|
|
|
|
|
|
|
JSObject::DefineAccessor(base, property_name, getter, setter, DONT_ENUM)
|
|
|
|
.Check();
|
|
|
|
|
|
|
|
return getter;
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
V8_NOINLINE Handle<JSFunction> SimpleInstallGetter(Isolate* isolate,
|
|
|
|
Handle<JSObject> base,
|
2017-10-02 05:28:41 +00:00
|
|
|
Handle<Name> name,
|
2017-09-15 08:45:45 +00:00
|
|
|
Builtins::Name call,
|
|
|
|
bool adapt) {
|
2018-05-31 14:14:48 +00:00
|
|
|
return SimpleInstallGetter(isolate, base, name, name, call, adapt);
|
2016-06-08 07:40:11 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
V8_NOINLINE Handle<JSFunction> SimpleInstallGetter(
|
|
|
|
Isolate* isolate, Handle<JSObject> base, Handle<Name> name,
|
|
|
|
Builtins::Name call, bool adapt, BuiltinFunctionId id) {
|
|
|
|
Handle<JSFunction> fun =
|
|
|
|
SimpleInstallGetter(isolate, base, name, call, adapt);
|
2016-06-08 07:40:11 +00:00
|
|
|
fun->shared()->set_builtin_function_id(id);
|
|
|
|
return fun;
|
|
|
|
}
|
|
|
|
|
2017-09-15 08:45:45 +00:00
|
|
|
V8_NOINLINE void InstallConstant(Isolate* isolate, Handle<JSObject> holder,
|
|
|
|
const char* name, Handle<Object> value) {
|
2016-12-06 13:21:20 +00:00
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate, holder, isolate->factory()->NewStringFromAsciiChecked(name),
|
|
|
|
value,
|
2016-12-06 13:21:20 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY));
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
V8_NOINLINE void InstallSpeciesGetter(Isolate* isolate,
|
|
|
|
Handle<JSFunction> constructor) {
|
|
|
|
Factory* factory = isolate->factory();
|
2017-01-04 23:19:27 +00:00
|
|
|
// TODO(adamk): We should be able to share a SharedFunctionInfo
|
|
|
|
// between all these JSFunctins.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate, constructor, factory->symbol_species_string(),
|
2017-01-04 23:19:27 +00:00
|
|
|
factory->species_symbol(), Builtins::kReturnReceiver,
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
2016-04-06 08:37:09 +00:00
|
|
|
} // namespace
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2018-04-25 09:52:59 +00:00
|
|
|
Handle<JSFunction> Genesis::CreateEmptyFunction() {
|
2017-07-03 13:40:13 +00:00
|
|
|
// Allocate the function map first and then patch the prototype later.
|
2018-04-25 09:52:59 +00:00
|
|
|
Handle<Map> empty_function_map = factory()->CreateSloppyFunctionMap(
|
2017-07-07 09:24:57 +00:00
|
|
|
FUNCTION_WITHOUT_PROTOTYPE, MaybeHandle<JSFunction>());
|
2014-08-11 14:00:58 +00:00
|
|
|
empty_function_map->set_is_prototype_map(true);
|
2017-07-03 13:40:13 +00:00
|
|
|
DCHECK(!empty_function_map->is_dictionary_map());
|
2015-04-09 22:40:16 +00:00
|
|
|
|
2018-04-25 09:52:59 +00:00
|
|
|
// Allocate ScopeInfo for the empty function.
|
|
|
|
Handle<ScopeInfo> scope_info = ScopeInfo::CreateForEmptyFunction(isolate());
|
|
|
|
|
2017-07-03 13:40:13 +00:00
|
|
|
// Allocate the empty function as the prototype for function according to
|
|
|
|
// ES#sec-properties-of-the-function-prototype-object
|
2018-03-22 16:09:55 +00:00
|
|
|
NewFunctionArgs args = NewFunctionArgs::ForBuiltin(
|
2018-04-25 09:52:59 +00:00
|
|
|
factory()->empty_string(), empty_function_map, Builtins::kEmptyFunction);
|
|
|
|
Handle<JSFunction> empty_function = factory()->NewFunction(args);
|
|
|
|
native_context()->set_empty_function(*empty_function);
|
2014-08-11 14:00:58 +00:00
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
// --- E m p t y ---
|
2018-04-25 09:52:59 +00:00
|
|
|
Handle<String> source = factory()->NewStringFromStaticChars("() {}");
|
|
|
|
Handle<Script> script = factory()->NewScript(source);
|
2015-09-28 13:10:13 +00:00
|
|
|
script->set_type(Script::TYPE_NATIVE);
|
2018-04-25 09:52:59 +00:00
|
|
|
Handle<WeakFixedArray> infos = factory()->NewWeakFixedArray(2);
|
2016-12-15 17:19:55 +00:00
|
|
|
script->set_shared_function_infos(*infos);
|
2018-04-25 09:52:59 +00:00
|
|
|
empty_function->shared()->set_scope_info(*scope_info);
|
2010-03-23 11:40:38 +00:00
|
|
|
empty_function->shared()->DontAdaptArguments();
|
2018-05-31 08:31:07 +00:00
|
|
|
SharedFunctionInfo::SetScript(handle(empty_function->shared(), isolate()),
|
[sfi] Remove SFI function literal id field (reland^2)
SharedFunctionInfos store their original function literal's id. This is
also their index in the Script's SFI list.
The function literal id is only needed for lazy compilation and live edit,
and access only has to be fast in the former. So, we can move the SFI
function literal id field to UncompiledData, and if patching with live
edit, or discarding compiled code, we can perform a slower linear search
through the Script's SFI list.
This is a reland of
1) https://chromium-review.googlesource.com/1082480 and
2) https://chromium-review.googlesource.com/1128854
the differences being:
1) caching the literal id on UncompiledData rather than always linearly
searching the SFI list, and removing the unused runtime-liveedit.cc
file instead of fixing it to support this change.
2) clearing padding on UncompiledData now that it has 3 int32 fields,
making its end unaligned on x64.
TBR=yangguo@chromium.org,marja@chromium.org,ulan@chromium.org,cbruni@chromium.org
Bug: chromium:818642
Change-Id: I58dcb12a2a60a680f662568da428e01189c62638
Reviewed-on: https://chromium-review.googlesource.com/1138325
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54473}
2018-07-16 15:56:10 +00:00
|
|
|
script, 1);
|
2011-03-17 20:28:17 +00:00
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
return empty_function;
|
|
|
|
}
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
|
2017-07-03 13:40:13 +00:00
|
|
|
void Genesis::CreateSloppyModeFunctionMaps(Handle<JSFunction> empty) {
|
|
|
|
Factory* factory = isolate_->factory();
|
2017-07-07 09:24:57 +00:00
|
|
|
Handle<Map> map;
|
|
|
|
|
2017-07-13 09:33:22 +00:00
|
|
|
//
|
|
|
|
// Allocate maps for sloppy functions without prototype.
|
|
|
|
//
|
2017-07-07 09:24:57 +00:00
|
|
|
map = factory->CreateSloppyFunctionMap(FUNCTION_WITHOUT_PROTOTYPE, empty);
|
|
|
|
native_context()->set_sloppy_function_without_prototype_map(*map);
|
2017-07-03 13:40:13 +00:00
|
|
|
|
2017-07-13 09:33:22 +00:00
|
|
|
//
|
|
|
|
// Allocate maps for sloppy functions with readonly prototype.
|
|
|
|
//
|
2017-07-07 09:24:57 +00:00
|
|
|
map =
|
|
|
|
factory->CreateSloppyFunctionMap(FUNCTION_WITH_READONLY_PROTOTYPE, empty);
|
|
|
|
native_context()->set_sloppy_function_with_readonly_prototype_map(*map);
|
|
|
|
|
2017-07-13 09:33:22 +00:00
|
|
|
//
|
|
|
|
// Allocate maps for sloppy functions with writable prototype.
|
|
|
|
//
|
2017-07-07 09:24:57 +00:00
|
|
|
map = factory->CreateSloppyFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE,
|
|
|
|
empty);
|
|
|
|
native_context()->set_sloppy_function_map(*map);
|
2017-07-13 09:33:22 +00:00
|
|
|
|
|
|
|
map = factory->CreateSloppyFunctionMap(
|
|
|
|
FUNCTION_WITH_NAME_AND_WRITEABLE_PROTOTYPE, empty);
|
|
|
|
native_context()->set_sloppy_function_with_name_map(*map);
|
2017-07-03 13:40:13 +00:00
|
|
|
}
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
|
2017-07-10 07:57:09 +00:00
|
|
|
Handle<JSFunction> Genesis::GetThrowTypeErrorIntrinsic() {
|
|
|
|
if (!restricted_properties_thrower_.is_null()) {
|
|
|
|
return restricted_properties_thrower_;
|
|
|
|
}
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<String> name = factory()->empty_string();
|
2017-11-08 12:56:08 +00:00
|
|
|
NewFunctionArgs args = NewFunctionArgs::ForBuiltinWithoutPrototype(
|
2018-03-22 16:09:55 +00:00
|
|
|
name, Builtins::kStrictPoisonPillThrower, i::LanguageMode::kStrict);
|
2017-11-08 12:56:08 +00:00
|
|
|
Handle<JSFunction> function = factory()->NewFunction(args);
|
2015-04-15 17:15:32 +00:00
|
|
|
function->shared()->DontAdaptArguments();
|
|
|
|
|
|
|
|
// %ThrowTypeError% must not have a name property.
|
2015-11-26 09:34:11 +00:00
|
|
|
if (JSReceiver::DeleteProperty(function, factory()->name_string())
|
2015-12-09 18:06:49 +00:00
|
|
|
.IsNothing()) {
|
2015-11-26 09:34:11 +00:00
|
|
|
DCHECK(false);
|
2015-12-09 18:06:49 +00:00
|
|
|
}
|
2015-04-15 17:15:32 +00:00
|
|
|
|
|
|
|
// length needs to be non configurable.
|
2017-04-18 10:34:15 +00:00
|
|
|
Handle<Object> value(Smi::FromInt(function->shared()->GetLength()),
|
|
|
|
isolate());
|
2015-04-15 17:15:32 +00:00
|
|
|
JSObject::SetOwnPropertyIgnoreAttributes(
|
|
|
|
function, factory()->length_string(), value,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY))
|
|
|
|
.Assert();
|
|
|
|
|
2017-10-25 18:07:04 +00:00
|
|
|
if (JSObject::PreventExtensions(function, kThrowOnError).IsNothing()) {
|
2015-10-21 09:23:33 +00:00
|
|
|
DCHECK(false);
|
2015-12-09 18:06:49 +00:00
|
|
|
}
|
2015-04-15 17:15:32 +00:00
|
|
|
|
2017-07-18 07:59:59 +00:00
|
|
|
JSObject::MigrateSlowToFast(function, 0, "Bootstrapping");
|
|
|
|
|
2017-07-10 07:57:09 +00:00
|
|
|
restricted_properties_thrower_ = function;
|
2015-04-15 17:15:32 +00:00
|
|
|
return function;
|
|
|
|
}
|
|
|
|
|
2011-03-17 20:28:17 +00:00
|
|
|
void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) {
|
2017-07-07 09:24:57 +00:00
|
|
|
Factory* factory = isolate_->factory();
|
|
|
|
Handle<Map> map;
|
|
|
|
|
2017-07-13 09:33:22 +00:00
|
|
|
//
|
|
|
|
// Allocate maps for strict functions without prototype.
|
|
|
|
//
|
2017-07-07 09:24:57 +00:00
|
|
|
map = factory->CreateStrictFunctionMap(FUNCTION_WITHOUT_PROTOTYPE, empty);
|
|
|
|
native_context()->set_strict_function_without_prototype_map(*map);
|
|
|
|
|
2017-07-13 09:33:22 +00:00
|
|
|
map = factory->CreateStrictFunctionMap(METHOD_WITH_NAME, empty);
|
|
|
|
native_context()->set_method_with_name_map(*map);
|
|
|
|
|
|
|
|
map = factory->CreateStrictFunctionMap(METHOD_WITH_HOME_OBJECT, empty);
|
|
|
|
native_context()->set_method_with_home_object_map(*map);
|
|
|
|
|
|
|
|
map =
|
|
|
|
factory->CreateStrictFunctionMap(METHOD_WITH_NAME_AND_HOME_OBJECT, empty);
|
|
|
|
native_context()->set_method_with_name_and_home_object_map(*map);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate maps for strict functions with writable prototype.
|
|
|
|
//
|
2017-07-07 09:24:57 +00:00
|
|
|
map = factory->CreateStrictFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE,
|
|
|
|
empty);
|
|
|
|
native_context()->set_strict_function_map(*map);
|
|
|
|
|
2017-07-13 09:33:22 +00:00
|
|
|
map = factory->CreateStrictFunctionMap(
|
|
|
|
FUNCTION_WITH_NAME_AND_WRITEABLE_PROTOTYPE, empty);
|
|
|
|
native_context()->set_strict_function_with_name_map(*map);
|
|
|
|
|
|
|
|
strict_function_with_home_object_map_ = factory->CreateStrictFunctionMap(
|
|
|
|
FUNCTION_WITH_HOME_OBJECT_AND_WRITEABLE_PROTOTYPE, empty);
|
|
|
|
strict_function_with_name_and_home_object_map_ =
|
|
|
|
factory->CreateStrictFunctionMap(
|
|
|
|
FUNCTION_WITH_NAME_AND_HOME_OBJECT_AND_WRITEABLE_PROTOTYPE, empty);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate maps for strict functions with readonly prototype.
|
|
|
|
//
|
2017-07-07 09:24:57 +00:00
|
|
|
map =
|
|
|
|
factory->CreateStrictFunctionMap(FUNCTION_WITH_READONLY_PROTOTYPE, empty);
|
|
|
|
native_context()->set_strict_function_with_readonly_prototype_map(*map);
|
|
|
|
|
2017-07-13 09:33:22 +00:00
|
|
|
//
|
|
|
|
// Allocate map for class functions.
|
|
|
|
//
|
2017-07-07 09:24:57 +00:00
|
|
|
map = factory->CreateClassFunctionMap(empty);
|
|
|
|
native_context()->set_class_function_map(*map);
|
2016-12-07 10:34:15 +00:00
|
|
|
|
2016-05-25 17:00:28 +00:00
|
|
|
// Now that the strict mode function map is available, set up the
|
|
|
|
// restricted "arguments" and "caller" getters.
|
|
|
|
AddRestrictedFunctionProperties(empty);
|
2012-02-20 08:42:18 +00:00
|
|
|
}
|
|
|
|
|
2017-07-03 13:40:13 +00:00
|
|
|
void Genesis::CreateObjectFunction(Handle<JSFunction> empty_function) {
|
|
|
|
Factory* factory = isolate_->factory();
|
|
|
|
|
|
|
|
// --- O b j e c t ---
|
2017-10-18 20:14:09 +00:00
|
|
|
int inobject_properties = JSObject::kInitialGlobalObjectUnusedPropertiesCount;
|
|
|
|
int instance_size =
|
|
|
|
JSObject::kHeaderSize + kPointerSize * inobject_properties;
|
2017-07-03 13:40:13 +00:00
|
|
|
|
2017-09-07 13:21:19 +00:00
|
|
|
Handle<JSFunction> object_fun = CreateFunction(
|
|
|
|
isolate_, factory->Object_string(), JS_OBJECT_TYPE, instance_size,
|
2017-10-18 20:14:09 +00:00
|
|
|
inobject_properties, factory->null_value(), Builtins::kObjectConstructor);
|
2017-09-07 13:21:19 +00:00
|
|
|
object_fun->shared()->set_length(1);
|
|
|
|
object_fun->shared()->DontAdaptArguments();
|
2017-07-03 13:40:13 +00:00
|
|
|
native_context()->set_object_function(*object_fun);
|
|
|
|
|
|
|
|
{
|
|
|
|
// Finish setting up Object function's initial map.
|
|
|
|
Map* initial_map = object_fun->initial_map();
|
|
|
|
initial_map->set_elements_kind(HOLEY_ELEMENTS);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate a new prototype for the object function.
|
|
|
|
Handle<JSObject> object_function_prototype =
|
|
|
|
factory->NewFunctionPrototype(object_fun);
|
|
|
|
|
2018-05-31 08:31:07 +00:00
|
|
|
Handle<Map> map =
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::Copy(isolate(), handle(object_function_prototype->map(), isolate()),
|
2018-05-31 08:31:07 +00:00
|
|
|
"EmptyObjectPrototype");
|
2017-07-03 13:40:13 +00:00
|
|
|
map->set_is_prototype_map(true);
|
|
|
|
// Ban re-setting Object.prototype.__proto__ to prevent Proxy security bug
|
2017-12-07 11:03:41 +00:00
|
|
|
map->set_is_immutable_proto(true);
|
2017-07-03 13:40:13 +00:00
|
|
|
object_function_prototype->set_map(*map);
|
|
|
|
|
|
|
|
// Complete setting up empty function.
|
|
|
|
{
|
|
|
|
Handle<Map> empty_function_map(empty_function->map(), isolate_);
|
2018-06-25 10:54:01 +00:00
|
|
|
Map::SetPrototype(isolate(), empty_function_map, object_function_prototype);
|
2017-07-03 13:40:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
native_context()->set_initial_object_prototype(*object_function_prototype);
|
|
|
|
JSFunction::SetPrototype(object_fun, object_function_prototype);
|
|
|
|
|
|
|
|
{
|
|
|
|
// Set up slow map for Object.create(null) instances without in-object
|
|
|
|
// properties.
|
|
|
|
Handle<Map> map(object_fun->initial_map(), isolate_);
|
2018-06-21 14:49:44 +00:00
|
|
|
map = Map::CopyInitialMapNormalized(isolate(), map);
|
2018-06-25 10:54:01 +00:00
|
|
|
Map::SetPrototype(isolate(), map, factory->null_value());
|
2017-07-03 13:40:13 +00:00
|
|
|
native_context()->set_slow_object_with_null_prototype_map(*map);
|
|
|
|
|
|
|
|
// Set up slow map for literals with too many properties.
|
2018-06-19 09:00:37 +00:00
|
|
|
map = Map::Copy(isolate(), map, "slow_object_with_object_prototype_map");
|
2018-06-25 10:54:01 +00:00
|
|
|
Map::SetPrototype(isolate(), map, object_function_prototype);
|
2017-07-03 13:40:13 +00:00
|
|
|
native_context()->set_slow_object_with_object_prototype_map(*map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-13 09:33:22 +00:00
|
|
|
namespace {
|
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
Handle<Map> CreateNonConstructorMap(Isolate* isolate, Handle<Map> source_map,
|
2017-07-13 09:33:22 +00:00
|
|
|
Handle<JSObject> prototype,
|
|
|
|
const char* reason) {
|
2018-06-19 09:00:37 +00:00
|
|
|
Handle<Map> map = Map::Copy(isolate, source_map, reason);
|
2017-10-12 15:37:46 +00:00
|
|
|
// Ensure the resulting map has prototype slot (it is necessary for storing
|
|
|
|
// inital map even when the prototype property is not required).
|
|
|
|
if (!map->has_prototype_slot()) {
|
2017-10-20 12:49:15 +00:00
|
|
|
// Re-set the unused property fields after changing the instance size.
|
|
|
|
// TODO(ulan): Do not change instance size after map creation.
|
|
|
|
int unused_property_fields = map->UnusedPropertyFields();
|
2017-10-12 15:37:46 +00:00
|
|
|
map->set_instance_size(map->instance_size() + kPointerSize);
|
2017-11-17 21:24:02 +00:00
|
|
|
// The prototype slot shifts the in-object properties area by one slot.
|
|
|
|
map->SetInObjectPropertiesStartInWords(
|
|
|
|
map->GetInObjectPropertiesStartInWords() + 1);
|
2017-10-12 15:37:46 +00:00
|
|
|
map->set_has_prototype_slot(true);
|
2017-10-20 12:49:15 +00:00
|
|
|
map->SetInObjectUnusedPropertyFields(unused_property_fields);
|
2017-10-12 15:37:46 +00:00
|
|
|
}
|
2017-07-13 09:33:22 +00:00
|
|
|
map->set_is_constructor(false);
|
2018-06-25 10:54:01 +00:00
|
|
|
Map::SetPrototype(isolate, map, prototype);
|
2017-07-13 09:33:22 +00:00
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2016-04-06 08:37:09 +00:00
|
|
|
void Genesis::CreateIteratorMaps(Handle<JSFunction> empty) {
|
2015-10-16 11:27:14 +00:00
|
|
|
// Create iterator-related meta-objects.
|
|
|
|
Handle<JSObject> iterator_prototype =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
2016-09-21 14:17:42 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), iterator_prototype,
|
|
|
|
factory()->iterator_symbol(), "[Symbol.iterator]",
|
|
|
|
Builtins::kReturnReceiver, 0, true);
|
2016-09-21 14:17:42 +00:00
|
|
|
native_context()->set_initial_iterator_prototype(*iterator_prototype);
|
|
|
|
|
2015-10-16 11:27:14 +00:00
|
|
|
Handle<JSObject> generator_object_prototype =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
2016-05-18 09:15:40 +00:00
|
|
|
native_context()->set_initial_generator_prototype(
|
|
|
|
*generator_object_prototype);
|
2016-07-19 11:28:43 +00:00
|
|
|
JSObject::ForceSetPrototype(generator_object_prototype, iterator_prototype);
|
2015-10-16 11:27:14 +00:00
|
|
|
Handle<JSObject> generator_function_prototype =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
2016-07-19 11:28:43 +00:00
|
|
|
JSObject::ForceSetPrototype(generator_function_prototype, empty);
|
2015-10-16 11:27:14 +00:00
|
|
|
|
2016-04-06 08:37:09 +00:00
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate(), generator_function_prototype,
|
|
|
|
factory()->to_string_tag_symbol(),
|
2016-04-06 08:37:09 +00:00
|
|
|
factory()->NewStringFromAsciiChecked("GeneratorFunction"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate(), generator_function_prototype,
|
2016-04-06 08:37:09 +00:00
|
|
|
factory()->prototype_string(),
|
2015-10-16 11:27:14 +00:00
|
|
|
generator_object_prototype,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate(), generator_object_prototype,
|
2016-04-06 08:37:09 +00:00
|
|
|
factory()->constructor_string(),
|
|
|
|
generator_function_prototype,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate(), generator_object_prototype,
|
2016-04-06 08:37:09 +00:00
|
|
|
factory()->to_string_tag_symbol(),
|
|
|
|
factory()->NewStringFromAsciiChecked("Generator"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), generator_object_prototype, "next",
|
2017-06-19 10:42:08 +00:00
|
|
|
Builtins::kGeneratorPrototypeNext, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), generator_object_prototype, "return",
|
2017-06-19 10:42:08 +00:00
|
|
|
Builtins::kGeneratorPrototypeReturn, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), generator_object_prototype, "throw",
|
2017-06-19 10:42:08 +00:00
|
|
|
Builtins::kGeneratorPrototypeThrow, 1, false);
|
2016-04-06 08:37:09 +00:00
|
|
|
|
2017-02-01 14:02:59 +00:00
|
|
|
// Internal version of generator_prototype_next, flagged as non-native such
|
|
|
|
// that it doesn't show up in Error traces.
|
2016-09-30 07:53:43 +00:00
|
|
|
Handle<JSFunction> generator_next_internal =
|
|
|
|
SimpleCreateFunction(isolate(), factory()->next_string(),
|
2017-06-19 10:42:08 +00:00
|
|
|
Builtins::kGeneratorPrototypeNext, 1, false);
|
2017-02-01 14:02:59 +00:00
|
|
|
generator_next_internal->shared()->set_native(false);
|
2016-09-30 07:53:43 +00:00
|
|
|
native_context()->set_generator_next_internal(*generator_next_internal);
|
|
|
|
|
2015-10-16 11:27:14 +00:00
|
|
|
// Create maps for generator functions and their prototypes. Store those
|
|
|
|
// maps in the native context. The "prototype" property descriptor is
|
|
|
|
// writable, non-enumerable, and non-configurable (as per ES6 draft
|
|
|
|
// 04-14-15, section 25.2.4.3).
|
|
|
|
// Generator functions do not have "caller" or "arguments" accessors.
|
2017-07-13 09:33:22 +00:00
|
|
|
Handle<Map> map;
|
2018-06-19 09:00:37 +00:00
|
|
|
map = CreateNonConstructorMap(isolate(), isolate()->strict_function_map(),
|
2017-07-13 09:33:22 +00:00
|
|
|
generator_function_prototype,
|
|
|
|
"GeneratorFunction");
|
|
|
|
native_context()->set_generator_function_map(*map);
|
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
map = CreateNonConstructorMap(
|
|
|
|
isolate(), isolate()->strict_function_with_name_map(),
|
|
|
|
generator_function_prototype, "GeneratorFunction with name");
|
2017-07-13 09:33:22 +00:00
|
|
|
native_context()->set_generator_function_with_name_map(*map);
|
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
map = CreateNonConstructorMap(
|
|
|
|
isolate(), strict_function_with_home_object_map_,
|
|
|
|
generator_function_prototype, "GeneratorFunction with home object");
|
2017-07-13 09:33:22 +00:00
|
|
|
native_context()->set_generator_function_with_home_object_map(*map);
|
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
map = CreateNonConstructorMap(isolate(),
|
|
|
|
strict_function_with_name_and_home_object_map_,
|
2017-07-13 09:33:22 +00:00
|
|
|
generator_function_prototype,
|
|
|
|
"GeneratorFunction with name and home object");
|
|
|
|
native_context()->set_generator_function_with_name_and_home_object_map(*map);
|
2015-10-16 11:27:14 +00:00
|
|
|
|
2018-05-31 08:31:07 +00:00
|
|
|
Handle<JSFunction> object_function(native_context()->object_function(),
|
|
|
|
isolate());
|
2015-10-16 11:27:14 +00:00
|
|
|
Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0);
|
2018-06-25 10:54:01 +00:00
|
|
|
Map::SetPrototype(isolate(), generator_object_prototype_map,
|
|
|
|
generator_object_prototype);
|
2015-10-16 11:27:14 +00:00
|
|
|
native_context()->set_generator_object_prototype_map(
|
|
|
|
*generator_object_prototype_map);
|
|
|
|
}
|
|
|
|
|
[async-iteration] implement AsyncGenerator
- Introduce new struct AsyncGeneratorRequest, which holds
information pertinent to resuming execution of an
AsyncGenerator, such as the Promise associated with the async
generator request. It is intended to be used as a singly
linked list, and holds a pointer to the next item in te queue.
- Introduce JSAsyncGeneratorObject (subclass of
JSGeneratorObject), which includes several new internal fields
(`queue` which contains a singly linked list of
AsyncGeneratorRequest objects, and `await_input` which
contains the sent value from an Await expression (This is
necessary to prevent function.sent (used by yield*) from
having the sent value observably overwritten during
execution).
- Modify SuspendGenerator to accept a set of Flags, which
indicate whether the suspend is for a Yield or Await, and
whether it takes place on an async generator or ES6
generator.
- Introduce interpreter intrinsics and TF intrinsic lowering for
accessing the await input of an async generator
- Modify the JSGeneratorStore operator to understand whether or
not it's suspending for a normal yield, or an AsyncGenerator
Await. This ensures appropriate registers are stored.
- Add versions of ResumeGeneratorTrampoline which store the
input value in a different field depending on wether it's an
AsyncGenerator Await resume, or an ordinary resume. Also modifies
whether debug code will assert that the generator object is a
JSGeneratorObject or a JSAsyncGeneratorObject depending on the
resume type.
BUG=v8:5855
R=bmeurer@chromium.org, rmcilroy@chromium.org, jgruber@chromium.org,
littledan@chromium.org, neis@chromium.org
TBR=marja@chromium.org
Change-Id: I9d58df1d344465fc937fe7eed322424204497187
Reviewed-on: https://chromium-review.googlesource.com/446961
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44240}
2017-03-29 13:41:45 +00:00
|
|
|
void Genesis::CreateAsyncIteratorMaps(Handle<JSFunction> empty) {
|
2017-02-24 17:48:49 +00:00
|
|
|
// %AsyncIteratorPrototype%
|
|
|
|
// proposal-async-iteration/#sec-asynciteratorprototype
|
|
|
|
Handle<JSObject> async_iterator_prototype =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
|
|
|
|
2017-07-07 09:24:57 +00:00
|
|
|
SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate(), async_iterator_prototype, factory()->async_iterator_symbol(),
|
2017-07-07 09:24:57 +00:00
|
|
|
"[Symbol.asyncIterator]", Builtins::kReturnReceiver, 0, true);
|
2017-02-24 17:48:49 +00:00
|
|
|
|
|
|
|
// %AsyncFromSyncIteratorPrototype%
|
|
|
|
// proposal-async-iteration/#sec-%asyncfromsynciteratorprototype%-object
|
|
|
|
Handle<JSObject> async_from_sync_iterator_prototype =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), async_from_sync_iterator_prototype,
|
2017-02-24 17:48:49 +00:00
|
|
|
factory()->next_string(),
|
|
|
|
Builtins::kAsyncFromSyncIteratorPrototypeNext, 1, true);
|
|
|
|
SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate(), async_from_sync_iterator_prototype, factory()->return_string(),
|
2017-02-24 17:48:49 +00:00
|
|
|
Builtins::kAsyncFromSyncIteratorPrototypeReturn, 1, true);
|
|
|
|
SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate(), async_from_sync_iterator_prototype, factory()->throw_string(),
|
2017-02-24 17:48:49 +00:00
|
|
|
Builtins::kAsyncFromSyncIteratorPrototypeThrow, 1, true);
|
|
|
|
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate(), async_from_sync_iterator_prototype,
|
|
|
|
factory()->to_string_tag_symbol(),
|
2017-02-24 17:48:49 +00:00
|
|
|
factory()->NewStringFromAsciiChecked("Async-from-Sync Iterator"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
|
|
|
JSObject::ForceSetPrototype(async_from_sync_iterator_prototype,
|
|
|
|
async_iterator_prototype);
|
|
|
|
|
|
|
|
Handle<Map> async_from_sync_iterator_map = factory()->NewMap(
|
|
|
|
JS_ASYNC_FROM_SYNC_ITERATOR_TYPE, JSAsyncFromSyncIterator::kSize);
|
2018-06-25 10:54:01 +00:00
|
|
|
Map::SetPrototype(isolate(), async_from_sync_iterator_map,
|
2017-02-24 17:48:49 +00:00
|
|
|
async_from_sync_iterator_prototype);
|
|
|
|
native_context()->set_async_from_sync_iterator_map(
|
|
|
|
*async_from_sync_iterator_map);
|
[async-iteration] implement AsyncGenerator
- Introduce new struct AsyncGeneratorRequest, which holds
information pertinent to resuming execution of an
AsyncGenerator, such as the Promise associated with the async
generator request. It is intended to be used as a singly
linked list, and holds a pointer to the next item in te queue.
- Introduce JSAsyncGeneratorObject (subclass of
JSGeneratorObject), which includes several new internal fields
(`queue` which contains a singly linked list of
AsyncGeneratorRequest objects, and `await_input` which
contains the sent value from an Await expression (This is
necessary to prevent function.sent (used by yield*) from
having the sent value observably overwritten during
execution).
- Modify SuspendGenerator to accept a set of Flags, which
indicate whether the suspend is for a Yield or Await, and
whether it takes place on an async generator or ES6
generator.
- Introduce interpreter intrinsics and TF intrinsic lowering for
accessing the await input of an async generator
- Modify the JSGeneratorStore operator to understand whether or
not it's suspending for a normal yield, or an AsyncGenerator
Await. This ensures appropriate registers are stored.
- Add versions of ResumeGeneratorTrampoline which store the
input value in a different field depending on wether it's an
AsyncGenerator Await resume, or an ordinary resume. Also modifies
whether debug code will assert that the generator object is a
JSGeneratorObject or a JSAsyncGeneratorObject depending on the
resume type.
BUG=v8:5855
R=bmeurer@chromium.org, rmcilroy@chromium.org, jgruber@chromium.org,
littledan@chromium.org, neis@chromium.org
TBR=marja@chromium.org
Change-Id: I9d58df1d344465fc937fe7eed322424204497187
Reviewed-on: https://chromium-review.googlesource.com/446961
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44240}
2017-03-29 13:41:45 +00:00
|
|
|
|
|
|
|
// Async Generators
|
|
|
|
Handle<String> AsyncGeneratorFunction_string =
|
|
|
|
factory()->NewStringFromAsciiChecked("AsyncGeneratorFunction", TENURED);
|
|
|
|
|
|
|
|
Handle<JSObject> async_generator_object_prototype =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
|
|
|
Handle<JSObject> async_generator_function_prototype =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
|
|
|
|
|
|
|
// %AsyncGenerator% / %AsyncGeneratorFunction%.prototype
|
|
|
|
JSObject::ForceSetPrototype(async_generator_function_prototype, empty);
|
|
|
|
|
|
|
|
// The value of AsyncGeneratorFunction.prototype.prototype is the
|
|
|
|
// %AsyncGeneratorPrototype% intrinsic object.
|
|
|
|
// This property has the attributes
|
|
|
|
// { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate(), async_generator_function_prototype,
|
[async-iteration] implement AsyncGenerator
- Introduce new struct AsyncGeneratorRequest, which holds
information pertinent to resuming execution of an
AsyncGenerator, such as the Promise associated with the async
generator request. It is intended to be used as a singly
linked list, and holds a pointer to the next item in te queue.
- Introduce JSAsyncGeneratorObject (subclass of
JSGeneratorObject), which includes several new internal fields
(`queue` which contains a singly linked list of
AsyncGeneratorRequest objects, and `await_input` which
contains the sent value from an Await expression (This is
necessary to prevent function.sent (used by yield*) from
having the sent value observably overwritten during
execution).
- Modify SuspendGenerator to accept a set of Flags, which
indicate whether the suspend is for a Yield or Await, and
whether it takes place on an async generator or ES6
generator.
- Introduce interpreter intrinsics and TF intrinsic lowering for
accessing the await input of an async generator
- Modify the JSGeneratorStore operator to understand whether or
not it's suspending for a normal yield, or an AsyncGenerator
Await. This ensures appropriate registers are stored.
- Add versions of ResumeGeneratorTrampoline which store the
input value in a different field depending on wether it's an
AsyncGenerator Await resume, or an ordinary resume. Also modifies
whether debug code will assert that the generator object is a
JSGeneratorObject or a JSAsyncGeneratorObject depending on the
resume type.
BUG=v8:5855
R=bmeurer@chromium.org, rmcilroy@chromium.org, jgruber@chromium.org,
littledan@chromium.org, neis@chromium.org
TBR=marja@chromium.org
Change-Id: I9d58df1d344465fc937fe7eed322424204497187
Reviewed-on: https://chromium-review.googlesource.com/446961
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44240}
2017-03-29 13:41:45 +00:00
|
|
|
factory()->prototype_string(),
|
|
|
|
async_generator_object_prototype,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
2018-06-26 12:11:10 +00:00
|
|
|
JSObject::AddProperty(isolate(), async_generator_object_prototype,
|
|
|
|
factory()->constructor_string(),
|
|
|
|
async_generator_function_prototype,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate(), async_generator_function_prototype,
|
[async-iteration] implement AsyncGenerator
- Introduce new struct AsyncGeneratorRequest, which holds
information pertinent to resuming execution of an
AsyncGenerator, such as the Promise associated with the async
generator request. It is intended to be used as a singly
linked list, and holds a pointer to the next item in te queue.
- Introduce JSAsyncGeneratorObject (subclass of
JSGeneratorObject), which includes several new internal fields
(`queue` which contains a singly linked list of
AsyncGeneratorRequest objects, and `await_input` which
contains the sent value from an Await expression (This is
necessary to prevent function.sent (used by yield*) from
having the sent value observably overwritten during
execution).
- Modify SuspendGenerator to accept a set of Flags, which
indicate whether the suspend is for a Yield or Await, and
whether it takes place on an async generator or ES6
generator.
- Introduce interpreter intrinsics and TF intrinsic lowering for
accessing the await input of an async generator
- Modify the JSGeneratorStore operator to understand whether or
not it's suspending for a normal yield, or an AsyncGenerator
Await. This ensures appropriate registers are stored.
- Add versions of ResumeGeneratorTrampoline which store the
input value in a different field depending on wether it's an
AsyncGenerator Await resume, or an ordinary resume. Also modifies
whether debug code will assert that the generator object is a
JSGeneratorObject or a JSAsyncGeneratorObject depending on the
resume type.
BUG=v8:5855
R=bmeurer@chromium.org, rmcilroy@chromium.org, jgruber@chromium.org,
littledan@chromium.org, neis@chromium.org
TBR=marja@chromium.org
Change-Id: I9d58df1d344465fc937fe7eed322424204497187
Reviewed-on: https://chromium-review.googlesource.com/446961
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44240}
2017-03-29 13:41:45 +00:00
|
|
|
factory()->to_string_tag_symbol(),
|
|
|
|
AsyncGeneratorFunction_string,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
|
|
|
// %AsyncGeneratorPrototype%
|
|
|
|
JSObject::ForceSetPrototype(async_generator_object_prototype,
|
|
|
|
async_iterator_prototype);
|
2017-10-04 09:18:55 +00:00
|
|
|
native_context()->set_initial_async_generator_prototype(
|
|
|
|
*async_generator_object_prototype);
|
[async-iteration] implement AsyncGenerator
- Introduce new struct AsyncGeneratorRequest, which holds
information pertinent to resuming execution of an
AsyncGenerator, such as the Promise associated with the async
generator request. It is intended to be used as a singly
linked list, and holds a pointer to the next item in te queue.
- Introduce JSAsyncGeneratorObject (subclass of
JSGeneratorObject), which includes several new internal fields
(`queue` which contains a singly linked list of
AsyncGeneratorRequest objects, and `await_input` which
contains the sent value from an Await expression (This is
necessary to prevent function.sent (used by yield*) from
having the sent value observably overwritten during
execution).
- Modify SuspendGenerator to accept a set of Flags, which
indicate whether the suspend is for a Yield or Await, and
whether it takes place on an async generator or ES6
generator.
- Introduce interpreter intrinsics and TF intrinsic lowering for
accessing the await input of an async generator
- Modify the JSGeneratorStore operator to understand whether or
not it's suspending for a normal yield, or an AsyncGenerator
Await. This ensures appropriate registers are stored.
- Add versions of ResumeGeneratorTrampoline which store the
input value in a different field depending on wether it's an
AsyncGenerator Await resume, or an ordinary resume. Also modifies
whether debug code will assert that the generator object is a
JSGeneratorObject or a JSAsyncGeneratorObject depending on the
resume type.
BUG=v8:5855
R=bmeurer@chromium.org, rmcilroy@chromium.org, jgruber@chromium.org,
littledan@chromium.org, neis@chromium.org
TBR=marja@chromium.org
Change-Id: I9d58df1d344465fc937fe7eed322424204497187
Reviewed-on: https://chromium-review.googlesource.com/446961
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44240}
2017-03-29 13:41:45 +00:00
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate(), async_generator_object_prototype,
|
[async-iteration] implement AsyncGenerator
- Introduce new struct AsyncGeneratorRequest, which holds
information pertinent to resuming execution of an
AsyncGenerator, such as the Promise associated with the async
generator request. It is intended to be used as a singly
linked list, and holds a pointer to the next item in te queue.
- Introduce JSAsyncGeneratorObject (subclass of
JSGeneratorObject), which includes several new internal fields
(`queue` which contains a singly linked list of
AsyncGeneratorRequest objects, and `await_input` which
contains the sent value from an Await expression (This is
necessary to prevent function.sent (used by yield*) from
having the sent value observably overwritten during
execution).
- Modify SuspendGenerator to accept a set of Flags, which
indicate whether the suspend is for a Yield or Await, and
whether it takes place on an async generator or ES6
generator.
- Introduce interpreter intrinsics and TF intrinsic lowering for
accessing the await input of an async generator
- Modify the JSGeneratorStore operator to understand whether or
not it's suspending for a normal yield, or an AsyncGenerator
Await. This ensures appropriate registers are stored.
- Add versions of ResumeGeneratorTrampoline which store the
input value in a different field depending on wether it's an
AsyncGenerator Await resume, or an ordinary resume. Also modifies
whether debug code will assert that the generator object is a
JSGeneratorObject or a JSAsyncGeneratorObject depending on the
resume type.
BUG=v8:5855
R=bmeurer@chromium.org, rmcilroy@chromium.org, jgruber@chromium.org,
littledan@chromium.org, neis@chromium.org
TBR=marja@chromium.org
Change-Id: I9d58df1d344465fc937fe7eed322424204497187
Reviewed-on: https://chromium-review.googlesource.com/446961
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44240}
2017-03-29 13:41:45 +00:00
|
|
|
factory()->to_string_tag_symbol(),
|
|
|
|
factory()->NewStringFromAsciiChecked("AsyncGenerator"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), async_generator_object_prototype, "next",
|
2017-06-19 10:42:08 +00:00
|
|
|
Builtins::kAsyncGeneratorPrototypeNext, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), async_generator_object_prototype, "return",
|
2017-06-19 10:42:08 +00:00
|
|
|
Builtins::kAsyncGeneratorPrototypeReturn, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), async_generator_object_prototype, "throw",
|
2017-06-19 10:42:08 +00:00
|
|
|
Builtins::kAsyncGeneratorPrototypeThrow, 1, false);
|
[async-iteration] implement AsyncGenerator
- Introduce new struct AsyncGeneratorRequest, which holds
information pertinent to resuming execution of an
AsyncGenerator, such as the Promise associated with the async
generator request. It is intended to be used as a singly
linked list, and holds a pointer to the next item in te queue.
- Introduce JSAsyncGeneratorObject (subclass of
JSGeneratorObject), which includes several new internal fields
(`queue` which contains a singly linked list of
AsyncGeneratorRequest objects, and `await_input` which
contains the sent value from an Await expression (This is
necessary to prevent function.sent (used by yield*) from
having the sent value observably overwritten during
execution).
- Modify SuspendGenerator to accept a set of Flags, which
indicate whether the suspend is for a Yield or Await, and
whether it takes place on an async generator or ES6
generator.
- Introduce interpreter intrinsics and TF intrinsic lowering for
accessing the await input of an async generator
- Modify the JSGeneratorStore operator to understand whether or
not it's suspending for a normal yield, or an AsyncGenerator
Await. This ensures appropriate registers are stored.
- Add versions of ResumeGeneratorTrampoline which store the
input value in a different field depending on wether it's an
AsyncGenerator Await resume, or an ordinary resume. Also modifies
whether debug code will assert that the generator object is a
JSGeneratorObject or a JSAsyncGeneratorObject depending on the
resume type.
BUG=v8:5855
R=bmeurer@chromium.org, rmcilroy@chromium.org, jgruber@chromium.org,
littledan@chromium.org, neis@chromium.org
TBR=marja@chromium.org
Change-Id: I9d58df1d344465fc937fe7eed322424204497187
Reviewed-on: https://chromium-review.googlesource.com/446961
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44240}
2017-03-29 13:41:45 +00:00
|
|
|
|
|
|
|
// Create maps for generator functions and their prototypes. Store those
|
|
|
|
// maps in the native context. The "prototype" property descriptor is
|
|
|
|
// writable, non-enumerable, and non-configurable (as per ES6 draft
|
|
|
|
// 04-14-15, section 25.2.4.3).
|
|
|
|
// Async Generator functions do not have "caller" or "arguments" accessors.
|
2017-07-13 09:33:22 +00:00
|
|
|
Handle<Map> map;
|
2018-06-19 09:00:37 +00:00
|
|
|
map = CreateNonConstructorMap(isolate(), isolate()->strict_function_map(),
|
2017-07-13 09:33:22 +00:00
|
|
|
async_generator_function_prototype,
|
|
|
|
"AsyncGeneratorFunction");
|
|
|
|
native_context()->set_async_generator_function_map(*map);
|
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
map = CreateNonConstructorMap(
|
|
|
|
isolate(), isolate()->strict_function_with_name_map(),
|
|
|
|
async_generator_function_prototype, "AsyncGeneratorFunction with name");
|
2017-07-13 09:33:22 +00:00
|
|
|
native_context()->set_async_generator_function_with_name_map(*map);
|
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
map =
|
|
|
|
CreateNonConstructorMap(isolate(), strict_function_with_home_object_map_,
|
|
|
|
async_generator_function_prototype,
|
|
|
|
"AsyncGeneratorFunction with home object");
|
2017-07-13 09:33:22 +00:00
|
|
|
native_context()->set_async_generator_function_with_home_object_map(*map);
|
|
|
|
|
|
|
|
map = CreateNonConstructorMap(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate(), strict_function_with_name_and_home_object_map_,
|
2017-07-13 09:33:22 +00:00
|
|
|
async_generator_function_prototype,
|
|
|
|
"AsyncGeneratorFunction with name and home object");
|
|
|
|
native_context()->set_async_generator_function_with_name_and_home_object_map(
|
|
|
|
*map);
|
[async-iteration] implement AsyncGenerator
- Introduce new struct AsyncGeneratorRequest, which holds
information pertinent to resuming execution of an
AsyncGenerator, such as the Promise associated with the async
generator request. It is intended to be used as a singly
linked list, and holds a pointer to the next item in te queue.
- Introduce JSAsyncGeneratorObject (subclass of
JSGeneratorObject), which includes several new internal fields
(`queue` which contains a singly linked list of
AsyncGeneratorRequest objects, and `await_input` which
contains the sent value from an Await expression (This is
necessary to prevent function.sent (used by yield*) from
having the sent value observably overwritten during
execution).
- Modify SuspendGenerator to accept a set of Flags, which
indicate whether the suspend is for a Yield or Await, and
whether it takes place on an async generator or ES6
generator.
- Introduce interpreter intrinsics and TF intrinsic lowering for
accessing the await input of an async generator
- Modify the JSGeneratorStore operator to understand whether or
not it's suspending for a normal yield, or an AsyncGenerator
Await. This ensures appropriate registers are stored.
- Add versions of ResumeGeneratorTrampoline which store the
input value in a different field depending on wether it's an
AsyncGenerator Await resume, or an ordinary resume. Also modifies
whether debug code will assert that the generator object is a
JSGeneratorObject or a JSAsyncGeneratorObject depending on the
resume type.
BUG=v8:5855
R=bmeurer@chromium.org, rmcilroy@chromium.org, jgruber@chromium.org,
littledan@chromium.org, neis@chromium.org
TBR=marja@chromium.org
Change-Id: I9d58df1d344465fc937fe7eed322424204497187
Reviewed-on: https://chromium-review.googlesource.com/446961
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44240}
2017-03-29 13:41:45 +00:00
|
|
|
|
2018-05-31 08:31:07 +00:00
|
|
|
Handle<JSFunction> object_function(native_context()->object_function(),
|
|
|
|
isolate());
|
[async-iteration] implement AsyncGenerator
- Introduce new struct AsyncGeneratorRequest, which holds
information pertinent to resuming execution of an
AsyncGenerator, such as the Promise associated with the async
generator request. It is intended to be used as a singly
linked list, and holds a pointer to the next item in te queue.
- Introduce JSAsyncGeneratorObject (subclass of
JSGeneratorObject), which includes several new internal fields
(`queue` which contains a singly linked list of
AsyncGeneratorRequest objects, and `await_input` which
contains the sent value from an Await expression (This is
necessary to prevent function.sent (used by yield*) from
having the sent value observably overwritten during
execution).
- Modify SuspendGenerator to accept a set of Flags, which
indicate whether the suspend is for a Yield or Await, and
whether it takes place on an async generator or ES6
generator.
- Introduce interpreter intrinsics and TF intrinsic lowering for
accessing the await input of an async generator
- Modify the JSGeneratorStore operator to understand whether or
not it's suspending for a normal yield, or an AsyncGenerator
Await. This ensures appropriate registers are stored.
- Add versions of ResumeGeneratorTrampoline which store the
input value in a different field depending on wether it's an
AsyncGenerator Await resume, or an ordinary resume. Also modifies
whether debug code will assert that the generator object is a
JSGeneratorObject or a JSAsyncGeneratorObject depending on the
resume type.
BUG=v8:5855
R=bmeurer@chromium.org, rmcilroy@chromium.org, jgruber@chromium.org,
littledan@chromium.org, neis@chromium.org
TBR=marja@chromium.org
Change-Id: I9d58df1d344465fc937fe7eed322424204497187
Reviewed-on: https://chromium-review.googlesource.com/446961
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44240}
2017-03-29 13:41:45 +00:00
|
|
|
Handle<Map> async_generator_object_prototype_map = Map::Create(isolate(), 0);
|
2018-06-25 10:54:01 +00:00
|
|
|
Map::SetPrototype(isolate(), async_generator_object_prototype_map,
|
[async-iteration] implement AsyncGenerator
- Introduce new struct AsyncGeneratorRequest, which holds
information pertinent to resuming execution of an
AsyncGenerator, such as the Promise associated with the async
generator request. It is intended to be used as a singly
linked list, and holds a pointer to the next item in te queue.
- Introduce JSAsyncGeneratorObject (subclass of
JSGeneratorObject), which includes several new internal fields
(`queue` which contains a singly linked list of
AsyncGeneratorRequest objects, and `await_input` which
contains the sent value from an Await expression (This is
necessary to prevent function.sent (used by yield*) from
having the sent value observably overwritten during
execution).
- Modify SuspendGenerator to accept a set of Flags, which
indicate whether the suspend is for a Yield or Await, and
whether it takes place on an async generator or ES6
generator.
- Introduce interpreter intrinsics and TF intrinsic lowering for
accessing the await input of an async generator
- Modify the JSGeneratorStore operator to understand whether or
not it's suspending for a normal yield, or an AsyncGenerator
Await. This ensures appropriate registers are stored.
- Add versions of ResumeGeneratorTrampoline which store the
input value in a different field depending on wether it's an
AsyncGenerator Await resume, or an ordinary resume. Also modifies
whether debug code will assert that the generator object is a
JSGeneratorObject or a JSAsyncGeneratorObject depending on the
resume type.
BUG=v8:5855
R=bmeurer@chromium.org, rmcilroy@chromium.org, jgruber@chromium.org,
littledan@chromium.org, neis@chromium.org
TBR=marja@chromium.org
Change-Id: I9d58df1d344465fc937fe7eed322424204497187
Reviewed-on: https://chromium-review.googlesource.com/446961
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44240}
2017-03-29 13:41:45 +00:00
|
|
|
async_generator_object_prototype);
|
|
|
|
native_context()->set_async_generator_object_prototype_map(
|
|
|
|
*async_generator_object_prototype_map);
|
2017-02-24 17:48:49 +00:00
|
|
|
}
|
|
|
|
|
2016-05-17 00:26:53 +00:00
|
|
|
void Genesis::CreateAsyncFunctionMaps(Handle<JSFunction> empty) {
|
|
|
|
// %AsyncFunctionPrototype% intrinsic
|
|
|
|
Handle<JSObject> async_function_prototype =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
2016-07-19 11:28:43 +00:00
|
|
|
JSObject::ForceSetPrototype(async_function_prototype, empty);
|
2016-05-17 00:26:53 +00:00
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate(), async_function_prototype,
|
2016-05-17 00:26:53 +00:00
|
|
|
factory()->to_string_tag_symbol(),
|
|
|
|
factory()->NewStringFromAsciiChecked("AsyncFunction"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
2017-07-13 09:33:22 +00:00
|
|
|
Handle<Map> map;
|
|
|
|
map = CreateNonConstructorMap(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate(), isolate()->strict_function_without_prototype_map(),
|
2017-07-13 09:33:22 +00:00
|
|
|
async_function_prototype, "AsyncFunction");
|
|
|
|
native_context()->set_async_function_map(*map);
|
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
map = CreateNonConstructorMap(isolate(), isolate()->method_with_name_map(),
|
2017-07-13 09:33:22 +00:00
|
|
|
async_function_prototype,
|
|
|
|
"AsyncFunction with name");
|
|
|
|
native_context()->set_async_function_with_name_map(*map);
|
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
map = CreateNonConstructorMap(
|
|
|
|
isolate(), isolate()->method_with_home_object_map(),
|
|
|
|
async_function_prototype, "AsyncFunction with home object");
|
2017-07-13 09:33:22 +00:00
|
|
|
native_context()->set_async_function_with_home_object_map(*map);
|
|
|
|
|
|
|
|
map = CreateNonConstructorMap(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate(), isolate()->method_with_name_and_home_object_map(),
|
2017-07-13 09:33:22 +00:00
|
|
|
async_function_prototype, "AsyncFunction with name and home object");
|
|
|
|
native_context()->set_async_function_with_name_and_home_object_map(*map);
|
2016-05-17 00:26:53 +00:00
|
|
|
}
|
|
|
|
|
2016-03-21 19:39:16 +00:00
|
|
|
void Genesis::CreateJSProxyMaps() {
|
2017-07-03 13:40:13 +00:00
|
|
|
// Allocate maps for all Proxy types.
|
2016-03-21 19:39:16 +00:00
|
|
|
// Next to the default proxy, we need maps indicating callable and
|
|
|
|
// constructable proxies.
|
2017-11-22 11:17:03 +00:00
|
|
|
Handle<Map> proxy_map = factory()->NewMap(JS_PROXY_TYPE, JSProxy::kSize,
|
|
|
|
TERMINAL_FAST_ELEMENTS_KIND);
|
2017-12-07 11:03:41 +00:00
|
|
|
proxy_map->set_is_dictionary_map(true);
|
[builtins] Speed-up Object.prototype.toString.
The @@toStringTag lookup in Object.prototype.toString causes quite a
lot of overhead and oftentimes dominates the builtin performance. These
lookups are almost always negative, especially for primitive values,
and Object.prototype.toString is often used to implement predicates
(like in Node core or in AngularJS), so having a way to skip the
negative lookup yields big performance gains.
This CL introduces a "MayHaveInterestingSymbols" bit on every map,
which says whether instances with this map may have an interesting
symbol. Currently only @@toStringTag is considered an interesting
symbol, but we can extend that in the future.
In the Object.prototype.toString we can use the interesting symbols
bit to do a quick check on the prototype chain to see if there are
any maps that might have the @@toStringTag, and if not, we can just
immediately return the result, which is very fast because it's derived
from the instance type. This also avoids the ToObject conversions for
primitive values, which is important, since this causes unnecessary
GC traffic and in for example AngularJS, strings are also often probed
via the Object.prototype.toString based predicates.
This boosts Speedometer/AngularJS by over 3% and Speedometer overall
by up to 1%. On the microbenchmark from the similar SpiderMonkey bug
(https://bugzilla.mozilla.org/show_bug.cgi?id=1369042), we go from
roughly 450ms to 70ms, which corresponds to a 6.5x improvement.
```
function f() {
var res = "";
var a = [1, 2, 3];
var toString = Object.prototype.toString;
var t = new Date;
for (var i = 0; i < 5000000; i++)
res = toString.call(a);
print(new Date - t);
return res;
}
f();
```
The design document at https://goo.gl/e8CruQ has some additional
data points.
TBR=ulan@chromium.org
Bug: v8:6654
Change-Id: I31932cf41ecddad079d294e2c322a852af0ed244
Reviewed-on: https://chromium-review.googlesource.com/593620
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47034}
2017-08-01 08:11:14 +00:00
|
|
|
proxy_map->set_may_have_interesting_symbols(true);
|
2016-03-21 19:39:16 +00:00
|
|
|
native_context()->set_proxy_map(*proxy_map);
|
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
Handle<Map> proxy_callable_map =
|
|
|
|
Map::Copy(isolate_, proxy_map, "callable Proxy");
|
2017-12-07 11:03:41 +00:00
|
|
|
proxy_callable_map->set_is_callable(true);
|
2016-03-21 19:39:16 +00:00
|
|
|
native_context()->set_proxy_callable_map(*proxy_callable_map);
|
|
|
|
proxy_callable_map->SetConstructor(native_context()->function_function());
|
|
|
|
|
|
|
|
Handle<Map> proxy_constructor_map =
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::Copy(isolate_, proxy_callable_map, "constructor Proxy");
|
2016-03-21 19:39:16 +00:00
|
|
|
proxy_constructor_map->set_is_constructor(true);
|
|
|
|
native_context()->set_proxy_constructor_map(*proxy_constructor_map);
|
2018-01-05 14:40:40 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
Handle<Map> map =
|
|
|
|
factory()->NewMap(JS_OBJECT_TYPE, JSProxyRevocableResult::kSize,
|
|
|
|
TERMINAL_FAST_ELEMENTS_KIND, 2);
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::EnsureDescriptorSlack(isolate_, map, 2);
|
2018-01-05 14:40:40 +00:00
|
|
|
|
|
|
|
{ // proxy
|
2018-07-17 15:08:58 +00:00
|
|
|
Descriptor d = Descriptor::DataField(isolate(), factory()->proxy_string(),
|
2018-01-05 14:40:40 +00:00
|
|
|
JSProxyRevocableResult::kProxyIndex,
|
|
|
|
NONE, Representation::Tagged());
|
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
{ // revoke
|
2018-07-17 15:08:58 +00:00
|
|
|
Descriptor d = Descriptor::DataField(
|
|
|
|
isolate(), factory()->revoke_string(),
|
|
|
|
JSProxyRevocableResult::kRevokeIndex, NONE, Representation::Tagged());
|
2018-01-05 14:40:40 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
2018-06-25 10:54:01 +00:00
|
|
|
Map::SetPrototype(isolate(), map, isolate()->initial_object_prototype());
|
2018-01-05 14:40:40 +00:00
|
|
|
map->SetConstructor(native_context()->object_function());
|
|
|
|
|
|
|
|
native_context()->set_proxy_revocable_result_map(*map);
|
|
|
|
}
|
2016-03-21 19:39:16 +00:00
|
|
|
}
|
2015-10-16 11:27:14 +00:00
|
|
|
|
2017-07-10 07:57:09 +00:00
|
|
|
namespace {
|
2018-05-31 14:14:48 +00:00
|
|
|
void ReplaceAccessors(Isolate* isolate, Handle<Map> map, Handle<String> name,
|
2017-07-10 07:57:09 +00:00
|
|
|
PropertyAttributes attributes,
|
|
|
|
Handle<AccessorPair> accessor_pair) {
|
2014-05-19 10:47:00 +00:00
|
|
|
DescriptorArray* descriptors = map->instance_descriptors();
|
2018-05-31 14:14:48 +00:00
|
|
|
int idx = descriptors->SearchWithCache(isolate, *name, *map);
|
2016-12-21 16:40:00 +00:00
|
|
|
Descriptor d = Descriptor::AccessorConstant(name, accessor_pair, attributes);
|
|
|
|
descriptors->Replace(idx, &d);
|
2014-05-19 10:47:00 +00:00
|
|
|
}
|
2017-07-10 07:57:09 +00:00
|
|
|
} // namespace
|
2014-05-19 10:47:00 +00:00
|
|
|
|
2016-05-25 17:00:28 +00:00
|
|
|
void Genesis::AddRestrictedFunctionProperties(Handle<JSFunction> empty) {
|
2015-04-09 22:40:16 +00:00
|
|
|
PropertyAttributes rw_attribs = static_cast<PropertyAttributes>(DONT_ENUM);
|
2017-07-10 07:57:09 +00:00
|
|
|
Handle<JSFunction> thrower = GetThrowTypeErrorIntrinsic();
|
2015-04-09 22:40:16 +00:00
|
|
|
Handle<AccessorPair> accessors = factory()->NewAccessorPair();
|
|
|
|
accessors->set_getter(*thrower);
|
|
|
|
accessors->set_setter(*thrower);
|
|
|
|
|
2018-05-31 08:31:07 +00:00
|
|
|
Handle<Map> map(empty->map(), isolate());
|
2018-05-31 14:14:48 +00:00
|
|
|
ReplaceAccessors(isolate(), map, factory()->arguments_string(), rw_attribs,
|
|
|
|
accessors);
|
|
|
|
ReplaceAccessors(isolate(), map, factory()->caller_string(), rw_attribs,
|
|
|
|
accessors);
|
2011-03-17 20:28:17 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
static void AddToWeakNativeContextList(Isolate* isolate, Context* context) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(context->IsNativeContext());
|
2016-06-06 12:58:10 +00:00
|
|
|
Heap* heap = isolate->heap();
|
2010-12-07 11:31:57 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
{ // NOLINT
|
2016-06-06 12:58:10 +00:00
|
|
|
DCHECK(context->next_context_link()->IsUndefined(isolate));
|
2010-12-07 11:31:57 +00:00
|
|
|
// Check that context is not in the list yet.
|
2012-08-17 09:03:08 +00:00
|
|
|
for (Object* current = heap->native_contexts_list();
|
2016-06-06 12:58:10 +00:00
|
|
|
!current->IsUndefined(isolate);
|
2016-05-12 08:50:18 +00:00
|
|
|
current = Context::cast(current)->next_context_link()) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(current != context);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2015-05-27 14:13:04 +00:00
|
|
|
context->set(Context::NEXT_CONTEXT_LINK, heap->native_contexts_list(),
|
|
|
|
UPDATE_WEAK_WRITE_BARRIER);
|
2012-08-17 09:03:08 +00:00
|
|
|
heap->set_native_contexts_list(context);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
void Genesis::CreateRoots() {
|
2012-08-17 09:03:08 +00:00
|
|
|
// Allocate the native context FixedArray first and then patch the
|
2010-03-23 11:40:38 +00:00
|
|
|
// closure and extension object later (we need the empty function
|
|
|
|
// and the global object, but in order to create those, we need the
|
2012-08-17 09:03:08 +00:00
|
|
|
// native context).
|
2013-03-18 17:36:47 +00:00
|
|
|
native_context_ = factory()->NewNativeContext();
|
2018-05-31 14:14:48 +00:00
|
|
|
AddToWeakNativeContextList(isolate(), *native_context());
|
2012-08-17 09:03:08 +00:00
|
|
|
isolate()->set_context(*native_context());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
// Allocate the message listeners object.
|
|
|
|
{
|
2016-08-01 14:28:06 +00:00
|
|
|
Handle<TemplateList> list = TemplateList::New(isolate(), 1);
|
|
|
|
native_context()->set_message_listeners(*list);
|
2010-03-23 11:40:38 +00:00
|
|
|
}
|
|
|
|
}
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
|
|
|
|
|
2015-06-12 12:34:10 +00:00
|
|
|
void Genesis::InstallGlobalThisBinding() {
|
|
|
|
Handle<ScriptContextTable> script_contexts(
|
2018-05-31 08:31:07 +00:00
|
|
|
native_context()->script_context_table(), isolate());
|
2015-06-12 12:34:10 +00:00
|
|
|
Handle<ScopeInfo> scope_info = ScopeInfo::CreateGlobalThisBinding(isolate());
|
2018-05-02 13:57:26 +00:00
|
|
|
Handle<Context> context =
|
|
|
|
factory()->NewScriptContext(native_context(), scope_info);
|
2015-06-12 12:34:10 +00:00
|
|
|
|
|
|
|
// Go ahead and hook it up while we're at it.
|
|
|
|
int slot = scope_info->ReceiverContextSlotIndex();
|
|
|
|
DCHECK_EQ(slot, Context::MIN_CONTEXT_SLOTS);
|
|
|
|
context->set(slot, native_context()->global_proxy());
|
|
|
|
|
|
|
|
Handle<ScriptContextTable> new_script_contexts =
|
|
|
|
ScriptContextTable::Extend(script_contexts, context);
|
|
|
|
native_context()->set_script_context_table(*new_script_contexts);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-02 14:57:59 +00:00
|
|
|
Handle<JSGlobalObject> Genesis::CreateNewGlobals(
|
2015-07-06 07:09:07 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> global_proxy_template,
|
2015-01-14 16:42:15 +00:00
|
|
|
Handle<JSGlobalProxy> global_proxy) {
|
2014-07-01 12:12:34 +00:00
|
|
|
// The argument global_proxy_template aka data is an ObjectTemplateInfo.
|
2010-03-23 11:40:38 +00:00
|
|
|
// It has a constructor pointer that points at global_constructor which is a
|
|
|
|
// FunctionTemplateInfo.
|
2015-01-14 16:42:15 +00:00
|
|
|
// The global_proxy_constructor is used to (re)initialize the
|
2014-07-01 12:12:34 +00:00
|
|
|
// global_proxy. The global_proxy_constructor also has a prototype_template
|
|
|
|
// pointer that points at js_global_object_template which is an
|
|
|
|
// ObjectTemplateInfo.
|
2010-03-23 11:40:38 +00:00
|
|
|
// That in turn has a constructor pointer that points at
|
2014-07-01 12:12:34 +00:00
|
|
|
// js_global_object_constructor which is a FunctionTemplateInfo.
|
|
|
|
// js_global_object_constructor is used to make js_global_object_function
|
|
|
|
// js_global_object_function is used to make the new global_object.
|
2010-03-23 11:40:38 +00:00
|
|
|
//
|
|
|
|
// --- G l o b a l ---
|
2014-07-01 12:12:34 +00:00
|
|
|
// Step 1: Create a fresh JSGlobalObject.
|
|
|
|
Handle<JSFunction> js_global_object_function;
|
|
|
|
Handle<ObjectTemplateInfo> js_global_object_template;
|
|
|
|
if (!global_proxy_template.IsEmpty()) {
|
|
|
|
// Get prototype template of the global_proxy_template.
|
2010-03-23 11:40:38 +00:00
|
|
|
Handle<ObjectTemplateInfo> data =
|
2014-07-01 12:12:34 +00:00
|
|
|
v8::Utils::OpenHandle(*global_proxy_template);
|
2010-03-23 11:40:38 +00:00
|
|
|
Handle<FunctionTemplateInfo> global_constructor =
|
|
|
|
Handle<FunctionTemplateInfo>(
|
2018-06-20 10:10:43 +00:00
|
|
|
FunctionTemplateInfo::cast(data->constructor()), isolate());
|
2013-02-25 14:46:09 +00:00
|
|
|
Handle<Object> proto_template(global_constructor->prototype_template(),
|
|
|
|
isolate());
|
2016-06-06 12:58:10 +00:00
|
|
|
if (!proto_template->IsUndefined(isolate())) {
|
2014-07-01 12:12:34 +00:00
|
|
|
js_global_object_template =
|
2010-03-23 11:40:38 +00:00
|
|
|
Handle<ObjectTemplateInfo>::cast(proto_template);
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
}
|
2010-03-23 11:40:38 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-07-01 12:12:34 +00:00
|
|
|
if (js_global_object_template.is_null()) {
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<String> name = factory()->empty_string();
|
2016-06-27 18:03:59 +00:00
|
|
|
Handle<JSObject> prototype =
|
|
|
|
factory()->NewFunctionPrototype(isolate()->object_function());
|
2017-11-08 12:56:08 +00:00
|
|
|
NewFunctionArgs args = NewFunctionArgs::ForBuiltinWithPrototype(
|
2018-03-22 16:09:55 +00:00
|
|
|
name, prototype, JS_GLOBAL_OBJECT_TYPE, JSGlobalObject::kSize, 0,
|
2017-11-08 12:56:08 +00:00
|
|
|
Builtins::kIllegal, MUTABLE);
|
|
|
|
js_global_object_function = factory()->NewFunction(args);
|
2016-06-27 18:03:59 +00:00
|
|
|
#ifdef DEBUG
|
2018-06-19 09:00:37 +00:00
|
|
|
LookupIterator it(isolate(), prototype, factory()->constructor_string(),
|
2016-06-27 18:03:59 +00:00
|
|
|
LookupIterator::OWN_SKIP_INTERCEPTOR);
|
|
|
|
Handle<Object> value = Object::GetProperty(&it).ToHandleChecked();
|
|
|
|
DCHECK(it.IsFound());
|
|
|
|
DCHECK_EQ(*isolate()->object_function(), *value);
|
|
|
|
#endif
|
2010-03-23 11:40:38 +00:00
|
|
|
} else {
|
2014-07-01 12:12:34 +00:00
|
|
|
Handle<FunctionTemplateInfo> js_global_object_constructor(
|
2018-05-31 08:31:07 +00:00
|
|
|
FunctionTemplateInfo::cast(js_global_object_template->constructor()),
|
|
|
|
isolate());
|
2015-02-04 13:01:34 +00:00
|
|
|
js_global_object_function = ApiNatives::CreateApiFunction(
|
2016-06-27 18:03:59 +00:00
|
|
|
isolate(), js_global_object_constructor, factory()->the_hole_value(),
|
|
|
|
ApiNatives::GlobalObjectType);
|
2010-03-23 11:40:38 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2015-04-07 10:42:45 +00:00
|
|
|
js_global_object_function->initial_map()->set_is_prototype_map(true);
|
2017-12-07 11:03:41 +00:00
|
|
|
js_global_object_function->initial_map()->set_is_dictionary_map(true);
|
[builtins] Speed-up Object.prototype.toString.
The @@toStringTag lookup in Object.prototype.toString causes quite a
lot of overhead and oftentimes dominates the builtin performance. These
lookups are almost always negative, especially for primitive values,
and Object.prototype.toString is often used to implement predicates
(like in Node core or in AngularJS), so having a way to skip the
negative lookup yields big performance gains.
This CL introduces a "MayHaveInterestingSymbols" bit on every map,
which says whether instances with this map may have an interesting
symbol. Currently only @@toStringTag is considered an interesting
symbol, but we can extend that in the future.
In the Object.prototype.toString we can use the interesting symbols
bit to do a quick check on the prototype chain to see if there are
any maps that might have the @@toStringTag, and if not, we can just
immediately return the result, which is very fast because it's derived
from the instance type. This also avoids the ToObject conversions for
primitive values, which is important, since this causes unnecessary
GC traffic and in for example AngularJS, strings are also often probed
via the Object.prototype.toString based predicates.
This boosts Speedometer/AngularJS by over 3% and Speedometer overall
by up to 1%. On the microbenchmark from the similar SpiderMonkey bug
(https://bugzilla.mozilla.org/show_bug.cgi?id=1369042), we go from
roughly 450ms to 70ms, which corresponds to a 6.5x improvement.
```
function f() {
var res = "";
var a = [1, 2, 3];
var toString = Object.prototype.toString;
var t = new Date;
for (var i = 0; i < 5000000; i++)
res = toString.call(a);
print(new Date - t);
return res;
}
f();
```
The design document at https://goo.gl/e8CruQ has some additional
data points.
TBR=ulan@chromium.org
Bug: v8:6654
Change-Id: I31932cf41ecddad079d294e2c322a852af0ed244
Reviewed-on: https://chromium-review.googlesource.com/593620
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47034}
2017-08-01 08:11:14 +00:00
|
|
|
js_global_object_function->initial_map()->set_may_have_interesting_symbols(
|
|
|
|
true);
|
2015-11-02 14:57:59 +00:00
|
|
|
Handle<JSGlobalObject> global_object =
|
|
|
|
factory()->NewJSGlobalObject(js_global_object_function);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2015-01-14 16:42:15 +00:00
|
|
|
// Step 2: (re)initialize the global proxy object.
|
2010-03-23 11:40:38 +00:00
|
|
|
Handle<JSFunction> global_proxy_function;
|
2014-07-01 12:12:34 +00:00
|
|
|
if (global_proxy_template.IsEmpty()) {
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<String> name = factory()->empty_string();
|
2017-11-08 12:56:08 +00:00
|
|
|
NewFunctionArgs args = NewFunctionArgs::ForBuiltinWithPrototype(
|
2018-03-22 16:09:55 +00:00
|
|
|
name, factory()->the_hole_value(), JS_GLOBAL_PROXY_TYPE,
|
2017-11-08 12:56:08 +00:00
|
|
|
JSGlobalProxy::SizeWithEmbedderFields(0), 0, Builtins::kIllegal,
|
|
|
|
MUTABLE);
|
|
|
|
global_proxy_function = factory()->NewFunction(args);
|
2010-03-23 11:40:38 +00:00
|
|
|
} else {
|
|
|
|
Handle<ObjectTemplateInfo> data =
|
2014-07-01 12:12:34 +00:00
|
|
|
v8::Utils::OpenHandle(*global_proxy_template);
|
2010-03-23 11:40:38 +00:00
|
|
|
Handle<FunctionTemplateInfo> global_constructor(
|
2018-05-31 08:31:07 +00:00
|
|
|
FunctionTemplateInfo::cast(data->constructor()), isolate());
|
2015-02-04 13:01:34 +00:00
|
|
|
global_proxy_function = ApiNatives::CreateApiFunction(
|
2016-06-27 18:03:59 +00:00
|
|
|
isolate(), global_constructor, factory()->the_hole_value(),
|
|
|
|
ApiNatives::GlobalProxyType);
|
2010-03-23 11:40:38 +00:00
|
|
|
}
|
|
|
|
global_proxy_function->initial_map()->set_is_access_check_needed(true);
|
2016-02-08 13:49:47 +00:00
|
|
|
global_proxy_function->initial_map()->set_has_hidden_prototype(true);
|
[builtins] Speed-up Object.prototype.toString.
The @@toStringTag lookup in Object.prototype.toString causes quite a
lot of overhead and oftentimes dominates the builtin performance. These
lookups are almost always negative, especially for primitive values,
and Object.prototype.toString is often used to implement predicates
(like in Node core or in AngularJS), so having a way to skip the
negative lookup yields big performance gains.
This CL introduces a "MayHaveInterestingSymbols" bit on every map,
which says whether instances with this map may have an interesting
symbol. Currently only @@toStringTag is considered an interesting
symbol, but we can extend that in the future.
In the Object.prototype.toString we can use the interesting symbols
bit to do a quick check on the prototype chain to see if there are
any maps that might have the @@toStringTag, and if not, we can just
immediately return the result, which is very fast because it's derived
from the instance type. This also avoids the ToObject conversions for
primitive values, which is important, since this causes unnecessary
GC traffic and in for example AngularJS, strings are also often probed
via the Object.prototype.toString based predicates.
This boosts Speedometer/AngularJS by over 3% and Speedometer overall
by up to 1%. On the microbenchmark from the similar SpiderMonkey bug
(https://bugzilla.mozilla.org/show_bug.cgi?id=1369042), we go from
roughly 450ms to 70ms, which corresponds to a 6.5x improvement.
```
function f() {
var res = "";
var a = [1, 2, 3];
var toString = Object.prototype.toString;
var t = new Date;
for (var i = 0; i < 5000000; i++)
res = toString.call(a);
print(new Date - t);
return res;
}
f();
```
The design document at https://goo.gl/e8CruQ has some additional
data points.
TBR=ulan@chromium.org
Bug: v8:6654
Change-Id: I31932cf41ecddad079d294e2c322a852af0ed244
Reviewed-on: https://chromium-review.googlesource.com/593620
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47034}
2017-08-01 08:11:14 +00:00
|
|
|
global_proxy_function->initial_map()->set_may_have_interesting_symbols(true);
|
2016-12-13 11:24:24 +00:00
|
|
|
native_context()->set_global_proxy_function(*global_proxy_function);
|
2010-03-23 11:40:38 +00:00
|
|
|
|
|
|
|
// Set global_proxy.__proto__ to js_global after ConfigureGlobalObjects
|
|
|
|
// Return the global proxy.
|
|
|
|
|
2015-01-14 16:42:15 +00:00
|
|
|
factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function);
|
2010-03-23 11:40:38 +00:00
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
// Set the native context for the global object.
|
2014-07-01 12:12:34 +00:00
|
|
|
global_object->set_native_context(*native_context());
|
|
|
|
global_object->set_global_proxy(*global_proxy);
|
2016-12-13 11:24:24 +00:00
|
|
|
// Set the native context of the global proxy.
|
2012-08-20 11:35:50 +00:00
|
|
|
global_proxy->set_native_context(*native_context());
|
2016-12-13 11:24:24 +00:00
|
|
|
// Set the global proxy of the native context. If the native context has been
|
|
|
|
// deserialized, the global proxy is already correctly set up by the
|
|
|
|
// deserializer. Otherwise it's undefined.
|
2016-06-06 12:58:10 +00:00
|
|
|
DCHECK(native_context()
|
|
|
|
->get(Context::GLOBAL_PROXY_INDEX)
|
|
|
|
->IsUndefined(isolate()) ||
|
2015-01-14 16:42:15 +00:00
|
|
|
native_context()->global_proxy() == *global_proxy);
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_global_proxy(*global_proxy);
|
2016-12-13 11:24:24 +00:00
|
|
|
|
|
|
|
return global_object;
|
2010-03-23 11:40:38 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 11:24:24 +00:00
|
|
|
void Genesis::HookUpGlobalProxy(Handle<JSGlobalProxy> global_proxy) {
|
|
|
|
// Re-initialize the global proxy with the global proxy function from the
|
|
|
|
// snapshot, and then set up the link to the native context.
|
|
|
|
Handle<JSFunction> global_proxy_function(
|
2018-06-20 10:10:43 +00:00
|
|
|
native_context()->global_proxy_function(), isolate());
|
2016-12-13 11:24:24 +00:00
|
|
|
factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function);
|
|
|
|
Handle<JSObject> global_object(
|
2018-06-20 10:10:43 +00:00
|
|
|
JSObject::cast(native_context()->global_object()), isolate());
|
2016-12-13 11:24:24 +00:00
|
|
|
JSObject::ForceSetPrototype(global_proxy, global_object);
|
|
|
|
global_proxy->set_native_context(*native_context());
|
|
|
|
DCHECK(native_context()->global_proxy() == *global_proxy);
|
|
|
|
}
|
2010-03-23 11:40:38 +00:00
|
|
|
|
2015-12-01 23:35:57 +00:00
|
|
|
void Genesis::HookUpGlobalObject(Handle<JSGlobalObject> global_object) {
|
2015-11-02 14:57:59 +00:00
|
|
|
Handle<JSGlobalObject> global_object_from_snapshot(
|
2018-06-20 10:10:43 +00:00
|
|
|
JSGlobalObject::cast(native_context()->extension()), isolate());
|
2014-07-01 12:12:34 +00:00
|
|
|
native_context()->set_extension(*global_object);
|
|
|
|
native_context()->set_security_token(*global_object);
|
2015-01-13 08:48:00 +00:00
|
|
|
|
2014-07-01 12:12:34 +00:00
|
|
|
TransferNamedProperties(global_object_from_snapshot, global_object);
|
|
|
|
TransferIndexedProperties(global_object_from_snapshot, global_object);
|
2010-03-23 11:40:38 +00:00
|
|
|
}
|
|
|
|
|
2015-12-07 16:35:03 +00:00
|
|
|
static void InstallWithIntrinsicDefaultProto(Isolate* isolate,
|
|
|
|
Handle<JSFunction> function,
|
|
|
|
int context_index) {
|
|
|
|
Handle<Smi> index(Smi::FromInt(context_index), isolate);
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate, function,
|
|
|
|
isolate->factory()->native_context_index_symbol(),
|
|
|
|
index, NONE);
|
2015-12-07 16:35:03 +00:00
|
|
|
isolate->native_context()->set(context_index, *function);
|
|
|
|
}
|
|
|
|
|
2016-07-20 13:02:36 +00:00
|
|
|
static void InstallError(Isolate* isolate, Handle<JSObject> global,
|
|
|
|
Handle<String> name, int context_index) {
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
|
2017-06-30 08:54:01 +00:00
|
|
|
Handle<JSFunction> error_fun = InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate, global, name, JS_ERROR_TYPE, JSObject::kHeaderSize, 0,
|
2017-06-30 08:54:01 +00:00
|
|
|
factory->the_hole_value(), Builtins::kErrorConstructor, DONT_ENUM);
|
2016-07-20 13:02:36 +00:00
|
|
|
error_fun->shared()->DontAdaptArguments();
|
|
|
|
error_fun->shared()->set_length(1);
|
|
|
|
|
|
|
|
if (context_index == Context::ERROR_FUNCTION_INDEX) {
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate, error_fun, "captureStackTrace",
|
2016-09-27 22:29:37 +00:00
|
|
|
Builtins::kErrorCaptureStackTrace, 2, false);
|
2016-07-20 13:02:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InstallWithIntrinsicDefaultProto(isolate, error_fun, context_index);
|
|
|
|
|
|
|
|
{
|
2017-06-30 08:54:01 +00:00
|
|
|
// Setup %XXXErrorPrototype%.
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSObject> prototype(JSObject::cast(error_fun->instance_prototype()),
|
|
|
|
isolate);
|
2016-07-20 13:02:36 +00:00
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate, prototype, factory->name_string(), name,
|
|
|
|
DONT_ENUM);
|
|
|
|
JSObject::AddProperty(isolate, prototype, factory->message_string(),
|
2016-07-20 13:02:36 +00:00
|
|
|
factory->empty_string(), DONT_ENUM);
|
|
|
|
|
2016-08-03 12:20:39 +00:00
|
|
|
if (context_index == Context::ERROR_FUNCTION_INDEX) {
|
|
|
|
Handle<JSFunction> to_string_fun =
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate, prototype, factory->toString_string(),
|
2016-08-03 12:20:39 +00:00
|
|
|
Builtins::kErrorPrototypeToString, 0, true);
|
|
|
|
isolate->native_context()->set_error_to_string(*to_string_fun);
|
2017-07-04 13:46:27 +00:00
|
|
|
isolate->native_context()->set_initial_error_prototype(*prototype);
|
2016-08-03 12:20:39 +00:00
|
|
|
} else {
|
|
|
|
DCHECK(isolate->native_context()->error_to_string()->IsJSFunction());
|
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
InstallFunction(isolate, prototype, isolate->error_to_string(),
|
2016-08-03 12:20:39 +00:00
|
|
|
factory->toString_string(), DONT_ENUM);
|
2016-07-20 13:02:36 +00:00
|
|
|
|
|
|
|
Handle<JSFunction> global_error = isolate->error_function();
|
|
|
|
CHECK(JSReceiver::SetPrototype(error_fun, global_error, false,
|
2017-10-25 18:07:04 +00:00
|
|
|
kThrowOnError)
|
2016-07-20 13:02:36 +00:00
|
|
|
.FromMaybe(false));
|
|
|
|
CHECK(JSReceiver::SetPrototype(prototype,
|
|
|
|
handle(global_error->prototype(), isolate),
|
2017-10-25 18:07:04 +00:00
|
|
|
false, kThrowOnError)
|
2016-07-20 13:02:36 +00:00
|
|
|
.FromMaybe(false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<Map> initial_map(error_fun->initial_map(), isolate);
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::EnsureDescriptorSlack(isolate, initial_map, 1);
|
2016-07-20 13:02:36 +00:00
|
|
|
|
|
|
|
{
|
2017-10-27 09:06:44 +00:00
|
|
|
Handle<AccessorInfo> info = factory->error_stack_accessor();
|
2017-10-26 15:18:09 +00:00
|
|
|
Descriptor d = Descriptor::AccessorConstant(handle(info->name(), isolate),
|
|
|
|
info, DONT_ENUM);
|
2016-07-20 13:02:36 +00:00
|
|
|
initial_map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
}
|
2015-12-07 16:35:03 +00:00
|
|
|
|
2017-07-07 09:24:57 +00:00
|
|
|
namespace {
|
|
|
|
|
2017-11-08 12:56:08 +00:00
|
|
|
void InstallMakeError(Isolate* isolate, int builtin_id, int context_index) {
|
|
|
|
NewFunctionArgs args = NewFunctionArgs::ForBuiltinWithPrototype(
|
2018-03-22 16:09:55 +00:00
|
|
|
isolate->factory()->empty_string(), isolate->factory()->the_hole_value(),
|
|
|
|
JS_OBJECT_TYPE, JSObject::kHeaderSize, 0, builtin_id, MUTABLE);
|
2017-11-08 12:56:08 +00:00
|
|
|
|
|
|
|
Handle<JSFunction> function = isolate->factory()->NewFunction(args);
|
2016-08-09 07:36:19 +00:00
|
|
|
function->shared()->DontAdaptArguments();
|
|
|
|
isolate->native_context()->set(context_index, *function);
|
|
|
|
}
|
|
|
|
|
2017-07-07 09:24:57 +00:00
|
|
|
} // namespace
|
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
// This is only called if we are not using snapshots. The equivalent
|
2014-07-01 12:12:34 +00:00
|
|
|
// work in the snapshot case is done in HookUpGlobalObject.
|
2015-11-02 14:57:59 +00:00
|
|
|
void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
|
2015-07-13 09:45:43 +00:00
|
|
|
Handle<JSFunction> empty_function,
|
2016-02-02 07:25:30 +00:00
|
|
|
GlobalContextType context_type) {
|
2013-10-14 13:25:36 +00:00
|
|
|
// --- N a t i v e C o n t e x t ---
|
2018-05-02 13:57:26 +00:00
|
|
|
// Use the empty scope info.
|
|
|
|
native_context()->set_scope_info(empty_function->shared()->scope_info());
|
2017-10-13 16:33:03 +00:00
|
|
|
native_context()->set_previous(nullptr);
|
2010-03-23 11:40:38 +00:00
|
|
|
// Set extension and global object.
|
2014-07-01 12:12:34 +00:00
|
|
|
native_context()->set_extension(*global_object);
|
|
|
|
// Security setup: Set the security token of the native context to the global
|
|
|
|
// object. This makes the security check between two different contexts fail
|
|
|
|
// by default even in case of global object reinitialization.
|
|
|
|
native_context()->set_security_token(*global_object);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
Factory* factory = isolate_->factory();
|
2011-03-28 13:09:37 +00:00
|
|
|
|
2014-11-12 11:34:09 +00:00
|
|
|
Handle<ScriptContextTable> script_context_table =
|
|
|
|
factory->NewScriptContextTable();
|
|
|
|
native_context()->set_script_context_table(*script_context_table);
|
2015-06-12 12:34:10 +00:00
|
|
|
InstallGlobalThisBinding();
|
2014-11-07 16:29:13 +00:00
|
|
|
|
2016-01-04 08:10:13 +00:00
|
|
|
{ // --- O b j e c t ---
|
|
|
|
Handle<String> object_name = factory->Object_string();
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSFunction> object_function = isolate_->object_function();
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, global_object, object_name, object_function,
|
2016-01-04 08:10:13 +00:00
|
|
|
DONT_ENUM);
|
2016-04-25 11:44:13 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, factory->assign_string(),
|
2016-01-04 08:10:13 +00:00
|
|
|
Builtins::kObjectAssign, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "getOwnPropertyDescriptor",
|
2016-02-05 13:12:00 +00:00
|
|
|
Builtins::kObjectGetOwnPropertyDescriptor, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function,
|
2016-10-31 22:52:55 +00:00
|
|
|
factory->getOwnPropertyDescriptors_string(),
|
|
|
|
Builtins::kObjectGetOwnPropertyDescriptors, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "getOwnPropertyNames",
|
2018-06-25 01:19:41 +00:00
|
|
|
Builtins::kObjectGetOwnPropertyNames, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "getOwnPropertySymbols",
|
2016-01-15 09:51:41 +00:00
|
|
|
Builtins::kObjectGetOwnPropertySymbols, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "is", Builtins::kObjectIs,
|
|
|
|
2, true);
|
|
|
|
SimpleInstallFunction(isolate_, object_function, "preventExtensions",
|
2016-04-25 11:44:13 +00:00
|
|
|
Builtins::kObjectPreventExtensions, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "seal",
|
2016-04-25 11:44:13 +00:00
|
|
|
Builtins::kObjectSeal, 1, false);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSFunction> object_create = SimpleInstallFunction(
|
|
|
|
isolate_, object_function, factory->create_string(),
|
|
|
|
Builtins::kObjectCreate, 2, false);
|
2016-12-19 21:36:16 +00:00
|
|
|
native_context()->set_object_create(*object_create);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSFunction> object_define_properties =
|
|
|
|
SimpleInstallFunction(isolate_, object_function, "defineProperties",
|
|
|
|
Builtins::kObjectDefineProperties, 2, true);
|
2016-04-25 12:24:02 +00:00
|
|
|
native_context()->set_object_define_properties(*object_define_properties);
|
|
|
|
|
|
|
|
Handle<JSFunction> object_define_property = SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, object_function, factory->defineProperty_string(),
|
2016-04-25 12:24:02 +00:00
|
|
|
Builtins::kObjectDefineProperty, 3, true);
|
|
|
|
native_context()->set_object_define_property(*object_define_property);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "freeze",
|
|
|
|
Builtins::kObjectFreeze, 1, false);
|
2016-04-25 11:44:13 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSFunction> object_get_prototype_of =
|
|
|
|
SimpleInstallFunction(isolate_, object_function, "getPrototypeOf",
|
|
|
|
Builtins::kObjectGetPrototypeOf, 1, false);
|
2016-04-25 11:44:13 +00:00
|
|
|
native_context()->set_object_get_prototype_of(*object_get_prototype_of);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "setPrototypeOf",
|
2016-10-14 08:09:53 +00:00
|
|
|
Builtins::kObjectSetPrototypeOf, 2, false);
|
2016-04-25 11:44:13 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "isExtensible",
|
2018-04-23 08:13:39 +00:00
|
|
|
Builtins::kObjectIsExtensible, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "isFrozen",
|
2018-04-23 08:13:39 +00:00
|
|
|
Builtins::kObjectIsFrozen, 1, false);
|
2016-04-25 11:44:13 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSFunction> object_is_sealed =
|
|
|
|
SimpleInstallFunction(isolate_, object_function, "isSealed",
|
|
|
|
Builtins::kObjectIsSealed, 1, false);
|
2016-01-04 08:10:13 +00:00
|
|
|
native_context()->set_object_is_sealed(*object_is_sealed);
|
2016-04-25 11:44:13 +00:00
|
|
|
|
2016-01-08 06:40:18 +00:00
|
|
|
Handle<JSFunction> object_keys = SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, object_function, "keys", Builtins::kObjectKeys, 1, true);
|
2016-01-08 06:40:18 +00:00
|
|
|
native_context()->set_object_keys(*object_keys);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, factory->entries_string(),
|
2018-02-07 03:43:37 +00:00
|
|
|
Builtins::kObjectEntries, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, factory->values_string(),
|
2018-02-07 03:43:37 +00:00
|
|
|
Builtins::kObjectValues, 1, true);
|
2016-02-29 10:54:23 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, isolate_->initial_object_prototype(),
|
2016-04-29 10:14:42 +00:00
|
|
|
"__defineGetter__", Builtins::kObjectDefineGetter, 2,
|
|
|
|
true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, isolate_->initial_object_prototype(),
|
2016-04-29 10:14:42 +00:00
|
|
|
"__defineSetter__", Builtins::kObjectDefineSetter, 2,
|
|
|
|
true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, isolate_->initial_object_prototype(),
|
|
|
|
"hasOwnProperty",
|
2017-08-28 05:26:15 +00:00
|
|
|
Builtins::kObjectPrototypeHasOwnProperty, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, isolate_->initial_object_prototype(),
|
2016-04-29 10:14:42 +00:00
|
|
|
"__lookupGetter__", Builtins::kObjectLookupGetter, 1,
|
|
|
|
true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, isolate_->initial_object_prototype(),
|
2016-04-29 10:14:42 +00:00
|
|
|
"__lookupSetter__", Builtins::kObjectLookupSetter, 1,
|
|
|
|
true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, isolate_->initial_object_prototype(),
|
|
|
|
"isPrototypeOf",
|
[builtins] Properly optimize Object.prototype.isPrototypeOf.
Port the baseline implementation of Object.prototype.isPrototypeOf to
the CodeStubAssembler, sharing the existing prototype chain lookup logic
with the instanceof / OrdinaryHasInstance implementation. Based on that,
do the same in TurboFan, introducing a new JSHasInPrototypeChain
operator, which encapsulates the central prototype chain walk logic.
This speeds up Object.prototype.isPrototypeOf by more than a factor of
four, so that the code
A.prototype.isPrototypeOf(a)
is now performance-wise on par with
a instanceof A
for the case where A is a regular constructor function and a is an
instance of A.
Since instanceof does more than just the fundamental prototype chain
lookup, it was discovered in Node core that O.p.isPrototypeOf would
be a more appropriate alternative for certain sanity checks, since
it's less vulnerable to monkey-patching. In addition, the Object
builtin would also avoid the performance-cliff associated with
instanceof (due to the Symbol.hasInstance hook), as for example hit
by https://github.com/nodejs/node/pull/13403#issuecomment-305915874.
The main blocker was the missing performance of isPrototypeOf, since
it was still a JS builtin backed by a runtime call.
This CL also adds more test coverage for the
Object.prototype.isPrototypeOf builtin, especially when called from
optimized code.
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_chromium_rel_ng
BUG=v8:5269,v8:5989,v8:6483
R=jgruber@chromium.org
Review-Url: https://codereview.chromium.org/2934893002
Cr-Commit-Position: refs/heads/master@{#45925}
2017-06-13 19:14:00 +00:00
|
|
|
Builtins::kObjectPrototypeIsPrototypeOf, 1, true);
|
2016-07-12 06:38:40 +00:00
|
|
|
SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, isolate_->initial_object_prototype(), "propertyIsEnumerable",
|
2016-07-12 06:38:40 +00:00
|
|
|
Builtins::kObjectPrototypePropertyIsEnumerable, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSFunction> object_to_string =
|
|
|
|
SimpleInstallFunction(isolate_, isolate_->initial_object_prototype(),
|
|
|
|
factory->toString_string(),
|
|
|
|
Builtins::kObjectPrototypeToString, 0, true);
|
2017-04-14 22:22:40 +00:00
|
|
|
native_context()->set_object_to_string(*object_to_string);
|
2017-03-03 06:30:26 +00:00
|
|
|
Handle<JSFunction> object_value_of = SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, isolate_->initial_object_prototype(), "valueOf",
|
2017-03-03 06:30:26 +00:00
|
|
|
Builtins::kObjectPrototypeValueOf, 0, true);
|
|
|
|
native_context()->set_object_value_of(*object_value_of);
|
2016-10-14 11:24:44 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetterSetter(isolate_, isolate_->initial_object_prototype(),
|
2016-10-14 11:24:44 +00:00
|
|
|
factory->proto_string(),
|
|
|
|
Builtins::kObjectPrototypeGetProto,
|
|
|
|
Builtins::kObjectPrototypeSetProto, DONT_ENUM);
|
2017-12-19 19:42:59 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, isolate_->initial_object_prototype(),
|
|
|
|
"toLocaleString",
|
2017-12-19 19:42:59 +00:00
|
|
|
Builtins::kObjectPrototypeToLocaleString, 0, true);
|
2016-01-04 08:10:13 +00:00
|
|
|
}
|
2010-03-23 11:40:38 +00:00
|
|
|
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSObject> global(native_context()->global_object(), isolate());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2015-12-10 17:27:44 +00:00
|
|
|
{ // --- F u n c t i o n ---
|
2016-01-12 16:43:28 +00:00
|
|
|
Handle<JSFunction> prototype = empty_function;
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSFunction> function_fun =
|
|
|
|
InstallFunction(isolate_, global, "Function", JS_FUNCTION_TYPE,
|
|
|
|
JSFunction::kSizeWithPrototype, 0, prototype,
|
|
|
|
Builtins::kFunctionConstructor);
|
2017-07-07 09:24:57 +00:00
|
|
|
// Function instances are sloppy by default.
|
2018-05-31 14:14:48 +00:00
|
|
|
function_fun->set_prototype_or_initial_map(
|
|
|
|
*isolate_->sloppy_function_map());
|
2016-01-12 16:43:28 +00:00
|
|
|
function_fun->shared()->DontAdaptArguments();
|
|
|
|
function_fun->shared()->set_length(1);
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate_, function_fun,
|
2015-12-07 16:35:03 +00:00
|
|
|
Context::FUNCTION_FUNCTION_INDEX);
|
2015-12-10 17:27:44 +00:00
|
|
|
|
2016-01-12 16:43:28 +00:00
|
|
|
// Setup the methods on the %FunctionPrototype%.
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, prototype, factory->constructor_string(),
|
2017-07-07 09:24:57 +00:00
|
|
|
function_fun, DONT_ENUM);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, factory->apply_string(),
|
2016-01-12 16:43:28 +00:00
|
|
|
Builtins::kFunctionPrototypeApply, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, factory->bind_string(),
|
2016-12-01 21:15:08 +00:00
|
|
|
Builtins::kFastFunctionPrototypeBind, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, factory->call_string(),
|
2016-01-12 16:43:28 +00:00
|
|
|
Builtins::kFunctionPrototypeCall, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, factory->toString_string(),
|
2016-01-12 16:43:28 +00:00
|
|
|
Builtins::kFunctionPrototypeToString, 0, false);
|
|
|
|
|
2016-02-11 11:58:47 +00:00
|
|
|
// Install the @@hasInstance function.
|
2017-07-03 13:40:13 +00:00
|
|
|
Handle<JSFunction> has_instance = SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, prototype, factory->has_instance_symbol(),
|
|
|
|
"[Symbol.hasInstance]", Builtins::kFunctionPrototypeHasInstance, 1,
|
|
|
|
true,
|
2017-07-03 13:40:13 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY),
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
BuiltinFunctionId::kFunctionHasInstance);
|
2016-11-17 06:39:28 +00:00
|
|
|
native_context()->set_function_has_instance(*has_instance);
|
2016-02-11 11:58:47 +00:00
|
|
|
|
2017-07-07 09:24:57 +00:00
|
|
|
// Complete setting up function maps.
|
|
|
|
{
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_->sloppy_function_map()->SetConstructor(*function_fun);
|
|
|
|
isolate_->sloppy_function_with_name_map()->SetConstructor(*function_fun);
|
|
|
|
isolate_->sloppy_function_with_readonly_prototype_map()->SetConstructor(
|
2017-07-07 09:24:57 +00:00
|
|
|
*function_fun);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_->strict_function_map()->SetConstructor(*function_fun);
|
|
|
|
isolate_->strict_function_with_name_map()->SetConstructor(*function_fun);
|
2017-07-13 09:33:22 +00:00
|
|
|
strict_function_with_home_object_map_->SetConstructor(*function_fun);
|
|
|
|
strict_function_with_name_and_home_object_map_->SetConstructor(
|
|
|
|
*function_fun);
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_->strict_function_with_readonly_prototype_map()->SetConstructor(
|
2017-07-07 09:24:57 +00:00
|
|
|
*function_fun);
|
2016-01-12 16:43:28 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_->class_function_map()->SetConstructor(*function_fun);
|
2017-07-07 09:24:57 +00:00
|
|
|
}
|
2015-12-07 16:35:03 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2017-06-30 08:54:01 +00:00
|
|
|
{ // --- A s y n c F r o m S y n c I t e r a t o r
|
2017-09-07 07:24:11 +00:00
|
|
|
Handle<SharedFunctionInfo> info = SimpleCreateSharedFunctionInfo(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, Builtins::kAsyncIteratorValueUnwrap, factory->empty_string(),
|
2017-09-07 07:24:11 +00:00
|
|
|
1);
|
2017-02-24 17:48:49 +00:00
|
|
|
native_context()->set_async_iterator_value_unwrap_shared_fun(*info);
|
|
|
|
}
|
|
|
|
|
2018-05-14 08:55:07 +00:00
|
|
|
{ // --- A s y n c G e n e r a t o r ---
|
|
|
|
Handle<JSFunction> await_caught =
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleCreateFunction(isolate_, factory->empty_string(),
|
2018-05-14 08:55:07 +00:00
|
|
|
Builtins::kAsyncGeneratorAwaitCaught, 1, false);
|
|
|
|
native_context()->set_async_generator_await_caught(*await_caught);
|
|
|
|
|
|
|
|
Handle<JSFunction> await_uncaught =
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleCreateFunction(isolate_, factory->empty_string(),
|
2018-05-14 08:55:07 +00:00
|
|
|
Builtins::kAsyncGeneratorAwaitUncaught, 1, false);
|
|
|
|
native_context()->set_async_generator_await_uncaught(*await_uncaught);
|
|
|
|
|
|
|
|
Handle<SharedFunctionInfo> info = SimpleCreateSharedFunctionInfo(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, Builtins::kAsyncGeneratorAwaitResolveClosure,
|
2018-05-14 08:55:07 +00:00
|
|
|
factory->empty_string(), 1);
|
|
|
|
native_context()->set_async_generator_await_resolve_shared_fun(*info);
|
|
|
|
|
|
|
|
info = SimpleCreateSharedFunctionInfo(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, Builtins::kAsyncGeneratorAwaitRejectClosure,
|
2018-05-14 08:55:07 +00:00
|
|
|
factory->empty_string(), 1);
|
|
|
|
native_context()->set_async_generator_await_reject_shared_fun(*info);
|
|
|
|
|
|
|
|
info = SimpleCreateSharedFunctionInfo(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, Builtins::kAsyncGeneratorYieldResolveClosure,
|
2018-05-14 08:55:07 +00:00
|
|
|
factory->empty_string(), 1);
|
|
|
|
native_context()->set_async_generator_yield_resolve_shared_fun(*info);
|
|
|
|
|
|
|
|
info = SimpleCreateSharedFunctionInfo(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, Builtins::kAsyncGeneratorReturnResolveClosure,
|
2018-05-14 08:55:07 +00:00
|
|
|
factory->empty_string(), 1);
|
|
|
|
native_context()->set_async_generator_return_resolve_shared_fun(*info);
|
|
|
|
|
|
|
|
info = SimpleCreateSharedFunctionInfo(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, Builtins::kAsyncGeneratorReturnClosedResolveClosure,
|
2018-05-14 08:55:07 +00:00
|
|
|
factory->empty_string(), 1);
|
|
|
|
native_context()->set_async_generator_return_closed_resolve_shared_fun(
|
|
|
|
*info);
|
|
|
|
|
|
|
|
info = SimpleCreateSharedFunctionInfo(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, Builtins::kAsyncGeneratorReturnClosedRejectClosure,
|
2018-05-14 08:55:07 +00:00
|
|
|
factory->empty_string(), 1);
|
|
|
|
native_context()->set_async_generator_return_closed_reject_shared_fun(
|
|
|
|
*info);
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
{ // --- A r r a y ---
|
2017-08-07 12:12:37 +00:00
|
|
|
Handle<JSFunction> array_function = InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, global, "Array", JS_ARRAY_TYPE, JSArray::kSize, 0,
|
|
|
|
isolate_->initial_object_prototype(), Builtins::kArrayConstructor);
|
2008-09-16 10:12:32 +00:00
|
|
|
array_function->shared()->DontAdaptArguments();
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
array_function->shared()->set_builtin_function_id(
|
|
|
|
BuiltinFunctionId::kArrayConstructor);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// This seems a bit hackish, but we need to make sure Array.length
|
|
|
|
// is 1.
|
|
|
|
array_function->shared()->set_length(1);
|
2012-07-18 14:00:58 +00:00
|
|
|
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<Map> initial_map(array_function->initial_map(), isolate());
|
2013-06-28 13:16:14 +00:00
|
|
|
|
|
|
|
// This assert protects an optimization in
|
|
|
|
// HGraphBuilder::JSArrayBuilder::EmitMapCode()
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(initial_map->elements_kind() == GetInitialFastElementsKind());
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::EnsureDescriptorSlack(isolate_, initial_map, 1);
|
2012-07-23 16:18:25 +00:00
|
|
|
|
2012-07-18 14:00:58 +00:00
|
|
|
PropertyAttributes attribs = static_cast<PropertyAttributes>(
|
|
|
|
DONT_ENUM | DONT_DELETE);
|
|
|
|
|
2018-04-09 11:34:41 +00:00
|
|
|
STATIC_ASSERT(JSArray::kLengthDescriptorIndex == 0);
|
2012-07-18 14:00:58 +00:00
|
|
|
{ // Add length.
|
2017-10-27 09:06:44 +00:00
|
|
|
Descriptor d = Descriptor::AccessorConstant(
|
|
|
|
factory->length_string(), factory->array_length_accessor(), attribs);
|
2014-11-11 10:24:52 +00:00
|
|
|
initial_map->AppendDescriptor(&d);
|
2012-07-18 14:00:58 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate_, array_function,
|
2015-12-07 16:35:03 +00:00
|
|
|
Context::ARRAY_FUNCTION_INDEX);
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallSpeciesGetter(isolate_, array_function);
|
2013-04-25 16:00:32 +00:00
|
|
|
|
2013-06-25 16:31:07 +00:00
|
|
|
// Cache the array maps, needed by ArrayConstructorStub
|
|
|
|
CacheInitialJSArrayMaps(native_context(), initial_map);
|
2015-05-20 07:07:54 +00:00
|
|
|
|
2017-04-21 00:07:19 +00:00
|
|
|
// Set up %ArrayPrototype%.
|
2017-11-06 09:38:47 +00:00
|
|
|
// The %ArrayPrototype% has TERMINAL_FAST_ELEMENTS_KIND in order to ensure
|
|
|
|
// that constant functions stay constant after turning prototype to setup
|
|
|
|
// mode and back when constant field tracking is enabled.
|
2017-06-26 10:03:43 +00:00
|
|
|
Handle<JSArray> proto =
|
2017-11-06 09:38:47 +00:00
|
|
|
factory->NewJSArray(0, TERMINAL_FAST_ELEMENTS_KIND, TENURED);
|
2017-06-26 10:03:43 +00:00
|
|
|
JSFunction::SetPrototype(array_function, proto);
|
|
|
|
native_context()->set_initial_array_prototype(*proto);
|
2017-04-21 00:07:19 +00:00
|
|
|
|
2015-12-14 15:11:55 +00:00
|
|
|
Handle<JSFunction> is_arraylike = SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, array_function, "isArray", Builtins::kArrayIsArray, 1, true);
|
2015-12-14 15:11:55 +00:00
|
|
|
native_context()->set_is_arraylike(*is_arraylike);
|
2017-06-26 10:03:43 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, array_function, "from",
|
|
|
|
Builtins::kArrayFrom, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, array_function, "of", Builtins::kArrayOf, 0,
|
2018-02-08 17:27:59 +00:00
|
|
|
false);
|
2018-01-18 13:03:16 +00:00
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, proto, factory->constructor_string(),
|
|
|
|
array_function, DONT_ENUM);
|
2017-06-26 10:03:43 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "concat", Builtins::kArrayConcat, 1,
|
2017-12-05 04:14:36 +00:00
|
|
|
false);
|
2018-07-18 13:21:06 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "fill",
|
|
|
|
Builtins::kArrayPrototypeFill, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "find",
|
|
|
|
Builtins::kArrayPrototypeFind, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "findIndex",
|
2017-12-05 04:14:36 +00:00
|
|
|
Builtins::kArrayPrototypeFindIndex, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "pop", Builtins::kArrayPrototypePop,
|
|
|
|
0, false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "push",
|
|
|
|
Builtins::kArrayPrototypePush, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "shift",
|
|
|
|
Builtins::kArrayPrototypeShift, 0, false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "unshift", Builtins::kArrayUnshift,
|
|
|
|
1, false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "slice",
|
|
|
|
Builtins::kArrayPrototypeSlice, 2, false);
|
2018-04-16 09:24:22 +00:00
|
|
|
if (FLAG_enable_experimental_builtins) {
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "splice",
|
|
|
|
Builtins::kArraySpliceTorque, 2, false);
|
2018-04-16 09:24:22 +00:00
|
|
|
} else {
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "splice", Builtins::kArraySplice,
|
|
|
|
2, false);
|
2018-04-16 09:24:22 +00:00
|
|
|
}
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "includes", Builtins::kArrayIncludes,
|
|
|
|
1, false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "indexOf", Builtins::kArrayIndexOf,
|
|
|
|
1, false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "keys",
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
Builtins::kArrayPrototypeKeys, 0, true,
|
|
|
|
BuiltinFunctionId::kArrayKeys);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "entries",
|
|
|
|
Builtins::kArrayPrototypeEntries, 0, true,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
BuiltinFunctionId::kArrayEntries);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, factory->iterator_symbol(), "values",
|
2017-06-30 13:54:24 +00:00
|
|
|
Builtins::kArrayPrototypeValues, 0, true, DONT_ENUM,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
BuiltinFunctionId::kArrayValues);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "forEach", Builtins::kArrayForEach,
|
|
|
|
1, false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "filter", Builtins::kArrayFilter, 1,
|
|
|
|
false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "map", Builtins::kArrayMap, 1,
|
|
|
|
false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "every", Builtins::kArrayEvery, 1,
|
2017-06-26 10:03:43 +00:00
|
|
|
false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "some", Builtins::kArraySome, 1,
|
|
|
|
false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "reduce", Builtins::kArrayReduce, 1,
|
|
|
|
false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "reduceRight",
|
|
|
|
Builtins::kArrayReduceRight, 1, false);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2016-10-18 02:42:42 +00:00
|
|
|
{ // --- A r r a y I t e r a t o r ---
|
|
|
|
Handle<JSObject> iterator_prototype(
|
2018-06-20 10:10:43 +00:00
|
|
|
native_context()->initial_iterator_prototype(), isolate());
|
2016-10-18 02:42:42 +00:00
|
|
|
|
|
|
|
Handle<JSObject> array_iterator_prototype =
|
2018-05-31 14:14:48 +00:00
|
|
|
factory->NewJSObject(isolate_->object_function(), TENURED);
|
2016-10-18 02:42:42 +00:00
|
|
|
JSObject::ForceSetPrototype(array_iterator_prototype, iterator_prototype);
|
|
|
|
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, array_iterator_prototype, factory->to_string_tag_symbol(),
|
2016-10-18 02:42:42 +00:00
|
|
|
factory->ArrayIterator_string(),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, array_iterator_prototype, "next",
|
2017-07-03 13:40:13 +00:00
|
|
|
Builtins::kArrayIteratorPrototypeNext, 0, true,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
BuiltinFunctionId::kArrayIteratorNext);
|
2016-10-18 02:42:42 +00:00
|
|
|
|
[es2015] Refactor the JSArrayIterator.
This changes the JSArrayIterator to always have only a single instance
type, instead of the zoo of instance types that we had before, and
which became less useful with the specification update to when "next"
is loaded from the iterator now. This greatly simplifies the baseline
implementation of the array iterator, which now only looks at the
iterated object during %ArrayIteratorPrototype%.next invocations.
In TurboFan we introduce a new JSCreateArrayIterator operator, that
holds the IterationKind and get's the iterated object as input. When
optimizing %ArrayIteratorPrototype%.next in the JSCallReducer, we
check whether the receiver is a JSCreateArrayIterator, and if so,
we try to infer maps for the iterated object from there. If we find
any, we speculatively assume that these won't have changed during
iteration (as we did before with the previous approach), and generate
fast code for both JSArray and JSTypedArray iteration.
Drive-by-fix: Drop the fast_array_iteration protector, it's not
necessary anymore since we have the deoptimization guard bit in
the JSCallReducer now.
This addresses the performance cliff noticed in webpack 4. The minimal
repro on the tracking bug goes from
console.timeEnd: mono, 124.773000
console.timeEnd: poly, 670.353000
to
console.timeEnd: mono, 118.709000
console.timeEnd: poly, 141.393000
so that's a 4.7x improvement.
Also make presubmit happy by adding the missing #undef's.
Bug: v8:7510, v7:7514
Change-Id: I79a46bfa2cd0f0710e09365ef72519b1bbb667b5
Reviewed-on: https://chromium-review.googlesource.com/946098
Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51725}
2018-03-02 19:31:01 +00:00
|
|
|
Handle<JSFunction> array_iterator_function =
|
2018-05-31 14:14:48 +00:00
|
|
|
CreateFunction(isolate_, factory->ArrayIterator_string(),
|
[es2015] Refactor the JSArrayIterator.
This changes the JSArrayIterator to always have only a single instance
type, instead of the zoo of instance types that we had before, and
which became less useful with the specification update to when "next"
is loaded from the iterator now. This greatly simplifies the baseline
implementation of the array iterator, which now only looks at the
iterated object during %ArrayIteratorPrototype%.next invocations.
In TurboFan we introduce a new JSCreateArrayIterator operator, that
holds the IterationKind and get's the iterated object as input. When
optimizing %ArrayIteratorPrototype%.next in the JSCallReducer, we
check whether the receiver is a JSCreateArrayIterator, and if so,
we try to infer maps for the iterated object from there. If we find
any, we speculatively assume that these won't have changed during
iteration (as we did before with the previous approach), and generate
fast code for both JSArray and JSTypedArray iteration.
Drive-by-fix: Drop the fast_array_iteration protector, it's not
necessary anymore since we have the deoptimization guard bit in
the JSCallReducer now.
This addresses the performance cliff noticed in webpack 4. The minimal
repro on the tracking bug goes from
console.timeEnd: mono, 124.773000
console.timeEnd: poly, 670.353000
to
console.timeEnd: mono, 118.709000
console.timeEnd: poly, 141.393000
so that's a 4.7x improvement.
Also make presubmit happy by adding the missing #undef's.
Bug: v8:7510, v7:7514
Change-Id: I79a46bfa2cd0f0710e09365ef72519b1bbb667b5
Reviewed-on: https://chromium-review.googlesource.com/946098
Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51725}
2018-03-02 19:31:01 +00:00
|
|
|
JS_ARRAY_ITERATOR_TYPE, JSArrayIterator::kSize, 0,
|
|
|
|
array_iterator_prototype, Builtins::kIllegal);
|
2017-02-01 14:02:59 +00:00
|
|
|
array_iterator_function->shared()->set_native(false);
|
2016-10-18 02:42:42 +00:00
|
|
|
|
[es2015] Refactor the JSArrayIterator.
This changes the JSArrayIterator to always have only a single instance
type, instead of the zoo of instance types that we had before, and
which became less useful with the specification update to when "next"
is loaded from the iterator now. This greatly simplifies the baseline
implementation of the array iterator, which now only looks at the
iterated object during %ArrayIteratorPrototype%.next invocations.
In TurboFan we introduce a new JSCreateArrayIterator operator, that
holds the IterationKind and get's the iterated object as input. When
optimizing %ArrayIteratorPrototype%.next in the JSCallReducer, we
check whether the receiver is a JSCreateArrayIterator, and if so,
we try to infer maps for the iterated object from there. If we find
any, we speculatively assume that these won't have changed during
iteration (as we did before with the previous approach), and generate
fast code for both JSArray and JSTypedArray iteration.
Drive-by-fix: Drop the fast_array_iteration protector, it's not
necessary anymore since we have the deoptimization guard bit in
the JSCallReducer now.
This addresses the performance cliff noticed in webpack 4. The minimal
repro on the tracking bug goes from
console.timeEnd: mono, 124.773000
console.timeEnd: poly, 670.353000
to
console.timeEnd: mono, 118.709000
console.timeEnd: poly, 141.393000
so that's a 4.7x improvement.
Also make presubmit happy by adding the missing #undef's.
Bug: v8:7510, v7:7514
Change-Id: I79a46bfa2cd0f0710e09365ef72519b1bbb667b5
Reviewed-on: https://chromium-review.googlesource.com/946098
Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51725}
2018-03-02 19:31:01 +00:00
|
|
|
native_context()->set_initial_array_iterator_map(
|
|
|
|
array_iterator_function->initial_map());
|
2016-11-15 14:41:27 +00:00
|
|
|
native_context()->set_initial_array_iterator_prototype(
|
|
|
|
*array_iterator_prototype);
|
2016-10-18 02:42:42 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
{ // --- N u m b e r ---
|
2016-01-13 15:14:16 +00:00
|
|
|
Handle<JSFunction> number_fun = InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, global, "Number", JS_VALUE_TYPE, JSValue::kSize, 0,
|
|
|
|
isolate_->initial_object_prototype(), Builtins::kNumberConstructor);
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
number_fun->shared()->set_builtin_function_id(
|
|
|
|
BuiltinFunctionId::kNumberConstructor);
|
2016-01-13 15:14:16 +00:00
|
|
|
number_fun->shared()->DontAdaptArguments();
|
|
|
|
number_fun->shared()->set_length(1);
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate_, number_fun,
|
2015-12-07 16:35:03 +00:00
|
|
|
Context::NUMBER_FUNCTION_INDEX);
|
2016-07-05 10:03:38 +00:00
|
|
|
|
|
|
|
// Create the %NumberPrototype%
|
|
|
|
Handle<JSValue> prototype =
|
|
|
|
Handle<JSValue>::cast(factory->NewJSObject(number_fun, TENURED));
|
2016-10-07 13:05:07 +00:00
|
|
|
prototype->set_value(Smi::kZero);
|
2017-04-19 21:55:04 +00:00
|
|
|
JSFunction::SetPrototype(number_fun, prototype);
|
2016-07-05 10:03:38 +00:00
|
|
|
|
|
|
|
// Install the "constructor" property on the {prototype}.
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, prototype, factory->constructor_string(),
|
|
|
|
number_fun, DONT_ENUM);
|
2016-07-05 10:03:38 +00:00
|
|
|
|
|
|
|
// Install the Number.prototype methods.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toExponential",
|
2016-07-05 10:03:38 +00:00
|
|
|
Builtins::kNumberPrototypeToExponential, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toFixed",
|
2016-07-05 10:03:38 +00:00
|
|
|
Builtins::kNumberPrototypeToFixed, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toPrecision",
|
2016-07-05 10:03:38 +00:00
|
|
|
Builtins::kNumberPrototypeToPrecision, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toString",
|
2016-07-05 10:03:38 +00:00
|
|
|
Builtins::kNumberPrototypeToString, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "valueOf",
|
2016-07-05 10:03:38 +00:00
|
|
|
Builtins::kNumberPrototypeValueOf, 0, true);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toLocaleString",
|
2016-07-05 10:03:38 +00:00
|
|
|
Builtins::kNumberPrototypeToLocaleString, 0, false);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
|
|
|
// Install the Number functions.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, number_fun, "isFinite",
|
|
|
|
Builtins::kNumberIsFinite, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, number_fun, "isInteger",
|
|
|
|
Builtins::kNumberIsInteger, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, number_fun, "isNaN", Builtins::kNumberIsNaN,
|
2016-09-07 10:14:19 +00:00
|
|
|
1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, number_fun, "isSafeInteger",
|
2016-09-07 10:14:19 +00:00
|
|
|
Builtins::kNumberIsSafeInteger, 1, true);
|
2016-10-07 08:58:43 +00:00
|
|
|
|
|
|
|
// Install Number.parseFloat and Global.parseFloat.
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSFunction> parse_float_fun =
|
|
|
|
SimpleInstallFunction(isolate_, number_fun, "parseFloat",
|
|
|
|
Builtins::kNumberParseFloat, 1, true);
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, global_object,
|
2016-10-07 08:58:43 +00:00
|
|
|
factory->NewStringFromAsciiChecked("parseFloat"),
|
|
|
|
parse_float_fun, DONT_ENUM);
|
2016-10-18 12:44:48 +00:00
|
|
|
|
|
|
|
// Install Number.parseInt and Global.parseInt.
|
|
|
|
Handle<JSFunction> parse_int_fun = SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, number_fun, "parseInt", Builtins::kNumberParseInt, 2, true);
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, global_object,
|
2016-10-18 12:44:48 +00:00
|
|
|
factory->NewStringFromAsciiChecked("parseInt"),
|
|
|
|
parse_int_fun, DONT_ENUM);
|
2017-02-27 08:20:45 +00:00
|
|
|
|
|
|
|
// Install Number constants
|
|
|
|
double kMaxValue = 1.7976931348623157e+308;
|
|
|
|
double kMinValue = 5e-324;
|
2018-04-17 12:11:07 +00:00
|
|
|
double kMinSafeInteger = -kMaxSafeInteger;
|
2017-02-27 08:20:45 +00:00
|
|
|
double kEPS = 2.220446049250313e-16;
|
|
|
|
|
|
|
|
Handle<Object> infinity = factory->infinity_value();
|
|
|
|
Handle<Object> nan = factory->nan_value();
|
|
|
|
Handle<String> nan_name = factory->NewStringFromAsciiChecked("NaN");
|
|
|
|
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, number_fun, factory->NewStringFromAsciiChecked("MAX_VALUE"),
|
2017-02-27 08:20:45 +00:00
|
|
|
factory->NewNumber(kMaxValue),
|
|
|
|
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY));
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, number_fun, factory->NewStringFromAsciiChecked("MIN_VALUE"),
|
2017-02-27 08:20:45 +00:00
|
|
|
factory->NewNumber(kMinValue),
|
|
|
|
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY));
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, number_fun, nan_name, nan,
|
2017-02-27 08:20:45 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY));
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, number_fun,
|
|
|
|
factory->NewStringFromAsciiChecked("NEGATIVE_INFINITY"),
|
2017-02-27 08:20:45 +00:00
|
|
|
factory->NewNumber(-V8_INFINITY),
|
|
|
|
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY));
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, number_fun,
|
|
|
|
factory->NewStringFromAsciiChecked("POSITIVE_INFINITY"), infinity,
|
2017-02-27 08:20:45 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY));
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, number_fun,
|
|
|
|
factory->NewStringFromAsciiChecked("MAX_SAFE_INTEGER"),
|
2018-04-17 12:11:07 +00:00
|
|
|
factory->NewNumber(kMaxSafeInteger),
|
2017-02-27 08:20:45 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY));
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, number_fun,
|
|
|
|
factory->NewStringFromAsciiChecked("MIN_SAFE_INTEGER"),
|
2018-04-17 12:11:07 +00:00
|
|
|
factory->NewNumber(kMinSafeInteger),
|
2017-02-27 08:20:45 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY));
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, number_fun, factory->NewStringFromAsciiChecked("EPSILON"),
|
2017-02-27 08:20:45 +00:00
|
|
|
factory->NewNumber(kEPS),
|
|
|
|
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY));
|
|
|
|
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, global, factory->NewStringFromAsciiChecked("Infinity"),
|
|
|
|
infinity,
|
2017-02-27 08:20:45 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY));
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, global, nan_name, nan,
|
2017-02-27 08:20:45 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY));
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, global, factory->NewStringFromAsciiChecked("undefined"),
|
2017-02-27 08:20:45 +00:00
|
|
|
factory->undefined_value(),
|
|
|
|
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // --- B o o l e a n ---
|
2017-10-18 20:14:09 +00:00
|
|
|
Handle<JSFunction> boolean_fun = InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, global, "Boolean", JS_VALUE_TYPE, JSValue::kSize, 0,
|
|
|
|
isolate_->initial_object_prototype(), Builtins::kBooleanConstructor);
|
2016-02-16 14:02:59 +00:00
|
|
|
boolean_fun->shared()->DontAdaptArguments();
|
|
|
|
boolean_fun->shared()->set_length(1);
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate_, boolean_fun,
|
2015-12-07 16:35:03 +00:00
|
|
|
Context::BOOLEAN_FUNCTION_INDEX);
|
2016-02-17 10:35:53 +00:00
|
|
|
|
|
|
|
// Create the %BooleanPrototype%
|
|
|
|
Handle<JSValue> prototype =
|
|
|
|
Handle<JSValue>::cast(factory->NewJSObject(boolean_fun, TENURED));
|
2018-07-04 09:10:05 +00:00
|
|
|
prototype->set_value(ReadOnlyRoots(isolate_).false_value());
|
2017-04-19 21:55:04 +00:00
|
|
|
JSFunction::SetPrototype(boolean_fun, prototype);
|
2016-02-17 10:35:53 +00:00
|
|
|
|
|
|
|
// Install the "constructor" property on the {prototype}.
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, prototype, factory->constructor_string(),
|
|
|
|
boolean_fun, DONT_ENUM);
|
2016-02-17 10:35:53 +00:00
|
|
|
|
|
|
|
// Install the Boolean.prototype methods.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toString",
|
2016-07-05 10:03:38 +00:00
|
|
|
Builtins::kBooleanPrototypeToString, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "valueOf",
|
2016-07-05 10:03:38 +00:00
|
|
|
Builtins::kBooleanPrototypeValueOf, 0, true);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // --- S t r i n g ---
|
2015-09-16 10:44:36 +00:00
|
|
|
Handle<JSFunction> string_fun = InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, global, "String", JS_VALUE_TYPE, JSValue::kSize, 0,
|
|
|
|
isolate_->initial_object_prototype(), Builtins::kStringConstructor);
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
string_fun->shared()->set_builtin_function_id(
|
|
|
|
BuiltinFunctionId::kStringConstructor);
|
2015-09-16 10:44:36 +00:00
|
|
|
string_fun->shared()->DontAdaptArguments();
|
|
|
|
string_fun->shared()->set_length(1);
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate_, string_fun,
|
2015-12-07 16:35:03 +00:00
|
|
|
Context::STRING_FUNCTION_INDEX);
|
2012-07-18 14:00:58 +00:00
|
|
|
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<Map> string_map = Handle<Map>(
|
|
|
|
native_context()->string_function()->initial_map(), isolate());
|
2016-01-29 18:57:26 +00:00
|
|
|
string_map->set_elements_kind(FAST_STRING_WRAPPER_ELEMENTS);
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::EnsureDescriptorSlack(isolate_, string_map, 1);
|
2012-07-23 16:18:25 +00:00
|
|
|
|
2012-07-18 14:00:58 +00:00
|
|
|
PropertyAttributes attribs = static_cast<PropertyAttributes>(
|
|
|
|
DONT_ENUM | DONT_DELETE | READ_ONLY);
|
|
|
|
|
|
|
|
{ // Add length.
|
2017-10-27 09:06:44 +00:00
|
|
|
Descriptor d = Descriptor::AccessorConstant(
|
|
|
|
factory->length_string(), factory->string_length_accessor(), attribs);
|
2014-04-11 12:13:53 +00:00
|
|
|
string_map->AppendDescriptor(&d);
|
2012-07-18 14:00:58 +00:00
|
|
|
}
|
2016-04-12 10:29:49 +00:00
|
|
|
|
2016-05-21 16:58:17 +00:00
|
|
|
// Install the String.fromCharCode function.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, string_fun, "fromCharCode",
|
2016-11-07 21:26:18 +00:00
|
|
|
Builtins::kStringFromCharCode, 1, false);
|
2016-05-21 16:58:17 +00:00
|
|
|
|
2016-06-27 13:47:35 +00:00
|
|
|
// Install the String.fromCodePoint function.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, string_fun, "fromCodePoint",
|
2016-06-27 13:47:35 +00:00
|
|
|
Builtins::kStringFromCodePoint, 1, false);
|
|
|
|
|
2017-10-19 12:55:32 +00:00
|
|
|
// Install the String.raw function.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, string_fun, "raw", Builtins::kStringRaw, 1,
|
|
|
|
false);
|
2017-10-19 12:55:32 +00:00
|
|
|
|
2016-04-12 10:29:49 +00:00
|
|
|
// Create the %StringPrototype%
|
|
|
|
Handle<JSValue> prototype =
|
|
|
|
Handle<JSValue>::cast(factory->NewJSObject(string_fun, TENURED));
|
2018-07-04 09:10:05 +00:00
|
|
|
prototype->set_value(ReadOnlyRoots(isolate_).empty_string());
|
2017-04-19 21:55:04 +00:00
|
|
|
JSFunction::SetPrototype(string_fun, prototype);
|
2017-10-30 15:51:26 +00:00
|
|
|
native_context()->set_initial_string_prototype(*prototype);
|
2016-04-12 10:29:49 +00:00
|
|
|
|
|
|
|
// Install the "constructor" property on the {prototype}.
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, prototype, factory->constructor_string(),
|
|
|
|
string_fun, DONT_ENUM);
|
2016-04-12 10:29:49 +00:00
|
|
|
|
|
|
|
// Install the String.prototype methods.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "anchor",
|
|
|
|
Builtins::kStringPrototypeAnchor, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "big",
|
|
|
|
Builtins::kStringPrototypeBig, 0, true);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "blink",
|
|
|
|
Builtins::kStringPrototypeBlink, 0, true);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "bold",
|
|
|
|
Builtins::kStringPrototypeBold, 0, true);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "charAt",
|
|
|
|
Builtins::kStringPrototypeCharAt, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "charCodeAt",
|
2016-04-12 10:29:49 +00:00
|
|
|
Builtins::kStringPrototypeCharCodeAt, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "codePointAt",
|
2017-07-19 17:56:58 +00:00
|
|
|
Builtins::kStringPrototypeCodePointAt, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "concat",
|
|
|
|
Builtins::kStringPrototypeConcat, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "endsWith",
|
2016-10-11 11:27:55 +00:00
|
|
|
Builtins::kStringPrototypeEndsWith, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "fontcolor",
|
[builtins] Convert String HTML functions (ex. anchor, big, bold) to CSA
- Added TFJ builtins for S.p.{anchor, big, blink, bold, fontcolor,
fontsize, fixed, italics, link, small, strike, sub, sup}
- Removed functionality from string.js
Bug: v8:5049
Change-Id: I3a91b52eaceef5c47bb55ed62780d72ef1e802e9
Reviewed-on: https://chromium-review.googlesource.com/666487
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48056}
2017-09-15 19:24:24 +00:00
|
|
|
Builtins::kStringPrototypeFontcolor, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "fontsize",
|
[builtins] Convert String HTML functions (ex. anchor, big, bold) to CSA
- Added TFJ builtins for S.p.{anchor, big, blink, bold, fontcolor,
fontsize, fixed, italics, link, small, strike, sub, sup}
- Removed functionality from string.js
Bug: v8:5049
Change-Id: I3a91b52eaceef5c47bb55ed62780d72ef1e802e9
Reviewed-on: https://chromium-review.googlesource.com/666487
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48056}
2017-09-15 19:24:24 +00:00
|
|
|
Builtins::kStringPrototypeFontsize, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "fixed",
|
|
|
|
Builtins::kStringPrototypeFixed, 0, true);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "includes",
|
2016-10-10 15:01:21 +00:00
|
|
|
Builtins::kStringPrototypeIncludes, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "indexOf",
|
2016-10-07 17:03:55 +00:00
|
|
|
Builtins::kStringPrototypeIndexOf, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "italics",
|
[builtins] Convert String HTML functions (ex. anchor, big, bold) to CSA
- Added TFJ builtins for S.p.{anchor, big, blink, bold, fontcolor,
fontsize, fixed, italics, link, small, strike, sub, sup}
- Removed functionality from string.js
Bug: v8:5049
Change-Id: I3a91b52eaceef5c47bb55ed62780d72ef1e802e9
Reviewed-on: https://chromium-review.googlesource.com/666487
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48056}
2017-09-15 19:24:24 +00:00
|
|
|
Builtins::kStringPrototypeItalics, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "lastIndexOf",
|
2016-09-19 10:22:30 +00:00
|
|
|
Builtins::kStringPrototypeLastIndexOf, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "link",
|
|
|
|
Builtins::kStringPrototypeLink, 1, true);
|
2018-07-27 00:14:24 +00:00
|
|
|
#ifdef V8_INTL_SUPPORT
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "localeCompare",
|
|
|
|
Builtins::kStringPrototypeLocaleCompare, 1, false);
|
|
|
|
#else
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "localeCompare",
|
2016-09-12 11:39:57 +00:00
|
|
|
Builtins::kStringPrototypeLocaleCompare, 1, true);
|
2018-07-27 00:14:24 +00:00
|
|
|
#endif // V8_INTL_SUPPORT
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "match",
|
|
|
|
Builtins::kStringPrototypeMatch, 1, true);
|
2017-04-21 08:35:12 +00:00
|
|
|
#ifdef V8_INTL_SUPPORT
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "normalize",
|
2017-04-21 08:35:12 +00:00
|
|
|
Builtins::kStringPrototypeNormalizeIntl, 0, false);
|
2017-03-31 21:27:30 +00:00
|
|
|
#else
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "normalize",
|
2016-09-12 10:53:36 +00:00
|
|
|
Builtins::kStringPrototypeNormalize, 0, false);
|
2017-04-21 08:35:12 +00:00
|
|
|
#endif // V8_INTL_SUPPORT
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "padEnd",
|
|
|
|
Builtins::kStringPrototypePadEnd, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "padStart",
|
2017-10-16 13:23:28 +00:00
|
|
|
Builtins::kStringPrototypePadStart, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "repeat",
|
|
|
|
Builtins::kStringPrototypeRepeat, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "replace",
|
2017-02-02 11:31:01 +00:00
|
|
|
Builtins::kStringPrototypeReplace, 2, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "search",
|
|
|
|
Builtins::kStringPrototypeSearch, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "slice",
|
|
|
|
Builtins::kStringPrototypeSlice, 2, false);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "small",
|
|
|
|
Builtins::kStringPrototypeSmall, 0, true);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "split",
|
|
|
|
Builtins::kStringPrototypeSplit, 2, false);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "strike",
|
|
|
|
Builtins::kStringPrototypeStrike, 0, true);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "sub",
|
|
|
|
Builtins::kStringPrototypeSub, 0, true);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "substr",
|
|
|
|
Builtins::kStringPrototypeSubstr, 2, false);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "substring",
|
2017-06-08 14:29:09 +00:00
|
|
|
Builtins::kStringPrototypeSubstring, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "sup",
|
|
|
|
Builtins::kStringPrototypeSup, 0, true);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "startsWith",
|
2016-10-11 11:35:59 +00:00
|
|
|
Builtins::kStringPrototypeStartsWith, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toString",
|
2016-07-05 10:03:38 +00:00
|
|
|
Builtins::kStringPrototypeToString, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "trim",
|
|
|
|
Builtins::kStringPrototypeTrim, 0, false);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "trimLeft",
|
2018-01-19 13:05:01 +00:00
|
|
|
Builtins::kStringPrototypeTrimStart, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "trimRight",
|
2018-01-19 13:05:01 +00:00
|
|
|
Builtins::kStringPrototypeTrimEnd, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toLocaleLowerCase",
|
2017-02-16 13:01:41 +00:00
|
|
|
Builtins::kStringPrototypeToLocaleLowerCase, 0,
|
|
|
|
false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toLocaleUpperCase",
|
2017-02-16 13:01:41 +00:00
|
|
|
Builtins::kStringPrototypeToLocaleUpperCase, 0,
|
|
|
|
false);
|
2018-07-26 22:08:25 +00:00
|
|
|
#ifdef V8_INTL_SUPPORT
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "toLowerCase",
|
|
|
|
Builtins::kStringPrototypeToLowerCaseIntl, 0, true);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "toUpperCase",
|
|
|
|
Builtins::kStringPrototypeToUpperCaseIntl, 0, false);
|
|
|
|
#else
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toLowerCase",
|
2017-02-16 13:01:41 +00:00
|
|
|
Builtins::kStringPrototypeToLowerCase, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toUpperCase",
|
2017-02-16 13:01:41 +00:00
|
|
|
Builtins::kStringPrototypeToUpperCase, 0, false);
|
2017-06-29 03:01:13 +00:00
|
|
|
#endif
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "valueOf",
|
2016-07-05 10:03:38 +00:00
|
|
|
Builtins::kStringPrototypeValueOf, 0, true);
|
2016-09-21 14:17:42 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, factory->iterator_symbol(),
|
2017-07-03 13:40:13 +00:00
|
|
|
"[Symbol.iterator]",
|
|
|
|
Builtins::kStringPrototypeIterator, 0, true,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
DONT_ENUM, BuiltinFunctionId::kStringIterator);
|
2016-09-21 14:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // --- S t r i n g I t e r a t o r ---
|
|
|
|
Handle<JSObject> iterator_prototype(
|
2018-06-20 10:10:43 +00:00
|
|
|
native_context()->initial_iterator_prototype(), isolate());
|
2016-09-21 14:17:42 +00:00
|
|
|
|
|
|
|
Handle<JSObject> string_iterator_prototype =
|
2018-05-31 14:14:48 +00:00
|
|
|
factory->NewJSObject(isolate_->object_function(), TENURED);
|
2016-09-21 14:17:42 +00:00
|
|
|
JSObject::ForceSetPrototype(string_iterator_prototype, iterator_prototype);
|
|
|
|
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, string_iterator_prototype, factory->to_string_tag_symbol(),
|
2016-09-21 14:17:42 +00:00
|
|
|
factory->NewStringFromAsciiChecked("String Iterator"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, string_iterator_prototype, "next",
|
2017-07-03 13:40:13 +00:00
|
|
|
Builtins::kStringIteratorPrototypeNext, 0, true,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
BuiltinFunctionId::kStringIteratorNext);
|
2016-09-21 14:17:42 +00:00
|
|
|
|
|
|
|
Handle<JSFunction> string_iterator_function = CreateFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, factory->NewStringFromAsciiChecked("StringIterator"),
|
2017-10-18 20:14:09 +00:00
|
|
|
JS_STRING_ITERATOR_TYPE, JSStringIterator::kSize, 0,
|
2016-09-21 14:17:42 +00:00
|
|
|
string_iterator_prototype, Builtins::kIllegal);
|
2017-02-01 14:02:59 +00:00
|
|
|
string_iterator_function->shared()->set_native(false);
|
2016-09-21 14:17:42 +00:00
|
|
|
native_context()->set_string_iterator_map(
|
|
|
|
string_iterator_function->initial_map());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2017-06-30 08:54:01 +00:00
|
|
|
{ // --- S y m b o l ---
|
|
|
|
Handle<JSFunction> symbol_fun = InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, global, "Symbol", JS_VALUE_TYPE, JSValue::kSize, 0,
|
2017-06-30 08:54:01 +00:00
|
|
|
factory->the_hole_value(), Builtins::kSymbolConstructor);
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
symbol_fun->shared()->set_builtin_function_id(
|
|
|
|
BuiltinFunctionId::kSymbolConstructor);
|
2016-04-05 10:56:16 +00:00
|
|
|
symbol_fun->shared()->set_length(0);
|
2015-12-28 20:17:13 +00:00
|
|
|
symbol_fun->shared()->DontAdaptArguments();
|
2014-08-06 09:31:21 +00:00
|
|
|
native_context()->set_symbol_function(*symbol_fun);
|
2016-01-15 09:51:41 +00:00
|
|
|
|
2016-12-06 13:21:20 +00:00
|
|
|
// Install the Symbol.for and Symbol.keyFor functions.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, symbol_fun, "for", Builtins::kSymbolFor, 1,
|
2016-12-06 13:21:20 +00:00
|
|
|
false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, symbol_fun, "keyFor",
|
|
|
|
Builtins::kSymbolKeyFor, 1, false);
|
2016-12-06 13:21:20 +00:00
|
|
|
|
|
|
|
// Install well-known symbols.
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallConstant(isolate_, symbol_fun, "asyncIterator",
|
2018-01-12 19:33:13 +00:00
|
|
|
factory->async_iterator_symbol());
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallConstant(isolate_, symbol_fun, "hasInstance",
|
2016-12-06 13:21:20 +00:00
|
|
|
factory->has_instance_symbol());
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallConstant(isolate_, symbol_fun, "isConcatSpreadable",
|
2016-12-06 13:21:20 +00:00
|
|
|
factory->is_concat_spreadable_symbol());
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallConstant(isolate_, symbol_fun, "iterator",
|
2016-12-06 13:21:20 +00:00
|
|
|
factory->iterator_symbol());
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallConstant(isolate_, symbol_fun, "match", factory->match_symbol());
|
|
|
|
InstallConstant(isolate_, symbol_fun, "replace", factory->replace_symbol());
|
|
|
|
InstallConstant(isolate_, symbol_fun, "search", factory->search_symbol());
|
|
|
|
InstallConstant(isolate_, symbol_fun, "species", factory->species_symbol());
|
|
|
|
InstallConstant(isolate_, symbol_fun, "split", factory->split_symbol());
|
|
|
|
InstallConstant(isolate_, symbol_fun, "toPrimitive",
|
2016-12-06 13:21:20 +00:00
|
|
|
factory->to_primitive_symbol());
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallConstant(isolate_, symbol_fun, "toStringTag",
|
2016-12-06 13:21:20 +00:00
|
|
|
factory->to_string_tag_symbol());
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallConstant(isolate_, symbol_fun, "unscopables",
|
2016-12-06 13:21:20 +00:00
|
|
|
factory->unscopables_symbol());
|
|
|
|
|
2017-06-30 08:54:01 +00:00
|
|
|
// Setup %SymbolPrototype%.
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSObject> prototype(JSObject::cast(symbol_fun->instance_prototype()),
|
|
|
|
isolate());
|
2017-06-30 08:54:01 +00:00
|
|
|
|
2016-07-05 10:03:38 +00:00
|
|
|
// Install the @@toStringTag property on the {prototype}.
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, prototype, factory->to_string_tag_symbol(),
|
2016-07-05 10:03:38 +00:00
|
|
|
factory->NewStringFromAsciiChecked("Symbol"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
|
|
|
// Install the Symbol.prototype methods.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toString",
|
2016-07-05 10:03:38 +00:00
|
|
|
Builtins::kSymbolPrototypeToString, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "valueOf",
|
2016-07-05 10:03:38 +00:00
|
|
|
Builtins::kSymbolPrototypeValueOf, 0, true);
|
|
|
|
|
|
|
|
// Install the @@toPrimitive function.
|
|
|
|
Handle<JSFunction> to_primitive = InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, prototype, factory->to_primitive_symbol(), JS_OBJECT_TYPE,
|
2017-10-18 20:14:09 +00:00
|
|
|
JSObject::kHeaderSize, 0, MaybeHandle<JSObject>(),
|
2016-07-05 10:03:38 +00:00
|
|
|
Builtins::kSymbolPrototypeToPrimitive,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
|
|
|
// Set the expected parameters for @@toPrimitive to 1; required by builtin.
|
|
|
|
to_primitive->shared()->set_internal_formal_parameter_count(1);
|
|
|
|
|
|
|
|
// Set the length for the function to satisfy ECMA-262.
|
|
|
|
to_primitive->shared()->set_length(1);
|
2014-08-06 09:31:21 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
{ // --- D a t e ---
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSFunction> date_fun = InstallFunction(
|
|
|
|
isolate_, global, "Date", JS_DATE_TYPE, JSDate::kSize, 0,
|
|
|
|
factory->the_hole_value(), Builtins::kDateConstructor);
|
|
|
|
InstallWithIntrinsicDefaultProto(isolate_, date_fun,
|
2015-12-07 16:35:03 +00:00
|
|
|
Context::DATE_FUNCTION_INDEX);
|
2016-01-05 11:05:41 +00:00
|
|
|
date_fun->shared()->set_length(7);
|
|
|
|
date_fun->shared()->DontAdaptArguments();
|
2016-01-12 10:47:27 +00:00
|
|
|
|
|
|
|
// Install the Date.now, Date.parse and Date.UTC functions.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, date_fun, "now", Builtins::kDateNow, 0,
|
|
|
|
false);
|
|
|
|
SimpleInstallFunction(isolate_, date_fun, "parse", Builtins::kDateParse, 1,
|
|
|
|
false);
|
|
|
|
SimpleInstallFunction(isolate_, date_fun, "UTC", Builtins::kDateUTC, 7,
|
|
|
|
false);
|
2016-01-12 10:47:27 +00:00
|
|
|
|
2017-06-30 08:54:01 +00:00
|
|
|
// Setup %DatePrototype%.
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSObject> prototype(JSObject::cast(date_fun->instance_prototype()),
|
|
|
|
isolate());
|
2016-01-12 10:47:27 +00:00
|
|
|
|
|
|
|
// Install the Date.prototype methods.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toString",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeToString, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toDateString",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeToDateString, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toTimeString",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeToTimeString, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toISOString",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeToISOString, 0, false);
|
2016-02-19 02:18:44 +00:00
|
|
|
Handle<JSFunction> to_utc_string =
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toUTCString",
|
2016-02-19 02:18:44 +00:00
|
|
|
Builtins::kDatePrototypeToUTCString, 0, false);
|
2018-06-19 09:00:37 +00:00
|
|
|
InstallFunction(isolate_, prototype, to_utc_string,
|
2016-02-19 02:18:44 +00:00
|
|
|
factory->InternalizeUtf8String("toGMTString"), DONT_ENUM);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getDate",
|
|
|
|
Builtins::kDatePrototypeGetDate, 0, true);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "setDate",
|
|
|
|
Builtins::kDatePrototypeSetDate, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "getDay",
|
|
|
|
Builtins::kDatePrototypeGetDay, 0, true);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "getFullYear",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeGetFullYear, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setFullYear",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeSetFullYear, 3, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getHours",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeGetHours, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setHours",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeSetHours, 4, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getMilliseconds",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeGetMilliseconds, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setMilliseconds",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeSetMilliseconds, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getMinutes",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeGetMinutes, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setMinutes",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeSetMinutes, 3, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getMonth",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeGetMonth, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setMonth",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeSetMonth, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getSeconds",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeGetSeconds, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setSeconds",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeSetSeconds, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getTime",
|
|
|
|
Builtins::kDatePrototypeGetTime, 0, true);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "setTime",
|
|
|
|
Builtins::kDatePrototypeSetTime, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "getTimezoneOffset",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeGetTimezoneOffset, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getUTCDate",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeGetUTCDate, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setUTCDate",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeSetUTCDate, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getUTCDay",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeGetUTCDay, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getUTCFullYear",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeGetUTCFullYear, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setUTCFullYear",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeSetUTCFullYear, 3, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getUTCHours",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeGetUTCHours, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setUTCHours",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeSetUTCHours, 4, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getUTCMilliseconds",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeGetUTCMilliseconds, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setUTCMilliseconds",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeSetUTCMilliseconds, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getUTCMinutes",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeGetUTCMinutes, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setUTCMinutes",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeSetUTCMinutes, 3, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getUTCMonth",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeGetUTCMonth, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setUTCMonth",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeSetUTCMonth, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getUTCSeconds",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeGetUTCSeconds, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setUTCSeconds",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeSetUTCSeconds, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "valueOf",
|
|
|
|
Builtins::kDatePrototypeValueOf, 0, true);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "getYear",
|
|
|
|
Builtins::kDatePrototypeGetYear, 0, true);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "setYear",
|
|
|
|
Builtins::kDatePrototypeSetYear, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "toJSON",
|
|
|
|
Builtins::kDatePrototypeToJson, 1, false);
|
2016-01-12 10:47:27 +00:00
|
|
|
|
2017-04-21 08:35:12 +00:00
|
|
|
// Install Intl fallback functions.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toLocaleString",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeToString, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toLocaleDateString",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeToDateString, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toLocaleTimeString",
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeToTimeString, 0, false);
|
|
|
|
|
|
|
|
// Install the @@toPrimitive function.
|
|
|
|
Handle<JSFunction> to_primitive = InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, prototype, factory->to_primitive_symbol(), JS_OBJECT_TYPE,
|
2017-10-18 20:14:09 +00:00
|
|
|
JSObject::kHeaderSize, 0, MaybeHandle<JSObject>(),
|
2016-01-12 10:47:27 +00:00
|
|
|
Builtins::kDatePrototypeToPrimitive,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
|
|
|
// Set the expected parameters for @@toPrimitive to 1; required by builtin.
|
|
|
|
to_primitive->shared()->set_internal_formal_parameter_count(1);
|
|
|
|
|
|
|
|
// Set the length for the function to satisfy ECMA-262.
|
|
|
|
to_primitive->shared()->set_length(1);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2017-01-02 17:22:30 +00:00
|
|
|
{
|
2018-03-23 14:24:03 +00:00
|
|
|
Handle<SharedFunctionInfo> info = SimpleCreateBuiltinSharedFunctionInfo(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, Builtins::kPromiseGetCapabilitiesExecutor,
|
2018-02-15 05:26:29 +00:00
|
|
|
factory->empty_string(), 2);
|
2017-01-02 17:22:30 +00:00
|
|
|
native_context()->set_promise_get_capabilities_executor_shared_fun(*info);
|
|
|
|
}
|
|
|
|
|
2016-12-01 21:09:44 +00:00
|
|
|
{ // -- P r o m i s e
|
2017-05-23 17:54:12 +00:00
|
|
|
Handle<JSFunction> promise_fun = InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, global, "Promise", JS_PROMISE_TYPE,
|
|
|
|
JSPromise::kSizeWithEmbedderFields, 0, factory->the_hole_value(),
|
|
|
|
Builtins::kPromiseConstructor);
|
|
|
|
InstallWithIntrinsicDefaultProto(isolate_, promise_fun,
|
2016-12-01 21:09:44 +00:00
|
|
|
Context::PROMISE_FUNCTION_INDEX);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(promise_fun->shared(), isolate_);
|
2016-12-01 21:09:44 +00:00
|
|
|
shared->set_internal_formal_parameter_count(1);
|
|
|
|
shared->set_length(1);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallSpeciesGetter(isolate_, promise_fun);
|
2017-06-30 08:54:01 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, promise_fun, "all", Builtins::kPromiseAll,
|
|
|
|
1, true);
|
2017-06-30 08:54:01 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, promise_fun, "race", Builtins::kPromiseRace,
|
|
|
|
1, true);
|
2017-07-08 00:43:24 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, promise_fun, "resolve",
|
2018-02-20 07:31:02 +00:00
|
|
|
Builtins::kPromiseResolveTrampoline, 1, true);
|
2017-06-30 08:54:01 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, promise_fun, "reject",
|
|
|
|
Builtins::kPromiseReject, 1, true);
|
2017-06-30 08:54:01 +00:00
|
|
|
|
|
|
|
// Setup %PromisePrototype%.
|
|
|
|
Handle<JSObject> prototype(
|
2018-06-20 10:10:43 +00:00
|
|
|
JSObject::cast(promise_fun->instance_prototype()), isolate());
|
2018-01-23 08:43:08 +00:00
|
|
|
native_context()->set_promise_prototype(*prototype);
|
2016-12-01 21:09:44 +00:00
|
|
|
|
|
|
|
// Install the @@toStringTag property on the {prototype}.
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, prototype, factory->to_string_tag_symbol(),
|
|
|
|
factory->Promise_string(),
|
2016-12-01 21:09:44 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSFunction> promise_then = SimpleInstallFunction(
|
|
|
|
isolate_, prototype, isolate_->factory()->then_string(),
|
|
|
|
Builtins::kPromisePrototypeThen, 2, true);
|
2017-06-19 15:17:22 +00:00
|
|
|
native_context()->set_promise_then(*promise_then);
|
2016-12-08 06:12:35 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSFunction> promise_catch =
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "catch",
|
|
|
|
Builtins::kPromisePrototypeCatch, 1, true);
|
2017-06-19 15:17:22 +00:00
|
|
|
native_context()->set_promise_catch(*promise_catch);
|
2016-12-06 18:42:49 +00:00
|
|
|
|
2018-06-04 19:37:50 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "finally",
|
|
|
|
Builtins::kPromisePrototypeFinally, 1, true,
|
|
|
|
DONT_ENUM);
|
|
|
|
|
|
|
|
{
|
|
|
|
Handle<SharedFunctionInfo> info = SimpleCreateSharedFunctionInfo(
|
|
|
|
isolate(), Builtins::kPromiseThenFinally,
|
|
|
|
isolate_->factory()->empty_string(), 1);
|
|
|
|
info->set_native(true);
|
|
|
|
native_context()->set_promise_then_finally_shared_fun(*info);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Handle<SharedFunctionInfo> info = SimpleCreateSharedFunctionInfo(
|
|
|
|
isolate(), Builtins::kPromiseCatchFinally,
|
|
|
|
isolate_->factory()->empty_string(), 1);
|
|
|
|
info->set_native(true);
|
|
|
|
native_context()->set_promise_catch_finally_shared_fun(*info);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Handle<SharedFunctionInfo> info = SimpleCreateSharedFunctionInfo(
|
|
|
|
isolate(), Builtins::kPromiseValueThunkFinally,
|
|
|
|
isolate_->factory()->empty_string(), 0);
|
|
|
|
native_context()->set_promise_value_thunk_finally_shared_fun(*info);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Handle<SharedFunctionInfo> info = SimpleCreateSharedFunctionInfo(
|
|
|
|
isolate(), Builtins::kPromiseThrowerFinally,
|
|
|
|
isolate_->factory()->empty_string(), 0);
|
|
|
|
native_context()->set_promise_thrower_finally_shared_fun(*info);
|
|
|
|
}
|
|
|
|
|
2017-07-08 00:43:24 +00:00
|
|
|
// Force the Promise constructor to fast properties, so that we can use the
|
|
|
|
// fast paths for various things like
|
|
|
|
//
|
|
|
|
// x instanceof Promise
|
|
|
|
//
|
|
|
|
// etc. We should probably come up with a more principled approach once
|
|
|
|
// the JavaScript builtins are gone.
|
|
|
|
JSObject::MigrateSlowToFast(Handle<JSObject>::cast(promise_fun), 0,
|
|
|
|
"Bootstrapping");
|
2017-01-06 20:06:32 +00:00
|
|
|
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<Map> prototype_map(prototype->map(), isolate());
|
2018-05-31 14:14:48 +00:00
|
|
|
Map::SetShouldBeFastPrototypeMap(prototype_map, true, isolate_);
|
2016-12-08 06:12:35 +00:00
|
|
|
|
2016-12-01 21:09:44 +00:00
|
|
|
{ // Internal: IsPromise
|
|
|
|
Handle<JSFunction> function = SimpleCreateFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, factory->empty_string(), Builtins::kIsPromise, 1, false);
|
2017-06-19 15:17:22 +00:00
|
|
|
native_context()->set_is_promise(*function);
|
2016-12-01 21:09:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2017-09-07 07:24:11 +00:00
|
|
|
Handle<SharedFunctionInfo> info = SimpleCreateSharedFunctionInfo(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, Builtins::kPromiseCapabilityDefaultResolve,
|
2018-04-11 15:07:23 +00:00
|
|
|
factory->empty_string(), 1, FunctionKind::kConciseMethod);
|
2018-02-19 13:31:18 +00:00
|
|
|
info->set_native(true);
|
2018-04-11 15:07:23 +00:00
|
|
|
info->set_function_map_index(
|
|
|
|
Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
|
[builtins] Refactor the promise resolution and rejection logic.
This introduces dedicated builtins
- FulfillPromise,
- RejectPromise, and
- ResolvePromise,
which perform the corresponding operations from the language
specification, and removes the redundant entry points and the
excessive inlining of these operations into other builtins. We
also add the same logic on the C++ side, so that we don't need
to go into JavaScript land when resolving/rejecting from the
API.
The C++ side has a complete implementation, including full support
for the debugger and the current PromiseHook machinery. This is to
avoid constantly crossing the boundary for those cases, and to also
simplify the CSA side (and soon the TurboFan side), where we only
do the fast-path and bail out to the runtime for the general handling.
On top of this we introduce %_RejectPromise and %_ResolvePromise,
which are entry points used by the bytecode and parser desugarings
for async functions, and also used by the V8 Extras API. Thanks to
this we can uniformly optimize these in TurboFan, where we have
corresponding operators JSRejectPromise and JSResolvePromise, which
currently just call into the builtins, but middle-term can be further
optimized, i.e. to skip the "then" lookup for JSResolvePromise when
we know something about the resolution.
In TurboFan we can also already inline the default PromiseCapability
[[Reject]] and [[Resolve]] functions, although this is not as effective
as it can be right now, until we have inlining support for the Promise
constructor (being worked on by petermarshall@ right now) and/or SFI
based CALL_IC feedback.
Overall this change is meant as a refactoring without significant
performance impact anywhere; it seems to improve performance of
simple async functions a bit, but otherwise is neutral.
Bug: v8:7253
Change-Id: Id0b979f9b2843560e38cd8df4b02627dad4b6d8c
Reviewed-on: https://chromium-review.googlesource.com/911632
Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51260}
2018-02-12 19:10:29 +00:00
|
|
|
native_context()->set_promise_capability_default_resolve_shared_fun(
|
|
|
|
*info);
|
2016-12-01 21:09:44 +00:00
|
|
|
|
2017-09-07 07:24:11 +00:00
|
|
|
info = SimpleCreateSharedFunctionInfo(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, Builtins::kPromiseCapabilityDefaultReject,
|
2018-04-11 15:07:23 +00:00
|
|
|
factory->empty_string(), 1, FunctionKind::kConciseMethod);
|
2018-02-19 13:31:18 +00:00
|
|
|
info->set_native(true);
|
2018-04-11 15:07:23 +00:00
|
|
|
info->set_function_map_index(
|
|
|
|
Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
|
[builtins] Refactor the promise resolution and rejection logic.
This introduces dedicated builtins
- FulfillPromise,
- RejectPromise, and
- ResolvePromise,
which perform the corresponding operations from the language
specification, and removes the redundant entry points and the
excessive inlining of these operations into other builtins. We
also add the same logic on the C++ side, so that we don't need
to go into JavaScript land when resolving/rejecting from the
API.
The C++ side has a complete implementation, including full support
for the debugger and the current PromiseHook machinery. This is to
avoid constantly crossing the boundary for those cases, and to also
simplify the CSA side (and soon the TurboFan side), where we only
do the fast-path and bail out to the runtime for the general handling.
On top of this we introduce %_RejectPromise and %_ResolvePromise,
which are entry points used by the bytecode and parser desugarings
for async functions, and also used by the V8 Extras API. Thanks to
this we can uniformly optimize these in TurboFan, where we have
corresponding operators JSRejectPromise and JSResolvePromise, which
currently just call into the builtins, but middle-term can be further
optimized, i.e. to skip the "then" lookup for JSResolvePromise when
we know something about the resolution.
In TurboFan we can also already inline the default PromiseCapability
[[Reject]] and [[Resolve]] functions, although this is not as effective
as it can be right now, until we have inlining support for the Promise
constructor (being worked on by petermarshall@ right now) and/or SFI
based CALL_IC feedback.
Overall this change is meant as a refactoring without significant
performance impact anywhere; it seems to improve performance of
simple async functions a bit, but otherwise is neutral.
Bug: v8:7253
Change-Id: Id0b979f9b2843560e38cd8df4b02627dad4b6d8c
Reviewed-on: https://chromium-review.googlesource.com/911632
Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51260}
2018-02-12 19:10:29 +00:00
|
|
|
native_context()->set_promise_capability_default_reject_shared_fun(*info);
|
2016-12-01 21:09:44 +00:00
|
|
|
}
|
Reland "[builtins] port Promise.all to CSA"
Simplifies the implementation of IteratorClose in IteratorBuiltinsAssembler, and makes clear that it is only invoked when an exception occurs. Adds exception handling support to GetIterator, IteratorStep, and IteratorCloseOnException.
Moves the Promise.all resolveElement closure and it's caller to
builtins-promise-gen.cc.
Instead of creating an internal array (and copying its elements into a
result
array), a single JSArray is allocated, and appended with
BuildAppendJSArray(),
falling back to %CreateDataProperty(), and elements are updated in the
resolve
closure the same way. This should always be unobservable.
This CL increases the size of snapshot_blob.bin on an x64.release build
by 8.51kb
BUG=v8:5343
R=cbruni@chromium.org, gsathysa@chromium.org, jgruber@chromium.org, hpayer@chromium.org, tebbi@chromium.org
Change-Id: I29c4a529154ef49ad65555ce6ddc2c5b7c9de6b3
Reviewed-on: https://chromium-review.googlesource.com/508473
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45946}
2017-06-13 17:14:57 +00:00
|
|
|
|
|
|
|
{
|
2017-09-07 07:24:11 +00:00
|
|
|
Handle<SharedFunctionInfo> info = SimpleCreateSharedFunctionInfo(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, Builtins::kPromiseAllResolveElementClosure,
|
2017-09-07 07:24:11 +00:00
|
|
|
factory->empty_string(), 1);
|
Reland "[builtins] port Promise.all to CSA"
Simplifies the implementation of IteratorClose in IteratorBuiltinsAssembler, and makes clear that it is only invoked when an exception occurs. Adds exception handling support to GetIterator, IteratorStep, and IteratorCloseOnException.
Moves the Promise.all resolveElement closure and it's caller to
builtins-promise-gen.cc.
Instead of creating an internal array (and copying its elements into a
result
array), a single JSArray is allocated, and appended with
BuildAppendJSArray(),
falling back to %CreateDataProperty(), and elements are updated in the
resolve
closure the same way. This should always be unobservable.
This CL increases the size of snapshot_blob.bin on an x64.release build
by 8.51kb
BUG=v8:5343
R=cbruni@chromium.org, gsathysa@chromium.org, jgruber@chromium.org, hpayer@chromium.org, tebbi@chromium.org
Change-Id: I29c4a529154ef49ad65555ce6ddc2c5b7c9de6b3
Reviewed-on: https://chromium-review.googlesource.com/508473
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45946}
2017-06-13 17:14:57 +00:00
|
|
|
native_context()->set_promise_all_resolve_element_shared_fun(*info);
|
|
|
|
}
|
2017-06-28 14:33:20 +00:00
|
|
|
|
|
|
|
// Force the Promise constructor to fast properties, so that we can use the
|
|
|
|
// fast paths for various things like
|
|
|
|
//
|
|
|
|
// x instanceof Promise
|
|
|
|
//
|
|
|
|
// etc. We should probably come up with a more principled approach once
|
|
|
|
// the JavaScript builtins are gone.
|
|
|
|
JSObject::MigrateSlowToFast(promise_fun, 0, "Bootstrapping");
|
2016-12-01 21:09:44 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
{ // -- R e g E x p
|
|
|
|
// Builtin functions for RegExp.prototype.
|
2017-06-30 08:54:01 +00:00
|
|
|
Handle<JSFunction> regexp_fun = InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, global, "RegExp", JS_REGEXP_TYPE,
|
2017-10-18 20:14:09 +00:00
|
|
|
JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize,
|
|
|
|
JSRegExp::kInObjectFieldCount, factory->the_hole_value(),
|
|
|
|
Builtins::kRegExpConstructor);
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate_, regexp_fun,
|
2015-12-07 16:35:03 +00:00
|
|
|
Context::REGEXP_FUNCTION_INDEX);
|
2016-10-05 09:13:04 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(regexp_fun->shared(), isolate_);
|
2016-12-05 13:50:31 +00:00
|
|
|
shared->set_internal_formal_parameter_count(2);
|
2016-10-05 09:13:04 +00:00
|
|
|
shared->set_length(2);
|
2016-10-14 11:46:43 +00:00
|
|
|
|
2016-10-06 13:00:56 +00:00
|
|
|
{
|
2017-06-30 08:54:01 +00:00
|
|
|
// Setup %RegExpPrototype%.
|
|
|
|
Handle<JSObject> prototype(
|
2018-06-20 10:10:43 +00:00
|
|
|
JSObject::cast(regexp_fun->instance_prototype()), isolate());
|
2016-10-06 13:00:56 +00:00
|
|
|
|
2016-10-10 13:56:46 +00:00
|
|
|
{
|
|
|
|
Handle<JSFunction> fun = SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, prototype, factory->exec_string(),
|
|
|
|
Builtins::kRegExpPrototypeExec, 1, true, DONT_ENUM);
|
2016-10-10 13:56:46 +00:00
|
|
|
native_context()->set_regexp_exec_function(*fun);
|
|
|
|
}
|
2016-10-06 13:00:56 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->dotAll_string(),
|
2017-11-17 00:45:55 +00:00
|
|
|
Builtins::kRegExpPrototypeDotAllGetter, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->flags_string(),
|
2016-10-06 13:00:56 +00:00
|
|
|
Builtins::kRegExpPrototypeFlagsGetter, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->global_string(),
|
2016-10-06 13:00:56 +00:00
|
|
|
Builtins::kRegExpPrototypeGlobalGetter, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->ignoreCase_string(),
|
2016-10-06 13:00:56 +00:00
|
|
|
Builtins::kRegExpPrototypeIgnoreCaseGetter, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->multiline_string(),
|
2016-10-06 13:00:56 +00:00
|
|
|
Builtins::kRegExpPrototypeMultilineGetter, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->source_string(),
|
2016-12-01 14:45:39 +00:00
|
|
|
Builtins::kRegExpPrototypeSourceGetter, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->sticky_string(),
|
2016-10-06 13:00:56 +00:00
|
|
|
Builtins::kRegExpPrototypeStickyGetter, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->unicode_string(),
|
2016-10-06 13:00:56 +00:00
|
|
|
Builtins::kRegExpPrototypeUnicodeGetter, true);
|
2016-10-10 13:06:24 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "compile",
|
2016-12-05 13:50:31 +00:00
|
|
|
Builtins::kRegExpPrototypeCompile, 2, true,
|
2016-10-10 13:06:24 +00:00
|
|
|
DONT_ENUM);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, factory->toString_string(),
|
2016-10-10 13:06:24 +00:00
|
|
|
Builtins::kRegExpPrototypeToString, 0, false,
|
|
|
|
DONT_ENUM);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "test",
|
|
|
|
Builtins::kRegExpPrototypeTest, 1, true, DONT_ENUM);
|
2016-10-10 13:56:46 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, factory->match_symbol(),
|
2017-07-07 09:24:57 +00:00
|
|
|
"[Symbol.match]", Builtins::kRegExpPrototypeMatch,
|
|
|
|
1, true);
|
2016-10-10 13:56:46 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, factory->replace_symbol(),
|
2017-07-07 09:24:57 +00:00
|
|
|
"[Symbol.replace]",
|
|
|
|
Builtins::kRegExpPrototypeReplace, 2, false);
|
2016-10-13 11:27:25 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, factory->search_symbol(),
|
2017-07-07 09:24:57 +00:00
|
|
|
"[Symbol.search]", Builtins::kRegExpPrototypeSearch,
|
|
|
|
1, true);
|
2016-10-11 10:38:02 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, factory->split_symbol(),
|
2017-07-07 09:24:57 +00:00
|
|
|
"[Symbol.split]", Builtins::kRegExpPrototypeSplit,
|
|
|
|
2, false);
|
2016-10-13 11:27:25 +00:00
|
|
|
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<Map> prototype_map(prototype->map(), isolate());
|
2018-05-31 14:14:48 +00:00
|
|
|
Map::SetShouldBeFastPrototypeMap(prototype_map, true, isolate_);
|
2016-11-29 07:41:08 +00:00
|
|
|
|
2016-10-13 11:27:25 +00:00
|
|
|
// Store the initial RegExp.prototype map. This is used in fast-path
|
|
|
|
// checks. Do not alter the prototype after this point.
|
2016-11-29 07:41:08 +00:00
|
|
|
native_context()->set_regexp_prototype_map(*prototype_map);
|
2016-10-06 13:00:56 +00:00
|
|
|
}
|
2016-10-05 09:13:04 +00:00
|
|
|
|
2016-10-06 13:00:56 +00:00
|
|
|
{
|
|
|
|
// RegExp getters and setters.
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallSpeciesGetter(isolate_, regexp_fun);
|
2016-10-06 13:00:56 +00:00
|
|
|
|
|
|
|
// Static properties set by a successful match.
|
|
|
|
|
2016-10-27 08:25:24 +00:00
|
|
|
const PropertyAttributes no_enum = DONT_ENUM;
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun, factory->input_string(),
|
2016-10-06 13:00:56 +00:00
|
|
|
Builtins::kRegExpInputGetter,
|
2016-10-27 08:25:24 +00:00
|
|
|
Builtins::kRegExpInputSetter, no_enum);
|
2016-10-06 13:00:56 +00:00
|
|
|
SimpleInstallGetterSetter(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, regexp_fun, factory->InternalizeUtf8String("$_"),
|
2016-10-06 13:00:56 +00:00
|
|
|
Builtins::kRegExpInputGetter, Builtins::kRegExpInputSetter, no_enum);
|
|
|
|
|
|
|
|
SimpleInstallGetterSetter(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, regexp_fun, factory->InternalizeUtf8String("lastMatch"),
|
2016-10-06 13:00:56 +00:00
|
|
|
Builtins::kRegExpLastMatchGetter, Builtins::kEmptyFunction, no_enum);
|
|
|
|
SimpleInstallGetterSetter(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, regexp_fun, factory->InternalizeUtf8String("$&"),
|
2016-10-06 13:00:56 +00:00
|
|
|
Builtins::kRegExpLastMatchGetter, Builtins::kEmptyFunction, no_enum);
|
|
|
|
|
|
|
|
SimpleInstallGetterSetter(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, regexp_fun, factory->InternalizeUtf8String("lastParen"),
|
2016-10-06 13:00:56 +00:00
|
|
|
Builtins::kRegExpLastParenGetter, Builtins::kEmptyFunction, no_enum);
|
|
|
|
SimpleInstallGetterSetter(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, regexp_fun, factory->InternalizeUtf8String("$+"),
|
2016-10-06 13:00:56 +00:00
|
|
|
Builtins::kRegExpLastParenGetter, Builtins::kEmptyFunction, no_enum);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun,
|
2016-10-06 13:00:56 +00:00
|
|
|
factory->InternalizeUtf8String("leftContext"),
|
|
|
|
Builtins::kRegExpLeftContextGetter,
|
|
|
|
Builtins::kEmptyFunction, no_enum);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun,
|
2016-10-06 13:00:56 +00:00
|
|
|
factory->InternalizeUtf8String("$`"),
|
|
|
|
Builtins::kRegExpLeftContextGetter,
|
|
|
|
Builtins::kEmptyFunction, no_enum);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun,
|
2016-10-06 13:00:56 +00:00
|
|
|
factory->InternalizeUtf8String("rightContext"),
|
|
|
|
Builtins::kRegExpRightContextGetter,
|
|
|
|
Builtins::kEmptyFunction, no_enum);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun,
|
2016-10-06 13:00:56 +00:00
|
|
|
factory->InternalizeUtf8String("$'"),
|
|
|
|
Builtins::kRegExpRightContextGetter,
|
|
|
|
Builtins::kEmptyFunction, no_enum);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
#define INSTALL_CAPTURE_GETTER(i) \
|
|
|
|
SimpleInstallGetterSetter( \
|
|
|
|
isolate_, regexp_fun, factory->InternalizeUtf8String("$" #i), \
|
2016-10-27 08:25:24 +00:00
|
|
|
Builtins::kRegExpCapture##i##Getter, Builtins::kEmptyFunction, no_enum)
|
2016-10-06 13:00:56 +00:00
|
|
|
INSTALL_CAPTURE_GETTER(1);
|
|
|
|
INSTALL_CAPTURE_GETTER(2);
|
|
|
|
INSTALL_CAPTURE_GETTER(3);
|
|
|
|
INSTALL_CAPTURE_GETTER(4);
|
|
|
|
INSTALL_CAPTURE_GETTER(5);
|
|
|
|
INSTALL_CAPTURE_GETTER(6);
|
|
|
|
INSTALL_CAPTURE_GETTER(7);
|
|
|
|
INSTALL_CAPTURE_GETTER(8);
|
|
|
|
INSTALL_CAPTURE_GETTER(9);
|
|
|
|
#undef INSTALL_CAPTURE_GETTER
|
|
|
|
}
|
2016-09-05 11:52:53 +00:00
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(regexp_fun->has_initial_map());
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<Map> initial_map(regexp_fun->initial_map(), isolate());
|
2010-03-26 14:19:47 +00:00
|
|
|
|
2017-10-18 20:14:09 +00:00
|
|
|
DCHECK_EQ(1, initial_map->GetInObjectProperties());
|
2010-03-26 14:19:47 +00:00
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::EnsureDescriptorSlack(isolate_, initial_map, 1);
|
2015-11-05 19:10:07 +00:00
|
|
|
|
|
|
|
// ECMA-262, section 15.10.7.5.
|
|
|
|
PropertyAttributes writable =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE);
|
2018-07-17 15:08:58 +00:00
|
|
|
Descriptor d = Descriptor::DataField(isolate(), factory->lastIndex_string(),
|
2016-12-21 16:40:00 +00:00
|
|
|
JSRegExp::kLastIndexFieldIndex,
|
|
|
|
writable, Representation::Tagged());
|
|
|
|
initial_map->AppendDescriptor(&d);
|
2010-03-26 14:19:47 +00:00
|
|
|
|
2016-10-13 15:02:47 +00:00
|
|
|
{ // Internal: RegExpInternalMatch
|
|
|
|
Handle<JSFunction> function =
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleCreateFunction(isolate_, isolate_->factory()->empty_string(),
|
2017-07-03 13:40:13 +00:00
|
|
|
Builtins::kRegExpInternalMatch, 2, true);
|
2016-10-14 11:46:43 +00:00
|
|
|
native_context()->set(Context::REGEXP_INTERNAL_MATCH, *function);
|
2016-10-13 15:02:47 +00:00
|
|
|
}
|
2016-10-14 11:46:43 +00:00
|
|
|
|
|
|
|
// Create the last match info. One for external use, and one for internal
|
|
|
|
// use when we don't want to modify the externally visible match info.
|
|
|
|
Handle<RegExpMatchInfo> last_match_info = factory->NewRegExpMatchInfo();
|
|
|
|
native_context()->set_regexp_last_match_info(*last_match_info);
|
|
|
|
Handle<RegExpMatchInfo> internal_match_info = factory->NewRegExpMatchInfo();
|
|
|
|
native_context()->set_regexp_internal_match_info(*internal_match_info);
|
2017-03-31 18:27:30 +00:00
|
|
|
|
|
|
|
// Force the RegExp constructor to fast properties, so that we can use the
|
|
|
|
// fast paths for various things like
|
|
|
|
//
|
|
|
|
// x instanceof RegExp
|
|
|
|
//
|
|
|
|
// etc. We should probably come up with a more principled approach once
|
|
|
|
// the JavaScript builtins are gone.
|
|
|
|
JSObject::MigrateSlowToFast(regexp_fun, 0, "Bootstrapping");
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2015-12-09 07:53:19 +00:00
|
|
|
{ // -- E r r o r
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallError(isolate_, global, factory->Error_string(),
|
2016-07-20 13:02:36 +00:00
|
|
|
Context::ERROR_FUNCTION_INDEX);
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallMakeError(isolate_, Builtins::kMakeError, Context::MAKE_ERROR_INDEX);
|
2015-12-09 07:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- E v a l E r r o r
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallError(isolate_, global, factory->EvalError_string(),
|
2016-07-20 13:02:36 +00:00
|
|
|
Context::EVAL_ERROR_FUNCTION_INDEX);
|
2015-12-09 07:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- R a n g e E r r o r
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallError(isolate_, global, factory->RangeError_string(),
|
2016-07-20 13:02:36 +00:00
|
|
|
Context::RANGE_ERROR_FUNCTION_INDEX);
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallMakeError(isolate_, Builtins::kMakeRangeError,
|
2016-08-09 07:36:19 +00:00
|
|
|
Context::MAKE_RANGE_ERROR_INDEX);
|
2015-12-09 07:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- R e f e r e n c e E r r o r
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallError(isolate_, global, factory->ReferenceError_string(),
|
2016-07-20 13:02:36 +00:00
|
|
|
Context::REFERENCE_ERROR_FUNCTION_INDEX);
|
2015-12-09 07:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- S y n t a x E r r o r
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallError(isolate_, global, factory->SyntaxError_string(),
|
2016-07-20 13:02:36 +00:00
|
|
|
Context::SYNTAX_ERROR_FUNCTION_INDEX);
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallMakeError(isolate_, Builtins::kMakeSyntaxError,
|
2016-08-09 07:36:19 +00:00
|
|
|
Context::MAKE_SYNTAX_ERROR_INDEX);
|
2015-12-09 07:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- T y p e E r r o r
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallError(isolate_, global, factory->TypeError_string(),
|
2016-07-20 13:02:36 +00:00
|
|
|
Context::TYPE_ERROR_FUNCTION_INDEX);
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallMakeError(isolate_, Builtins::kMakeTypeError,
|
2016-08-09 07:36:19 +00:00
|
|
|
Context::MAKE_TYPE_ERROR_INDEX);
|
2015-12-09 07:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- U R I E r r o r
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallError(isolate_, global, factory->URIError_string(),
|
2016-07-20 13:02:36 +00:00
|
|
|
Context::URI_ERROR_FUNCTION_INDEX);
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallMakeError(isolate_, Builtins::kMakeURIError,
|
2016-08-09 07:36:19 +00:00
|
|
|
Context::MAKE_URI_ERROR_INDEX);
|
2015-12-09 07:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-10-13 16:17:44 +00:00
|
|
|
{ // -- C o m p i l e E r r o r
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSObject> dummy = factory->NewJSObject(isolate_->object_function());
|
|
|
|
InstallError(isolate_, dummy, factory->CompileError_string(),
|
2016-10-13 16:17:44 +00:00
|
|
|
Context::WASM_COMPILE_ERROR_FUNCTION_INDEX);
|
|
|
|
|
2016-12-16 14:23:35 +00:00
|
|
|
// -- L i n k E r r o r
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallError(isolate_, dummy, factory->LinkError_string(),
|
2016-12-16 14:23:35 +00:00
|
|
|
Context::WASM_LINK_ERROR_FUNCTION_INDEX);
|
|
|
|
|
2016-10-13 16:17:44 +00:00
|
|
|
// -- R u n t i m e E r r o r
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallError(isolate_, dummy, factory->RuntimeError_string(),
|
2016-10-13 16:17:44 +00:00
|
|
|
Context::WASM_RUNTIME_ERROR_FUNCTION_INDEX);
|
|
|
|
}
|
|
|
|
|
2015-07-13 09:45:43 +00:00
|
|
|
// Initialize the embedder data slot.
|
2018-03-08 11:40:04 +00:00
|
|
|
native_context()->set_embedder_data(*factory->empty_fixed_array());
|
2015-07-13 09:45:43 +00:00
|
|
|
|
2009-04-24 08:13:09 +00:00
|
|
|
{ // -- J S O N
|
2013-09-25 15:11:48 +00:00
|
|
|
Handle<String> name = factory->InternalizeUtf8String("JSON");
|
2017-06-15 17:56:35 +00:00
|
|
|
Handle<JSObject> json_object =
|
2018-05-31 14:14:48 +00:00
|
|
|
factory->NewJSObject(isolate_->object_function(), TENURED);
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, global, name, json_object, DONT_ENUM);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, json_object, "parse", Builtins::kJsonParse,
|
|
|
|
2, false);
|
|
|
|
SimpleInstallFunction(isolate_, json_object, "stringify",
|
|
|
|
Builtins::kJsonStringify, 3, true);
|
2016-05-31 09:32:25 +00:00
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, json_object, factory->to_string_tag_symbol(),
|
2016-05-31 09:32:25 +00:00
|
|
|
factory->NewStringFromAsciiChecked("JSON"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
2015-08-14 15:12:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- M a t h
|
|
|
|
Handle<String> name = factory->InternalizeUtf8String("Math");
|
2017-06-15 17:56:35 +00:00
|
|
|
Handle<JSObject> math =
|
2018-05-31 14:14:48 +00:00
|
|
|
factory->NewJSObject(isolate_->object_function(), TENURED);
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, global, name, math, DONT_ENUM);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, math, "abs", Builtins::kMathAbs, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "acos", Builtins::kMathAcos, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "acosh", Builtins::kMathAcosh, 1,
|
|
|
|
true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "asin", Builtins::kMathAsin, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "asinh", Builtins::kMathAsinh, 1,
|
|
|
|
true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "atan", Builtins::kMathAtan, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "atanh", Builtins::kMathAtanh, 1,
|
|
|
|
true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "atan2", Builtins::kMathAtan2, 2,
|
|
|
|
true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "ceil", Builtins::kMathCeil, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "cbrt", Builtins::kMathCbrt, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "expm1", Builtins::kMathExpm1, 1,
|
|
|
|
true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "clz32", Builtins::kMathClz32, 1,
|
|
|
|
true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "cos", Builtins::kMathCos, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "cosh", Builtins::kMathCosh, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "exp", Builtins::kMathExp, 1, true);
|
|
|
|
Handle<JSFunction> math_floor = SimpleInstallFunction(
|
|
|
|
isolate_, math, "floor", Builtins::kMathFloor, 1, true);
|
2016-03-28 17:30:05 +00:00
|
|
|
native_context()->set_math_floor(*math_floor);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, math, "fround", Builtins::kMathFround, 1,
|
|
|
|
true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "hypot", Builtins::kMathHypot, 2,
|
|
|
|
false);
|
|
|
|
SimpleInstallFunction(isolate_, math, "imul", Builtins::kMathImul, 2, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "log", Builtins::kMathLog, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "log1p", Builtins::kMathLog1p, 1,
|
|
|
|
true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "log2", Builtins::kMathLog2, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "log10", Builtins::kMathLog10, 1,
|
|
|
|
true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "max", Builtins::kMathMax, 2, false);
|
|
|
|
SimpleInstallFunction(isolate_, math, "min", Builtins::kMathMin, 2, false);
|
|
|
|
Handle<JSFunction> math_pow = SimpleInstallFunction(
|
|
|
|
isolate_, math, "pow", Builtins::kMathPow, 2, true);
|
2016-06-28 10:23:58 +00:00
|
|
|
native_context()->set_math_pow(*math_pow);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, math, "random", Builtins::kMathRandom, 0,
|
|
|
|
true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "round", Builtins::kMathRound, 1,
|
|
|
|
true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "sign", Builtins::kMathSign, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "sin", Builtins::kMathSin, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "sinh", Builtins::kMathSinh, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "sqrt", Builtins::kMathSqrt, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "tan", Builtins::kMathTan, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "tanh", Builtins::kMathTanh, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "trunc", Builtins::kMathTrunc, 1,
|
|
|
|
true);
|
2016-06-21 07:01:59 +00:00
|
|
|
|
|
|
|
// Install math constants.
|
|
|
|
double const kE = base::ieee754::exp(1.0);
|
[builtins] Unify most of the remaining Math builtins.
Import fdlibm versions of acos, acosh, asin and asinh, which are more
precise and produce the same result across platforms (we were using
libm versions for asin and acos so far, where both speed and precision
depended on the operating system so far). Introduce appropriate TurboFan
operators for these functions and use them both for inlining and for the
generic builtin.
Also migrate the Math.imul and Math.fround builtins to TurboFan builtins
to ensure that their behavior is always exactly the same as the inlined
TurboFan version (i.e. C++ truncation semantics for double to float
don't necessarily meet the JavaScript semantics).
For completeness, also migrate Math.sign, which can even get some nice
love in TurboFan.
Drive-by-fix: Some alpha-sorting on the Math related functions, and
cleanup the list of Math intrinsics that we have to export via the
native context currently.
BUG=v8:3266,v8:3496,v8:3509,v8:3952,v8:5169,v8:5170,v8:5171,v8:5172
TBR=rossberg@chromium.org
R=franzih@chromium.org
Review-Url: https://codereview.chromium.org/2116753002
Cr-Commit-Position: refs/heads/master@{#37476}
2016-07-01 11:11:33 +00:00
|
|
|
double const kPI = 3.1415926535897932;
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallConstant(isolate_, math, "E", factory->NewNumber(kE));
|
|
|
|
InstallConstant(isolate_, math, "LN10",
|
2016-12-06 13:21:20 +00:00
|
|
|
factory->NewNumber(base::ieee754::log(10.0)));
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallConstant(isolate_, math, "LN2",
|
2016-12-06 13:21:20 +00:00
|
|
|
factory->NewNumber(base::ieee754::log(2.0)));
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallConstant(isolate_, math, "LOG10E",
|
2016-12-06 13:21:20 +00:00
|
|
|
factory->NewNumber(base::ieee754::log10(kE)));
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallConstant(isolate_, math, "LOG2E",
|
2016-12-06 13:21:20 +00:00
|
|
|
factory->NewNumber(base::ieee754::log2(kE)));
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallConstant(isolate_, math, "PI", factory->NewNumber(kPI));
|
|
|
|
InstallConstant(isolate_, math, "SQRT1_2",
|
2016-12-06 13:21:20 +00:00
|
|
|
factory->NewNumber(std::sqrt(0.5)));
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallConstant(isolate_, math, "SQRT2",
|
|
|
|
factory->NewNumber(std::sqrt(2.0)));
|
2016-10-11 06:46:56 +00:00
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, math, factory->to_string_tag_symbol(),
|
2016-10-11 06:46:56 +00:00
|
|
|
factory->NewStringFromAsciiChecked("Math"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
2009-04-24 08:13:09 +00:00
|
|
|
}
|
|
|
|
|
2017-04-18 20:50:30 +00:00
|
|
|
{ // -- C o n s o l e
|
|
|
|
Handle<String> name = factory->InternalizeUtf8String("console");
|
2017-11-08 12:56:08 +00:00
|
|
|
NewFunctionArgs args = NewFunctionArgs::ForFunctionWithoutCode(
|
2018-05-31 14:14:48 +00:00
|
|
|
name, isolate_->strict_function_map(), LanguageMode::kStrict);
|
2017-11-08 12:56:08 +00:00
|
|
|
Handle<JSFunction> cons = factory->NewFunction(args);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSObject> empty = factory->NewJSObject(isolate_->object_function());
|
2017-04-20 23:21:00 +00:00
|
|
|
JSFunction::SetPrototype(cons, empty);
|
2017-11-08 12:56:08 +00:00
|
|
|
|
2017-04-18 20:50:30 +00:00
|
|
|
Handle<JSObject> console = factory->NewJSObject(cons, TENURED);
|
|
|
|
DCHECK(console->IsJSObject());
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, global, name, console, DONT_ENUM);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "debug", Builtins::kConsoleDebug,
|
2018-05-05 16:23:38 +00:00
|
|
|
1, false, NONE);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "error", Builtins::kConsoleError,
|
|
|
|
1, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "info", Builtins::kConsoleInfo, 1,
|
2017-04-25 22:17:24 +00:00
|
|
|
false, NONE);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "log", Builtins::kConsoleLog, 1,
|
2017-04-25 22:17:24 +00:00
|
|
|
false, NONE);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "warn", Builtins::kConsoleWarn, 1,
|
2017-04-25 22:17:24 +00:00
|
|
|
false, NONE);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "dir", Builtins::kConsoleDir, 1,
|
2017-04-25 22:17:24 +00:00
|
|
|
false, NONE);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "dirxml", Builtins::kConsoleDirXml,
|
|
|
|
1, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "table", Builtins::kConsoleTable,
|
|
|
|
1, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "trace", Builtins::kConsoleTrace,
|
|
|
|
1, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "group", Builtins::kConsoleGroup,
|
|
|
|
1, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "groupCollapsed",
|
|
|
|
Builtins::kConsoleGroupCollapsed, 1, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "groupEnd",
|
|
|
|
Builtins::kConsoleGroupEnd, 1, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "clear", Builtins::kConsoleClear,
|
|
|
|
1, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "count", Builtins::kConsoleCount,
|
|
|
|
1, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "countReset",
|
|
|
|
Builtins::kConsoleCountReset, 1, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "assert",
|
|
|
|
Builtins::kFastConsoleAssert, 1, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "profile",
|
|
|
|
Builtins::kConsoleProfile, 1, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "profileEnd",
|
|
|
|
Builtins::kConsoleProfileEnd, 1, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "time", Builtins::kConsoleTime, 1,
|
2017-04-25 22:17:24 +00:00
|
|
|
false, NONE);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "timeEnd",
|
|
|
|
Builtins::kConsoleTimeEnd, 1, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "timeStamp",
|
|
|
|
Builtins::kConsoleTimeStamp, 1, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "context",
|
|
|
|
Builtins::kConsoleContext, 1, true, NONE);
|
2017-04-18 20:50:30 +00:00
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, console, factory->to_string_tag_symbol(),
|
2017-04-18 20:50:30 +00:00
|
|
|
factory->NewStringFromAsciiChecked("Object"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
}
|
|
|
|
|
2017-04-21 08:35:12 +00:00
|
|
|
#ifdef V8_INTL_SUPPORT
|
2016-12-27 17:10:00 +00:00
|
|
|
{ // -- I n t l
|
|
|
|
Handle<String> name = factory->InternalizeUtf8String("Intl");
|
2017-06-15 17:56:35 +00:00
|
|
|
Handle<JSObject> intl =
|
2018-05-31 14:14:48 +00:00
|
|
|
factory->NewJSObject(isolate_->object_function(), TENURED);
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, global, name, intl, DONT_ENUM);
|
2016-12-27 17:10:00 +00:00
|
|
|
|
2017-06-30 08:54:01 +00:00
|
|
|
{
|
|
|
|
Handle<JSFunction> date_time_format_constructor = InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, intl, "DateTimeFormat", JS_OBJECT_TYPE, DateFormat::kSize,
|
|
|
|
0, factory->the_hole_value(), Builtins::kIllegal);
|
2017-06-30 08:54:01 +00:00
|
|
|
native_context()->set_intl_date_time_format_function(
|
|
|
|
*date_time_format_constructor);
|
|
|
|
|
|
|
|
Handle<JSObject> prototype(
|
2018-05-31 14:14:48 +00:00
|
|
|
JSObject::cast(date_time_format_constructor->prototype()), isolate_);
|
2017-06-30 08:54:01 +00:00
|
|
|
|
|
|
|
// Install the @@toStringTag property on the {prototype}.
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, prototype, factory->to_string_tag_symbol(),
|
|
|
|
factory->Object_string(),
|
2017-06-30 08:54:01 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
2018-05-03 00:03:56 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "formatToParts",
|
2018-05-03 00:03:56 +00:00
|
|
|
Builtins::kDateTimeFormatPrototypeFormatToParts, 1,
|
|
|
|
false);
|
2017-06-30 08:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Handle<JSFunction> number_format_constructor = InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, intl, "NumberFormat", JS_OBJECT_TYPE, NumberFormat::kSize,
|
|
|
|
0, factory->the_hole_value(), Builtins::kIllegal);
|
2017-06-30 08:54:01 +00:00
|
|
|
native_context()->set_intl_number_format_function(
|
|
|
|
*number_format_constructor);
|
|
|
|
|
|
|
|
Handle<JSObject> prototype(
|
2018-05-31 14:14:48 +00:00
|
|
|
JSObject::cast(number_format_constructor->prototype()), isolate_);
|
2017-06-30 08:54:01 +00:00
|
|
|
|
|
|
|
// Install the @@toStringTag property on the {prototype}.
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, prototype, factory->to_string_tag_symbol(),
|
|
|
|
factory->Object_string(),
|
2017-06-30 08:54:01 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
2018-04-27 19:09:03 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "formatToParts",
|
2018-05-03 00:03:56 +00:00
|
|
|
Builtins::kNumberFormatPrototypeFormatToParts, 1,
|
|
|
|
false);
|
2018-07-09 10:36:42 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype,
|
|
|
|
factory->InternalizeUtf8String("format"),
|
|
|
|
Builtins::kNumberFormatPrototypeFormatNumber, false);
|
|
|
|
|
|
|
|
{
|
|
|
|
Handle<SharedFunctionInfo> info = SimpleCreateBuiltinSharedFunctionInfo(
|
|
|
|
isolate_, Builtins::kNumberFormatInternalFormatNumber,
|
|
|
|
factory->empty_string(), 1);
|
|
|
|
native_context()->set_number_format_internal_format_number_shared_fun(
|
|
|
|
*info);
|
|
|
|
}
|
2017-06-30 08:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSFunction> collator_constructor = InstallFunction(
|
|
|
|
isolate_, intl, "Collator", JS_OBJECT_TYPE, Collator::kSize, 0,
|
|
|
|
factory->the_hole_value(), Builtins::kIllegal);
|
2017-06-30 08:54:01 +00:00
|
|
|
native_context()->set_intl_collator_function(*collator_constructor);
|
|
|
|
|
|
|
|
Handle<JSObject> prototype(
|
2018-05-31 14:14:48 +00:00
|
|
|
JSObject::cast(collator_constructor->prototype()), isolate_);
|
2017-06-30 08:54:01 +00:00
|
|
|
|
|
|
|
// Install the @@toStringTag property on the {prototype}.
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, prototype, factory->to_string_tag_symbol(),
|
|
|
|
factory->Object_string(),
|
2017-06-30 08:54:01 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSFunction> v8_break_iterator_constructor =
|
|
|
|
InstallFunction(isolate_, intl, "v8BreakIterator", JS_OBJECT_TYPE,
|
|
|
|
V8BreakIterator::kSize, 0, factory->the_hole_value(),
|
|
|
|
Builtins::kIllegal);
|
2017-06-30 08:54:01 +00:00
|
|
|
native_context()->set_intl_v8_break_iterator_function(
|
|
|
|
*v8_break_iterator_constructor);
|
|
|
|
|
|
|
|
Handle<JSObject> prototype(
|
2018-05-31 14:14:48 +00:00
|
|
|
JSObject::cast(v8_break_iterator_constructor->prototype()), isolate_);
|
2017-06-30 08:54:01 +00:00
|
|
|
|
|
|
|
// Install the @@toStringTag property on the {prototype}.
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, prototype, factory->to_string_tag_symbol(),
|
|
|
|
factory->Object_string(),
|
2017-06-30 08:54:01 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
}
|
2018-04-27 19:09:03 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
Handle<JSFunction> plural_rules_constructor = InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, intl, "PluralRules", JS_OBJECT_TYPE, PluralRules::kSize, 0,
|
2018-04-27 19:09:03 +00:00
|
|
|
factory->the_hole_value(), Builtins::kIllegal);
|
|
|
|
native_context()->set_intl_plural_rules_function(
|
|
|
|
*plural_rules_constructor);
|
|
|
|
|
|
|
|
Handle<JSObject> prototype(
|
2018-05-31 14:14:48 +00:00
|
|
|
JSObject::cast(plural_rules_constructor->prototype()), isolate_);
|
2018-04-27 19:09:03 +00:00
|
|
|
|
|
|
|
// Install the @@toStringTag property on the {prototype}.
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, prototype, factory->to_string_tag_symbol(),
|
|
|
|
factory->Object_string(),
|
2018-04-27 19:09:03 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
}
|
2016-12-27 17:10:00 +00:00
|
|
|
}
|
2017-04-21 08:35:12 +00:00
|
|
|
#endif // V8_INTL_SUPPORT
|
2016-12-27 17:10:00 +00:00
|
|
|
|
2014-06-06 08:15:05 +00:00
|
|
|
{ // -- A r r a y B u f f e r
|
2018-02-15 05:26:29 +00:00
|
|
|
Handle<String> name = factory->ArrayBuffer_string();
|
2018-01-10 23:52:53 +00:00
|
|
|
Handle<JSFunction> array_buffer_fun = CreateArrayBuffer(name, ARRAY_BUFFER);
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, global, name, array_buffer_fun, DONT_ENUM);
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate_, array_buffer_fun,
|
2015-12-07 16:35:03 +00:00
|
|
|
Context::ARRAY_BUFFER_FUN_INDEX);
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallSpeciesGetter(isolate_, array_buffer_fun);
|
2017-04-06 13:09:38 +00:00
|
|
|
|
|
|
|
Handle<JSFunction> array_buffer_noinit_fun = SimpleCreateFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_,
|
2017-04-06 13:09:38 +00:00
|
|
|
factory->NewStringFromAsciiChecked(
|
|
|
|
"arrayBufferConstructor_DoNotInitialize"),
|
|
|
|
Builtins::kArrayBufferConstructor_DoNotInitialize, 1, false);
|
|
|
|
native_context()->set_array_buffer_noinit_fun(*array_buffer_noinit_fun);
|
2013-08-20 13:55:52 +00:00
|
|
|
}
|
|
|
|
|
2017-06-13 23:17:05 +00:00
|
|
|
{ // -- S h a r e d A r r a y B u f f e r
|
2018-02-15 05:26:29 +00:00
|
|
|
Handle<String> name = factory->SharedArrayBuffer_string();
|
2018-01-10 23:52:53 +00:00
|
|
|
Handle<JSFunction> shared_array_buffer_fun =
|
|
|
|
CreateArrayBuffer(name, SHARED_ARRAY_BUFFER);
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate_, shared_array_buffer_fun,
|
2017-06-13 23:17:05 +00:00
|
|
|
Context::SHARED_ARRAY_BUFFER_FUN_INDEX);
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallSpeciesGetter(isolate_, shared_array_buffer_fun);
|
2017-06-13 23:17:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- A t o m i c s
|
2017-06-15 18:44:40 +00:00
|
|
|
Handle<JSObject> atomics_object =
|
2018-05-31 14:14:48 +00:00
|
|
|
factory->NewJSObject(isolate_->object_function(), TENURED);
|
2017-06-13 23:17:05 +00:00
|
|
|
native_context()->set_atomics_object(*atomics_object);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "load",
|
|
|
|
Builtins::kAtomicsLoad, 2, true);
|
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "store",
|
|
|
|
Builtins::kAtomicsStore, 3, true);
|
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "add",
|
|
|
|
Builtins::kAtomicsAdd, 3, true);
|
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "sub",
|
|
|
|
Builtins::kAtomicsSub, 3, true);
|
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "and",
|
|
|
|
Builtins::kAtomicsAnd, 3, true);
|
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "or", Builtins::kAtomicsOr,
|
|
|
|
3, true);
|
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "xor",
|
|
|
|
Builtins::kAtomicsXor, 3, true);
|
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "exchange",
|
2017-06-13 23:17:05 +00:00
|
|
|
Builtins::kAtomicsExchange, 3, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "compareExchange",
|
2017-06-13 23:17:05 +00:00
|
|
|
Builtins::kAtomicsCompareExchange, 4, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "isLockFree",
|
2017-06-13 23:17:05 +00:00
|
|
|
Builtins::kAtomicsIsLockFree, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "wait",
|
|
|
|
Builtins::kAtomicsWait, 4, true);
|
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "wake",
|
|
|
|
Builtins::kAtomicsWake, 3, true);
|
2018-07-18 18:19:55 +00:00
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "notify",
|
|
|
|
Builtins::kAtomicsWake, 3, true);
|
2017-06-13 23:17:05 +00:00
|
|
|
}
|
|
|
|
|
2016-06-08 07:40:11 +00:00
|
|
|
{ // -- T y p e d A r r a y
|
2018-04-06 11:58:43 +00:00
|
|
|
Handle<JSFunction> typed_array_fun = CreateFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, factory->InternalizeUtf8String("TypedArray"),
|
2018-04-06 11:58:43 +00:00
|
|
|
JS_TYPED_ARRAY_TYPE, JSTypedArray::kSize, 0, factory->the_hole_value(),
|
|
|
|
Builtins::kTypedArrayBaseConstructor);
|
2017-02-01 14:02:59 +00:00
|
|
|
typed_array_fun->shared()->set_native(false);
|
2018-04-06 11:58:43 +00:00
|
|
|
typed_array_fun->shared()->set_length(0);
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallSpeciesGetter(isolate_, typed_array_fun);
|
2016-06-08 07:40:11 +00:00
|
|
|
native_context()->set_typed_array_function(*typed_array_fun);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, typed_array_fun, "of",
|
|
|
|
Builtins::kTypedArrayOf, 0, false);
|
|
|
|
SimpleInstallFunction(isolate_, typed_array_fun, "from",
|
|
|
|
Builtins::kTypedArrayFrom, 1, false);
|
2018-02-07 11:49:24 +00:00
|
|
|
|
2017-06-30 08:54:01 +00:00
|
|
|
// Setup %TypedArrayPrototype%.
|
|
|
|
Handle<JSObject> prototype(
|
2018-06-20 10:10:43 +00:00
|
|
|
JSObject::cast(typed_array_fun->instance_prototype()), isolate());
|
2017-06-30 08:54:01 +00:00
|
|
|
native_context()->set_typed_array_prototype(*prototype);
|
|
|
|
|
2017-10-02 05:28:41 +00:00
|
|
|
// Install the "buffer", "byteOffset", "byteLength", "length"
|
|
|
|
// and @@toStringTag getters on the {prototype}.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->buffer_string(),
|
2016-06-08 07:40:11 +00:00
|
|
|
Builtins::kTypedArrayPrototypeBuffer, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->byte_length_string(),
|
2016-06-08 07:40:11 +00:00
|
|
|
Builtins::kTypedArrayPrototypeByteLength, true,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
BuiltinFunctionId::kTypedArrayByteLength);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->byte_offset_string(),
|
2016-06-08 07:40:11 +00:00
|
|
|
Builtins::kTypedArrayPrototypeByteOffset, true,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
BuiltinFunctionId::kTypedArrayByteOffset);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->length_string(),
|
2016-06-08 07:40:11 +00:00
|
|
|
Builtins::kTypedArrayPrototypeLength, true,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
BuiltinFunctionId::kTypedArrayLength);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->to_string_tag_symbol(),
|
2017-10-02 05:28:41 +00:00
|
|
|
Builtins::kTypedArrayPrototypeToStringTag, true,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
BuiltinFunctionId::kTypedArrayToStringTag);
|
2016-10-18 02:42:42 +00:00
|
|
|
|
|
|
|
// Install "keys", "values" and "entries" methods on the {prototype}.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "entries",
|
2017-06-30 13:54:24 +00:00
|
|
|
Builtins::kTypedArrayPrototypeEntries, 0, true,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
BuiltinFunctionId::kTypedArrayEntries);
|
2017-06-30 13:54:24 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "keys",
|
|
|
|
Builtins::kTypedArrayPrototypeKeys, 0, true,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
BuiltinFunctionId::kTypedArrayKeys);
|
2017-06-30 13:54:24 +00:00
|
|
|
|
|
|
|
Handle<JSFunction> values = SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, prototype, "values", Builtins::kTypedArrayPrototypeValues, 0,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
true, BuiltinFunctionId::kTypedArrayValues);
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, prototype, factory->iterator_symbol(),
|
|
|
|
values, DONT_ENUM);
|
2017-02-15 14:21:18 +00:00
|
|
|
|
|
|
|
// TODO(caitp): alphasort accessors/methods
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "copyWithin",
|
2017-02-15 14:21:18 +00:00
|
|
|
Builtins::kTypedArrayPrototypeCopyWithin, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "every",
|
2017-05-19 11:36:25 +00:00
|
|
|
Builtins::kTypedArrayPrototypeEvery, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "fill",
|
2017-03-20 13:32:54 +00:00
|
|
|
Builtins::kTypedArrayPrototypeFill, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "filter",
|
2018-02-13 14:51:28 +00:00
|
|
|
Builtins::kTypedArrayPrototypeFilter, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "find",
|
|
|
|
Builtins::kTypedArrayPrototypeFind, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "findIndex",
|
2017-11-29 13:57:20 +00:00
|
|
|
Builtins::kTypedArrayPrototypeFindIndex, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "forEach",
|
2017-05-22 08:23:34 +00:00
|
|
|
Builtins::kTypedArrayPrototypeForEach, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "includes",
|
2017-03-07 05:06:30 +00:00
|
|
|
Builtins::kTypedArrayPrototypeIncludes, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "indexOf",
|
2017-03-13 09:40:09 +00:00
|
|
|
Builtins::kTypedArrayPrototypeIndexOf, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "lastIndexOf",
|
2017-03-16 16:28:00 +00:00
|
|
|
Builtins::kTypedArrayPrototypeLastIndexOf, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "map",
|
|
|
|
Builtins::kTypedArrayPrototypeMap, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "reverse",
|
2017-03-25 16:04:35 +00:00
|
|
|
Builtins::kTypedArrayPrototypeReverse, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "reduce",
|
2017-05-19 11:36:25 +00:00
|
|
|
Builtins::kTypedArrayPrototypeReduce, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "reduceRight",
|
2017-05-19 11:36:25 +00:00
|
|
|
Builtins::kTypedArrayPrototypeReduceRight, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "set",
|
|
|
|
Builtins::kTypedArrayPrototypeSet, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "slice",
|
2017-04-01 16:46:10 +00:00
|
|
|
Builtins::kTypedArrayPrototypeSlice, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "some",
|
|
|
|
Builtins::kTypedArrayPrototypeSome, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "sort",
|
|
|
|
Builtins::kTypedArrayPrototypeSort, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "subarray",
|
2018-01-24 03:54:00 +00:00
|
|
|
Builtins::kTypedArrayPrototypeSubArray, 2, false);
|
2016-06-08 07:40:11 +00:00
|
|
|
}
|
|
|
|
|
2014-06-06 08:15:05 +00:00
|
|
|
{ // -- T y p e d A r r a y s
|
2015-12-07 16:35:03 +00:00
|
|
|
#define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype, size) \
|
|
|
|
{ \
|
2017-11-28 08:35:49 +00:00
|
|
|
Handle<JSFunction> fun = \
|
|
|
|
InstallTypedArray(#Type "Array", TYPE##_ELEMENTS); \
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate_, fun, \
|
2015-12-07 16:35:03 +00:00
|
|
|
Context::TYPE##_ARRAY_FUN_INDEX); \
|
2015-07-28 09:29:34 +00:00
|
|
|
}
|
2014-01-24 16:01:15 +00:00
|
|
|
TYPED_ARRAYS(INSTALL_TYPED_ARRAY)
|
|
|
|
#undef INSTALL_TYPED_ARRAY
|
2016-06-08 07:40:11 +00:00
|
|
|
}
|
2013-08-20 13:55:52 +00:00
|
|
|
|
2016-06-08 07:40:11 +00:00
|
|
|
{ // -- D a t a V i e w
|
2017-06-30 08:54:01 +00:00
|
|
|
Handle<JSFunction> data_view_fun = InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, global, "DataView", JS_DATA_VIEW_TYPE,
|
2017-10-18 20:14:09 +00:00
|
|
|
JSDataView::kSizeWithEmbedderFields, 0, factory->the_hole_value(),
|
2017-06-30 08:54:01 +00:00
|
|
|
Builtins::kDataViewConstructor);
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate_, data_view_fun,
|
2015-12-07 16:35:03 +00:00
|
|
|
Context::DATA_VIEW_FUN_INDEX);
|
2018-06-12 17:46:47 +00:00
|
|
|
data_view_fun->shared()->set_length(1);
|
2016-02-19 08:58:33 +00:00
|
|
|
data_view_fun->shared()->DontAdaptArguments();
|
2016-06-08 07:40:11 +00:00
|
|
|
|
2017-06-30 08:54:01 +00:00
|
|
|
// Setup %DataViewPrototype%.
|
|
|
|
Handle<JSObject> prototype(
|
2018-06-20 10:10:43 +00:00
|
|
|
JSObject::cast(data_view_fun->instance_prototype()), isolate());
|
2017-06-30 08:54:01 +00:00
|
|
|
|
2016-06-08 07:40:11 +00:00
|
|
|
// Install the @@toStringTag property on the {prototype}.
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, prototype, factory->to_string_tag_symbol(),
|
2016-06-08 07:40:11 +00:00
|
|
|
factory->NewStringFromAsciiChecked("DataView"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
|
|
|
// Install the "buffer", "byteOffset" and "byteLength" getters
|
|
|
|
// on the {prototype}.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->buffer_string(),
|
2016-06-08 07:40:11 +00:00
|
|
|
Builtins::kDataViewPrototypeGetBuffer, false,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
BuiltinFunctionId::kDataViewBuffer);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->byte_length_string(),
|
2016-06-08 07:40:11 +00:00
|
|
|
Builtins::kDataViewPrototypeGetByteLength, false,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
BuiltinFunctionId::kDataViewByteLength);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->byte_offset_string(),
|
2016-06-08 07:40:11 +00:00
|
|
|
Builtins::kDataViewPrototypeGetByteOffset, false,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
BuiltinFunctionId::kDataViewByteOffset);
|
2016-09-02 18:31:41 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getInt8",
|
2016-09-02 18:31:41 +00:00
|
|
|
Builtins::kDataViewPrototypeGetInt8, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setInt8",
|
2016-09-02 18:31:41 +00:00
|
|
|
Builtins::kDataViewPrototypeSetInt8, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getUint8",
|
2016-09-02 18:31:41 +00:00
|
|
|
Builtins::kDataViewPrototypeGetUint8, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setUint8",
|
2016-09-02 18:31:41 +00:00
|
|
|
Builtins::kDataViewPrototypeSetUint8, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getInt16",
|
2016-09-02 18:31:41 +00:00
|
|
|
Builtins::kDataViewPrototypeGetInt16, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setInt16",
|
2016-09-02 18:31:41 +00:00
|
|
|
Builtins::kDataViewPrototypeSetInt16, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getUint16",
|
2016-09-02 18:31:41 +00:00
|
|
|
Builtins::kDataViewPrototypeGetUint16, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setUint16",
|
2016-09-02 18:31:41 +00:00
|
|
|
Builtins::kDataViewPrototypeSetUint16, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getInt32",
|
2016-09-02 18:31:41 +00:00
|
|
|
Builtins::kDataViewPrototypeGetInt32, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setInt32",
|
2016-09-02 18:31:41 +00:00
|
|
|
Builtins::kDataViewPrototypeSetInt32, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getUint32",
|
2016-09-02 18:31:41 +00:00
|
|
|
Builtins::kDataViewPrototypeGetUint32, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setUint32",
|
2016-09-02 18:31:41 +00:00
|
|
|
Builtins::kDataViewPrototypeSetUint32, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getFloat32",
|
2016-09-02 18:31:41 +00:00
|
|
|
Builtins::kDataViewPrototypeGetFloat32, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setFloat32",
|
2016-09-02 18:31:41 +00:00
|
|
|
Builtins::kDataViewPrototypeSetFloat32, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getFloat64",
|
2016-09-02 18:31:41 +00:00
|
|
|
Builtins::kDataViewPrototypeGetFloat64, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setFloat64",
|
2016-09-02 18:31:41 +00:00
|
|
|
Builtins::kDataViewPrototypeSetFloat64, 2, false);
|
2013-08-20 13:55:52 +00:00
|
|
|
}
|
|
|
|
|
2015-05-26 17:36:48 +00:00
|
|
|
{ // -- M a p
|
2017-05-23 09:06:51 +00:00
|
|
|
Handle<JSFunction> js_map_fun =
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallFunction(isolate_, global, "Map", JS_MAP_TYPE, JSMap::kSize, 0,
|
2017-06-30 08:54:01 +00:00
|
|
|
factory->the_hole_value(), Builtins::kMapConstructor);
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate_, js_map_fun,
|
2015-12-07 16:35:03 +00:00
|
|
|
Context::JS_MAP_FUN_INDEX);
|
2017-05-23 09:06:51 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(js_map_fun->shared(), isolate_);
|
2017-06-07 19:36:36 +00:00
|
|
|
shared->DontAdaptArguments();
|
2017-05-23 09:06:51 +00:00
|
|
|
shared->set_length(0);
|
|
|
|
|
2017-06-30 08:54:01 +00:00
|
|
|
// Setup %MapPrototype%.
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSObject> prototype(JSObject::cast(js_map_fun->instance_prototype()),
|
|
|
|
isolate());
|
2017-05-23 09:06:51 +00:00
|
|
|
|
|
|
|
// Install the @@toStringTag property on the {prototype}.
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, prototype, factory->to_string_tag_symbol(),
|
|
|
|
factory->Map_string(),
|
2017-05-23 09:06:51 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
2017-10-09 18:15:51 +00:00
|
|
|
Handle<JSFunction> map_get = SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, prototype, "get", Builtins::kMapPrototypeGet, 1, true);
|
2017-06-19 15:17:22 +00:00
|
|
|
native_context()->set_map_get(*map_get);
|
2017-06-01 15:33:05 +00:00
|
|
|
|
2017-10-09 18:15:51 +00:00
|
|
|
Handle<JSFunction> map_set = SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, prototype, "set", Builtins::kMapPrototypeSet, 2, true);
|
2017-07-23 13:46:28 +00:00
|
|
|
native_context()->set_map_set(*map_set);
|
|
|
|
|
2017-10-09 18:15:51 +00:00
|
|
|
Handle<JSFunction> map_has = SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, prototype, "has", Builtins::kMapPrototypeHas, 1, true);
|
2017-06-19 15:17:22 +00:00
|
|
|
native_context()->set_map_has(*map_has);
|
2017-06-02 10:28:57 +00:00
|
|
|
|
2017-07-24 11:45:28 +00:00
|
|
|
Handle<JSFunction> map_delete = SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, prototype, "delete", Builtins::kMapPrototypeDelete, 1, true);
|
2017-07-24 11:45:28 +00:00
|
|
|
native_context()->set_map_delete(*map_delete);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "clear",
|
|
|
|
Builtins::kMapPrototypeClear, 0, true);
|
|
|
|
Handle<JSFunction> entries =
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "entries",
|
|
|
|
Builtins::kMapPrototypeEntries, 0, true);
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, prototype, factory->iterator_symbol(),
|
|
|
|
entries, DONT_ENUM);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "forEach",
|
|
|
|
Builtins::kMapPrototypeForEach, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "keys",
|
|
|
|
Builtins::kMapPrototypeKeys, 0, true);
|
|
|
|
SimpleInstallGetter(
|
|
|
|
isolate_, prototype, factory->InternalizeUtf8String("size"),
|
|
|
|
Builtins::kMapPrototypeGetSize, true, BuiltinFunctionId::kMapSize);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "values",
|
|
|
|
Builtins::kMapPrototypeValues, 0, true);
|
2018-01-18 14:53:18 +00:00
|
|
|
|
|
|
|
native_context()->set_initial_map_prototype_map(prototype->map());
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallSpeciesGetter(isolate_, js_map_fun);
|
2015-05-26 17:36:48 +00:00
|
|
|
}
|
2014-08-05 19:37:32 +00:00
|
|
|
|
2015-05-26 17:36:48 +00:00
|
|
|
{ // -- S e t
|
2017-06-02 12:29:59 +00:00
|
|
|
Handle<JSFunction> js_set_fun =
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallFunction(isolate_, global, "Set", JS_SET_TYPE, JSSet::kSize, 0,
|
2017-06-30 08:54:01 +00:00
|
|
|
factory->the_hole_value(), Builtins::kSetConstructor);
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate_, js_set_fun,
|
2015-12-07 16:35:03 +00:00
|
|
|
Context::JS_SET_FUN_INDEX);
|
2017-06-02 12:29:59 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(js_set_fun->shared(), isolate_);
|
2017-06-07 19:36:36 +00:00
|
|
|
shared->DontAdaptArguments();
|
2017-06-07 14:22:44 +00:00
|
|
|
shared->set_length(0);
|
|
|
|
|
2017-06-30 08:54:01 +00:00
|
|
|
// Setup %SetPrototype%.
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSObject> prototype(JSObject::cast(js_set_fun->instance_prototype()),
|
|
|
|
isolate());
|
2017-06-07 14:22:44 +00:00
|
|
|
|
|
|
|
// Install the @@toStringTag property on the {prototype}.
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, prototype, factory->to_string_tag_symbol(),
|
|
|
|
factory->Set_string(),
|
2017-06-07 14:22:44 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
2017-10-09 18:15:51 +00:00
|
|
|
Handle<JSFunction> set_has = SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, prototype, "has", Builtins::kSetPrototypeHas, 1, true);
|
2017-06-19 15:17:22 +00:00
|
|
|
native_context()->set_set_has(*set_has);
|
2017-07-24 14:23:38 +00:00
|
|
|
|
2017-10-09 18:15:51 +00:00
|
|
|
Handle<JSFunction> set_add = SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, prototype, "add", Builtins::kSetPrototypeAdd, 1, true);
|
2017-07-24 14:23:38 +00:00
|
|
|
native_context()->set_set_add(*set_add);
|
|
|
|
|
|
|
|
Handle<JSFunction> set_delete = SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, prototype, "delete", Builtins::kSetPrototypeDelete, 1, true);
|
2017-07-24 14:23:38 +00:00
|
|
|
native_context()->set_set_delete(*set_delete);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "clear",
|
|
|
|
Builtins::kSetPrototypeClear, 0, true);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "entries",
|
|
|
|
Builtins::kSetPrototypeEntries, 0, true);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "forEach",
|
|
|
|
Builtins::kSetPrototypeForEach, 1, false);
|
|
|
|
SimpleInstallGetter(
|
|
|
|
isolate_, prototype, factory->InternalizeUtf8String("size"),
|
|
|
|
Builtins::kSetPrototypeGetSize, true, BuiltinFunctionId::kSetSize);
|
2017-07-06 10:39:28 +00:00
|
|
|
Handle<JSFunction> values = SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, prototype, "values", Builtins::kSetPrototypeValues, 0, true);
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, prototype, factory->keys_string(), values,
|
2017-07-06 10:39:28 +00:00
|
|
|
DONT_ENUM);
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, prototype, factory->iterator_symbol(),
|
|
|
|
values, DONT_ENUM);
|
2018-01-18 14:53:18 +00:00
|
|
|
|
|
|
|
native_context()->set_initial_set_prototype_map(prototype->map());
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallSpeciesGetter(isolate_, js_set_fun);
|
2015-05-26 17:36:48 +00:00
|
|
|
}
|
2014-08-05 19:37:32 +00:00
|
|
|
|
2016-10-07 19:37:04 +00:00
|
|
|
{ // -- J S M o d u l e N a m e s p a c e
|
2017-10-18 20:14:09 +00:00
|
|
|
Handle<Map> map = factory->NewMap(
|
|
|
|
JS_MODULE_NAMESPACE_TYPE, JSModuleNamespace::kSize,
|
|
|
|
TERMINAL_FAST_ELEMENTS_KIND, JSModuleNamespace::kInObjectFieldCount);
|
2018-06-25 10:54:01 +00:00
|
|
|
Map::SetPrototype(isolate(), map, isolate_->factory()->null_value());
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::EnsureDescriptorSlack(isolate_, map, 1);
|
2016-10-07 19:37:04 +00:00
|
|
|
native_context()->set_js_module_namespace_map(*map);
|
|
|
|
|
2016-10-13 13:34:50 +00:00
|
|
|
{ // Install @@toStringTag.
|
|
|
|
PropertyAttributes attribs =
|
2017-01-04 06:33:10 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY);
|
2017-01-12 21:40:04 +00:00
|
|
|
Descriptor d =
|
2018-07-17 15:08:58 +00:00
|
|
|
Descriptor::DataField(isolate(), factory->to_string_tag_symbol(),
|
2017-01-12 21:40:04 +00:00
|
|
|
JSModuleNamespace::kToStringTagFieldIndex,
|
|
|
|
attribs, Representation::Tagged());
|
2016-10-13 13:34:50 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
2016-10-07 19:37:04 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 12:16:15 +00:00
|
|
|
{ // -- I t e r a t o r R e s u l t
|
2017-10-18 20:14:09 +00:00
|
|
|
Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSIteratorResult::kSize,
|
|
|
|
TERMINAL_FAST_ELEMENTS_KIND, 2);
|
2018-06-25 10:54:01 +00:00
|
|
|
Map::SetPrototype(isolate(), map, isolate_->initial_object_prototype());
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::EnsureDescriptorSlack(isolate_, map, 2);
|
2015-09-03 12:16:15 +00:00
|
|
|
|
|
|
|
{ // value
|
2018-07-17 15:08:58 +00:00
|
|
|
Descriptor d = Descriptor::DataField(isolate(), factory->value_string(),
|
2016-12-21 16:40:00 +00:00
|
|
|
JSIteratorResult::kValueIndex, NONE,
|
|
|
|
Representation::Tagged());
|
2015-09-03 12:16:15 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // done
|
2018-07-17 15:08:58 +00:00
|
|
|
Descriptor d = Descriptor::DataField(isolate(), factory->done_string(),
|
2016-12-21 16:40:00 +00:00
|
|
|
JSIteratorResult::kDoneIndex, NONE,
|
|
|
|
Representation::Tagged());
|
2015-09-03 12:16:15 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
2016-02-08 07:00:02 +00:00
|
|
|
map->SetConstructor(native_context()->object_function());
|
2015-09-03 12:16:15 +00:00
|
|
|
native_context()->set_iterator_result_map(*map);
|
2014-08-05 19:37:32 +00:00
|
|
|
}
|
|
|
|
|
2015-12-07 16:35:03 +00:00
|
|
|
{ // -- W e a k M a p
|
2017-11-12 14:50:59 +00:00
|
|
|
Handle<JSFunction> cons = InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, global, "WeakMap", JS_WEAK_MAP_TYPE, JSWeakMap::kSize, 0,
|
2017-11-12 14:50:59 +00:00
|
|
|
factory->the_hole_value(), Builtins::kWeakMapConstructor);
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate_, cons,
|
2015-12-07 16:35:03 +00:00
|
|
|
Context::JS_WEAK_MAP_FUN_INDEX);
|
2017-11-12 14:50:59 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(cons->shared(), isolate_);
|
2017-11-12 14:50:59 +00:00
|
|
|
shared->DontAdaptArguments();
|
|
|
|
shared->set_length(0);
|
|
|
|
|
2017-06-29 14:21:59 +00:00
|
|
|
// Setup %WeakMapPrototype%.
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSObject> prototype(JSObject::cast(cons->instance_prototype()),
|
|
|
|
isolate());
|
2017-06-29 14:21:59 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "delete",
|
2017-10-30 14:08:30 +00:00
|
|
|
Builtins::kWeakMapPrototypeDelete, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "get", Builtins::kWeakMapGet, 1,
|
|
|
|
true);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "has", Builtins::kWeakMapHas, 1,
|
|
|
|
true);
|
2018-01-18 14:53:18 +00:00
|
|
|
Handle<JSFunction> weakmap_set = SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, prototype, "set", Builtins::kWeakMapPrototypeSet, 2, true);
|
2018-01-18 14:53:18 +00:00
|
|
|
native_context()->set_weakmap_set(*weakmap_set);
|
2017-07-17 06:44:47 +00:00
|
|
|
|
2017-06-29 14:21:59 +00:00
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, prototype, factory->to_string_tag_symbol(),
|
2017-06-29 14:21:59 +00:00
|
|
|
factory->NewStringFromAsciiChecked("WeakMap"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
2018-01-18 14:53:18 +00:00
|
|
|
|
|
|
|
native_context()->set_initial_weakmap_prototype_map(prototype->map());
|
2015-12-07 16:35:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- W e a k S e t
|
2017-11-12 14:50:59 +00:00
|
|
|
Handle<JSFunction> cons = InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, global, "WeakSet", JS_WEAK_SET_TYPE, JSWeakSet::kSize, 0,
|
2017-11-12 14:50:59 +00:00
|
|
|
factory->the_hole_value(), Builtins::kWeakSetConstructor);
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate_, cons,
|
2015-12-07 16:35:03 +00:00
|
|
|
Context::JS_WEAK_SET_FUN_INDEX);
|
2017-11-12 14:50:59 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(cons->shared(), isolate_);
|
2017-11-12 14:50:59 +00:00
|
|
|
shared->DontAdaptArguments();
|
|
|
|
shared->set_length(0);
|
|
|
|
|
2017-06-29 14:21:59 +00:00
|
|
|
// Setup %WeakSetPrototype%.
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSObject> prototype(JSObject::cast(cons->instance_prototype()),
|
|
|
|
isolate());
|
2017-06-29 14:21:59 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "delete",
|
2017-10-30 14:08:30 +00:00
|
|
|
Builtins::kWeakSetPrototypeDelete, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "has", Builtins::kWeakSetHas, 1,
|
|
|
|
true);
|
2018-01-18 14:53:18 +00:00
|
|
|
Handle<JSFunction> weakset_add = SimpleInstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, prototype, "add", Builtins::kWeakSetPrototypeAdd, 1, true);
|
2018-01-18 14:53:18 +00:00
|
|
|
native_context()->set_weakset_add(*weakset_add);
|
2017-07-17 08:18:14 +00:00
|
|
|
|
2017-06-29 14:21:59 +00:00
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, prototype, factory->to_string_tag_symbol(),
|
2017-06-29 14:21:59 +00:00
|
|
|
factory->NewStringFromAsciiChecked("WeakSet"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
2018-01-18 14:53:18 +00:00
|
|
|
|
|
|
|
native_context()->set_initial_weakset_prototype_map(prototype->map());
|
2015-12-07 16:35:03 +00:00
|
|
|
}
|
2014-05-06 14:48:34 +00:00
|
|
|
|
2016-03-21 19:39:16 +00:00
|
|
|
{ // -- P r o x y
|
|
|
|
CreateJSProxyMaps();
|
2017-10-12 15:37:46 +00:00
|
|
|
// Proxy function map has prototype slot for storing initial map but does
|
|
|
|
// not have a prototype property.
|
2018-06-19 09:00:37 +00:00
|
|
|
Handle<Map> proxy_function_map = Map::Copy(
|
|
|
|
isolate_, isolate_->strict_function_without_prototype_map(), "Proxy");
|
2017-07-03 13:40:13 +00:00
|
|
|
proxy_function_map->set_is_constructor(true);
|
|
|
|
|
2016-03-21 19:39:16 +00:00
|
|
|
Handle<String> name = factory->Proxy_string();
|
2017-11-08 12:56:08 +00:00
|
|
|
|
|
|
|
NewFunctionArgs args = NewFunctionArgs::ForBuiltin(
|
2018-03-22 16:09:55 +00:00
|
|
|
name, proxy_function_map, Builtins::kProxyConstructor);
|
2017-11-08 12:56:08 +00:00
|
|
|
Handle<JSFunction> proxy_function = factory->NewFunction(args);
|
2016-03-21 19:39:16 +00:00
|
|
|
|
|
|
|
proxy_function->shared()->set_internal_formal_parameter_count(2);
|
|
|
|
proxy_function->shared()->set_length(2);
|
|
|
|
|
|
|
|
native_context()->set_proxy_function(*proxy_function);
|
2018-06-19 09:00:37 +00:00
|
|
|
InstallFunction(isolate_, global, name, proxy_function,
|
|
|
|
factory->Object_string());
|
2018-01-05 14:40:40 +00:00
|
|
|
|
2018-07-26 11:32:20 +00:00
|
|
|
DCHECK(!proxy_function->has_prototype_property());
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, proxy_function, "revocable",
|
2018-01-05 14:40:40 +00:00
|
|
|
Builtins::kProxyRevocable, 2, true);
|
|
|
|
|
|
|
|
{ // Internal: ProxyRevoke
|
|
|
|
Handle<SharedFunctionInfo> info = SimpleCreateSharedFunctionInfo(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, Builtins::kProxyRevoke, factory->empty_string(), 0);
|
2018-01-05 14:40:40 +00:00
|
|
|
native_context()->set_proxy_revoke_shared_fun(*info);
|
|
|
|
}
|
2016-03-21 19:39:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- R e f l e c t
|
|
|
|
Handle<String> reflect_string = factory->InternalizeUtf8String("Reflect");
|
|
|
|
Handle<JSObject> reflect =
|
2018-05-31 14:14:48 +00:00
|
|
|
factory->NewJSObject(isolate_->object_function(), TENURED);
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, global, reflect_string, reflect, DONT_ENUM);
|
2016-03-21 19:39:16 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSFunction> define_property = SimpleInstallFunction(
|
|
|
|
isolate_, reflect, factory->defineProperty_string(),
|
|
|
|
Builtins::kReflectDefineProperty, 3, true);
|
2016-03-21 19:39:16 +00:00
|
|
|
native_context()->set_reflect_define_property(*define_property);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSFunction> delete_property = SimpleInstallFunction(
|
|
|
|
isolate_, reflect, factory->deleteProperty_string(),
|
|
|
|
Builtins::kReflectDeleteProperty, 2, true);
|
2016-03-21 19:39:16 +00:00
|
|
|
native_context()->set_reflect_delete_property(*delete_property);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSFunction> apply =
|
|
|
|
SimpleInstallFunction(isolate_, reflect, factory->apply_string(),
|
|
|
|
Builtins::kReflectApply, 3, false);
|
2016-03-21 19:39:16 +00:00
|
|
|
native_context()->set_reflect_apply(*apply);
|
|
|
|
|
|
|
|
Handle<JSFunction> construct =
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, reflect, factory->construct_string(),
|
2016-03-21 19:39:16 +00:00
|
|
|
Builtins::kReflectConstruct, 2, false);
|
|
|
|
native_context()->set_reflect_construct(*construct);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, reflect, factory->get_string(),
|
|
|
|
Builtins::kReflectGet, 2, false);
|
|
|
|
SimpleInstallFunction(isolate_, reflect,
|
|
|
|
factory->getOwnPropertyDescriptor_string(),
|
2016-03-21 19:39:16 +00:00
|
|
|
Builtins::kReflectGetOwnPropertyDescriptor, 2, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, reflect, factory->getPrototypeOf_string(),
|
2016-03-21 19:39:16 +00:00
|
|
|
Builtins::kReflectGetPrototypeOf, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, reflect, factory->has_string(),
|
|
|
|
Builtins::kReflectHas, 2, true);
|
|
|
|
SimpleInstallFunction(isolate_, reflect, factory->isExtensible_string(),
|
2016-03-21 19:39:16 +00:00
|
|
|
Builtins::kReflectIsExtensible, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, reflect, factory->ownKeys_string(),
|
2016-03-21 19:39:16 +00:00
|
|
|
Builtins::kReflectOwnKeys, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, reflect,
|
|
|
|
factory->preventExtensions_string(),
|
2016-03-21 19:39:16 +00:00
|
|
|
Builtins::kReflectPreventExtensions, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, reflect, factory->set_string(),
|
|
|
|
Builtins::kReflectSet, 3, false);
|
|
|
|
SimpleInstallFunction(isolate_, reflect, factory->setPrototypeOf_string(),
|
2016-03-21 19:39:16 +00:00
|
|
|
Builtins::kReflectSetPrototypeOf, 2, true);
|
|
|
|
}
|
|
|
|
|
2015-12-27 06:30:53 +00:00
|
|
|
{ // --- B o u n d F u n c t i o n
|
|
|
|
Handle<Map> map =
|
2017-10-18 20:14:09 +00:00
|
|
|
factory->NewMap(JS_BOUND_FUNCTION_TYPE, JSBoundFunction::kSize,
|
|
|
|
TERMINAL_FAST_ELEMENTS_KIND, 0);
|
2017-10-26 07:46:14 +00:00
|
|
|
map->SetConstructor(native_context()->object_function());
|
2017-12-07 11:03:41 +00:00
|
|
|
map->set_is_callable(true);
|
2018-06-25 10:54:01 +00:00
|
|
|
Map::SetPrototype(isolate(), map, empty_function);
|
2015-12-27 06:30:53 +00:00
|
|
|
|
|
|
|
PropertyAttributes roc_attribs =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::EnsureDescriptorSlack(isolate_, map, 2);
|
2015-12-27 06:30:53 +00:00
|
|
|
|
|
|
|
{ // length
|
2017-10-27 09:06:44 +00:00
|
|
|
Descriptor d = Descriptor::AccessorConstant(
|
|
|
|
factory->length_string(), factory->bound_function_length_accessor(),
|
|
|
|
roc_attribs);
|
2015-12-27 06:30:53 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
2017-10-26 15:18:09 +00:00
|
|
|
|
2016-12-21 16:40:00 +00:00
|
|
|
{ // name
|
2017-10-27 09:06:44 +00:00
|
|
|
Descriptor d = Descriptor::AccessorConstant(
|
|
|
|
factory->name_string(), factory->bound_function_name_accessor(),
|
|
|
|
roc_attribs);
|
2015-12-27 06:30:53 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
native_context()->set_bound_function_without_constructor_map(*map);
|
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
map = Map::Copy(isolate_, map, "IsConstructor");
|
2016-01-18 13:10:38 +00:00
|
|
|
map->set_is_constructor(true);
|
2015-12-27 06:30:53 +00:00
|
|
|
native_context()->set_bound_function_with_constructor_map(*map);
|
|
|
|
}
|
|
|
|
|
2014-07-07 13:27:37 +00:00
|
|
|
{ // --- sloppy arguments map
|
2014-08-18 07:54:19 +00:00
|
|
|
Handle<String> arguments_string = factory->Arguments_string();
|
2017-11-08 12:56:08 +00:00
|
|
|
NewFunctionArgs args = NewFunctionArgs::ForBuiltinWithPrototype(
|
2018-05-31 14:14:48 +00:00
|
|
|
arguments_string, isolate_->initial_object_prototype(),
|
2018-03-22 16:09:55 +00:00
|
|
|
JS_ARGUMENTS_TYPE, JSSloppyArgumentsObject::kSize, 2,
|
|
|
|
Builtins::kIllegal, MUTABLE);
|
2017-11-08 12:56:08 +00:00
|
|
|
Handle<JSFunction> function = factory->NewFunction(args);
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<Map> map(function->initial_map(), isolate());
|
2017-10-12 15:37:46 +00:00
|
|
|
|
2014-07-07 13:27:37 +00:00
|
|
|
// Create the descriptor array for the arguments object.
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::EnsureDescriptorSlack(isolate_, map, 2);
|
2014-07-07 13:27:37 +00:00
|
|
|
|
|
|
|
{ // length
|
2018-07-17 15:08:58 +00:00
|
|
|
Descriptor d =
|
|
|
|
Descriptor::DataField(isolate(), factory->length_string(),
|
|
|
|
JSSloppyArgumentsObject::kLengthIndex,
|
|
|
|
DONT_ENUM, Representation::Tagged());
|
2014-07-07 13:27:37 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
{ // callee
|
2018-07-17 15:08:58 +00:00
|
|
|
Descriptor d =
|
|
|
|
Descriptor::DataField(isolate(), factory->callee_string(),
|
|
|
|
JSSloppyArgumentsObject::kCalleeIndex,
|
|
|
|
DONT_ENUM, Representation::Tagged());
|
2014-07-07 13:27:37 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
2014-08-25 09:12:22 +00:00
|
|
|
// @@iterator method is added later.
|
2014-07-07 13:27:37 +00:00
|
|
|
|
|
|
|
native_context()->set_sloppy_arguments_map(*map);
|
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!map->is_dictionary_map());
|
2017-06-30 18:00:44 +00:00
|
|
|
DCHECK(IsObjectElementsKind(map->elements_kind()));
|
2014-07-07 12:21:01 +00:00
|
|
|
}
|
|
|
|
|
2015-07-02 14:38:37 +00:00
|
|
|
{ // --- fast and slow aliased arguments map
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<Map> map = isolate_->sloppy_arguments_map();
|
2018-06-19 09:00:37 +00:00
|
|
|
map = Map::Copy(isolate_, map, "FastAliasedArguments");
|
2015-07-02 14:38:37 +00:00
|
|
|
map->set_elements_kind(FAST_SLOPPY_ARGUMENTS_ELEMENTS);
|
2015-08-11 19:36:04 +00:00
|
|
|
DCHECK_EQ(2, map->GetInObjectProperties());
|
2015-07-02 14:38:37 +00:00
|
|
|
native_context()->set_fast_aliased_arguments_map(*map);
|
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
map = Map::Copy(isolate_, map, "SlowAliasedArguments");
|
2015-07-02 14:38:37 +00:00
|
|
|
map->set_elements_kind(SLOW_SLOPPY_ARGUMENTS_ELEMENTS);
|
2015-08-11 19:36:04 +00:00
|
|
|
DCHECK_EQ(2, map->GetInObjectProperties());
|
2015-07-02 14:38:37 +00:00
|
|
|
native_context()->set_slow_aliased_arguments_map(*map);
|
2014-07-07 13:27:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // --- strict mode arguments map
|
2011-03-17 20:28:41 +00:00
|
|
|
const PropertyAttributes attributes =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
|
|
|
|
|
2016-11-04 14:29:46 +00:00
|
|
|
// Create the ThrowTypeError function.
|
2012-01-10 16:11:33 +00:00
|
|
|
Handle<AccessorPair> callee = factory->NewAccessorPair();
|
2011-03-17 20:28:41 +00:00
|
|
|
|
2017-07-10 07:57:09 +00:00
|
|
|
Handle<JSFunction> poison = GetThrowTypeErrorIntrinsic();
|
2011-03-17 20:28:41 +00:00
|
|
|
|
2016-11-04 14:29:46 +00:00
|
|
|
// Install the ThrowTypeError function.
|
2014-05-19 10:47:00 +00:00
|
|
|
callee->set_getter(*poison);
|
|
|
|
callee->set_setter(*poison);
|
2011-03-17 20:28:41 +00:00
|
|
|
|
2012-07-18 15:38:58 +00:00
|
|
|
// Create the map. Allocate one in-object field for length.
|
2015-11-11 12:08:26 +00:00
|
|
|
Handle<Map> map = factory->NewMap(
|
2017-10-18 20:14:09 +00:00
|
|
|
JS_ARGUMENTS_TYPE, JSStrictArgumentsObject::kSize, PACKED_ELEMENTS, 1);
|
2011-03-17 20:28:41 +00:00
|
|
|
// Create the descriptor array for the arguments object.
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::EnsureDescriptorSlack(isolate_, map, 2);
|
2012-07-19 10:01:52 +00:00
|
|
|
|
2011-03-17 20:28:41 +00:00
|
|
|
{ // length
|
2018-07-17 15:08:58 +00:00
|
|
|
Descriptor d =
|
|
|
|
Descriptor::DataField(isolate(), factory->length_string(),
|
|
|
|
JSStrictArgumentsObject::kLengthIndex,
|
|
|
|
DONT_ENUM, Representation::Tagged());
|
2014-04-11 12:13:53 +00:00
|
|
|
map->AppendDescriptor(&d);
|
2011-03-17 20:28:41 +00:00
|
|
|
}
|
|
|
|
{ // callee
|
2016-12-21 16:40:00 +00:00
|
|
|
Descriptor d = Descriptor::AccessorConstant(factory->callee_string(),
|
|
|
|
callee, attributes);
|
2014-04-11 12:13:53 +00:00
|
|
|
map->AppendDescriptor(&d);
|
2011-03-17 20:28:41 +00:00
|
|
|
}
|
2014-08-25 09:12:22 +00:00
|
|
|
// @@iterator method is added later.
|
2012-07-18 15:38:58 +00:00
|
|
|
|
2014-12-15 19:57:37 +00:00
|
|
|
DCHECK_EQ(native_context()->object_function()->prototype(),
|
2018-05-31 14:14:48 +00:00
|
|
|
*isolate_->initial_object_prototype());
|
2018-06-25 10:54:01 +00:00
|
|
|
Map::SetPrototype(isolate(), map, isolate_->initial_object_prototype());
|
2011-03-17 20:28:41 +00:00
|
|
|
|
2014-03-11 14:39:08 +00:00
|
|
|
// Copy constructor from the sloppy arguments boilerplate.
|
2015-02-24 20:50:06 +00:00
|
|
|
map->SetConstructor(
|
|
|
|
native_context()->sloppy_arguments_map()->GetConstructor());
|
2014-07-07 13:12:29 +00:00
|
|
|
|
2014-07-07 13:27:37 +00:00
|
|
|
native_context()->set_strict_arguments_map(*map);
|
2008-10-23 08:46:32 +00:00
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!map->is_dictionary_map());
|
2017-06-30 18:00:44 +00:00
|
|
|
DCHECK(IsObjectElementsKind(map->elements_kind()));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // --- context extension
|
|
|
|
// Create a function for the context extension objects.
|
2017-10-18 20:14:09 +00:00
|
|
|
Handle<JSFunction> context_extension_fun =
|
2018-05-31 14:14:48 +00:00
|
|
|
CreateFunction(isolate_, factory->empty_string(),
|
2017-10-18 20:14:09 +00:00
|
|
|
JS_CONTEXT_EXTENSION_OBJECT_TYPE, JSObject::kHeaderSize,
|
|
|
|
0, factory->the_hole_value(), Builtins::kIllegal);
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_context_extension_function(*context_extension_fun);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2009-05-20 19:33:44 +00:00
|
|
|
{
|
2011-08-30 09:35:20 +00:00
|
|
|
// Set up the call-as-function delegate.
|
2017-07-03 13:40:13 +00:00
|
|
|
Handle<JSFunction> delegate =
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleCreateFunction(isolate_, factory->empty_string(),
|
2017-07-03 13:40:13 +00:00
|
|
|
Builtins::kHandleApiCallAsFunction, 0, false);
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_call_as_function_delegate(*delegate);
|
2009-05-20 19:33:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2011-08-30 09:35:20 +00:00
|
|
|
// Set up the call-as-constructor delegate.
|
2017-07-03 13:40:13 +00:00
|
|
|
Handle<JSFunction> delegate =
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleCreateFunction(isolate_, factory->empty_string(),
|
2017-07-03 13:40:13 +00:00
|
|
|
Builtins::kHandleApiCallAsConstructor, 0, false);
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_call_as_constructor_delegate(*delegate);
|
2009-05-20 19:33:44 +00:00
|
|
|
}
|
2016-01-12 10:47:27 +00:00
|
|
|
} // NOLINT(readability/fn_size)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2017-11-28 08:35:49 +00:00
|
|
|
Handle<JSFunction> Genesis::InstallTypedArray(const char* name,
|
|
|
|
ElementsKind elements_kind) {
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSObject> global =
|
|
|
|
Handle<JSObject>(native_context()->global_object(), isolate());
|
2016-06-08 07:40:11 +00:00
|
|
|
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSObject> typed_array_prototype = isolate()->typed_array_prototype();
|
|
|
|
Handle<JSFunction> typed_array_function = isolate()->typed_array_function();
|
2016-06-08 07:40:11 +00:00
|
|
|
|
2016-11-10 01:49:23 +00:00
|
|
|
Handle<JSFunction> result = InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate(), global, name, JS_TYPED_ARRAY_TYPE,
|
|
|
|
JSTypedArray::kSizeWithEmbedderFields, 0, factory()->the_hole_value(),
|
|
|
|
Builtins::kTypedArrayConstructor);
|
2016-11-10 01:49:23 +00:00
|
|
|
result->initial_map()->set_elements_kind(elements_kind);
|
2016-06-08 07:40:11 +00:00
|
|
|
|
2018-01-19 13:47:33 +00:00
|
|
|
result->shared()->DontAdaptArguments();
|
|
|
|
result->shared()->set_length(3);
|
|
|
|
|
2017-10-25 18:07:04 +00:00
|
|
|
CHECK(JSObject::SetPrototype(result, typed_array_function, false, kDontThrow)
|
2016-06-08 07:40:11 +00:00
|
|
|
.FromJust());
|
|
|
|
|
2017-11-28 08:35:49 +00:00
|
|
|
Handle<Smi> bytes_per_element(
|
|
|
|
Smi::FromInt(1 << ElementsKindToShiftSize(elements_kind)), isolate());
|
|
|
|
|
|
|
|
InstallConstant(isolate(), result, "BYTES_PER_ELEMENT", bytes_per_element);
|
|
|
|
|
|
|
|
// Setup prototype object.
|
|
|
|
DCHECK(result->prototype()->IsJSObject());
|
|
|
|
Handle<JSObject> prototype(JSObject::cast(result->prototype()), isolate());
|
|
|
|
|
2016-06-08 07:40:11 +00:00
|
|
|
CHECK(JSObject::SetPrototype(prototype, typed_array_prototype, false,
|
2017-10-25 18:07:04 +00:00
|
|
|
kDontThrow)
|
2016-06-08 07:40:11 +00:00
|
|
|
.FromJust());
|
2017-11-28 08:35:49 +00:00
|
|
|
|
|
|
|
InstallConstant(isolate(), prototype, "BYTES_PER_ELEMENT", bytes_per_element);
|
|
|
|
return result;
|
2013-04-16 14:16:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-19 07:36:05 +00:00
|
|
|
void Genesis::InitializeExperimentalGlobal() {
|
2014-10-20 13:33:34 +00:00
|
|
|
#define FEATURE_INITIALIZE_GLOBAL(id, descr) InitializeGlobal_##id();
|
2014-09-19 07:36:05 +00:00
|
|
|
|
2014-11-04 16:05:27 +00:00
|
|
|
HARMONY_INPROGRESS(FEATURE_INITIALIZE_GLOBAL)
|
|
|
|
HARMONY_STAGED(FEATURE_INITIALIZE_GLOBAL)
|
2014-11-28 20:07:11 +00:00
|
|
|
HARMONY_SHIPPING(FEATURE_INITIALIZE_GLOBAL)
|
2014-10-20 13:33:34 +00:00
|
|
|
#undef FEATURE_INITIALIZE_GLOBAL
|
2014-09-19 07:36:05 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 09:45:43 +00:00
|
|
|
bool Bootstrapper::CompileBuiltin(Isolate* isolate, int index) {
|
2008-07-03 15:10:15 +00:00
|
|
|
Vector<const char> name = Natives::GetScriptName(index);
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<String> source_code =
|
2017-04-11 05:46:46 +00:00
|
|
|
isolate->bootstrapper()->GetNativeSource(CORE, index);
|
2015-09-16 21:00:45 +00:00
|
|
|
|
|
|
|
// We pass in extras_utils so that builtin code can set it up for later use
|
|
|
|
// by actual extras code, compiled with CompileExtraBuiltin.
|
2015-05-12 14:00:47 +00:00
|
|
|
Handle<Object> global = isolate->global_object();
|
2015-05-21 06:15:33 +00:00
|
|
|
Handle<Object> utils = isolate->natives_utils_object();
|
2015-09-16 21:00:45 +00:00
|
|
|
Handle<Object> extras_utils = isolate->extras_utils_object();
|
|
|
|
Handle<Object> args[] = {global, utils, extras_utils};
|
2015-07-13 09:45:43 +00:00
|
|
|
|
2015-11-02 13:04:20 +00:00
|
|
|
return Bootstrapper::CompileNative(isolate, name, source_code,
|
2016-02-05 12:33:20 +00:00
|
|
|
arraysize(args), args, NATIVES_CODE);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-13 09:45:43 +00:00
|
|
|
bool Bootstrapper::CompileExtraBuiltin(Isolate* isolate, int index) {
|
2015-05-12 14:00:47 +00:00
|
|
|
HandleScope scope(isolate);
|
2015-05-08 08:44:47 +00:00
|
|
|
Vector<const char> name = ExtraNatives::GetScriptName(index);
|
|
|
|
Handle<String> source_code =
|
2017-04-11 05:46:46 +00:00
|
|
|
isolate->bootstrapper()->GetNativeSource(EXTRAS, index);
|
2015-05-12 14:00:47 +00:00
|
|
|
Handle<Object> global = isolate->global_object();
|
2015-08-06 23:52:47 +00:00
|
|
|
Handle<Object> binding = isolate->extras_binding_object();
|
2015-09-16 21:00:45 +00:00
|
|
|
Handle<Object> extras_utils = isolate->extras_utils_object();
|
|
|
|
Handle<Object> args[] = {global, binding, extras_utils};
|
2015-11-02 13:04:20 +00:00
|
|
|
return Bootstrapper::CompileNative(isolate, name, source_code,
|
2016-02-05 12:33:20 +00:00
|
|
|
arraysize(args), args, EXTENSION_CODE);
|
2015-05-08 08:44:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-20 00:01:07 +00:00
|
|
|
bool Bootstrapper::CompileExperimentalExtraBuiltin(Isolate* isolate,
|
|
|
|
int index) {
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
Vector<const char> name = ExperimentalExtraNatives::GetScriptName(index);
|
|
|
|
Handle<String> source_code =
|
2017-04-11 05:46:46 +00:00
|
|
|
isolate->bootstrapper()->GetNativeSource(EXPERIMENTAL_EXTRAS, index);
|
2015-08-20 00:01:07 +00:00
|
|
|
Handle<Object> global = isolate->global_object();
|
|
|
|
Handle<Object> binding = isolate->extras_binding_object();
|
2015-09-16 21:00:45 +00:00
|
|
|
Handle<Object> extras_utils = isolate->extras_utils_object();
|
|
|
|
Handle<Object> args[] = {global, binding, extras_utils};
|
2015-11-02 13:04:20 +00:00
|
|
|
return Bootstrapper::CompileNative(isolate, name, source_code,
|
2016-02-05 12:33:20 +00:00
|
|
|
arraysize(args), args, EXTENSION_CODE);
|
2015-08-20 00:01:07 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 09:45:43 +00:00
|
|
|
bool Bootstrapper::CompileNative(Isolate* isolate, Vector<const char> name,
|
|
|
|
Handle<String> source, int argc,
|
2016-02-05 12:33:20 +00:00
|
|
|
Handle<Object> argv[],
|
|
|
|
NativesFlag natives_flag) {
|
2014-06-02 11:41:50 +00:00
|
|
|
SuppressDebug compiling_natives(isolate->debug());
|
2012-04-03 15:54:07 +00:00
|
|
|
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<Context> context(isolate->context(), isolate);
|
2015-05-12 14:00:47 +00:00
|
|
|
Handle<String> script_name =
|
|
|
|
isolate->factory()->NewStringFromUtf8(name).ToHandleChecked();
|
2017-10-04 22:48:12 +00:00
|
|
|
MaybeHandle<SharedFunctionInfo> maybe_function_info =
|
2016-03-08 12:07:27 +00:00
|
|
|
Compiler::GetSharedFunctionInfoForScript(
|
2018-07-17 15:08:58 +00:00
|
|
|
isolate, source, Compiler::ScriptDetails(script_name),
|
|
|
|
ScriptOriginOptions(), nullptr, nullptr,
|
|
|
|
ScriptCompiler::kNoCompileOptions, ScriptCompiler::kNoCacheNoReason,
|
|
|
|
natives_flag);
|
2017-10-04 22:48:12 +00:00
|
|
|
Handle<SharedFunctionInfo> function_info;
|
|
|
|
if (!maybe_function_info.ToHandle(&function_info)) return false;
|
2015-05-12 14:00:47 +00:00
|
|
|
|
|
|
|
DCHECK(context->IsNativeContext());
|
|
|
|
|
|
|
|
Handle<JSFunction> fun =
|
|
|
|
isolate->factory()->NewFunctionFromSharedFunctionInfo(function_info,
|
2015-11-27 16:59:28 +00:00
|
|
|
context);
|
2015-11-02 13:04:20 +00:00
|
|
|
Handle<Object> receiver = isolate->factory()->undefined_value();
|
2015-05-12 14:00:47 +00:00
|
|
|
|
|
|
|
// For non-extension scripts, run script to get the function wrapper.
|
|
|
|
Handle<Object> wrapper;
|
2017-01-17 13:01:03 +00:00
|
|
|
if (!Execution::TryCall(isolate, fun, receiver, 0, nullptr,
|
|
|
|
Execution::MessageHandling::kKeepPending, nullptr)
|
|
|
|
.ToHandle(&wrapper)) {
|
2015-05-12 14:00:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Then run the function wrapper.
|
2017-01-17 13:01:03 +00:00
|
|
|
return !Execution::TryCall(isolate, Handle<JSFunction>::cast(wrapper),
|
|
|
|
receiver, argc, argv,
|
|
|
|
Execution::MessageHandling::kKeepPending, nullptr)
|
|
|
|
.is_null();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-21 06:15:33 +00:00
|
|
|
bool Genesis::CallUtilsFunction(Isolate* isolate, const char* name) {
|
|
|
|
Handle<JSObject> utils =
|
|
|
|
Handle<JSObject>::cast(isolate->natives_utils_object());
|
2015-08-31 10:09:52 +00:00
|
|
|
Handle<String> name_string =
|
|
|
|
isolate->factory()->NewStringFromAsciiChecked(name);
|
2015-05-21 06:15:33 +00:00
|
|
|
Handle<Object> fun = JSObject::GetDataProperty(utils, name_string);
|
|
|
|
Handle<Object> receiver = isolate->factory()->undefined_value();
|
2015-05-26 07:24:13 +00:00
|
|
|
Handle<Object> args[] = {utils};
|
2017-01-17 13:01:03 +00:00
|
|
|
return !Execution::TryCall(isolate, fun, receiver, 1, args,
|
|
|
|
Execution::MessageHandling::kKeepPending, nullptr)
|
|
|
|
.is_null();
|
2015-05-21 06:15:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-12 14:00:47 +00:00
|
|
|
bool Genesis::CompileExtension(Isolate* isolate, v8::Extension* extension) {
|
2013-02-15 09:27:10 +00:00
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
HandleScope scope(isolate);
|
2010-03-23 06:04:44 +00:00
|
|
|
Handle<SharedFunctionInfo> function_info;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2015-05-12 14:00:47 +00:00
|
|
|
Handle<String> source =
|
|
|
|
isolate->factory()
|
|
|
|
->NewExternalStringFromOneByte(extension->source())
|
|
|
|
.ToHandleChecked();
|
|
|
|
DCHECK(source->IsOneByteRepresentation());
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// If we can't find the function in the cache, we compile a new
|
|
|
|
// function and insert it into the cache.
|
2015-05-12 14:00:47 +00:00
|
|
|
Vector<const char> name = CStrVector(extension->name());
|
|
|
|
SourceCodeCache* cache = isolate->bootstrapper()->extensions_cache();
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<Context> context(isolate->context(), isolate);
|
2015-05-12 14:00:47 +00:00
|
|
|
DCHECK(context->IsNativeContext());
|
|
|
|
|
2018-06-20 10:10:43 +00:00
|
|
|
if (!cache->Lookup(isolate, name, &function_info)) {
|
2014-04-17 13:27:02 +00:00
|
|
|
Handle<String> script_name =
|
|
|
|
factory->NewStringFromUtf8(name).ToHandleChecked();
|
2017-10-04 22:48:12 +00:00
|
|
|
MaybeHandle<SharedFunctionInfo> maybe_function_info =
|
|
|
|
Compiler::GetSharedFunctionInfoForScript(
|
2018-07-17 15:08:58 +00:00
|
|
|
isolate, source, Compiler::ScriptDetails(script_name),
|
|
|
|
ScriptOriginOptions(), extension, nullptr,
|
|
|
|
ScriptCompiler::kNoCompileOptions,
|
2018-02-21 14:35:23 +00:00
|
|
|
ScriptCompiler::kNoCacheBecauseV8Extension, EXTENSION_CODE);
|
2017-10-04 22:48:12 +00:00
|
|
|
if (!maybe_function_info.ToHandle(&function_info)) return false;
|
2018-05-31 14:14:48 +00:00
|
|
|
cache->Add(isolate, name, function_info);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up the function context. Conceptually, we should clone the
|
2008-07-03 15:10:15 +00:00
|
|
|
// function before overwriting the context but since we're in a
|
|
|
|
// single-threaded environment it is not strictly necessary.
|
|
|
|
Handle<JSFunction> fun =
|
2011-03-28 13:09:37 +00:00
|
|
|
factory->NewFunctionFromSharedFunctionInfo(function_info, context);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-01-28 10:46:58 +00:00
|
|
|
// Call function using either the runtime object or the global
|
2008-07-03 15:10:15 +00:00
|
|
|
// object as the receiver. Provide no parameters.
|
2015-05-12 14:00:47 +00:00
|
|
|
Handle<Object> receiver = isolate->global_object();
|
2017-01-17 13:01:03 +00:00
|
|
|
return !Execution::TryCall(isolate, fun, receiver, 0, nullptr,
|
|
|
|
Execution::MessageHandling::kKeepPending, nullptr)
|
|
|
|
.is_null();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
static Handle<JSObject> ResolveBuiltinIdHolder(Isolate* isolate,
|
|
|
|
Handle<Context> native_context,
|
2014-07-30 13:54:45 +00:00
|
|
|
const char* holder_expr) {
|
|
|
|
Factory* factory = isolate->factory();
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSGlobalObject> global(native_context->global_object(), isolate);
|
2014-07-30 13:54:45 +00:00
|
|
|
const char* period_pos = strchr(holder_expr, '.');
|
2017-10-13 16:33:03 +00:00
|
|
|
if (period_pos == nullptr) {
|
2014-07-30 13:54:45 +00:00
|
|
|
return Handle<JSObject>::cast(
|
|
|
|
Object::GetPropertyOrElement(
|
2018-07-13 09:17:37 +00:00
|
|
|
isolate, global, factory->InternalizeUtf8String(holder_expr))
|
2014-07-30 13:54:45 +00:00
|
|
|
.ToHandleChecked());
|
|
|
|
}
|
|
|
|
const char* inner = period_pos + 1;
|
2015-01-30 09:29:25 +00:00
|
|
|
DCHECK(!strchr(inner, '.'));
|
2014-07-30 13:54:45 +00:00
|
|
|
Vector<const char> property(holder_expr,
|
|
|
|
static_cast<int>(period_pos - holder_expr));
|
|
|
|
Handle<String> property_string = factory->InternalizeUtf8String(property);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!property_string.is_null());
|
2014-07-30 13:54:45 +00:00
|
|
|
Handle<JSObject> object = Handle<JSObject>::cast(
|
2018-06-19 09:00:37 +00:00
|
|
|
JSReceiver::GetProperty(isolate, global, property_string)
|
|
|
|
.ToHandleChecked());
|
2014-07-30 13:54:45 +00:00
|
|
|
if (strcmp("prototype", inner) == 0) {
|
|
|
|
Handle<JSFunction> function = Handle<JSFunction>::cast(object);
|
2018-06-20 10:10:43 +00:00
|
|
|
return Handle<JSObject>(JSObject::cast(function->prototype()), isolate);
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
Handle<String> inner_string = factory->InternalizeUtf8String(inner);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!inner_string.is_null());
|
2014-07-30 13:54:45 +00:00
|
|
|
Handle<Object> value =
|
2018-06-19 09:00:37 +00:00
|
|
|
JSReceiver::GetProperty(isolate, object, inner_string).ToHandleChecked();
|
2014-07-30 13:54:45 +00:00
|
|
|
return Handle<JSObject>::cast(value);
|
|
|
|
}
|
|
|
|
|
2016-02-02 07:25:30 +00:00
|
|
|
void Genesis::ConfigureUtilsObject(GlobalContextType context_type) {
|
2015-10-16 11:27:14 +00:00
|
|
|
switch (context_type) {
|
|
|
|
// We still need the utils object to find debug functions.
|
|
|
|
case DEBUG_CONTEXT:
|
|
|
|
return;
|
|
|
|
// Expose the natives in global if a valid name for it is specified.
|
|
|
|
case FULL_CONTEXT: {
|
|
|
|
// We still need the utils object after deserialization.
|
|
|
|
if (isolate()->serializer_enabled()) return;
|
2017-10-13 16:33:03 +00:00
|
|
|
if (FLAG_expose_natives_as == nullptr) break;
|
2015-10-16 11:27:14 +00:00
|
|
|
if (strlen(FLAG_expose_natives_as) == 0) break;
|
|
|
|
HandleScope scope(isolate());
|
|
|
|
Handle<String> natives_key =
|
|
|
|
factory()->InternalizeUtf8String(FLAG_expose_natives_as);
|
|
|
|
uint32_t dummy_index;
|
|
|
|
if (natives_key->AsArrayIndex(&dummy_index)) break;
|
|
|
|
Handle<Object> utils = isolate()->natives_utils_object();
|
|
|
|
Handle<JSObject> global = isolate()->global_object();
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate(), global, natives_key, utils, DONT_ENUM);
|
2015-10-16 11:27:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The utils object can be removed for cases that reach this point.
|
2018-07-04 09:10:05 +00:00
|
|
|
HeapObject* undefined = ReadOnlyRoots(heap()).undefined_value();
|
|
|
|
native_context()->set_natives_utils_object(undefined);
|
|
|
|
native_context()->set_extras_utils_object(undefined);
|
2015-10-16 11:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-28 10:22:31 +00:00
|
|
|
void Bootstrapper::ExportFromRuntime(Isolate* isolate,
|
|
|
|
Handle<JSObject> container) {
|
2015-10-19 11:36:00 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2015-08-21 06:44:17 +00:00
|
|
|
HandleScope scope(isolate);
|
2015-10-19 11:36:00 +00:00
|
|
|
Handle<Context> native_context = isolate->native_context();
|
|
|
|
#define EXPORT_PRIVATE_SYMBOL(NAME) \
|
|
|
|
Handle<String> NAME##_name = factory->NewStringFromAsciiChecked(#NAME); \
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate, container, NAME##_name, factory->NAME(), NONE);
|
2015-08-21 06:44:17 +00:00
|
|
|
PRIVATE_SYMBOL_LIST(EXPORT_PRIVATE_SYMBOL)
|
|
|
|
#undef EXPORT_PRIVATE_SYMBOL
|
2015-08-28 10:22:31 +00:00
|
|
|
|
2015-10-19 11:36:00 +00:00
|
|
|
#define EXPORT_PUBLIC_SYMBOL(NAME, DESCRIPTION) \
|
|
|
|
Handle<String> NAME##_name = factory->NewStringFromAsciiChecked(#NAME); \
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate, container, NAME##_name, factory->NAME(), NONE);
|
2015-08-28 10:22:31 +00:00
|
|
|
PUBLIC_SYMBOL_LIST(EXPORT_PUBLIC_SYMBOL)
|
2015-10-06 18:10:20 +00:00
|
|
|
WELL_KNOWN_SYMBOL_LIST(EXPORT_PUBLIC_SYMBOL)
|
2015-08-28 10:22:31 +00:00
|
|
|
#undef EXPORT_PUBLIC_SYMBOL
|
|
|
|
|
2016-09-21 14:17:42 +00:00
|
|
|
Handle<JSObject> iterator_prototype(
|
2018-06-20 10:10:43 +00:00
|
|
|
native_context->initial_iterator_prototype(), isolate);
|
2015-10-16 11:27:14 +00:00
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate, container,
|
2016-09-21 14:17:42 +00:00
|
|
|
factory->InternalizeUtf8String("IteratorPrototype"),
|
|
|
|
iterator_prototype, NONE);
|
2015-10-16 11:27:14 +00:00
|
|
|
|
|
|
|
{
|
2018-07-17 08:49:20 +00:00
|
|
|
PrototypeIterator iter(isolate, native_context->generator_function_map());
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSObject> generator_function_prototype(iter.GetCurrent<JSObject>(),
|
|
|
|
isolate);
|
2015-10-16 11:27:14 +00:00
|
|
|
|
2015-10-19 11:36:00 +00:00
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate, container,
|
|
|
|
factory->InternalizeUtf8String("GeneratorFunctionPrototype"),
|
2015-10-19 11:36:00 +00:00
|
|
|
generator_function_prototype, NONE);
|
2015-10-16 11:27:14 +00:00
|
|
|
|
2015-12-22 14:15:19 +00:00
|
|
|
Handle<JSFunction> generator_function_function = InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate, container, "GeneratorFunction", JS_FUNCTION_TYPE,
|
2017-10-18 20:14:09 +00:00
|
|
|
JSFunction::kSizeWithPrototype, 0, generator_function_prototype,
|
2017-10-12 15:37:46 +00:00
|
|
|
Builtins::kGeneratorFunctionConstructor);
|
2015-12-10 17:27:44 +00:00
|
|
|
generator_function_function->set_prototype_or_initial_map(
|
2017-01-03 21:38:22 +00:00
|
|
|
native_context->generator_function_map());
|
2015-12-22 14:15:19 +00:00
|
|
|
generator_function_function->shared()->DontAdaptArguments();
|
|
|
|
generator_function_function->shared()->set_length(1);
|
2015-12-07 16:35:03 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(
|
|
|
|
isolate, generator_function_function,
|
|
|
|
Context::GENERATOR_FUNCTION_FUNCTION_INDEX);
|
2015-12-10 17:27:44 +00:00
|
|
|
|
2016-07-19 11:28:43 +00:00
|
|
|
JSObject::ForceSetPrototype(generator_function_function,
|
|
|
|
isolate->function_function());
|
2016-04-06 08:37:09 +00:00
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate, generator_function_prototype, factory->constructor_string(),
|
2016-04-06 08:37:09 +00:00
|
|
|
generator_function_function,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
2017-01-03 21:38:22 +00:00
|
|
|
native_context->generator_function_map()->SetConstructor(
|
2015-12-10 17:27:44 +00:00
|
|
|
*generator_function_function);
|
2015-10-16 11:27:14 +00:00
|
|
|
}
|
|
|
|
|
[async-iteration] implement AsyncGenerator
- Introduce new struct AsyncGeneratorRequest, which holds
information pertinent to resuming execution of an
AsyncGenerator, such as the Promise associated with the async
generator request. It is intended to be used as a singly
linked list, and holds a pointer to the next item in te queue.
- Introduce JSAsyncGeneratorObject (subclass of
JSGeneratorObject), which includes several new internal fields
(`queue` which contains a singly linked list of
AsyncGeneratorRequest objects, and `await_input` which
contains the sent value from an Await expression (This is
necessary to prevent function.sent (used by yield*) from
having the sent value observably overwritten during
execution).
- Modify SuspendGenerator to accept a set of Flags, which
indicate whether the suspend is for a Yield or Await, and
whether it takes place on an async generator or ES6
generator.
- Introduce interpreter intrinsics and TF intrinsic lowering for
accessing the await input of an async generator
- Modify the JSGeneratorStore operator to understand whether or
not it's suspending for a normal yield, or an AsyncGenerator
Await. This ensures appropriate registers are stored.
- Add versions of ResumeGeneratorTrampoline which store the
input value in a different field depending on wether it's an
AsyncGenerator Await resume, or an ordinary resume. Also modifies
whether debug code will assert that the generator object is a
JSGeneratorObject or a JSAsyncGeneratorObject depending on the
resume type.
BUG=v8:5855
R=bmeurer@chromium.org, rmcilroy@chromium.org, jgruber@chromium.org,
littledan@chromium.org, neis@chromium.org
TBR=marja@chromium.org
Change-Id: I9d58df1d344465fc937fe7eed322424204497187
Reviewed-on: https://chromium-review.googlesource.com/446961
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44240}
2017-03-29 13:41:45 +00:00
|
|
|
{
|
2018-07-17 08:49:20 +00:00
|
|
|
PrototypeIterator iter(isolate,
|
|
|
|
native_context->async_generator_function_map());
|
[async-iteration] implement AsyncGenerator
- Introduce new struct AsyncGeneratorRequest, which holds
information pertinent to resuming execution of an
AsyncGenerator, such as the Promise associated with the async
generator request. It is intended to be used as a singly
linked list, and holds a pointer to the next item in te queue.
- Introduce JSAsyncGeneratorObject (subclass of
JSGeneratorObject), which includes several new internal fields
(`queue` which contains a singly linked list of
AsyncGeneratorRequest objects, and `await_input` which
contains the sent value from an Await expression (This is
necessary to prevent function.sent (used by yield*) from
having the sent value observably overwritten during
execution).
- Modify SuspendGenerator to accept a set of Flags, which
indicate whether the suspend is for a Yield or Await, and
whether it takes place on an async generator or ES6
generator.
- Introduce interpreter intrinsics and TF intrinsic lowering for
accessing the await input of an async generator
- Modify the JSGeneratorStore operator to understand whether or
not it's suspending for a normal yield, or an AsyncGenerator
Await. This ensures appropriate registers are stored.
- Add versions of ResumeGeneratorTrampoline which store the
input value in a different field depending on wether it's an
AsyncGenerator Await resume, or an ordinary resume. Also modifies
whether debug code will assert that the generator object is a
JSGeneratorObject or a JSAsyncGeneratorObject depending on the
resume type.
BUG=v8:5855
R=bmeurer@chromium.org, rmcilroy@chromium.org, jgruber@chromium.org,
littledan@chromium.org, neis@chromium.org
TBR=marja@chromium.org
Change-Id: I9d58df1d344465fc937fe7eed322424204497187
Reviewed-on: https://chromium-review.googlesource.com/446961
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44240}
2017-03-29 13:41:45 +00:00
|
|
|
Handle<JSObject> async_generator_function_prototype(
|
2018-06-20 10:10:43 +00:00
|
|
|
iter.GetCurrent<JSObject>(), isolate);
|
[async-iteration] implement AsyncGenerator
- Introduce new struct AsyncGeneratorRequest, which holds
information pertinent to resuming execution of an
AsyncGenerator, such as the Promise associated with the async
generator request. It is intended to be used as a singly
linked list, and holds a pointer to the next item in te queue.
- Introduce JSAsyncGeneratorObject (subclass of
JSGeneratorObject), which includes several new internal fields
(`queue` which contains a singly linked list of
AsyncGeneratorRequest objects, and `await_input` which
contains the sent value from an Await expression (This is
necessary to prevent function.sent (used by yield*) from
having the sent value observably overwritten during
execution).
- Modify SuspendGenerator to accept a set of Flags, which
indicate whether the suspend is for a Yield or Await, and
whether it takes place on an async generator or ES6
generator.
- Introduce interpreter intrinsics and TF intrinsic lowering for
accessing the await input of an async generator
- Modify the JSGeneratorStore operator to understand whether or
not it's suspending for a normal yield, or an AsyncGenerator
Await. This ensures appropriate registers are stored.
- Add versions of ResumeGeneratorTrampoline which store the
input value in a different field depending on wether it's an
AsyncGenerator Await resume, or an ordinary resume. Also modifies
whether debug code will assert that the generator object is a
JSGeneratorObject or a JSAsyncGeneratorObject depending on the
resume type.
BUG=v8:5855
R=bmeurer@chromium.org, rmcilroy@chromium.org, jgruber@chromium.org,
littledan@chromium.org, neis@chromium.org
TBR=marja@chromium.org
Change-Id: I9d58df1d344465fc937fe7eed322424204497187
Reviewed-on: https://chromium-review.googlesource.com/446961
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44240}
2017-03-29 13:41:45 +00:00
|
|
|
|
2017-10-12 15:37:46 +00:00
|
|
|
Handle<JSFunction> async_generator_function_function = InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate, container, "AsyncGeneratorFunction", JS_FUNCTION_TYPE,
|
2017-10-18 20:14:09 +00:00
|
|
|
JSFunction::kSizeWithPrototype, 0, async_generator_function_prototype,
|
2017-10-12 15:37:46 +00:00
|
|
|
Builtins::kAsyncGeneratorFunctionConstructor);
|
[async-iteration] implement AsyncGenerator
- Introduce new struct AsyncGeneratorRequest, which holds
information pertinent to resuming execution of an
AsyncGenerator, such as the Promise associated with the async
generator request. It is intended to be used as a singly
linked list, and holds a pointer to the next item in te queue.
- Introduce JSAsyncGeneratorObject (subclass of
JSGeneratorObject), which includes several new internal fields
(`queue` which contains a singly linked list of
AsyncGeneratorRequest objects, and `await_input` which
contains the sent value from an Await expression (This is
necessary to prevent function.sent (used by yield*) from
having the sent value observably overwritten during
execution).
- Modify SuspendGenerator to accept a set of Flags, which
indicate whether the suspend is for a Yield or Await, and
whether it takes place on an async generator or ES6
generator.
- Introduce interpreter intrinsics and TF intrinsic lowering for
accessing the await input of an async generator
- Modify the JSGeneratorStore operator to understand whether or
not it's suspending for a normal yield, or an AsyncGenerator
Await. This ensures appropriate registers are stored.
- Add versions of ResumeGeneratorTrampoline which store the
input value in a different field depending on wether it's an
AsyncGenerator Await resume, or an ordinary resume. Also modifies
whether debug code will assert that the generator object is a
JSGeneratorObject or a JSAsyncGeneratorObject depending on the
resume type.
BUG=v8:5855
R=bmeurer@chromium.org, rmcilroy@chromium.org, jgruber@chromium.org,
littledan@chromium.org, neis@chromium.org
TBR=marja@chromium.org
Change-Id: I9d58df1d344465fc937fe7eed322424204497187
Reviewed-on: https://chromium-review.googlesource.com/446961
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44240}
2017-03-29 13:41:45 +00:00
|
|
|
async_generator_function_function->set_prototype_or_initial_map(
|
|
|
|
native_context->async_generator_function_map());
|
|
|
|
async_generator_function_function->shared()->DontAdaptArguments();
|
|
|
|
async_generator_function_function->shared()->set_length(1);
|
|
|
|
InstallWithIntrinsicDefaultProto(
|
|
|
|
isolate, async_generator_function_function,
|
|
|
|
Context::ASYNC_GENERATOR_FUNCTION_FUNCTION_INDEX);
|
|
|
|
|
|
|
|
JSObject::ForceSetPrototype(async_generator_function_function,
|
|
|
|
isolate->function_function());
|
|
|
|
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate, async_generator_function_prototype,
|
|
|
|
factory->constructor_string(), async_generator_function_function,
|
[async-iteration] implement AsyncGenerator
- Introduce new struct AsyncGeneratorRequest, which holds
information pertinent to resuming execution of an
AsyncGenerator, such as the Promise associated with the async
generator request. It is intended to be used as a singly
linked list, and holds a pointer to the next item in te queue.
- Introduce JSAsyncGeneratorObject (subclass of
JSGeneratorObject), which includes several new internal fields
(`queue` which contains a singly linked list of
AsyncGeneratorRequest objects, and `await_input` which
contains the sent value from an Await expression (This is
necessary to prevent function.sent (used by yield*) from
having the sent value observably overwritten during
execution).
- Modify SuspendGenerator to accept a set of Flags, which
indicate whether the suspend is for a Yield or Await, and
whether it takes place on an async generator or ES6
generator.
- Introduce interpreter intrinsics and TF intrinsic lowering for
accessing the await input of an async generator
- Modify the JSGeneratorStore operator to understand whether or
not it's suspending for a normal yield, or an AsyncGenerator
Await. This ensures appropriate registers are stored.
- Add versions of ResumeGeneratorTrampoline which store the
input value in a different field depending on wether it's an
AsyncGenerator Await resume, or an ordinary resume. Also modifies
whether debug code will assert that the generator object is a
JSGeneratorObject or a JSAsyncGeneratorObject depending on the
resume type.
BUG=v8:5855
R=bmeurer@chromium.org, rmcilroy@chromium.org, jgruber@chromium.org,
littledan@chromium.org, neis@chromium.org
TBR=marja@chromium.org
Change-Id: I9d58df1d344465fc937fe7eed322424204497187
Reviewed-on: https://chromium-review.googlesource.com/446961
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44240}
2017-03-29 13:41:45 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
|
|
|
native_context->async_generator_function_map()->SetConstructor(
|
|
|
|
*async_generator_function_function);
|
|
|
|
}
|
|
|
|
|
2015-10-16 11:27:14 +00:00
|
|
|
{ // -- S e t I t e r a t o r
|
2018-02-15 05:26:29 +00:00
|
|
|
Handle<String> name = factory->SetIterator_string();
|
2017-06-30 10:32:50 +00:00
|
|
|
|
|
|
|
// Setup %SetIteratorPrototype%.
|
|
|
|
Handle<JSObject> prototype =
|
|
|
|
factory->NewJSObject(isolate->object_function(), TENURED);
|
|
|
|
JSObject::ForceSetPrototype(prototype, iterator_prototype);
|
|
|
|
|
|
|
|
// Install the @@toStringTag property on the {prototype}.
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate, prototype, factory->to_string_tag_symbol(), name,
|
2017-06-30 10:32:50 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
2017-07-06 10:39:28 +00:00
|
|
|
// Install the next function on the {prototype}.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate, prototype, "next",
|
2017-07-06 10:39:28 +00:00
|
|
|
Builtins::kSetIteratorPrototypeNext, 0, true,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
BuiltinFunctionId::kSetIteratorNext);
|
2017-07-06 10:39:28 +00:00
|
|
|
|
2017-06-30 10:32:50 +00:00
|
|
|
// Setup SetIterator constructor.
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSFunction> set_iterator_function = InstallFunction(
|
|
|
|
isolate, container, "SetIterator", JS_SET_VALUE_ITERATOR_TYPE,
|
|
|
|
JSSetIterator::kSize, 0, prototype, Builtins::kIllegal);
|
2017-07-10 06:46:56 +00:00
|
|
|
set_iterator_function->shared()->set_native(false);
|
|
|
|
|
|
|
|
Handle<Map> set_value_iterator_map(set_iterator_function->initial_map(),
|
|
|
|
isolate);
|
|
|
|
native_context->set_set_value_iterator_map(*set_value_iterator_map);
|
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
Handle<Map> set_key_value_iterator_map = Map::Copy(
|
|
|
|
isolate, set_value_iterator_map, "JS_SET_KEY_VALUE_ITERATOR_TYPE");
|
2017-07-10 06:46:56 +00:00
|
|
|
set_key_value_iterator_map->set_instance_type(
|
|
|
|
JS_SET_KEY_VALUE_ITERATOR_TYPE);
|
|
|
|
native_context->set_set_key_value_iterator_map(*set_key_value_iterator_map);
|
2015-10-16 11:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- M a p I t e r a t o r
|
2018-02-15 05:26:29 +00:00
|
|
|
Handle<String> name = factory->MapIterator_string();
|
2017-06-30 10:32:50 +00:00
|
|
|
|
|
|
|
// Setup %MapIteratorPrototype%.
|
|
|
|
Handle<JSObject> prototype =
|
|
|
|
factory->NewJSObject(isolate->object_function(), TENURED);
|
|
|
|
JSObject::ForceSetPrototype(prototype, iterator_prototype);
|
|
|
|
|
|
|
|
// Install the @@toStringTag property on the {prototype}.
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate, prototype, factory->to_string_tag_symbol(), name,
|
2017-06-30 10:32:50 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
2017-07-06 10:39:28 +00:00
|
|
|
// Install the next function on the {prototype}.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate, prototype, "next",
|
2017-07-06 10:39:28 +00:00
|
|
|
Builtins::kMapIteratorPrototypeNext, 0, true,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
BuiltinFunctionId::kMapIteratorNext);
|
2017-07-06 10:39:28 +00:00
|
|
|
|
2017-06-30 10:32:50 +00:00
|
|
|
// Setup MapIterator constructor.
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSFunction> map_iterator_function = InstallFunction(
|
|
|
|
isolate, container, "MapIterator", JS_MAP_KEY_ITERATOR_TYPE,
|
|
|
|
JSMapIterator::kSize, 0, prototype, Builtins::kIllegal);
|
2017-07-10 06:46:56 +00:00
|
|
|
map_iterator_function->shared()->set_native(false);
|
|
|
|
|
|
|
|
Handle<Map> map_key_iterator_map(map_iterator_function->initial_map(),
|
|
|
|
isolate);
|
|
|
|
native_context->set_map_key_iterator_map(*map_key_iterator_map);
|
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
Handle<Map> map_key_value_iterator_map = Map::Copy(
|
|
|
|
isolate, map_key_iterator_map, "JS_MAP_KEY_VALUE_ITERATOR_TYPE");
|
2017-07-10 06:46:56 +00:00
|
|
|
map_key_value_iterator_map->set_instance_type(
|
|
|
|
JS_MAP_KEY_VALUE_ITERATOR_TYPE);
|
|
|
|
native_context->set_map_key_value_iterator_map(*map_key_value_iterator_map);
|
|
|
|
|
|
|
|
Handle<Map> map_value_iterator_map =
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::Copy(isolate, map_key_iterator_map, "JS_MAP_VALUE_ITERATOR_TYPE");
|
2017-07-10 06:46:56 +00:00
|
|
|
map_value_iterator_map->set_instance_type(JS_MAP_VALUE_ITERATOR_TYPE);
|
|
|
|
native_context->set_map_value_iterator_map(*map_value_iterator_map);
|
2015-10-19 11:36:00 +00:00
|
|
|
}
|
|
|
|
|
2017-01-20 19:36:28 +00:00
|
|
|
{ // -- A s y n c F u n c t i o n
|
|
|
|
// Builtin functions for AsyncFunction.
|
2018-07-17 08:49:20 +00:00
|
|
|
PrototypeIterator iter(isolate, native_context->async_function_map());
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSObject> async_function_prototype(iter.GetCurrent<JSObject>(),
|
|
|
|
isolate);
|
2017-01-20 19:36:28 +00:00
|
|
|
|
|
|
|
Handle<JSFunction> async_function_constructor = InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate, container, "AsyncFunction", JS_FUNCTION_TYPE,
|
2017-10-18 20:14:09 +00:00
|
|
|
JSFunction::kSizeWithPrototype, 0, async_function_prototype,
|
2017-10-12 15:37:46 +00:00
|
|
|
Builtins::kAsyncFunctionConstructor);
|
2017-05-26 17:19:03 +00:00
|
|
|
async_function_constructor->set_prototype_or_initial_map(
|
|
|
|
native_context->async_function_map());
|
2017-01-20 19:36:28 +00:00
|
|
|
async_function_constructor->shared()->DontAdaptArguments();
|
|
|
|
async_function_constructor->shared()->set_length(1);
|
2017-06-19 15:17:22 +00:00
|
|
|
native_context->set_async_function_constructor(*async_function_constructor);
|
2017-01-20 19:36:28 +00:00
|
|
|
JSObject::ForceSetPrototype(async_function_constructor,
|
|
|
|
isolate->function_function());
|
|
|
|
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate, async_function_prototype, factory->constructor_string(),
|
2017-01-20 19:36:28 +00:00
|
|
|
async_function_constructor,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
|
|
|
JSFunction::SetPrototype(async_function_constructor,
|
|
|
|
async_function_prototype);
|
2015-10-19 11:36:00 +00:00
|
|
|
|
2018-05-14 08:55:07 +00:00
|
|
|
{
|
|
|
|
Handle<JSFunction> function =
|
|
|
|
SimpleCreateFunction(isolate, factory->empty_string(),
|
|
|
|
Builtins::kAsyncFunctionAwaitCaught, 2, false);
|
|
|
|
native_context->set_async_function_await_caught(*function);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Handle<JSFunction> function =
|
|
|
|
SimpleCreateFunction(isolate, factory->empty_string(),
|
|
|
|
Builtins::kAsyncFunctionAwaitUncaught, 2, false);
|
|
|
|
native_context->set_async_function_await_uncaught(*function);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Handle<SharedFunctionInfo> info = SimpleCreateSharedFunctionInfo(
|
|
|
|
isolate, Builtins::kAsyncFunctionAwaitRejectClosure,
|
|
|
|
factory->empty_string(), 1);
|
|
|
|
native_context->set_async_function_await_reject_shared_fun(*info);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Handle<SharedFunctionInfo> info = SimpleCreateSharedFunctionInfo(
|
|
|
|
isolate, Builtins::kAsyncFunctionAwaitResolveClosure,
|
|
|
|
factory->empty_string(), 1);
|
|
|
|
native_context->set_async_function_await_resolve_shared_fun(*info);
|
|
|
|
}
|
|
|
|
|
2017-01-20 19:36:28 +00:00
|
|
|
{
|
|
|
|
Handle<JSFunction> function =
|
|
|
|
SimpleCreateFunction(isolate, factory->empty_string(),
|
|
|
|
Builtins::kAsyncFunctionPromiseCreate, 0, false);
|
2017-06-19 15:17:22 +00:00
|
|
|
native_context->set_async_function_promise_create(*function);
|
2017-01-20 19:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Handle<JSFunction> function = SimpleCreateFunction(
|
|
|
|
isolate, factory->empty_string(),
|
2018-05-30 14:21:39 +00:00
|
|
|
Builtins::kAsyncFunctionPromiseRelease, 2, false);
|
2017-06-19 15:17:22 +00:00
|
|
|
native_context->set_async_function_promise_release(*function);
|
2016-05-17 00:26:53 +00:00
|
|
|
}
|
2015-10-16 11:27:14 +00:00
|
|
|
}
|
2016-07-22 10:12:24 +00:00
|
|
|
|
|
|
|
{ // -- C a l l S i t e
|
|
|
|
// Builtin functions for CallSite.
|
|
|
|
|
2016-08-02 09:29:14 +00:00
|
|
|
// CallSites are a special case; the constructor is for our private use
|
|
|
|
// only, therefore we set it up as a builtin that throws. Internally, we use
|
|
|
|
// CallSiteUtils::Construct to create CallSite objects.
|
|
|
|
|
2016-07-22 10:12:24 +00:00
|
|
|
Handle<JSFunction> callsite_fun = InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate, container, "CallSite", JS_OBJECT_TYPE, JSObject::kHeaderSize,
|
|
|
|
0, factory->the_hole_value(), Builtins::kUnsupportedThrower);
|
2016-07-22 10:12:24 +00:00
|
|
|
callsite_fun->shared()->DontAdaptArguments();
|
2016-08-01 14:26:53 +00:00
|
|
|
isolate->native_context()->set_callsite_function(*callsite_fun);
|
|
|
|
|
2016-07-22 10:12:24 +00:00
|
|
|
{
|
2017-06-30 08:54:01 +00:00
|
|
|
// Setup CallSite.prototype.
|
|
|
|
Handle<JSObject> prototype(
|
2018-06-20 10:10:43 +00:00
|
|
|
JSObject::cast(callsite_fun->instance_prototype()), isolate);
|
2016-07-22 10:12:24 +00:00
|
|
|
|
|
|
|
struct FunctionInfo {
|
|
|
|
const char* name;
|
|
|
|
Builtins::Name id;
|
|
|
|
};
|
|
|
|
|
|
|
|
FunctionInfo infos[] = {
|
|
|
|
{"getColumnNumber", Builtins::kCallSitePrototypeGetColumnNumber},
|
|
|
|
{"getEvalOrigin", Builtins::kCallSitePrototypeGetEvalOrigin},
|
|
|
|
{"getFileName", Builtins::kCallSitePrototypeGetFileName},
|
|
|
|
{"getFunction", Builtins::kCallSitePrototypeGetFunction},
|
|
|
|
{"getFunctionName", Builtins::kCallSitePrototypeGetFunctionName},
|
|
|
|
{"getLineNumber", Builtins::kCallSitePrototypeGetLineNumber},
|
|
|
|
{"getMethodName", Builtins::kCallSitePrototypeGetMethodName},
|
|
|
|
{"getPosition", Builtins::kCallSitePrototypeGetPosition},
|
|
|
|
{"getScriptNameOrSourceURL",
|
|
|
|
Builtins::kCallSitePrototypeGetScriptNameOrSourceURL},
|
|
|
|
{"getThis", Builtins::kCallSitePrototypeGetThis},
|
|
|
|
{"getTypeName", Builtins::kCallSitePrototypeGetTypeName},
|
|
|
|
{"isConstructor", Builtins::kCallSitePrototypeIsConstructor},
|
|
|
|
{"isEval", Builtins::kCallSitePrototypeIsEval},
|
|
|
|
{"isNative", Builtins::kCallSitePrototypeIsNative},
|
2016-07-28 13:39:18 +00:00
|
|
|
{"isToplevel", Builtins::kCallSitePrototypeIsToplevel},
|
|
|
|
{"toString", Builtins::kCallSitePrototypeToString}};
|
2016-07-22 10:12:24 +00:00
|
|
|
|
|
|
|
PropertyAttributes attrs =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
|
|
|
|
|
|
|
|
Handle<JSFunction> fun;
|
|
|
|
for (const FunctionInfo& info : infos) {
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate, prototype, info.name, info.id, 0, true,
|
|
|
|
attrs);
|
2016-07-22 10:12:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-21 06:44:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-20 13:33:34 +00:00
|
|
|
#define EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(id) \
|
|
|
|
void Genesis::InitializeGlobal_##id() {}
|
|
|
|
|
2015-10-21 02:55:47 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_do_expressions)
|
Implement new Function.prototype.toString --harmony-function-tostring
For functions declared in source code, the .toString() representation
will be an excerpt of the source code.
* For functions declared with the "function" keyword, the excerpt
starts at the "function" or "async" keyword and ends at the final "}".
The previous behavior would start the excerpt at the "(" of the
parameter list, and prepend a canonical `"function " + name` or
similar, which would discard comments and formatting surrounding the
function's name. Anonymous functions declared as function expressions
no longer get the name "anonymous" in their toString representation.
* For methods, the excerpt starts at the "get", "set", "*" (for
generator methods), or property name, whichever comes first.
Previously, the toString representation for methods would use a
canonical prefix before the "(" of the parameter list. Note that any
"static" keyword is omitted.
* For arrow functions and class declarations, the excerpt is unchanged.
For functions created with the Function, GeneratorFunction, or
AsyncFunction constructors:
* The string separating the parameter text and body text is now
"\n) {\n", where previously it was "\n/*``*/) {\n" or ") {\n".
* At one point, newline normalization was required by the spec here,
but that was removed from the spec, and so this CL does not do it.
Included in this CL is a fix for CreateDynamicFunction parsing. ')'
and '`' characters in the parameter string are no longer disallowed,
and Function("a=function(", "}){") is no longer allowed.
BUG=v8:4958, v8:4230
Review-Url: https://codereview.chromium.org/2156303002
Cr-Commit-Position: refs/heads/master@{#43262}
2017-02-16 20:19:24 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_function_tostring)
|
2017-11-28 09:42:57 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_public_fields)
|
2018-01-16 18:44:56 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_private_fields)
|
2017-12-21 17:58:28 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_static_fields)
|
2016-09-16 00:42:30 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_class_fields)
|
2017-01-31 18:58:53 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_dynamic_import)
|
2017-10-07 17:12:07 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_import_meta)
|
2018-03-02 04:05:24 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_numeric_separator)
|
2015-09-16 18:01:38 +00:00
|
|
|
|
[es2015] Refactor the JSArrayIterator.
This changes the JSArrayIterator to always have only a single instance
type, instead of the zoo of instance types that we had before, and
which became less useful with the specification update to when "next"
is loaded from the iterator now. This greatly simplifies the baseline
implementation of the array iterator, which now only looks at the
iterated object during %ArrayIteratorPrototype%.next invocations.
In TurboFan we introduce a new JSCreateArrayIterator operator, that
holds the IterationKind and get's the iterated object as input. When
optimizing %ArrayIteratorPrototype%.next in the JSCallReducer, we
check whether the receiver is a JSCreateArrayIterator, and if so,
we try to infer maps for the iterated object from there. If we find
any, we speculatively assume that these won't have changed during
iteration (as we did before with the previous approach), and generate
fast code for both JSArray and JSTypedArray iteration.
Drive-by-fix: Drop the fast_array_iteration protector, it's not
necessary anymore since we have the deoptimization guard bit in
the JSCallReducer now.
This addresses the performance cliff noticed in webpack 4. The minimal
repro on the tracking bug goes from
console.timeEnd: mono, 124.773000
console.timeEnd: poly, 670.353000
to
console.timeEnd: mono, 118.709000
console.timeEnd: poly, 141.393000
so that's a 4.7x improvement.
Also make presubmit happy by adding the missing #undef's.
Bug: v8:7510, v7:7514
Change-Id: I79a46bfa2cd0f0710e09365ef72519b1bbb667b5
Reviewed-on: https://chromium-review.googlesource.com/946098
Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51725}
2018-03-02 19:31:01 +00:00
|
|
|
#undef EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE
|
|
|
|
|
2015-05-22 13:43:38 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_sharedarraybuffer() {
|
|
|
|
if (!FLAG_harmony_sharedarraybuffer) return;
|
|
|
|
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSGlobalObject> global(native_context()->global_object(), isolate());
|
2018-05-31 14:14:48 +00:00
|
|
|
Factory* factory = isolate()->factory();
|
2016-04-13 18:21:30 +00:00
|
|
|
|
2017-06-13 23:17:05 +00:00
|
|
|
{
|
|
|
|
Handle<String> name = factory->InternalizeUtf8String("SharedArrayBuffer");
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, global, name,
|
|
|
|
isolate()->shared_array_buffer_fun(), DONT_ENUM);
|
2017-06-13 23:17:05 +00:00
|
|
|
}
|
2016-04-13 18:21:30 +00:00
|
|
|
|
2017-06-13 23:17:05 +00:00
|
|
|
{
|
|
|
|
Handle<String> name = factory->InternalizeUtf8String("Atomics");
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, global, name, isolate()->atomics_object(),
|
|
|
|
DONT_ENUM);
|
2017-06-13 23:17:05 +00:00
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate_, isolate()->atomics_object(), factory->to_string_tag_symbol(),
|
|
|
|
name, static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
2017-06-13 23:17:05 +00:00
|
|
|
}
|
2015-05-22 13:43:38 +00:00
|
|
|
}
|
|
|
|
|
2018-01-19 13:05:01 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_string_trimming() {
|
|
|
|
if (!FLAG_harmony_string_trimming) return;
|
|
|
|
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSGlobalObject> global(native_context()->global_object(), isolate());
|
2018-05-31 14:14:48 +00:00
|
|
|
Factory* factory = isolate()->factory();
|
2018-01-19 13:05:01 +00:00
|
|
|
|
|
|
|
Handle<JSObject> string_prototype(
|
2018-06-20 10:10:43 +00:00
|
|
|
native_context()->initial_string_prototype(), isolate());
|
2018-01-19 13:05:01 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
Handle<String> trim_left_name = factory->InternalizeUtf8String("trimLeft");
|
|
|
|
Handle<String> trim_start_name =
|
|
|
|
factory->InternalizeUtf8String("trimStart");
|
|
|
|
Handle<JSFunction> trim_left_fun = Handle<JSFunction>::cast(
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::GetProperty(isolate_, string_prototype, trim_left_name)
|
2018-01-19 13:05:01 +00:00
|
|
|
.ToHandleChecked());
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, string_prototype, trim_start_name,
|
|
|
|
trim_left_fun, DONT_ENUM);
|
2018-03-16 15:48:17 +00:00
|
|
|
trim_left_fun->shared()->SetName(*trim_start_name);
|
2018-01-19 13:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Handle<String> trim_right_name =
|
|
|
|
factory->InternalizeUtf8String("trimRight");
|
|
|
|
Handle<String> trim_end_name = factory->InternalizeUtf8String("trimEnd");
|
|
|
|
Handle<JSFunction> trim_right_fun = Handle<JSFunction>::cast(
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::GetProperty(isolate_, string_prototype, trim_right_name)
|
2018-01-19 13:05:01 +00:00
|
|
|
.ToHandleChecked());
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, string_prototype, trim_end_name,
|
|
|
|
trim_right_fun, DONT_ENUM);
|
2018-03-16 15:48:17 +00:00
|
|
|
trim_right_fun->shared()->SetName(*trim_end_name);
|
2018-01-19 13:05:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-09 22:27:29 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_array_prototype_values() {
|
|
|
|
if (!FLAG_harmony_array_prototype_values) return;
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSFunction> array_constructor(native_context()->array_function(),
|
|
|
|
isolate());
|
2016-03-09 22:27:29 +00:00
|
|
|
Handle<JSObject> array_prototype(
|
2018-06-20 10:10:43 +00:00
|
|
|
JSObject::cast(array_constructor->instance_prototype()), isolate());
|
2016-03-09 22:27:29 +00:00
|
|
|
Handle<Object> values_iterator =
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::GetProperty(isolate(), array_prototype,
|
|
|
|
factory()->iterator_symbol())
|
2016-03-09 22:27:29 +00:00
|
|
|
.ToHandleChecked();
|
|
|
|
DCHECK(values_iterator->IsJSFunction());
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate(), array_prototype, factory()->values_string(),
|
2016-03-09 22:27:29 +00:00
|
|
|
values_iterator, DONT_ENUM);
|
|
|
|
|
|
|
|
Handle<Object> unscopables =
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::GetProperty(isolate(), array_prototype,
|
|
|
|
factory()->unscopables_symbol())
|
2016-03-09 22:27:29 +00:00
|
|
|
.ToHandleChecked();
|
|
|
|
DCHECK(unscopables->IsJSObject());
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate(), Handle<JSObject>::cast(unscopables),
|
2016-03-09 22:27:29 +00:00
|
|
|
factory()->values_string(), factory()->true_value(),
|
|
|
|
NONE);
|
|
|
|
}
|
2015-11-13 14:13:50 +00:00
|
|
|
|
2018-05-23 01:25:41 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_array_flat() {
|
|
|
|
if (!FLAG_harmony_array_flat) return;
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSFunction> array_constructor(native_context()->array_function(),
|
|
|
|
isolate());
|
2018-03-15 16:51:01 +00:00
|
|
|
Handle<JSObject> array_prototype(
|
2018-06-20 10:10:43 +00:00
|
|
|
JSObject::cast(array_constructor->instance_prototype()), isolate());
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), array_prototype, "flat",
|
|
|
|
Builtins::kArrayPrototypeFlat, 0, false, DONT_ENUM);
|
|
|
|
SimpleInstallFunction(isolate(), array_prototype, "flatMap",
|
2018-03-15 16:51:01 +00:00
|
|
|
Builtins::kArrayPrototypeFlatMap, 1, false, DONT_ENUM);
|
|
|
|
}
|
|
|
|
|
2018-06-07 17:25:36 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_symbol_description() {
|
|
|
|
if (!FLAG_harmony_symbol_description) return;
|
|
|
|
|
|
|
|
// Symbol.prototype.description
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSFunction> symbol_fun(native_context()->symbol_function(), isolate());
|
2018-06-07 17:25:36 +00:00
|
|
|
Handle<JSObject> symbol_prototype(
|
2018-06-20 10:10:43 +00:00
|
|
|
JSObject::cast(symbol_fun->instance_prototype()), isolate());
|
2018-06-07 17:25:36 +00:00
|
|
|
SimpleInstallGetter(isolate(), symbol_prototype,
|
|
|
|
factory()->InternalizeUtf8String("description"),
|
|
|
|
Builtins::kSymbolPrototypeDescriptionGetter, true);
|
|
|
|
}
|
|
|
|
|
2018-04-05 14:41:26 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_string_matchall() {
|
|
|
|
if (!FLAG_harmony_string_matchall) return;
|
|
|
|
|
|
|
|
{ // String.prototype.matchAll
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSFunction> string_fun(native_context()->string_function(),
|
|
|
|
isolate());
|
2018-04-05 14:41:26 +00:00
|
|
|
Handle<JSObject> string_prototype(
|
2018-06-20 10:10:43 +00:00
|
|
|
JSObject::cast(string_fun->instance_prototype()), isolate());
|
2018-04-05 14:41:26 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), string_prototype, "matchAll",
|
2018-04-05 14:41:26 +00:00
|
|
|
Builtins::kStringPrototypeMatchAll, 1, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // RegExp.prototype[@@matchAll]
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSFunction> regexp_fun(native_context()->regexp_function(),
|
|
|
|
isolate());
|
2018-04-05 14:41:26 +00:00
|
|
|
Handle<JSObject> regexp_prototype(
|
2018-06-20 10:10:43 +00:00
|
|
|
JSObject::cast(regexp_fun->instance_prototype()), isolate());
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), regexp_prototype,
|
|
|
|
factory()->match_all_symbol(), "[Symbol.matchAll]",
|
2018-04-05 14:41:26 +00:00
|
|
|
Builtins::kRegExpPrototypeMatchAll, 1, true);
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<Map> regexp_prototype_map(regexp_prototype->map(), isolate());
|
2018-04-05 14:41:26 +00:00
|
|
|
Map::SetShouldBeFastPrototypeMap(regexp_prototype_map, true, isolate());
|
|
|
|
native_context()->set_regexp_prototype_map(*regexp_prototype_map);
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // --- R e g E x p S t r i n g I t e r a t o r ---
|
|
|
|
Handle<JSObject> iterator_prototype(
|
2018-06-20 10:10:43 +00:00
|
|
|
native_context()->initial_iterator_prototype(), isolate());
|
2018-04-05 14:41:26 +00:00
|
|
|
|
|
|
|
Handle<JSObject> regexp_string_iterator_prototype =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
|
|
|
JSObject::ForceSetPrototype(regexp_string_iterator_prototype,
|
|
|
|
iterator_prototype);
|
|
|
|
|
|
|
|
JSObject::AddProperty(
|
2018-06-19 09:00:37 +00:00
|
|
|
isolate(), regexp_string_iterator_prototype,
|
|
|
|
factory()->to_string_tag_symbol(),
|
2018-04-05 14:41:26 +00:00
|
|
|
factory()->NewStringFromAsciiChecked("RegExp String Iterator"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), regexp_string_iterator_prototype, "next",
|
2018-04-05 14:41:26 +00:00
|
|
|
Builtins::kRegExpStringIteratorPrototypeNext, 0,
|
|
|
|
true);
|
|
|
|
|
|
|
|
Handle<JSFunction> regexp_string_iterator_function = CreateFunction(
|
|
|
|
isolate(), factory()->NewStringFromAsciiChecked("RegExpStringIterator"),
|
|
|
|
JS_REGEXP_STRING_ITERATOR_TYPE, JSRegExpStringIterator::kSize, 0,
|
|
|
|
regexp_string_iterator_prototype, Builtins::kIllegal);
|
|
|
|
regexp_string_iterator_function->shared()->set_native(false);
|
|
|
|
native_context()->set_initial_regexp_string_iterator_prototype_map_index(
|
|
|
|
regexp_string_iterator_function->initial_map());
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // @@matchAll Symbol
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSFunction> symbol_fun(native_context()->symbol_function(),
|
|
|
|
isolate());
|
2018-04-05 14:41:26 +00:00
|
|
|
InstallConstant(isolate(), symbol_fun, "matchAll",
|
|
|
|
factory()->match_all_symbol());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-20 05:32:15 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_bigint() {
|
2017-10-26 14:20:15 +00:00
|
|
|
Factory* factory = isolate()->factory();
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSGlobalObject> global(native_context()->global_object(), isolate());
|
2018-02-17 07:44:01 +00:00
|
|
|
if (!FLAG_harmony_bigint) {
|
|
|
|
// Typed arrays are installed by default; remove them if the flag is off.
|
|
|
|
CHECK(JSObject::DeleteProperty(
|
|
|
|
global, factory->InternalizeUtf8String("BigInt64Array"))
|
|
|
|
.ToChecked());
|
|
|
|
CHECK(JSObject::DeleteProperty(
|
|
|
|
global, factory->InternalizeUtf8String("BigUint64Array"))
|
|
|
|
.ToChecked());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSFunction> bigint_fun = InstallFunction(
|
|
|
|
isolate(), global, "BigInt", JS_VALUE_TYPE, JSValue::kSize, 0,
|
|
|
|
factory->the_hole_value(), Builtins::kBigIntConstructor);
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
bigint_fun->shared()->set_builtin_function_id(
|
|
|
|
BuiltinFunctionId::kBigIntConstructor);
|
2017-09-20 05:32:15 +00:00
|
|
|
bigint_fun->shared()->DontAdaptArguments();
|
|
|
|
bigint_fun->shared()->set_length(1);
|
|
|
|
InstallWithIntrinsicDefaultProto(isolate(), bigint_fun,
|
|
|
|
Context::BIGINT_FUNCTION_INDEX);
|
|
|
|
|
|
|
|
// Install the properties of the BigInt constructor.
|
|
|
|
// asUintN(bits, bigint)
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), bigint_fun, "asUintN",
|
|
|
|
Builtins::kBigIntAsUintN, 2, false);
|
2017-09-20 05:32:15 +00:00
|
|
|
// asIntN(bits, bigint)
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), bigint_fun, "asIntN",
|
|
|
|
Builtins::kBigIntAsIntN, 2, false);
|
2017-09-20 05:32:15 +00:00
|
|
|
|
|
|
|
// Set up the %BigIntPrototype%.
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSObject> prototype(JSObject::cast(bigint_fun->instance_prototype()),
|
|
|
|
isolate());
|
2017-09-20 05:32:15 +00:00
|
|
|
JSFunction::SetPrototype(bigint_fun, prototype);
|
|
|
|
|
|
|
|
// Install the properties of the BigInt.prototype.
|
|
|
|
// "constructor" is created implicitly by InstallFunction() above.
|
|
|
|
// toLocaleString([reserved1 [, reserved2]])
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), prototype, "toLocaleString",
|
2017-09-20 05:32:15 +00:00
|
|
|
Builtins::kBigIntPrototypeToLocaleString, 0, false);
|
|
|
|
// toString([radix])
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), prototype, "toString",
|
2017-09-20 05:32:15 +00:00
|
|
|
Builtins::kBigIntPrototypeToString, 0, false);
|
|
|
|
// valueOf()
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), prototype, "valueOf",
|
|
|
|
Builtins::kBigIntPrototypeValueOf, 0, false);
|
2017-10-26 14:20:15 +00:00
|
|
|
// @@toStringTag
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate(), prototype, factory->to_string_tag_symbol(),
|
2017-10-26 14:20:15 +00:00
|
|
|
factory->BigInt_string(),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
2018-02-23 00:18:45 +00:00
|
|
|
|
|
|
|
// Install 64-bit DataView accessors.
|
|
|
|
// TODO(jkummerow): Move these to the "DataView" section when dropping the
|
|
|
|
// FLAG_harmony_bigint.
|
|
|
|
Handle<JSObject> dataview_prototype(
|
2018-06-20 10:10:43 +00:00
|
|
|
JSObject::cast(native_context()->data_view_fun()->instance_prototype()),
|
|
|
|
isolate());
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), dataview_prototype, "getBigInt64",
|
2018-02-23 00:18:45 +00:00
|
|
|
Builtins::kDataViewPrototypeGetBigInt64, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), dataview_prototype, "setBigInt64",
|
2018-02-23 00:18:45 +00:00
|
|
|
Builtins::kDataViewPrototypeSetBigInt64, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), dataview_prototype, "getBigUint64",
|
2018-02-23 00:18:45 +00:00
|
|
|
Builtins::kDataViewPrototypeGetBigUint64, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), dataview_prototype, "setBigUint64",
|
2018-02-23 00:18:45 +00:00
|
|
|
Builtins::kDataViewPrototypeSetBigUint64, 2, false);
|
2017-09-20 05:32:15 +00:00
|
|
|
}
|
|
|
|
|
2018-06-20 21:12:53 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_await_optimization() {
|
|
|
|
if (!FLAG_harmony_await_optimization) return;
|
|
|
|
|
|
|
|
// async/await
|
|
|
|
Handle<JSFunction> await_caught_function = SimpleCreateFunction(
|
|
|
|
isolate(), factory()->empty_string(),
|
|
|
|
Builtins::kAsyncFunctionAwaitCaughtOptimized, 2, false);
|
|
|
|
native_context()->set_async_function_await_caught(*await_caught_function);
|
|
|
|
|
|
|
|
Handle<JSFunction> await_uncaught_function = SimpleCreateFunction(
|
|
|
|
isolate(), factory()->empty_string(),
|
|
|
|
Builtins::kAsyncFunctionAwaitUncaughtOptimized, 2, false);
|
|
|
|
native_context()->set_async_function_await_uncaught(*await_uncaught_function);
|
|
|
|
|
|
|
|
// async generators
|
|
|
|
Handle<JSObject> async_iterator_prototype =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
|
|
|
|
|
|
|
SimpleInstallFunction(
|
|
|
|
isolate(), async_iterator_prototype, factory()->async_iterator_symbol(),
|
|
|
|
"[Symbol.asyncIterator]", Builtins::kReturnReceiver, 0, true);
|
|
|
|
|
|
|
|
Handle<JSObject> async_from_sync_iterator_prototype =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
|
|
|
SimpleInstallFunction(
|
|
|
|
isolate(), async_from_sync_iterator_prototype, factory()->next_string(),
|
|
|
|
Builtins::kAsyncFromSyncIteratorPrototypeNextOptimized, 1, true);
|
|
|
|
SimpleInstallFunction(
|
|
|
|
isolate(), async_from_sync_iterator_prototype, factory()->return_string(),
|
|
|
|
Builtins::kAsyncFromSyncIteratorPrototypeReturnOptimized, 1, true);
|
|
|
|
SimpleInstallFunction(
|
|
|
|
isolate(), async_from_sync_iterator_prototype, factory()->throw_string(),
|
|
|
|
Builtins::kAsyncFromSyncIteratorPrototypeThrowOptimized, 1, true);
|
|
|
|
|
|
|
|
JSObject::AddProperty(
|
|
|
|
isolate(), async_from_sync_iterator_prototype,
|
|
|
|
factory()->to_string_tag_symbol(),
|
|
|
|
factory()->NewStringFromAsciiChecked("Async-from-Sync Iterator"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
|
|
|
JSObject::ForceSetPrototype(async_from_sync_iterator_prototype,
|
|
|
|
async_iterator_prototype);
|
|
|
|
|
|
|
|
Handle<Map> async_from_sync_iterator_map = factory()->NewMap(
|
|
|
|
JS_ASYNC_FROM_SYNC_ITERATOR_TYPE, JSAsyncFromSyncIterator::kSize);
|
2018-06-25 10:54:01 +00:00
|
|
|
Map::SetPrototype(isolate(), async_from_sync_iterator_map,
|
2018-06-20 21:12:53 +00:00
|
|
|
async_from_sync_iterator_prototype);
|
|
|
|
native_context()->set_async_from_sync_iterator_map(
|
|
|
|
*async_from_sync_iterator_map);
|
|
|
|
}
|
|
|
|
|
2018-05-15 20:50:46 +00:00
|
|
|
#ifdef V8_INTL_SUPPORT
|
2018-07-24 21:07:50 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_intl_list_format() {
|
|
|
|
if (!FLAG_harmony_intl_list_format) return;
|
|
|
|
Handle<JSObject> intl = Handle<JSObject>::cast(
|
|
|
|
JSReceiver::GetProperty(
|
|
|
|
isolate(),
|
|
|
|
Handle<JSReceiver>(native_context()->global_object(), isolate()),
|
|
|
|
factory()->InternalizeUtf8String("Intl"))
|
|
|
|
.ToHandleChecked());
|
|
|
|
|
|
|
|
Handle<JSFunction> list_format_fun =
|
|
|
|
InstallFunction(isolate(), intl, "ListFormat", JS_INTL_LIST_FORMAT_TYPE,
|
|
|
|
JSListFormat::kSize, 0, factory()->the_hole_value(),
|
|
|
|
Builtins::kListFormatConstructor);
|
|
|
|
list_format_fun->shared()->set_length(0);
|
|
|
|
list_format_fun->shared()->DontAdaptArguments();
|
|
|
|
|
|
|
|
// Setup %ListFormatPrototype%.
|
|
|
|
Handle<JSObject> prototype(
|
|
|
|
JSObject::cast(list_format_fun->instance_prototype()), isolate());
|
|
|
|
|
|
|
|
// Install the @@toStringTag property on the {prototype}.
|
|
|
|
JSObject::AddProperty(isolate(), prototype, factory()->to_string_tag_symbol(),
|
2018-07-30 21:08:36 +00:00
|
|
|
factory()->NewStringFromStaticChars("Intl.ListFormat"),
|
2018-07-24 21:07:50 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
2018-07-18 17:43:29 +00:00
|
|
|
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "resolvedOptions",
|
|
|
|
Builtins::kListFormatPrototypeResolvedOptions, 0,
|
|
|
|
false);
|
2018-07-24 21:07:50 +00:00
|
|
|
}
|
2018-05-15 20:50:46 +00:00
|
|
|
|
|
|
|
void Genesis::InitializeGlobal_harmony_locale() {
|
|
|
|
if (!FLAG_harmony_locale) return;
|
|
|
|
|
|
|
|
Handle<JSObject> intl = Handle<JSObject>::cast(
|
|
|
|
JSReceiver::GetProperty(
|
2018-06-20 10:10:43 +00:00
|
|
|
isolate(),
|
|
|
|
Handle<JSReceiver>(native_context()->global_object(), isolate()),
|
2018-05-15 20:50:46 +00:00
|
|
|
factory()->InternalizeUtf8String("Intl"))
|
|
|
|
.ToHandleChecked());
|
|
|
|
|
|
|
|
Handle<JSFunction> locale_fun = InstallFunction(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate(), intl, "Locale", JS_INTL_LOCALE_TYPE, JSLocale::kSize, 0,
|
2018-05-15 20:50:46 +00:00
|
|
|
factory()->the_hole_value(), Builtins::kLocaleConstructor);
|
|
|
|
InstallWithIntrinsicDefaultProto(isolate(), locale_fun,
|
|
|
|
Context::INTL_LOCALE_FUNCTION_INDEX);
|
|
|
|
locale_fun->shared()->set_length(1);
|
|
|
|
locale_fun->shared()->DontAdaptArguments();
|
|
|
|
|
|
|
|
// Setup %LocalePrototype%.
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSObject> prototype(JSObject::cast(locale_fun->instance_prototype()),
|
|
|
|
isolate());
|
2018-05-15 20:50:46 +00:00
|
|
|
|
|
|
|
// Install the @@toStringTag property on the {prototype}.
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate(), prototype, factory()->to_string_tag_symbol(),
|
2018-05-15 20:50:46 +00:00
|
|
|
factory()->NewStringFromAsciiChecked("Locale"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), prototype, "toString",
|
2018-05-15 20:50:46 +00:00
|
|
|
Builtins::kLocalePrototypeToString, 0, false);
|
2018-07-17 21:36:37 +00:00
|
|
|
SimpleInstallFunction(isolate(), prototype, "maximize",
|
|
|
|
Builtins::kLocalePrototypeMaximize, 0, false);
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "minimize",
|
|
|
|
Builtins::kLocalePrototypeMinimize, 0, false);
|
2018-05-15 20:50:46 +00:00
|
|
|
// Base locale getters.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype,
|
|
|
|
factory()->InternalizeUtf8String("language"),
|
2018-05-15 20:50:46 +00:00
|
|
|
Builtins::kLocalePrototypeLanguage, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype,
|
|
|
|
factory()->InternalizeUtf8String("script"),
|
2018-05-15 20:50:46 +00:00
|
|
|
Builtins::kLocalePrototypeScript, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype,
|
|
|
|
factory()->InternalizeUtf8String("region"),
|
2018-05-15 20:50:46 +00:00
|
|
|
Builtins::kLocalePrototypeRegion, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype,
|
|
|
|
factory()->InternalizeUtf8String("baseName"),
|
2018-05-15 20:50:46 +00:00
|
|
|
Builtins::kLocalePrototypeBaseName, true);
|
|
|
|
// Unicode extension getters.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype,
|
|
|
|
factory()->InternalizeUtf8String("calendar"),
|
2018-05-15 20:50:46 +00:00
|
|
|
Builtins::kLocalePrototypeCalendar, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype,
|
|
|
|
factory()->InternalizeUtf8String("caseFirst"),
|
2018-05-15 20:50:46 +00:00
|
|
|
Builtins::kLocalePrototypeCaseFirst, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype,
|
|
|
|
factory()->InternalizeUtf8String("collation"),
|
2018-05-15 20:50:46 +00:00
|
|
|
Builtins::kLocalePrototypeCollation, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype,
|
|
|
|
factory()->InternalizeUtf8String("hourCycle"),
|
2018-05-15 20:50:46 +00:00
|
|
|
Builtins::kLocalePrototypeHourCycle, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype,
|
|
|
|
factory()->InternalizeUtf8String("numeric"),
|
2018-05-15 20:50:46 +00:00
|
|
|
Builtins::kLocalePrototypeNumeric, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype,
|
2018-05-15 20:50:46 +00:00
|
|
|
factory()->InternalizeUtf8String("numberingSystem"),
|
|
|
|
Builtins::kLocalePrototypeNumberingSystem, true);
|
|
|
|
}
|
|
|
|
|
2018-07-10 12:52:05 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_intl_relative_time_format() {
|
|
|
|
if (!FLAG_harmony_intl_relative_time_format) return;
|
|
|
|
Handle<JSObject> intl = Handle<JSObject>::cast(
|
|
|
|
JSReceiver::GetProperty(
|
|
|
|
isolate(),
|
|
|
|
Handle<JSReceiver>(native_context()->global_object(), isolate()),
|
|
|
|
factory()->InternalizeUtf8String("Intl"))
|
|
|
|
.ToHandleChecked());
|
|
|
|
|
|
|
|
Handle<JSFunction> relative_time_format_fun = InstallFunction(
|
|
|
|
isolate(), intl, "RelativeTimeFormat", JS_INTL_RELATIVE_TIME_FORMAT_TYPE,
|
|
|
|
JSRelativeTimeFormat::kSize, 0, factory()->the_hole_value(),
|
|
|
|
Builtins::kRelativeTimeFormatConstructor);
|
|
|
|
relative_time_format_fun->shared()->set_length(0);
|
|
|
|
relative_time_format_fun->shared()->DontAdaptArguments();
|
|
|
|
|
|
|
|
// Setup %RelativeTimeFormatPrototype%.
|
|
|
|
Handle<JSObject> prototype(
|
|
|
|
JSObject::cast(relative_time_format_fun->instance_prototype()),
|
|
|
|
isolate());
|
|
|
|
|
|
|
|
// Install the @@toStringTag property on the {prototype}.
|
2018-07-30 21:08:36 +00:00
|
|
|
JSObject::AddProperty(
|
|
|
|
isolate(), prototype, factory()->to_string_tag_symbol(),
|
|
|
|
factory()->NewStringFromStaticChars("Intl.RelativeTimeFormat"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
2018-07-10 12:28:44 +00:00
|
|
|
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "resolvedOptions",
|
|
|
|
Builtins::kRelativeTimeFormatPrototypeResolvedOptions,
|
|
|
|
0, false);
|
2018-07-17 20:19:17 +00:00
|
|
|
SimpleInstallFunction(isolate(), prototype, "format",
|
|
|
|
Builtins::kRelativeTimeFormatPrototypeFormat, 2, false);
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "formatToParts",
|
|
|
|
Builtins::kRelativeTimeFormatPrototypeFormatToParts, 2,
|
|
|
|
false);
|
2018-07-10 12:52:05 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 20:50:46 +00:00
|
|
|
#endif // V8_INTL_SUPPORT
|
|
|
|
|
2018-01-10 23:52:53 +00:00
|
|
|
Handle<JSFunction> Genesis::CreateArrayBuffer(
|
|
|
|
Handle<String> name, ArrayBufferKind array_buffer_kind) {
|
2016-07-06 19:23:44 +00:00
|
|
|
// Create the %ArrayBufferPrototype%
|
2016-01-01 07:12:48 +00:00
|
|
|
// Setup the {prototype} with the given {name} for @@toStringTag.
|
|
|
|
Handle<JSObject> prototype =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate(), prototype, factory()->to_string_tag_symbol(),
|
|
|
|
name,
|
2016-01-01 07:12:48 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
|
|
|
// Allocate the constructor with the given {prototype}.
|
|
|
|
Handle<JSFunction> array_buffer_fun =
|
2017-06-13 23:17:05 +00:00
|
|
|
CreateFunction(isolate(), name, JS_ARRAY_BUFFER_TYPE,
|
2017-10-18 20:14:09 +00:00
|
|
|
JSArrayBuffer::kSizeWithEmbedderFields, 0, prototype,
|
2017-06-13 23:17:05 +00:00
|
|
|
Builtins::kArrayBufferConstructor);
|
2016-01-01 07:12:48 +00:00
|
|
|
array_buffer_fun->shared()->DontAdaptArguments();
|
|
|
|
array_buffer_fun->shared()->set_length(1);
|
|
|
|
|
|
|
|
// Install the "constructor" property on the {prototype}.
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate(), prototype, factory()->constructor_string(),
|
2016-01-01 07:12:48 +00:00
|
|
|
array_buffer_fun, DONT_ENUM);
|
|
|
|
|
2018-01-10 23:52:53 +00:00
|
|
|
switch (array_buffer_kind) {
|
|
|
|
case ARRAY_BUFFER:
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
SimpleInstallFunction(isolate(), array_buffer_fun,
|
|
|
|
factory()->isView_string(),
|
|
|
|
Builtins::kArrayBufferIsView, 1, true, DONT_ENUM,
|
|
|
|
BuiltinFunctionId::kArrayBufferIsView);
|
2018-01-10 23:52:53 +00:00
|
|
|
|
|
|
|
// Install the "byteLength" getter on the {prototype}.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype, factory()->byte_length_string(),
|
2018-01-10 23:52:53 +00:00
|
|
|
Builtins::kArrayBufferPrototypeGetByteLength, false,
|
|
|
|
BuiltinFunctionId::kArrayBufferByteLength);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), prototype, "slice",
|
2018-01-10 23:52:53 +00:00
|
|
|
Builtins::kArrayBufferPrototypeSlice, 2, true);
|
|
|
|
break;
|
2016-01-01 07:12:48 +00:00
|
|
|
|
2018-01-10 23:52:53 +00:00
|
|
|
case SHARED_ARRAY_BUFFER:
|
|
|
|
// Install the "byteLength" getter on the {prototype}.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype, factory()->byte_length_string(),
|
2018-01-10 23:52:53 +00:00
|
|
|
Builtins::kSharedArrayBufferPrototypeGetByteLength,
|
|
|
|
false,
|
|
|
|
BuiltinFunctionId::kSharedArrayBufferByteLength);
|
2016-07-06 19:23:44 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), prototype, "slice",
|
2018-01-10 23:52:53 +00:00
|
|
|
Builtins::kSharedArrayBufferPrototypeSlice, 2,
|
|
|
|
true);
|
|
|
|
break;
|
|
|
|
}
|
2017-02-28 20:31:02 +00:00
|
|
|
|
2016-01-01 07:12:48 +00:00
|
|
|
return array_buffer_fun;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-12 14:00:47 +00:00
|
|
|
Handle<JSFunction> Genesis::InstallInternalArray(Handle<JSObject> target,
|
|
|
|
const char* name,
|
|
|
|
ElementsKind elements_kind) {
|
2013-02-15 15:20:05 +00:00
|
|
|
// --- I n t e r n a l A r r a y ---
|
|
|
|
// An array constructor on the builtins object that works like
|
|
|
|
// the public Array constructor, except that its prototype
|
|
|
|
// doesn't inherit from Object.prototype.
|
|
|
|
// To be used only for internal work by builtins. Instances
|
|
|
|
// must not be leaked to user code.
|
|
|
|
Handle<JSObject> prototype =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
2015-05-12 14:00:47 +00:00
|
|
|
Handle<JSFunction> array_function =
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallFunction(isolate(), target, name, JS_ARRAY_TYPE, JSArray::kSize, 0,
|
|
|
|
prototype, Builtins::kInternalArrayConstructor);
|
2013-02-15 15:20:05 +00:00
|
|
|
|
|
|
|
array_function->shared()->DontAdaptArguments();
|
|
|
|
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<Map> original_map(array_function->initial_map(), isolate());
|
2018-06-19 09:00:37 +00:00
|
|
|
Handle<Map> initial_map = Map::Copy(isolate(), original_map, "InternalArray");
|
2013-05-29 15:38:09 +00:00
|
|
|
initial_map->set_elements_kind(elements_kind);
|
2014-08-11 14:00:58 +00:00
|
|
|
JSFunction::SetInitialMap(array_function, initial_map, prototype);
|
2013-02-15 15:20:05 +00:00
|
|
|
|
|
|
|
// Make "length" magic on instances.
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::EnsureDescriptorSlack(isolate(), initial_map, 1);
|
2013-02-15 15:20:05 +00:00
|
|
|
|
|
|
|
PropertyAttributes attribs = static_cast<PropertyAttributes>(
|
|
|
|
DONT_ENUM | DONT_DELETE);
|
|
|
|
|
|
|
|
{ // Add length.
|
2017-10-27 09:06:44 +00:00
|
|
|
Descriptor d = Descriptor::AccessorConstant(
|
|
|
|
factory()->length_string(), factory()->array_length_accessor(),
|
|
|
|
attribs);
|
2014-11-11 10:24:52 +00:00
|
|
|
initial_map->AppendDescriptor(&d);
|
2013-02-15 15:20:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return array_function;
|
|
|
|
}
|
|
|
|
|
2016-02-02 07:25:30 +00:00
|
|
|
bool Genesis::InstallNatives(GlobalContextType context_type) {
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(isolate());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2015-05-21 06:15:33 +00:00
|
|
|
// Set up the utils object as shared container between native scripts.
|
|
|
|
Handle<JSObject> utils = factory()->NewJSObject(isolate()->object_function());
|
|
|
|
JSObject::NormalizeProperties(utils, CLEAR_INOBJECT_PROPERTIES, 16,
|
|
|
|
"utils container for native scripts");
|
|
|
|
native_context()->set_natives_utils_object(*utils);
|
2015-05-12 14:00:47 +00:00
|
|
|
|
2015-09-16 21:00:45 +00:00
|
|
|
// Set up the extras utils object as a shared container between native
|
|
|
|
// scripts and extras. (Extras consume things added there by native scripts.)
|
|
|
|
Handle<JSObject> extras_utils =
|
|
|
|
factory()->NewJSObject(isolate()->object_function());
|
|
|
|
native_context()->set_extras_utils_object(*extras_utils);
|
|
|
|
|
2017-06-30 11:26:14 +00:00
|
|
|
InstallInternalArray(extras_utils, "InternalPackedArray", PACKED_ELEMENTS);
|
2015-09-16 21:00:45 +00:00
|
|
|
|
2018-02-16 19:10:09 +00:00
|
|
|
// v8.createPromise(parent)
|
2018-02-13 12:06:39 +00:00
|
|
|
Handle<JSFunction> promise_internal_constructor =
|
|
|
|
SimpleCreateFunction(isolate(), factory()->empty_string(),
|
|
|
|
Builtins::kPromiseInternalConstructor, 1, true);
|
|
|
|
promise_internal_constructor->shared()->set_native(false);
|
2018-06-19 09:00:37 +00:00
|
|
|
InstallFunction(isolate(), extras_utils, promise_internal_constructor,
|
2017-01-12 18:57:48 +00:00
|
|
|
factory()->NewStringFromAsciiChecked("createPromise"));
|
2018-02-16 19:10:09 +00:00
|
|
|
|
|
|
|
// v8.rejectPromise(promise, reason)
|
|
|
|
Handle<JSFunction> promise_internal_reject =
|
|
|
|
SimpleCreateFunction(isolate(), factory()->empty_string(),
|
|
|
|
Builtins::kPromiseInternalReject, 2, true);
|
|
|
|
promise_internal_reject->shared()->set_native(false);
|
2018-06-19 09:00:37 +00:00
|
|
|
InstallFunction(isolate(), extras_utils, promise_internal_reject,
|
2018-02-16 19:10:09 +00:00
|
|
|
factory()->NewStringFromAsciiChecked("rejectPromise"));
|
|
|
|
|
|
|
|
// v8.resolvePromise(promise, resolution)
|
|
|
|
Handle<JSFunction> promise_internal_resolve =
|
|
|
|
SimpleCreateFunction(isolate(), factory()->empty_string(),
|
|
|
|
Builtins::kPromiseInternalResolve, 2, true);
|
|
|
|
promise_internal_resolve->shared()->set_native(false);
|
2018-06-19 09:00:37 +00:00
|
|
|
InstallFunction(isolate(), extras_utils, promise_internal_resolve,
|
2018-02-16 19:10:09 +00:00
|
|
|
factory()->NewStringFromAsciiChecked("resolvePromise"));
|
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
InstallFunction(isolate(), extras_utils, isolate()->is_promise(),
|
2017-04-06 13:16:35 +00:00
|
|
|
factory()->NewStringFromAsciiChecked("isPromise"));
|
2016-12-08 06:12:35 +00:00
|
|
|
|
2015-08-18 11:15:34 +00:00
|
|
|
int builtin_index = Natives::GetDebuggerCount();
|
2017-04-15 00:25:59 +00:00
|
|
|
// Only run prologue.js at this point.
|
2015-08-18 11:15:34 +00:00
|
|
|
DCHECK_EQ(builtin_index, Natives::GetIndex("prologue"));
|
|
|
|
if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false;
|
|
|
|
|
2010-02-24 19:59:09 +00:00
|
|
|
{
|
|
|
|
// Builtin function for OpaqueReference -- a JSValue-based object,
|
|
|
|
// that keeps its field isolated from JavaScript code. It may store
|
|
|
|
// objects, that JavaScript code may not access.
|
|
|
|
Handle<JSObject> prototype =
|
2011-04-14 08:01:19 +00:00
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
2017-07-03 13:40:13 +00:00
|
|
|
Handle<JSFunction> opaque_reference_fun =
|
|
|
|
CreateFunction(isolate(), factory()->empty_string(), JS_VALUE_TYPE,
|
2017-10-18 20:14:09 +00:00
|
|
|
JSValue::kSize, 0, prototype, Builtins::kIllegal);
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_opaque_reference_function(*opaque_reference_fun);
|
2010-02-24 19:59:09 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-02-15 15:20:05 +00:00
|
|
|
// InternalArrays should not use Smi-Only array optimizations. There are too
|
|
|
|
// many places in the C++ runtime code (e.g. RegEx) that assume that
|
|
|
|
// elements in InternalArrays can be set to non-Smi values without going
|
|
|
|
// through a common bottleneck that would make the SMI_ONLY -> FAST_ELEMENT
|
|
|
|
// transition easy to trap. Moreover, they rarely are smi-only.
|
|
|
|
{
|
2015-05-12 14:00:47 +00:00
|
|
|
HandleScope scope(isolate());
|
2015-05-21 06:15:33 +00:00
|
|
|
Handle<JSObject> utils =
|
|
|
|
Handle<JSObject>::cast(isolate()->natives_utils_object());
|
|
|
|
Handle<JSFunction> array_function =
|
2017-06-30 11:26:14 +00:00
|
|
|
InstallInternalArray(utils, "InternalArray", HOLEY_ELEMENTS);
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_internal_array_function(*array_function);
|
2013-02-15 15:20:05 +00:00
|
|
|
}
|
|
|
|
|
2015-08-18 11:15:34 +00:00
|
|
|
// Run the rest of the native scripts.
|
|
|
|
while (builtin_index < Natives::GetBuiltinsCount()) {
|
|
|
|
if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2015-05-21 06:15:33 +00:00
|
|
|
if (!CallUtilsFunction(isolate(), "PostNatives")) return false;
|
2016-07-28 17:16:33 +00:00
|
|
|
auto fast_template_instantiations_cache = isolate()->factory()->NewFixedArray(
|
|
|
|
TemplateInfo::kFastTemplateInstantiationsCacheSize);
|
|
|
|
native_context()->set_fast_template_instantiations_cache(
|
|
|
|
*fast_template_instantiations_cache);
|
2015-05-21 06:15:33 +00:00
|
|
|
|
2018-01-25 08:42:56 +00:00
|
|
|
auto slow_template_instantiations_cache = SimpleNumberDictionary::New(
|
|
|
|
isolate(), ApiNatives::kInitialFunctionCacheSize);
|
2016-07-28 17:16:33 +00:00
|
|
|
native_context()->set_slow_template_instantiations_cache(
|
|
|
|
*slow_template_instantiations_cache);
|
2016-06-27 18:03:59 +00:00
|
|
|
|
2015-09-23 13:49:09 +00:00
|
|
|
// Store the map for the %ObjectPrototype% after the natives has been compiled
|
|
|
|
// and the Object function has been set up.
|
2017-04-27 14:48:32 +00:00
|
|
|
{
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSFunction> object_function(native_context()->object_function(),
|
|
|
|
isolate());
|
2017-04-27 14:48:32 +00:00
|
|
|
DCHECK(JSObject::cast(object_function->initial_map()->prototype())
|
|
|
|
->HasFastProperties());
|
|
|
|
native_context()->set_object_function_prototype_map(
|
|
|
|
HeapObject::cast(object_function->initial_map()->prototype())->map());
|
|
|
|
}
|
2016-06-23 12:16:35 +00:00
|
|
|
|
2015-09-23 13:49:09 +00:00
|
|
|
// Store the map for the %StringPrototype% after the natives has been compiled
|
2012-01-13 13:09:52 +00:00
|
|
|
// and the String function has been set up.
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSFunction> string_function(native_context()->string_function(),
|
|
|
|
isolate());
|
2017-02-10 09:38:50 +00:00
|
|
|
JSObject* string_function_prototype =
|
|
|
|
JSObject::cast(string_function->initial_map()->prototype());
|
|
|
|
DCHECK(string_function_prototype->HasFastProperties());
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_string_function_prototype_map(
|
2017-02-10 09:38:50 +00:00
|
|
|
string_function_prototype->map());
|
2010-08-12 13:43:08 +00:00
|
|
|
|
2016-05-17 10:54:14 +00:00
|
|
|
Handle<JSGlobalObject> global_object =
|
2018-05-31 08:31:07 +00:00
|
|
|
handle(native_context()->global_object(), isolate());
|
2016-05-17 10:54:14 +00:00
|
|
|
|
2016-05-27 09:56:04 +00:00
|
|
|
// Install Global.decodeURI.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), global_object, "decodeURI",
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
Builtins::kGlobalDecodeURI, 1, false,
|
|
|
|
BuiltinFunctionId::kGlobalDecodeURI);
|
2016-05-27 09:56:04 +00:00
|
|
|
|
|
|
|
// Install Global.decodeURIComponent.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), global_object, "decodeURIComponent",
|
2016-08-09 07:13:38 +00:00
|
|
|
Builtins::kGlobalDecodeURIComponent, 1, false,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
BuiltinFunctionId::kGlobalDecodeURIComponent);
|
2016-05-27 09:56:04 +00:00
|
|
|
|
2016-05-17 10:54:14 +00:00
|
|
|
// Install Global.encodeURI.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), global_object, "encodeURI",
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
Builtins::kGlobalEncodeURI, 1, false,
|
|
|
|
BuiltinFunctionId::kGlobalEncodeURI);
|
2016-05-17 10:54:14 +00:00
|
|
|
|
|
|
|
// Install Global.encodeURIComponent.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), global_object, "encodeURIComponent",
|
2016-08-09 07:13:38 +00:00
|
|
|
Builtins::kGlobalEncodeURIComponent, 1, false,
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
BuiltinFunctionId::kGlobalEncodeURIComponent);
|
2016-05-17 10:54:14 +00:00
|
|
|
|
2016-06-01 04:24:32 +00:00
|
|
|
// Install Global.escape.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), global_object, "escape",
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
Builtins::kGlobalEscape, 1, false,
|
|
|
|
BuiltinFunctionId::kGlobalEscape);
|
2016-06-01 04:24:32 +00:00
|
|
|
|
|
|
|
// Install Global.unescape.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), global_object, "unescape",
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
Builtins::kGlobalUnescape, 1, false,
|
|
|
|
BuiltinFunctionId::kGlobalUnescape);
|
2016-06-01 04:24:32 +00:00
|
|
|
|
2015-12-22 10:07:33 +00:00
|
|
|
// Install Global.eval.
|
|
|
|
{
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSFunction> eval = SimpleInstallFunction(
|
|
|
|
isolate(), global_object, factory()->eval_string(),
|
|
|
|
Builtins::kGlobalEval, 1, false);
|
2015-12-22 10:07:33 +00:00
|
|
|
native_context()->set_global_eval_fun(*eval);
|
|
|
|
}
|
|
|
|
|
2016-09-07 10:14:19 +00:00
|
|
|
// Install Global.isFinite
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), global_object, "isFinite",
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
Builtins::kGlobalIsFinite, 1, true,
|
|
|
|
BuiltinFunctionId::kGlobalIsFinite);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
|
|
|
// Install Global.isNaN
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), global_object, "isNaN",
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
Builtins::kGlobalIsNaN, 1, true,
|
|
|
|
BuiltinFunctionId::kGlobalIsNaN);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
2017-03-22 13:37:25 +00:00
|
|
|
// Install Array builtin functions.
|
2015-09-07 13:44:44 +00:00
|
|
|
{
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSFunction> array_constructor(native_context()->array_function(),
|
|
|
|
isolate());
|
|
|
|
Handle<JSArray> proto(JSArray::cast(array_constructor->prototype()),
|
|
|
|
isolate());
|
2017-03-22 13:37:25 +00:00
|
|
|
|
|
|
|
// Verification of important array prototype properties.
|
|
|
|
Object* length = proto->length();
|
|
|
|
CHECK(length->IsSmi());
|
2017-10-18 09:06:55 +00:00
|
|
|
CHECK_EQ(Smi::ToInt(length), 0);
|
2017-06-30 18:00:44 +00:00
|
|
|
CHECK(proto->HasSmiOrObjectElements());
|
2017-03-22 13:37:25 +00:00
|
|
|
// This is necessary to enable fast checks for absence of elements
|
|
|
|
// on Array.prototype and below.
|
2018-07-04 09:10:05 +00:00
|
|
|
proto->set_elements(ReadOnlyRoots(heap()).empty_fixed_array());
|
2015-09-07 13:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Install InternalArray.prototype.concat
|
|
|
|
{
|
|
|
|
Handle<JSFunction> array_constructor(
|
2018-06-20 10:10:43 +00:00
|
|
|
native_context()->internal_array_function(), isolate());
|
|
|
|
Handle<JSObject> proto(JSObject::cast(array_constructor->prototype()),
|
|
|
|
isolate());
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), proto, "concat", Builtins::kArrayConcat, 1,
|
|
|
|
false);
|
2015-09-07 13:44:44 +00:00
|
|
|
}
|
2015-12-27 06:30:53 +00:00
|
|
|
|
2011-08-10 16:05:17 +00:00
|
|
|
InstallBuiltinFunctionIds();
|
|
|
|
|
2016-01-20 19:04:06 +00:00
|
|
|
// Create a map for accessor property descriptors (a variant of JSObject
|
|
|
|
// that predefines four properties get, set, configurable and enumerable).
|
|
|
|
{
|
|
|
|
// AccessorPropertyDescriptor initial map.
|
|
|
|
Handle<Map> map =
|
2017-10-18 20:14:09 +00:00
|
|
|
factory()->NewMap(JS_OBJECT_TYPE, JSAccessorPropertyDescriptor::kSize,
|
|
|
|
TERMINAL_FAST_ELEMENTS_KIND, 4);
|
2016-01-20 19:04:06 +00:00
|
|
|
// Create the descriptor array for the property descriptor object.
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::EnsureDescriptorSlack(isolate(), map, 4);
|
2016-01-20 19:04:06 +00:00
|
|
|
|
|
|
|
{ // get
|
2018-07-17 15:08:58 +00:00
|
|
|
Descriptor d =
|
|
|
|
Descriptor::DataField(isolate(), factory()->get_string(),
|
|
|
|
JSAccessorPropertyDescriptor::kGetIndex, NONE,
|
|
|
|
Representation::Tagged());
|
2016-01-20 19:04:06 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
{ // set
|
2018-07-17 15:08:58 +00:00
|
|
|
Descriptor d =
|
|
|
|
Descriptor::DataField(isolate(), factory()->set_string(),
|
|
|
|
JSAccessorPropertyDescriptor::kSetIndex, NONE,
|
|
|
|
Representation::Tagged());
|
2016-01-20 19:04:06 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
{ // enumerable
|
2016-12-21 16:40:00 +00:00
|
|
|
Descriptor d =
|
2018-07-17 15:08:58 +00:00
|
|
|
Descriptor::DataField(isolate(), factory()->enumerable_string(),
|
2016-12-21 16:40:00 +00:00
|
|
|
JSAccessorPropertyDescriptor::kEnumerableIndex,
|
|
|
|
NONE, Representation::Tagged());
|
2016-01-20 19:04:06 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
{ // configurable
|
2016-12-21 16:40:00 +00:00
|
|
|
Descriptor d = Descriptor::DataField(
|
2018-07-17 15:08:58 +00:00
|
|
|
isolate(), factory()->configurable_string(),
|
2016-12-21 16:40:00 +00:00
|
|
|
JSAccessorPropertyDescriptor::kConfigurableIndex, NONE,
|
|
|
|
Representation::Tagged());
|
2016-01-20 19:04:06 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
2018-06-25 10:54:01 +00:00
|
|
|
Map::SetPrototype(isolate(), map, isolate()->initial_object_prototype());
|
2016-02-08 07:00:02 +00:00
|
|
|
map->SetConstructor(native_context()->object_function());
|
2016-01-20 19:04:06 +00:00
|
|
|
|
|
|
|
native_context()->set_accessor_property_descriptor_map(*map);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a map for data property descriptors (a variant of JSObject
|
|
|
|
// that predefines four properties value, writable, configurable and
|
|
|
|
// enumerable).
|
|
|
|
{
|
|
|
|
// DataPropertyDescriptor initial map.
|
|
|
|
Handle<Map> map =
|
2017-10-18 20:14:09 +00:00
|
|
|
factory()->NewMap(JS_OBJECT_TYPE, JSDataPropertyDescriptor::kSize,
|
|
|
|
TERMINAL_FAST_ELEMENTS_KIND, 4);
|
2016-01-20 19:04:06 +00:00
|
|
|
// Create the descriptor array for the property descriptor object.
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::EnsureDescriptorSlack(isolate(), map, 4);
|
2016-01-20 19:04:06 +00:00
|
|
|
|
|
|
|
{ // value
|
2018-07-17 15:08:58 +00:00
|
|
|
Descriptor d =
|
|
|
|
Descriptor::DataField(isolate(), factory()->value_string(),
|
|
|
|
JSDataPropertyDescriptor::kValueIndex, NONE,
|
|
|
|
Representation::Tagged());
|
2016-01-20 19:04:06 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
{ // writable
|
2016-12-21 16:40:00 +00:00
|
|
|
Descriptor d =
|
2018-07-17 15:08:58 +00:00
|
|
|
Descriptor::DataField(isolate(), factory()->writable_string(),
|
2016-12-21 16:40:00 +00:00
|
|
|
JSDataPropertyDescriptor::kWritableIndex, NONE,
|
|
|
|
Representation::Tagged());
|
2016-01-20 19:04:06 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
{ // enumerable
|
2016-12-21 16:40:00 +00:00
|
|
|
Descriptor d =
|
2018-07-17 15:08:58 +00:00
|
|
|
Descriptor::DataField(isolate(), factory()->enumerable_string(),
|
2016-12-21 16:40:00 +00:00
|
|
|
JSDataPropertyDescriptor::kEnumerableIndex,
|
|
|
|
NONE, Representation::Tagged());
|
2016-01-20 19:04:06 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
{ // configurable
|
2016-12-21 16:40:00 +00:00
|
|
|
Descriptor d =
|
2018-07-17 15:08:58 +00:00
|
|
|
Descriptor::DataField(isolate(), factory()->configurable_string(),
|
2016-12-21 16:40:00 +00:00
|
|
|
JSDataPropertyDescriptor::kConfigurableIndex,
|
|
|
|
NONE, Representation::Tagged());
|
2016-01-20 19:04:06 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
2018-06-25 10:54:01 +00:00
|
|
|
Map::SetPrototype(isolate(), map, isolate()->initial_object_prototype());
|
2016-02-08 07:00:02 +00:00
|
|
|
map->SetConstructor(native_context()->object_function());
|
2016-01-20 19:04:06 +00:00
|
|
|
|
|
|
|
native_context()->set_data_property_descriptor_map(*map);
|
|
|
|
}
|
|
|
|
|
2010-04-13 09:31:03 +00:00
|
|
|
// Create a constructor for RegExp results (a variant of Array that
|
2017-12-15 12:33:39 +00:00
|
|
|
// predefines the properties index, input, and groups).
|
2010-04-13 09:31:03 +00:00
|
|
|
{
|
2017-12-15 12:33:39 +00:00
|
|
|
// JSRegExpResult initial map.
|
2010-04-13 09:31:03 +00:00
|
|
|
|
|
|
|
// Find global.Array.prototype to inherit from.
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSFunction> array_constructor(native_context()->array_function(),
|
|
|
|
isolate());
|
2010-04-13 09:31:03 +00:00
|
|
|
Handle<JSObject> array_prototype(
|
2018-06-20 10:10:43 +00:00
|
|
|
JSObject::cast(array_constructor->instance_prototype()), isolate());
|
2010-04-13 09:31:03 +00:00
|
|
|
|
|
|
|
// Add initial map.
|
2017-10-18 20:14:09 +00:00
|
|
|
Handle<Map> initial_map = factory()->NewMap(
|
2017-12-15 12:33:39 +00:00
|
|
|
JS_ARRAY_TYPE, JSRegExpResult::kSize, TERMINAL_FAST_ELEMENTS_KIND,
|
|
|
|
JSRegExpResult::kInObjectPropertyCount);
|
2015-02-24 20:50:06 +00:00
|
|
|
initial_map->SetConstructor(*array_constructor);
|
2010-04-13 09:31:03 +00:00
|
|
|
|
|
|
|
// Set prototype on map.
|
2017-12-07 11:03:41 +00:00
|
|
|
initial_map->set_has_non_instance_prototype(false);
|
2018-06-25 10:54:01 +00:00
|
|
|
Map::SetPrototype(isolate(), initial_map, array_prototype);
|
2010-04-13 09:31:03 +00:00
|
|
|
|
2017-12-15 12:33:39 +00:00
|
|
|
// Update map with length accessor from Array and add "index", "input" and
|
|
|
|
// "groups".
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::EnsureDescriptorSlack(isolate(), initial_map,
|
2017-12-15 12:33:39 +00:00
|
|
|
JSRegExpResult::kInObjectPropertyCount + 1);
|
2011-10-21 10:32:38 +00:00
|
|
|
|
2017-12-15 12:33:39 +00:00
|
|
|
// length descriptor.
|
2012-07-19 10:01:52 +00:00
|
|
|
{
|
2012-08-17 09:03:08 +00:00
|
|
|
JSFunction* array_function = native_context()->array_function();
|
2012-07-19 10:01:52 +00:00
|
|
|
Handle<DescriptorArray> array_descriptors(
|
2018-06-20 10:10:43 +00:00
|
|
|
array_function->initial_map()->instance_descriptors(), isolate());
|
2014-04-09 14:26:32 +00:00
|
|
|
Handle<String> length = factory()->length_string();
|
Sharing of descriptor arrays.
This CL adds multiple things:
Transition arrays do not directly point at their descriptor array anymore, but rather do so via an indirect pointer (a JSGlobalPropertyCell).
An ownership bit is added to maps indicating whether it owns its own descriptor array or not.
Maps owning a descriptor array can pass on ownership if a transition from that map is generated; but only if the descriptor array stays exactly the same; or if a descriptor is added.
Maps that don't have ownership get ownership back if their direct child to which ownership was passed is cleared in ClearNonLiveTransitions.
To detect which descriptors in an array are valid, each map knows its own NumberOfOwnDescriptors. Since the descriptors are sorted in order of addition, if we search and find a descriptor with index bigger than this number, it is not valid for the given map.
We currently still build up an enumeration cache (although this may disappear). The enumeration cache is always built for the entire descriptor array, even if not all descriptors are owned by the map. Once a descriptor array has an enumeration cache for a given map; this invariant will always be true, even if the descriptor array was extended. The extended array will inherit the enumeration cache from the smaller descriptor array. If a map with more descriptors needs an enumeration cache, it's EnumLength will still be set to invalid, so it will have to recompute the enumeration cache. This new cache will also be valid for smaller maps since they have their own enumlength; and use this to loop over the cache. If the EnumLength is still invalid, but there is already a cache present that is big enough; we just initialize the EnumLength field for the map.
When we apply ClearNonLiveTransitions and descriptor ownership is passed back to a parent map, the descriptor array is trimmed in-place and resorted. At the same time, the enumeration cache is trimmed in-place.
Only transition arrays contain descriptor arrays. If we transition to a map and pass ownership of the descriptor array along, the child map will not store the descriptor array it owns. Rather its parent will keep the pointer. So for every leaf-map, we find the descriptor array by following the back pointer, reading out the transition array, and fetching the descriptor array from the JSGlobalPropertyCell. If a map has a transition array, we fetch it from there. If a map has undefined as its back-pointer and has no transition array; it is considered to have an empty descriptor array.
When we modify properties, we cannot share the descriptor array. To accommodate this, the child map will get its own transition array; even if there are not necessarily any transitions leaving from the child map. This is necessary since it's the only way to store its own descriptor array.
Review URL: https://chromiumcodereview.appspot.com/10909007
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12492 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-09-12 16:43:57 +00:00
|
|
|
int old = array_descriptors->SearchWithCache(
|
2016-02-17 16:23:38 +00:00
|
|
|
isolate(), *length, array_function->initial_map());
|
2017-10-18 09:06:55 +00:00
|
|
|
DCHECK_NE(old, DescriptorArray::kNotFound);
|
2016-12-21 16:40:00 +00:00
|
|
|
Descriptor d = Descriptor::AccessorConstant(
|
2018-06-04 08:20:28 +00:00
|
|
|
length, handle(array_descriptors->GetStrongValue(old), isolate()),
|
2015-01-19 17:49:13 +00:00
|
|
|
array_descriptors->GetDetails(old).attributes());
|
2016-12-21 16:40:00 +00:00
|
|
|
initial_map->AppendDescriptor(&d);
|
2012-07-19 10:01:52 +00:00
|
|
|
}
|
2017-12-15 12:33:39 +00:00
|
|
|
|
|
|
|
// index descriptor.
|
2010-04-13 09:31:03 +00:00
|
|
|
{
|
2018-07-17 15:08:58 +00:00
|
|
|
Descriptor d = Descriptor::DataField(isolate(), factory()->index_string(),
|
2016-12-21 16:40:00 +00:00
|
|
|
JSRegExpResult::kIndexIndex, NONE,
|
|
|
|
Representation::Tagged());
|
|
|
|
initial_map->AppendDescriptor(&d);
|
2010-04-13 09:31:03 +00:00
|
|
|
}
|
|
|
|
|
2017-12-15 12:33:39 +00:00
|
|
|
// input descriptor.
|
2010-04-13 09:31:03 +00:00
|
|
|
{
|
2018-07-17 15:08:58 +00:00
|
|
|
Descriptor d = Descriptor::DataField(isolate(), factory()->input_string(),
|
2016-12-21 16:40:00 +00:00
|
|
|
JSRegExpResult::kInputIndex, NONE,
|
|
|
|
Representation::Tagged());
|
|
|
|
initial_map->AppendDescriptor(&d);
|
2010-04-13 09:31:03 +00:00
|
|
|
}
|
|
|
|
|
2017-12-15 12:33:39 +00:00
|
|
|
// groups descriptor.
|
|
|
|
{
|
2018-07-17 15:08:58 +00:00
|
|
|
Descriptor d = Descriptor::DataField(
|
|
|
|
isolate(), factory()->groups_string(), JSRegExpResult::kGroupsIndex,
|
|
|
|
NONE, Representation::Tagged());
|
2017-12-15 12:33:39 +00:00
|
|
|
initial_map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_regexp_result_map(*initial_map);
|
2010-04-13 09:31:03 +00:00
|
|
|
}
|
|
|
|
|
2014-08-25 09:12:22 +00:00
|
|
|
// Add @@iterator method to the arguments object maps.
|
|
|
|
{
|
|
|
|
PropertyAttributes attribs = DONT_ENUM;
|
|
|
|
Handle<AccessorInfo> arguments_iterator =
|
2017-10-27 09:06:44 +00:00
|
|
|
factory()->arguments_iterator_accessor();
|
2014-08-25 09:12:22 +00:00
|
|
|
{
|
2016-12-21 16:40:00 +00:00
|
|
|
Descriptor d = Descriptor::AccessorConstant(factory()->iterator_symbol(),
|
|
|
|
arguments_iterator, attribs);
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<Map> map(native_context()->sloppy_arguments_map(), isolate());
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::EnsureDescriptorSlack(isolate(), map, 1);
|
2014-08-25 09:12:22 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
{
|
2016-12-21 16:40:00 +00:00
|
|
|
Descriptor d = Descriptor::AccessorConstant(factory()->iterator_symbol(),
|
|
|
|
arguments_iterator, attribs);
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<Map> map(native_context()->fast_aliased_arguments_map(),
|
|
|
|
isolate());
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::EnsureDescriptorSlack(isolate(), map, 1);
|
2015-07-02 14:38:37 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
{
|
2016-12-21 16:40:00 +00:00
|
|
|
Descriptor d = Descriptor::AccessorConstant(factory()->iterator_symbol(),
|
|
|
|
arguments_iterator, attribs);
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<Map> map(native_context()->slow_aliased_arguments_map(),
|
|
|
|
isolate());
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::EnsureDescriptorSlack(isolate(), map, 1);
|
2014-08-25 09:12:22 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
{
|
2016-12-21 16:40:00 +00:00
|
|
|
Descriptor d = Descriptor::AccessorConstant(factory()->iterator_symbol(),
|
|
|
|
arguments_iterator, attribs);
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<Map> map(native_context()->strict_arguments_map(), isolate());
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::EnsureDescriptorSlack(isolate(), map, 1);
|
2014-08-25 09:12:22 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-08 08:44:47 +00:00
|
|
|
bool Genesis::InstallExtraNatives() {
|
2015-08-14 18:47:46 +00:00
|
|
|
HandleScope scope(isolate());
|
|
|
|
|
|
|
|
Handle<JSObject> extras_binding =
|
|
|
|
factory()->NewJSObject(isolate()->object_function());
|
2018-07-18 18:08:21 +00:00
|
|
|
|
|
|
|
// binding.isTraceCategoryEnabled(category)
|
|
|
|
SimpleInstallFunction(isolate(), extras_binding, "isTraceCategoryEnabled",
|
|
|
|
Builtins::kIsTraceCategoryEnabled, 1, true);
|
|
|
|
|
|
|
|
// binding.trace(phase, category, name, id, data)
|
|
|
|
SimpleInstallFunction(isolate(), extras_binding, "trace", Builtins::kTrace, 5,
|
|
|
|
true);
|
|
|
|
|
2015-08-14 18:47:46 +00:00
|
|
|
native_context()->set_extras_binding_object(*extras_binding);
|
|
|
|
|
2015-05-08 08:44:47 +00:00
|
|
|
for (int i = ExtraNatives::GetDebuggerCount();
|
|
|
|
i < ExtraNatives::GetBuiltinsCount(); i++) {
|
2015-07-13 09:45:43 +00:00
|
|
|
if (!Bootstrapper::CompileExtraBuiltin(isolate(), i)) return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-20 00:01:07 +00:00
|
|
|
bool Genesis::InstallExperimentalExtraNatives() {
|
|
|
|
for (int i = ExperimentalExtraNatives::GetDebuggerCount();
|
|
|
|
i < ExperimentalExtraNatives::GetBuiltinsCount(); i++) {
|
|
|
|
if (!Bootstrapper::CompileExperimentalExtraBuiltin(isolate(), i))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-12 14:22:07 +00:00
|
|
|
bool Genesis::InstallDebuggerNatives() {
|
|
|
|
for (int i = 0; i < Natives::GetDebuggerCount(); ++i) {
|
|
|
|
if (!Bootstrapper::CompileBuiltin(isolate(), i)) return false;
|
|
|
|
}
|
2017-03-13 20:59:15 +00:00
|
|
|
return true;
|
2015-08-12 14:22:07 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
static void InstallBuiltinFunctionId(Isolate* isolate, Handle<JSObject> holder,
|
2010-12-14 18:53:48 +00:00
|
|
|
const char* function_name,
|
|
|
|
BuiltinFunctionId id) {
|
2014-04-11 12:47:34 +00:00
|
|
|
Handle<Object> function_object =
|
2016-03-08 17:29:05 +00:00
|
|
|
JSReceiver::GetProperty(isolate, holder, function_name).ToHandleChecked();
|
2014-04-09 12:21:47 +00:00
|
|
|
Handle<JSFunction> function = Handle<JSFunction>::cast(function_object);
|
2016-02-25 16:06:01 +00:00
|
|
|
function->shared()->set_builtin_function_id(id);
|
2010-05-06 13:21:53 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:58:29 +00:00
|
|
|
#define INSTALL_BUILTIN_ID(holder_expr, fun_name, name) \
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
{#holder_expr, #fun_name, BuiltinFunctionId::k##name},
|
2015-06-03 17:58:29 +00:00
|
|
|
|
2010-12-14 18:53:48 +00:00
|
|
|
void Genesis::InstallBuiltinFunctionIds() {
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(isolate());
|
2015-02-27 15:21:42 +00:00
|
|
|
struct BuiltinFunctionIds {
|
|
|
|
const char* holder_expr;
|
|
|
|
const char* fun_name;
|
|
|
|
BuiltinFunctionId id;
|
|
|
|
};
|
|
|
|
|
|
|
|
const BuiltinFunctionIds builtins[] = {
|
|
|
|
FUNCTIONS_WITH_ID_LIST(INSTALL_BUILTIN_ID)};
|
|
|
|
|
|
|
|
for (const BuiltinFunctionIds& builtin : builtins) {
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSObject> holder = ResolveBuiltinIdHolder(
|
|
|
|
isolate(), native_context(), builtin.holder_expr);
|
|
|
|
InstallBuiltinFunctionId(isolate(), holder, builtin.fun_name, builtin.id);
|
2015-02-27 15:21:42 +00:00
|
|
|
}
|
2010-05-06 13:21:53 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:58:29 +00:00
|
|
|
#undef INSTALL_BUILTIN_ID
|
|
|
|
|
|
|
|
|
2010-08-25 13:25:54 +00:00
|
|
|
void Genesis::InitializeNormalizedMapCaches() {
|
2014-05-02 13:03:39 +00:00
|
|
|
Handle<NormalizedMapCache> cache = NormalizedMapCache::New(isolate());
|
|
|
|
native_context()->set_normalized_map_cache(*cache);
|
2010-08-25 13:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
bool Bootstrapper::InstallExtensions(Handle<Context> native_context,
|
2010-03-23 11:40:38 +00:00
|
|
|
v8::ExtensionConfiguration* extensions) {
|
2018-05-28 08:27:06 +00:00
|
|
|
// Don't install extensions into the snapshot.
|
|
|
|
if (isolate_->serializer_enabled()) return true;
|
2013-02-15 09:27:10 +00:00
|
|
|
BootstrapperActive active(this);
|
|
|
|
SaveContext saved_context(isolate_);
|
|
|
|
isolate_->set_context(*native_context);
|
2018-05-31 14:14:48 +00:00
|
|
|
return Genesis::InstallExtensions(isolate_, native_context, extensions) &&
|
|
|
|
Genesis::InstallSpecialObjects(isolate_, native_context);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
bool Genesis::InstallSpecialObjects(Isolate* isolate,
|
|
|
|
Handle<Context> native_context) {
|
2012-01-05 17:16:19 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(isolate);
|
2014-07-07 13:27:37 +00:00
|
|
|
|
2015-12-09 07:53:19 +00:00
|
|
|
Handle<JSObject> Error = isolate->error_function();
|
2014-07-07 13:27:37 +00:00
|
|
|
Handle<String> name =
|
2014-09-10 12:38:12 +00:00
|
|
|
factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("stackTraceLimit"));
|
2014-07-07 13:27:37 +00:00
|
|
|
Handle<Smi> stack_trace_limit(Smi::FromInt(FLAG_stack_trace_limit), isolate);
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate, Error, name, stack_trace_limit, NONE);
|
2014-07-07 13:27:37 +00:00
|
|
|
|
2017-09-04 12:15:18 +00:00
|
|
|
if (FLAG_expose_wasm) {
|
|
|
|
// Install the internal data structures into the isolate and expose on
|
|
|
|
// the global object.
|
|
|
|
WasmJs::Install(isolate, true);
|
|
|
|
} else if (FLAG_validate_asm) {
|
|
|
|
// Install the internal data structures only; these are needed for asm.js
|
|
|
|
// translated to WASM to work correctly.
|
|
|
|
WasmJs::Install(isolate, false);
|
2017-01-12 20:32:27 +00:00
|
|
|
}
|
2015-08-27 14:42:36 +00:00
|
|
|
|
2014-01-16 13:18:28 +00:00
|
|
|
return true;
|
2008-08-14 13:41:48 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2011-11-15 22:48:55 +00:00
|
|
|
static uint32_t Hash(RegisteredExtension* extension) {
|
|
|
|
return v8::internal::ComputePointerHash(extension);
|
|
|
|
}
|
|
|
|
|
2016-09-30 16:16:47 +00:00
|
|
|
Genesis::ExtensionStates::ExtensionStates() : map_(8) {}
|
2011-11-15 22:48:55 +00:00
|
|
|
|
|
|
|
Genesis::ExtensionTraversalState Genesis::ExtensionStates::get_state(
|
|
|
|
RegisteredExtension* extension) {
|
2016-06-09 17:58:10 +00:00
|
|
|
base::HashMap::Entry* entry = map_.Lookup(extension, Hash(extension));
|
2017-10-13 16:33:03 +00:00
|
|
|
if (entry == nullptr) {
|
2011-11-15 22:48:55 +00:00
|
|
|
return UNVISITED;
|
|
|
|
}
|
|
|
|
return static_cast<ExtensionTraversalState>(
|
|
|
|
reinterpret_cast<intptr_t>(entry->value));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Genesis::ExtensionStates::set_state(RegisteredExtension* extension,
|
|
|
|
ExtensionTraversalState state) {
|
2015-04-13 19:01:15 +00:00
|
|
|
map_.LookupOrInsert(extension, Hash(extension))->value =
|
2011-11-15 22:48:55 +00:00
|
|
|
reinterpret_cast<void*>(static_cast<intptr_t>(state));
|
|
|
|
}
|
2008-08-14 13:41:48 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
bool Genesis::InstallExtensions(Isolate* isolate,
|
|
|
|
Handle<Context> native_context,
|
2010-03-23 11:40:38 +00:00
|
|
|
v8::ExtensionConfiguration* extensions) {
|
2011-11-15 23:26:22 +00:00
|
|
|
ExtensionStates extension_states; // All extensions have state UNVISITED.
|
2014-01-16 13:18:28 +00:00
|
|
|
return InstallAutoExtensions(isolate, &extension_states) &&
|
2016-04-27 11:10:41 +00:00
|
|
|
(!FLAG_expose_free_buffer ||
|
|
|
|
InstallExtension(isolate, "v8/free-buffer", &extension_states)) &&
|
|
|
|
(!FLAG_expose_gc ||
|
|
|
|
InstallExtension(isolate, "v8/gc", &extension_states)) &&
|
|
|
|
(!FLAG_expose_externalize_string ||
|
|
|
|
InstallExtension(isolate, "v8/externalize", &extension_states)) &&
|
2016-11-08 03:13:42 +00:00
|
|
|
(!FLAG_gc_stats ||
|
2016-04-27 11:10:41 +00:00
|
|
|
InstallExtension(isolate, "v8/statistics", &extension_states)) &&
|
|
|
|
(!FLAG_expose_trigger_failure ||
|
|
|
|
InstallExtension(isolate, "v8/trigger-failure", &extension_states)) &&
|
2016-10-27 12:17:13 +00:00
|
|
|
(!FLAG_trace_ignition_dispatches ||
|
2016-04-27 11:10:41 +00:00
|
|
|
InstallExtension(isolate, "v8/ignition-statistics",
|
|
|
|
&extension_states)) &&
|
|
|
|
InstallRequestedExtensions(isolate, extensions, &extension_states);
|
2014-01-16 13:18:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-01-16 13:18:28 +00:00
|
|
|
|
|
|
|
bool Genesis::InstallAutoExtensions(Isolate* isolate,
|
|
|
|
ExtensionStates* extension_states) {
|
|
|
|
for (v8::RegisteredExtension* it = v8::RegisteredExtension::first_extension();
|
2017-10-13 16:33:03 +00:00
|
|
|
it != nullptr; it = it->next()) {
|
2014-01-16 13:18:28 +00:00
|
|
|
if (it->extension()->auto_enable() &&
|
|
|
|
!InstallExtension(isolate, it, extension_states)) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-05 17:26:22 +00:00
|
|
|
}
|
2014-01-16 13:18:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-01-16 13:18:28 +00:00
|
|
|
bool Genesis::InstallRequestedExtensions(Isolate* isolate,
|
|
|
|
v8::ExtensionConfiguration* extensions,
|
|
|
|
ExtensionStates* extension_states) {
|
2014-01-16 08:17:40 +00:00
|
|
|
for (const char** it = extensions->begin(); it != extensions->end(); ++it) {
|
2014-01-16 13:18:28 +00:00
|
|
|
if (!InstallExtension(isolate, *it, extension_states)) return false;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Installs a named extension. This methods is unoptimized and does
|
|
|
|
// not scale well if we want to support a large number of extensions.
|
2013-02-15 09:27:10 +00:00
|
|
|
bool Genesis::InstallExtension(Isolate* isolate,
|
|
|
|
const char* name,
|
2011-11-15 22:48:55 +00:00
|
|
|
ExtensionStates* extension_states) {
|
2014-01-16 13:18:28 +00:00
|
|
|
for (v8::RegisteredExtension* it = v8::RegisteredExtension::first_extension();
|
2017-10-13 16:33:03 +00:00
|
|
|
it != nullptr; it = it->next()) {
|
2014-01-16 13:18:28 +00:00
|
|
|
if (strcmp(name, it->extension()->name()) == 0) {
|
|
|
|
return InstallExtension(isolate, it, extension_states);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2014-01-16 13:18:28 +00:00
|
|
|
return Utils::ApiCheck(false,
|
|
|
|
"v8::Context::New()",
|
|
|
|
"Cannot find required extension");
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-15 09:27:10 +00:00
|
|
|
bool Genesis::InstallExtension(Isolate* isolate,
|
|
|
|
v8::RegisteredExtension* current,
|
2011-11-15 22:48:55 +00:00
|
|
|
ExtensionStates* extension_states) {
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-11-15 22:48:55 +00:00
|
|
|
if (extension_states->get_state(current) == INSTALLED) return true;
|
2008-07-03 15:10:15 +00:00
|
|
|
// The current node has already been visited so there must be a
|
|
|
|
// cycle in the dependency graph; fail.
|
2014-01-13 09:42:23 +00:00
|
|
|
if (!Utils::ApiCheck(extension_states->get_state(current) != VISITED,
|
|
|
|
"v8::Context::New()",
|
|
|
|
"Circular extension dependency")) {
|
2008-07-03 15:10:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(extension_states->get_state(current) == UNVISITED);
|
2011-11-15 22:48:55 +00:00
|
|
|
extension_states->set_state(current, VISITED);
|
2008-07-03 15:10:15 +00:00
|
|
|
v8::Extension* extension = current->extension();
|
|
|
|
// Install the extension's dependencies
|
|
|
|
for (int i = 0; i < extension->dependency_count(); i++) {
|
2013-02-15 09:27:10 +00:00
|
|
|
if (!InstallExtension(isolate,
|
|
|
|
extension->dependencies()[i],
|
|
|
|
extension_states)) {
|
2011-11-15 22:48:55 +00:00
|
|
|
return false;
|
2013-02-15 09:27:10 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2014-03-25 09:09:24 +00:00
|
|
|
// We do not expect this to throw an exception. Change this if it does.
|
2015-05-12 14:00:47 +00:00
|
|
|
bool result = CompileExtension(isolate, extension);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(isolate->has_pending_exception() != result);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (!result) {
|
2011-10-25 13:43:19 +00:00
|
|
|
// We print out the name of the extension that fail to install.
|
|
|
|
// When an error is thrown during bootstrapping we automatically print
|
|
|
|
// the line number at which this happened to the console in the isolate
|
|
|
|
// error throwing functionality.
|
2014-06-30 13:25:46 +00:00
|
|
|
base::OS::PrintError("Error installing extension '%s'.\n",
|
|
|
|
current->extension()->name());
|
2011-03-28 13:09:37 +00:00
|
|
|
isolate->clear_pending_exception();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-11-15 22:48:55 +00:00
|
|
|
extension_states->set_state(current, INSTALLED);
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
bool Genesis::ConfigureGlobalObjects(
|
2015-07-06 07:09:07 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> global_proxy_template) {
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
Handle<JSObject> global_proxy(
|
2018-06-20 10:10:43 +00:00
|
|
|
JSObject::cast(native_context()->global_proxy()), isolate());
|
2014-07-01 12:12:34 +00:00
|
|
|
Handle<JSObject> global_object(
|
2018-06-20 10:10:43 +00:00
|
|
|
JSObject::cast(native_context()->global_object()), isolate());
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
|
|
|
|
if (!global_proxy_template.IsEmpty()) {
|
2008-10-21 20:08:49 +00:00
|
|
|
// Configure the global proxy object.
|
2014-07-01 12:12:34 +00:00
|
|
|
Handle<ObjectTemplateInfo> global_proxy_data =
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
v8::Utils::OpenHandle(*global_proxy_template);
|
2014-07-01 12:12:34 +00:00
|
|
|
if (!ConfigureApiObject(global_proxy, global_proxy_data)) return false;
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
|
2014-07-01 12:12:34 +00:00
|
|
|
// Configure the global object.
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
Handle<FunctionTemplateInfo> proxy_constructor(
|
2018-06-20 10:10:43 +00:00
|
|
|
FunctionTemplateInfo::cast(global_proxy_data->constructor()),
|
|
|
|
isolate());
|
2016-06-06 12:58:10 +00:00
|
|
|
if (!proxy_constructor->prototype_template()->IsUndefined(isolate())) {
|
2014-07-01 12:12:34 +00:00
|
|
|
Handle<ObjectTemplateInfo> global_object_data(
|
2018-06-20 10:10:43 +00:00
|
|
|
ObjectTemplateInfo::cast(proxy_constructor->prototype_template()),
|
|
|
|
isolate());
|
2014-07-01 12:12:34 +00:00
|
|
|
if (!ConfigureApiObject(global_object, global_object_data)) return false;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
|
2016-07-19 11:28:43 +00:00
|
|
|
JSObject::ForceSetPrototype(global_proxy, global_object);
|
2013-05-13 07:35:26 +00:00
|
|
|
|
2015-06-01 14:22:58 +00:00
|
|
|
native_context()->set_array_buffer_map(
|
|
|
|
native_context()->array_buffer_fun()->initial_map());
|
2017-06-01 13:54:12 +00:00
|
|
|
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSFunction> js_map_fun(native_context()->js_map_fun(), isolate());
|
|
|
|
Handle<JSFunction> js_set_fun(native_context()->js_set_fun(), isolate());
|
2017-06-01 13:54:12 +00:00
|
|
|
// Force the Map/Set constructor to fast properties, so that we can use the
|
|
|
|
// fast paths for various things like
|
|
|
|
//
|
|
|
|
// x instanceof Map
|
|
|
|
// x instanceof Set
|
|
|
|
//
|
|
|
|
// etc. We should probably come up with a more principled approach once
|
|
|
|
// the JavaScript builtins are gone.
|
|
|
|
JSObject::MigrateSlowToFast(js_map_fun, 0, "Bootstrapping");
|
|
|
|
JSObject::MigrateSlowToFast(js_set_fun, 0, "Bootstrapping");
|
|
|
|
|
|
|
|
native_context()->set_js_map_map(js_map_fun->initial_map());
|
|
|
|
native_context()->set_js_set_map(js_set_fun->initial_map());
|
2013-05-13 07:35:26 +00:00
|
|
|
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-10-21 20:08:49 +00:00
|
|
|
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
bool Genesis::ConfigureApiObject(Handle<JSObject> object,
|
2014-07-01 12:12:34 +00:00
|
|
|
Handle<ObjectTemplateInfo> object_template) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!object_template.is_null());
|
|
|
|
DCHECK(FunctionTemplateInfo::cast(object_template->constructor())
|
2013-11-19 13:38:15 +00:00
|
|
|
->IsTemplateFor(object->map()));;
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
|
2014-04-11 10:41:09 +00:00
|
|
|
MaybeHandle<JSObject> maybe_obj =
|
2018-06-23 09:05:50 +00:00
|
|
|
ApiNatives::InstantiateObject(object->GetIsolate(), object_template);
|
2014-04-11 10:41:09 +00:00
|
|
|
Handle<JSObject> obj;
|
|
|
|
if (!maybe_obj.ToHandle(&obj)) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(isolate()->has_pending_exception());
|
2011-04-14 08:01:19 +00:00
|
|
|
isolate()->clear_pending_exception();
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
TransferObject(obj, object);
|
2008-07-03 15:10:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Genesis::TransferNamedProperties(Handle<JSObject> from,
|
|
|
|
Handle<JSObject> to) {
|
2015-01-14 11:06:38 +00:00
|
|
|
// If JSObject::AddProperty asserts due to already existing property,
|
|
|
|
// it is likely due to both global objects sharing property name(s).
|
|
|
|
// Merging those two global objects is impossible.
|
|
|
|
// The global template must not create properties that already exist
|
|
|
|
// in the snapshotted global object.
|
2008-07-03 15:10:15 +00:00
|
|
|
if (from->HasFastProperties()) {
|
|
|
|
Handle<DescriptorArray> descs =
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<DescriptorArray>(from->map()->instance_descriptors(), isolate());
|
2013-05-07 13:09:23 +00:00
|
|
|
for (int i = 0; i < from->map()->NumberOfOwnDescriptors(); i++) {
|
2012-04-17 07:16:19 +00:00
|
|
|
PropertyDetails details = descs->GetDetails(i);
|
2017-01-12 16:37:12 +00:00
|
|
|
if (details.location() == kField) {
|
|
|
|
if (details.kind() == kData) {
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope inner(isolate());
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<Name> key = Handle<Name>(descs->GetKey(i), isolate());
|
2014-06-10 14:01:08 +00:00
|
|
|
FieldIndex index = FieldIndex::ForDescriptor(from->map(), i);
|
2017-08-16 10:44:18 +00:00
|
|
|
Handle<Object> value =
|
|
|
|
JSObject::FastPropertyAt(from, details.representation(), index);
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate(), to, key, value,
|
|
|
|
details.attributes());
|
2017-01-12 16:37:12 +00:00
|
|
|
} else {
|
|
|
|
DCHECK_EQ(kAccessor, details.kind());
|
|
|
|
UNREACHABLE();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2017-01-12 16:37:12 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
DCHECK_EQ(kDescriptor, details.location());
|
|
|
|
if (details.kind() == kData) {
|
2017-02-10 08:05:25 +00:00
|
|
|
DCHECK(!FLAG_track_constant_fields);
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope inner(isolate());
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<Name> key = Handle<Name>(descs->GetKey(i), isolate());
|
2018-06-04 08:20:28 +00:00
|
|
|
Handle<Object> value(descs->GetStrongValue(i), isolate());
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate(), to, key, value,
|
|
|
|
details.attributes());
|
2017-01-12 16:37:12 +00:00
|
|
|
} else {
|
|
|
|
DCHECK_EQ(kAccessor, details.kind());
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<Name> key(descs->GetKey(i), isolate());
|
2018-07-17 08:49:20 +00:00
|
|
|
LookupIterator it(isolate(), to, key,
|
|
|
|
LookupIterator::OWN_SKIP_INTERCEPTOR);
|
2014-09-03 14:05:55 +00:00
|
|
|
CHECK_NE(LookupIterator::ACCESS_CHECK, it.state());
|
2008-07-03 15:10:15 +00:00
|
|
|
// If the property is already there we skip it
|
2014-09-04 12:28:13 +00:00
|
|
|
if (it.IsFound()) continue;
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope inner(isolate());
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!to->HasFastProperties());
|
2010-03-23 11:40:38 +00:00
|
|
|
// Add to dictionary.
|
2018-06-04 08:20:28 +00:00
|
|
|
Handle<Object> value(descs->GetStrongValue(i), isolate());
|
2017-06-22 09:52:28 +00:00
|
|
|
PropertyDetails d(kAccessor, details.attributes(),
|
2015-03-17 13:27:25 +00:00
|
|
|
PropertyCellType::kMutable);
|
2017-01-13 13:23:27 +00:00
|
|
|
JSObject::SetNormalizedProperty(to, key, value, d);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-02 14:57:59 +00:00
|
|
|
} else if (from->IsJSGlobalObject()) {
|
2016-12-05 20:17:13 +00:00
|
|
|
// Copy all keys and values in enumeration order.
|
2017-07-11 20:56:40 +00:00
|
|
|
Handle<GlobalDictionary> properties(
|
2018-06-20 10:10:43 +00:00
|
|
|
JSGlobalObject::cast(*from)->global_dictionary(), isolate());
|
2018-07-13 09:32:35 +00:00
|
|
|
Handle<FixedArray> indices =
|
|
|
|
GlobalDictionary::IterationIndices(isolate(), properties);
|
2017-06-27 11:57:13 +00:00
|
|
|
for (int i = 0; i < indices->length(); i++) {
|
2017-07-10 12:58:27 +00:00
|
|
|
int index = Smi::ToInt(indices->get(i));
|
2016-12-05 20:17:13 +00:00
|
|
|
// If the property is already there we skip it.
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<PropertyCell> cell(properties->CellAt(index), isolate());
|
2017-06-27 11:57:13 +00:00
|
|
|
Handle<Name> key(cell->name(), isolate());
|
2018-07-17 08:49:20 +00:00
|
|
|
LookupIterator it(isolate(), to, key,
|
|
|
|
LookupIterator::OWN_SKIP_INTERCEPTOR);
|
2016-12-05 20:17:13 +00:00
|
|
|
CHECK_NE(LookupIterator::ACCESS_CHECK, it.state());
|
|
|
|
if (it.IsFound()) continue;
|
|
|
|
// Set the property.
|
|
|
|
Handle<Object> value(cell->value(), isolate());
|
|
|
|
if (value->IsTheHole(isolate())) continue;
|
|
|
|
PropertyDetails details = cell->property_details();
|
2016-12-08 12:44:29 +00:00
|
|
|
if (details.kind() != kData) continue;
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate(), to, key, value, details.attributes());
|
2015-06-01 16:24:59 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
2016-12-05 20:17:13 +00:00
|
|
|
// Copy all keys and values in enumeration order.
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<NameDictionary> properties =
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<NameDictionary>(from->property_dictionary(), isolate());
|
2016-12-05 20:17:13 +00:00
|
|
|
Handle<FixedArray> key_indices =
|
2018-07-13 09:32:35 +00:00
|
|
|
NameDictionary::IterationIndices(isolate(), properties);
|
2018-07-12 08:02:49 +00:00
|
|
|
ReadOnlyRoots roots(isolate());
|
2016-12-05 20:17:13 +00:00
|
|
|
for (int i = 0; i < key_indices->length(); i++) {
|
2017-07-10 12:58:27 +00:00
|
|
|
int key_index = Smi::ToInt(key_indices->get(i));
|
2016-12-05 20:17:13 +00:00
|
|
|
Object* raw_key = properties->KeyAt(key_index);
|
2018-07-12 08:02:49 +00:00
|
|
|
DCHECK(properties->IsKey(roots, raw_key));
|
2016-12-05 20:17:13 +00:00
|
|
|
DCHECK(raw_key->IsName());
|
|
|
|
// If the property is already there we skip it.
|
|
|
|
Handle<Name> key(Name::cast(raw_key), isolate());
|
2018-07-17 08:49:20 +00:00
|
|
|
LookupIterator it(isolate(), to, key,
|
|
|
|
LookupIterator::OWN_SKIP_INTERCEPTOR);
|
2016-12-05 20:17:13 +00:00
|
|
|
CHECK_NE(LookupIterator::ACCESS_CHECK, it.state());
|
|
|
|
if (it.IsFound()) continue;
|
|
|
|
// Set the property.
|
|
|
|
Handle<Object> value =
|
|
|
|
Handle<Object>(properties->ValueAt(key_index), isolate());
|
|
|
|
DCHECK(!value->IsCell());
|
|
|
|
DCHECK(!value->IsTheHole(isolate()));
|
|
|
|
PropertyDetails details = properties->DetailsAt(key_index);
|
|
|
|
DCHECK_EQ(kData, details.kind());
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate(), to, key, value, details.attributes());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Genesis::TransferIndexedProperties(Handle<JSObject> from,
|
|
|
|
Handle<JSObject> to) {
|
|
|
|
// Cloning the elements array is sufficient.
|
|
|
|
Handle<FixedArray> from_elements =
|
2018-06-19 09:00:37 +00:00
|
|
|
Handle<FixedArray>(FixedArray::cast(from->elements()), isolate());
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<FixedArray> to_elements = factory()->CopyFixedArray(from_elements);
|
2008-07-03 15:10:15 +00:00
|
|
|
to->set_elements(*to_elements);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Genesis::TransferObject(Handle<JSObject> from, Handle<JSObject> to) {
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope outer(isolate());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!from->IsJSArray());
|
|
|
|
DCHECK(!to->IsJSArray());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
TransferNamedProperties(from, to);
|
|
|
|
TransferIndexedProperties(from, to);
|
|
|
|
|
|
|
|
// Transfer the prototype (new map is needed).
|
2014-06-24 14:53:48 +00:00
|
|
|
Handle<Object> proto(from->map()->prototype(), isolate());
|
2016-07-19 11:28:43 +00:00
|
|
|
JSObject::ForceSetPrototype(to, proto);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2014-01-29 14:18:55 +00:00
|
|
|
|
2017-01-09 10:12:04 +00:00
|
|
|
Genesis::Genesis(
|
|
|
|
Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy,
|
|
|
|
v8::Local<v8::ObjectTemplate> global_proxy_template,
|
|
|
|
size_t context_snapshot_index,
|
2017-03-17 13:26:05 +00:00
|
|
|
v8::DeserializeEmbedderFieldsCallback embedder_fields_deserializer,
|
2017-01-09 10:12:04 +00:00
|
|
|
GlobalContextType context_type)
|
2015-07-06 07:09:07 +00:00
|
|
|
: isolate_(isolate), active_(isolate->bootstrapper()) {
|
2009-07-07 11:41:21 +00:00
|
|
|
result_ = Handle<Context>::null();
|
2016-07-07 19:37:05 +00:00
|
|
|
global_proxy_ = Handle<JSGlobalProxy>::null();
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Before creating the roots we must save the context and restore it
|
|
|
|
// on all function exits.
|
2011-03-18 20:35:07 +00:00
|
|
|
SaveContext saved_context(isolate);
|
2010-03-23 11:40:38 +00:00
|
|
|
|
2015-01-14 16:42:15 +00:00
|
|
|
// The deserializer needs to hook up references to the global proxy.
|
|
|
|
// Create an uninitialized global proxy now if we don't have one
|
|
|
|
// and initialize it later in CreateNewGlobals.
|
|
|
|
Handle<JSGlobalProxy> global_proxy;
|
2016-12-13 11:24:24 +00:00
|
|
|
if (!maybe_global_proxy.ToHandle(&global_proxy)) {
|
2016-12-16 12:40:38 +00:00
|
|
|
int instance_size = 0;
|
|
|
|
if (context_snapshot_index > 0) {
|
|
|
|
// The global proxy function to reinitialize this global proxy is in the
|
|
|
|
// context that is yet to be deserialized. We need to prepare a global
|
|
|
|
// proxy of the correct size.
|
|
|
|
Object* size = isolate->heap()->serialized_global_proxy_sizes()->get(
|
|
|
|
static_cast<int>(context_snapshot_index) - 1);
|
2017-07-10 12:58:27 +00:00
|
|
|
instance_size = Smi::ToInt(size);
|
2016-12-16 12:40:38 +00:00
|
|
|
} else {
|
2017-03-17 13:26:05 +00:00
|
|
|
instance_size = JSGlobalProxy::SizeWithEmbedderFields(
|
2016-12-16 12:40:38 +00:00
|
|
|
global_proxy_template.IsEmpty()
|
|
|
|
? 0
|
|
|
|
: global_proxy_template->InternalFieldCount());
|
|
|
|
}
|
|
|
|
global_proxy =
|
|
|
|
isolate->factory()->NewUninitializedJSGlobalProxy(instance_size);
|
2015-01-14 16:42:15 +00:00
|
|
|
}
|
|
|
|
|
2013-06-28 13:40:41 +00:00
|
|
|
// We can only de-serialize a context if the isolate was initialized from
|
|
|
|
// a snapshot. Otherwise we have to build the context from scratch.
|
2015-05-12 14:00:47 +00:00
|
|
|
// Also create a context from scratch to expose natives, if required by flag.
|
2015-05-12 07:26:05 +00:00
|
|
|
if (!isolate->initialized_from_snapshot() ||
|
2016-06-15 15:38:40 +00:00
|
|
|
!Snapshot::NewContextFromSnapshot(isolate, global_proxy,
|
2017-01-09 10:12:04 +00:00
|
|
|
context_snapshot_index,
|
2017-03-17 13:26:05 +00:00
|
|
|
embedder_fields_deserializer)
|
2015-01-13 08:48:00 +00:00
|
|
|
.ToHandle(&native_context_)) {
|
2013-06-28 13:40:41 +00:00
|
|
|
native_context_ = Handle<Context>();
|
|
|
|
}
|
|
|
|
|
2013-03-18 17:36:47 +00:00
|
|
|
if (!native_context().is_null()) {
|
2018-05-31 14:14:48 +00:00
|
|
|
AddToWeakNativeContextList(isolate, *native_context());
|
2013-03-18 17:36:47 +00:00
|
|
|
isolate->set_context(*native_context());
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->counters()->contexts_created_by_snapshot()->Increment();
|
2014-07-01 12:12:34 +00:00
|
|
|
|
2016-12-13 11:24:24 +00:00
|
|
|
if (context_snapshot_index == 0) {
|
2016-12-08 12:44:29 +00:00
|
|
|
Handle<JSGlobalObject> global_object =
|
|
|
|
CreateNewGlobals(global_proxy_template, global_proxy);
|
|
|
|
HookUpGlobalObject(global_object);
|
|
|
|
|
|
|
|
if (!ConfigureGlobalObjects(global_proxy_template)) return;
|
2016-12-13 11:24:24 +00:00
|
|
|
} else {
|
|
|
|
// The global proxy needs to be integrated into the native context.
|
|
|
|
HookUpGlobalProxy(global_proxy);
|
2016-12-08 12:44:29 +00:00
|
|
|
}
|
2016-12-13 11:24:24 +00:00
|
|
|
DCHECK(!global_proxy->IsDetachedFrom(native_context()->global_object()));
|
2010-03-23 11:40:38 +00:00
|
|
|
} else {
|
2017-07-14 09:22:07 +00:00
|
|
|
base::ElapsedTimer timer;
|
|
|
|
if (FLAG_profile_deserialization) timer.Start();
|
2016-12-13 11:24:24 +00:00
|
|
|
DCHECK_EQ(0u, context_snapshot_index);
|
2010-03-23 11:40:38 +00:00
|
|
|
// We get here if there was no context snapshot.
|
|
|
|
CreateRoots();
|
2018-04-25 09:52:59 +00:00
|
|
|
Handle<JSFunction> empty_function = CreateEmptyFunction();
|
2017-07-03 13:40:13 +00:00
|
|
|
CreateSloppyModeFunctionMaps(empty_function);
|
2011-03-17 20:28:17 +00:00
|
|
|
CreateStrictModeFunctionMaps(empty_function);
|
2017-07-03 13:40:13 +00:00
|
|
|
CreateObjectFunction(empty_function);
|
2016-04-06 08:37:09 +00:00
|
|
|
CreateIteratorMaps(empty_function);
|
[async-iteration] implement AsyncGenerator
- Introduce new struct AsyncGeneratorRequest, which holds
information pertinent to resuming execution of an
AsyncGenerator, such as the Promise associated with the async
generator request. It is intended to be used as a singly
linked list, and holds a pointer to the next item in te queue.
- Introduce JSAsyncGeneratorObject (subclass of
JSGeneratorObject), which includes several new internal fields
(`queue` which contains a singly linked list of
AsyncGeneratorRequest objects, and `await_input` which
contains the sent value from an Await expression (This is
necessary to prevent function.sent (used by yield*) from
having the sent value observably overwritten during
execution).
- Modify SuspendGenerator to accept a set of Flags, which
indicate whether the suspend is for a Yield or Await, and
whether it takes place on an async generator or ES6
generator.
- Introduce interpreter intrinsics and TF intrinsic lowering for
accessing the await input of an async generator
- Modify the JSGeneratorStore operator to understand whether or
not it's suspending for a normal yield, or an AsyncGenerator
Await. This ensures appropriate registers are stored.
- Add versions of ResumeGeneratorTrampoline which store the
input value in a different field depending on wether it's an
AsyncGenerator Await resume, or an ordinary resume. Also modifies
whether debug code will assert that the generator object is a
JSGeneratorObject or a JSAsyncGeneratorObject depending on the
resume type.
BUG=v8:5855
R=bmeurer@chromium.org, rmcilroy@chromium.org, jgruber@chromium.org,
littledan@chromium.org, neis@chromium.org
TBR=marja@chromium.org
Change-Id: I9d58df1d344465fc937fe7eed322424204497187
Reviewed-on: https://chromium-review.googlesource.com/446961
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44240}
2017-03-29 13:41:45 +00:00
|
|
|
CreateAsyncIteratorMaps(empty_function);
|
2016-05-17 00:26:53 +00:00
|
|
|
CreateAsyncFunctionMaps(empty_function);
|
2015-11-02 14:57:59 +00:00
|
|
|
Handle<JSGlobalObject> global_object =
|
2015-01-14 16:42:15 +00:00
|
|
|
CreateNewGlobals(global_proxy_template, global_proxy);
|
2015-07-13 09:45:43 +00:00
|
|
|
InitializeGlobal(global_object, empty_function, context_type);
|
2010-08-25 13:25:54 +00:00
|
|
|
InitializeNormalizedMapCaches();
|
2015-07-13 09:45:43 +00:00
|
|
|
|
|
|
|
if (!InstallNatives(context_type)) return;
|
2016-06-27 12:49:51 +00:00
|
|
|
if (!InstallExtraNatives()) return;
|
|
|
|
if (!ConfigureGlobalObjects(global_proxy_template)) return;
|
|
|
|
|
2014-02-12 13:27:13 +00:00
|
|
|
isolate->counters()->contexts_created_from_scratch()->Increment();
|
2017-07-14 09:22:07 +00:00
|
|
|
|
|
|
|
if (FLAG_profile_deserialization) {
|
|
|
|
double ms = timer.Elapsed().InMillisecondsF();
|
|
|
|
i::PrintF("[Initializing context from scratch took %0.3f ms]\n", ms);
|
|
|
|
}
|
2010-03-23 11:40:38 +00:00
|
|
|
}
|
2008-08-14 13:41:48 +00:00
|
|
|
|
2015-08-14 18:47:46 +00:00
|
|
|
// Install experimental natives. Do not include them into the
|
2015-05-08 08:44:47 +00:00
|
|
|
// snapshot as we should be able to turn them off at runtime. Re-installing
|
|
|
|
// them after they have already been deserialized would also fail.
|
2015-08-13 12:09:30 +00:00
|
|
|
if (context_type == FULL_CONTEXT) {
|
|
|
|
if (!isolate->serializer_enabled()) {
|
|
|
|
InitializeExperimentalGlobal();
|
2015-08-20 00:01:07 +00:00
|
|
|
|
|
|
|
if (FLAG_experimental_extras) {
|
|
|
|
if (!InstallExperimentalExtraNatives()) return;
|
|
|
|
}
|
2017-02-01 09:29:50 +00:00
|
|
|
|
|
|
|
// Store String.prototype's map again in case it has been changed by
|
|
|
|
// experimental natives.
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSFunction> string_function(native_context()->string_function(),
|
|
|
|
isolate);
|
2017-02-01 09:29:50 +00:00
|
|
|
JSObject* string_function_prototype =
|
|
|
|
JSObject::cast(string_function->initial_map()->prototype());
|
|
|
|
DCHECK(string_function_prototype->HasFastProperties());
|
|
|
|
native_context()->set_string_function_prototype_map(
|
|
|
|
string_function_prototype->map());
|
2015-07-13 09:45:43 +00:00
|
|
|
}
|
2015-08-13 12:09:30 +00:00
|
|
|
} else if (context_type == DEBUG_CONTEXT) {
|
|
|
|
DCHECK(!isolate->serializer_enabled());
|
|
|
|
InitializeExperimentalGlobal();
|
|
|
|
if (!InstallDebuggerNatives()) return;
|
2015-07-13 09:45:43 +00:00
|
|
|
}
|
2015-08-13 12:09:30 +00:00
|
|
|
|
2017-12-05 20:27:31 +00:00
|
|
|
if (FLAG_disallow_code_generation_from_strings) {
|
|
|
|
native_context()->set_allow_code_gen_from_strings(
|
2018-07-04 09:10:05 +00:00
|
|
|
ReadOnlyRoots(isolate).false_value());
|
2017-12-05 20:27:31 +00:00
|
|
|
}
|
|
|
|
|
2015-10-16 11:27:14 +00:00
|
|
|
ConfigureUtilsObject(context_type);
|
|
|
|
|
2018-03-08 14:07:39 +00:00
|
|
|
// We created new functions, which may require debug instrumentation.
|
|
|
|
if (isolate->debug()->is_active()) {
|
|
|
|
isolate->debug()->InstallDebugBreakTrampoline();
|
|
|
|
}
|
|
|
|
|
2016-12-08 12:44:29 +00:00
|
|
|
native_context()->ResetErrorsThrown();
|
2013-03-18 17:36:47 +00:00
|
|
|
result_ = native_context();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 19:37:05 +00:00
|
|
|
Genesis::Genesis(Isolate* isolate,
|
|
|
|
MaybeHandle<JSGlobalProxy> maybe_global_proxy,
|
|
|
|
v8::Local<v8::ObjectTemplate> global_proxy_template)
|
|
|
|
: isolate_(isolate), active_(isolate->bootstrapper()) {
|
|
|
|
result_ = Handle<Context>::null();
|
|
|
|
global_proxy_ = Handle<JSGlobalProxy>::null();
|
|
|
|
|
|
|
|
// Before creating the roots we must save the context and restore it
|
|
|
|
// on all function exits.
|
|
|
|
SaveContext saved_context(isolate);
|
|
|
|
|
2017-03-17 13:26:05 +00:00
|
|
|
const int proxy_size = JSGlobalProxy::SizeWithEmbedderFields(
|
2016-11-04 10:02:02 +00:00
|
|
|
global_proxy_template->InternalFieldCount());
|
|
|
|
|
2016-07-07 19:37:05 +00:00
|
|
|
Handle<JSGlobalProxy> global_proxy;
|
|
|
|
if (!maybe_global_proxy.ToHandle(&global_proxy)) {
|
2016-11-04 10:02:02 +00:00
|
|
|
global_proxy = factory()->NewUninitializedJSGlobalProxy(proxy_size);
|
2016-07-07 19:37:05 +00:00
|
|
|
}
|
|
|
|
|
2017-02-22 10:13:24 +00:00
|
|
|
// Create a remote object as the global object.
|
2016-07-07 19:37:05 +00:00
|
|
|
Handle<ObjectTemplateInfo> global_proxy_data =
|
2017-02-22 10:13:24 +00:00
|
|
|
Utils::OpenHandle(*global_proxy_template);
|
2016-07-07 19:37:05 +00:00
|
|
|
Handle<FunctionTemplateInfo> global_constructor(
|
2018-06-20 10:10:43 +00:00
|
|
|
FunctionTemplateInfo::cast(global_proxy_data->constructor()), isolate);
|
2017-02-22 10:13:24 +00:00
|
|
|
|
|
|
|
Handle<ObjectTemplateInfo> global_object_template(
|
2018-06-20 10:10:43 +00:00
|
|
|
ObjectTemplateInfo::cast(global_constructor->prototype_template()),
|
|
|
|
isolate);
|
2017-02-22 10:13:24 +00:00
|
|
|
Handle<JSObject> global_object =
|
|
|
|
ApiNatives::InstantiateRemoteObject(
|
|
|
|
global_object_template).ToHandleChecked();
|
|
|
|
|
|
|
|
// (Re)initialize the global proxy object.
|
2017-03-17 13:26:05 +00:00
|
|
|
DCHECK_EQ(global_proxy_data->embedder_field_count(),
|
2016-11-04 10:02:02 +00:00
|
|
|
global_proxy_template->InternalFieldCount());
|
2016-07-07 19:37:05 +00:00
|
|
|
Handle<Map> global_proxy_map = isolate->factory()->NewMap(
|
2017-11-22 11:17:03 +00:00
|
|
|
JS_GLOBAL_PROXY_TYPE, proxy_size, TERMINAL_FAST_ELEMENTS_KIND);
|
2016-07-07 19:37:05 +00:00
|
|
|
global_proxy_map->set_is_access_check_needed(true);
|
|
|
|
global_proxy_map->set_has_hidden_prototype(true);
|
[builtins] Speed-up Object.prototype.toString.
The @@toStringTag lookup in Object.prototype.toString causes quite a
lot of overhead and oftentimes dominates the builtin performance. These
lookups are almost always negative, especially for primitive values,
and Object.prototype.toString is often used to implement predicates
(like in Node core or in AngularJS), so having a way to skip the
negative lookup yields big performance gains.
This CL introduces a "MayHaveInterestingSymbols" bit on every map,
which says whether instances with this map may have an interesting
symbol. Currently only @@toStringTag is considered an interesting
symbol, but we can extend that in the future.
In the Object.prototype.toString we can use the interesting symbols
bit to do a quick check on the prototype chain to see if there are
any maps that might have the @@toStringTag, and if not, we can just
immediately return the result, which is very fast because it's derived
from the instance type. This also avoids the ToObject conversions for
primitive values, which is important, since this causes unnecessary
GC traffic and in for example AngularJS, strings are also often probed
via the Object.prototype.toString based predicates.
This boosts Speedometer/AngularJS by over 3% and Speedometer overall
by up to 1%. On the microbenchmark from the similar SpiderMonkey bug
(https://bugzilla.mozilla.org/show_bug.cgi?id=1369042), we go from
roughly 450ms to 70ms, which corresponds to a 6.5x improvement.
```
function f() {
var res = "";
var a = [1, 2, 3];
var toString = Object.prototype.toString;
var t = new Date;
for (var i = 0; i < 5000000; i++)
res = toString.call(a);
print(new Date - t);
return res;
}
f();
```
The design document at https://goo.gl/e8CruQ has some additional
data points.
TBR=ulan@chromium.org
Bug: v8:6654
Change-Id: I31932cf41ecddad079d294e2c322a852af0ed244
Reviewed-on: https://chromium-review.googlesource.com/593620
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47034}
2017-08-01 08:11:14 +00:00
|
|
|
global_proxy_map->set_may_have_interesting_symbols(true);
|
2016-07-07 19:37:05 +00:00
|
|
|
|
2017-02-22 10:13:24 +00:00
|
|
|
// A remote global proxy has no native context.
|
2018-07-04 09:10:05 +00:00
|
|
|
global_proxy->set_native_context(ReadOnlyRoots(heap()).null_value());
|
2016-07-07 19:37:05 +00:00
|
|
|
|
2017-02-22 10:13:24 +00:00
|
|
|
// Configure the hidden prototype chain of the global proxy.
|
|
|
|
JSObject::ForceSetPrototype(global_proxy, global_object);
|
2017-03-15 15:32:00 +00:00
|
|
|
global_proxy->map()->SetConstructor(*global_constructor);
|
2017-02-22 10:13:24 +00:00
|
|
|
// TODO(dcheng): This is a hack. Why does this need to be manually called
|
|
|
|
// here? Line 4812 should have taken care of it?
|
|
|
|
global_proxy->map()->set_has_hidden_prototype(true);
|
2016-07-07 19:37:05 +00:00
|
|
|
|
|
|
|
global_proxy_ = global_proxy;
|
|
|
|
}
|
2009-01-26 18:09:46 +00:00
|
|
|
|
|
|
|
// Support for thread preemption.
|
|
|
|
|
|
|
|
// Reserve space for statics needing saving and restoring.
|
|
|
|
int Bootstrapper::ArchiveSpacePerThread() {
|
2011-03-18 20:35:07 +00:00
|
|
|
return sizeof(NestingCounterType);
|
2009-01-26 18:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-22 15:27:57 +00:00
|
|
|
// Archive statics that are thread-local.
|
2009-01-26 18:09:46 +00:00
|
|
|
char* Bootstrapper::ArchiveState(char* to) {
|
2011-03-18 20:35:07 +00:00
|
|
|
*reinterpret_cast<NestingCounterType*>(to) = nesting_;
|
|
|
|
nesting_ = 0;
|
|
|
|
return to + sizeof(NestingCounterType);
|
2009-01-26 18:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-22 15:27:57 +00:00
|
|
|
// Restore statics that are thread-local.
|
2009-01-26 18:09:46 +00:00
|
|
|
char* Bootstrapper::RestoreState(char* from) {
|
2011-03-18 20:35:07 +00:00
|
|
|
nesting_ = *reinterpret_cast<NestingCounterType*>(from);
|
|
|
|
return from + sizeof(NestingCounterType);
|
2009-01-26 18:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-28 12:25:21 +00:00
|
|
|
// Called when the top-level V8 mutex is destroyed.
|
|
|
|
void Bootstrapper::FreeThreadResources() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!IsActive());
|
2009-01-26 18:09:46 +00:00
|
|
|
}
|
|
|
|
|
2015-06-01 22:46:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|