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
|
|
|
|
2019-05-16 10:26:57 +00:00
|
|
|
#include "src/init/bootstrapper.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2019-05-17 12:13:44 +00:00
|
|
|
#include "src/api/api-inl.h"
|
|
|
|
#include "src/api/api-natives.h"
|
2020-07-08 09:48:27 +00:00
|
|
|
#include "src/base/hashmap.h"
|
2016-06-21 07:01:59 +00:00
|
|
|
#include "src/base/ieee754.h"
|
2019-05-22 07:55:37 +00:00
|
|
|
#include "src/builtins/accessors.h"
|
2019-05-21 09:30:15 +00:00
|
|
|
#include "src/codegen/compiler.h"
|
2020-01-29 14:14:16 +00:00
|
|
|
#include "src/common/globals.h"
|
2017-02-23 11:46:29 +00:00
|
|
|
#include "src/debug/debug.h"
|
2019-05-22 07:55:37 +00:00
|
|
|
#include "src/execution/isolate-inl.h"
|
|
|
|
#include "src/execution/microtask-queue.h"
|
2019-09-26 17:48:59 +00:00
|
|
|
#include "src/execution/protectors.h"
|
2019-07-16 21:39:36 +00:00
|
|
|
#include "src/extensions/cputracemark-extension.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/extensions/externalize-string-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"
|
2019-12-14 08:46:38 +00:00
|
|
|
#ifdef ENABLE_VTUNE_TRACEMARK
|
|
|
|
#include "src/extensions/vtunedomain-support-extension.h"
|
|
|
|
#endif // ENABLE_VTUNE_TRACEMARK
|
2019-02-14 21:10:30 +00:00
|
|
|
#include "src/heap/heap-inl.h"
|
2019-05-20 09:15:06 +00:00
|
|
|
#include "src/logging/counters.h"
|
2020-04-15 07:22:02 +00:00
|
|
|
#include "src/logging/log.h"
|
2019-05-15 18:28:45 +00:00
|
|
|
#include "src/numbers/math-random.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"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/function-kind.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-09-04 18:32:51 +00:00
|
|
|
#endif // V8_INTL_SUPPORT
|
|
|
|
#include "src/objects/js-array-buffer-inl.h"
|
|
|
|
#include "src/objects/js-array-inl.h"
|
|
|
|
#ifdef V8_INTL_SUPPORT
|
2018-09-05 02:17:38 +00:00
|
|
|
#include "src/objects/js-break-iterator.h"
|
2018-08-08 09:23:07 +00:00
|
|
|
#include "src/objects/js-collator.h"
|
2018-09-11 09:57:14 +00:00
|
|
|
#include "src/objects/js-date-time-format.h"
|
2019-11-18 18:55:57 +00:00
|
|
|
#include "src/objects/js-display-names.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"
|
2018-09-04 18:32:51 +00:00
|
|
|
#include "src/objects/js-number-format.h"
|
|
|
|
#include "src/objects/js-plural-rules.h"
|
2018-05-15 20:50:46 +00:00
|
|
|
#endif // V8_INTL_SUPPORT
|
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"
|
2018-10-18 07:59:28 +00:00
|
|
|
#include "src/objects/js-segment-iterator.h"
|
2018-10-05 01:57:05 +00:00
|
|
|
#include "src/objects/js-segmenter.h"
|
2020-07-29 15:06:31 +00:00
|
|
|
#include "src/objects/js-segments.h"
|
2018-07-10 12:52:05 +00:00
|
|
|
#endif // V8_INTL_SUPPORT
|
2018-10-09 12:08:23 +00:00
|
|
|
#include "src/objects/js-weak-refs.h"
|
2020-07-20 13:27:14 +00:00
|
|
|
#include "src/objects/ordered-hash-table.h"
|
2018-11-30 13:09:34 +00:00
|
|
|
#include "src/objects/property-cell.h"
|
2018-11-25 02:24:43 +00:00
|
|
|
#include "src/objects/slots-inl.h"
|
2018-04-27 08:31:07 +00:00
|
|
|
#include "src/objects/templates.h"
|
2015-03-27 15:28:55 +00:00
|
|
|
#include "src/snapshot/snapshot.h"
|
2015-08-27 14:42:36 +00:00
|
|
|
#include "src/wasm/wasm-js.h"
|
2020-07-08 09:48:27 +00:00
|
|
|
#include "src/zone/zone-hashmap.h"
|
2015-08-27 14:42:36 +00:00
|
|
|
|
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()
|
2018-11-25 02:24:43 +00:00
|
|
|
: FixedArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SourceCodeCache::Iterate(RootVisitor* v) {
|
2018-12-06 17:53:25 +00:00
|
|
|
v->VisitRootPointer(Root::kExtensions, nullptr, FullObjectSlot(&cache_));
|
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) {
|
2018-11-27 00:48:42 +00:00
|
|
|
SeqOneByteString str = SeqOneByteString::cast(cache_.get(i));
|
2019-04-26 14:47:04 +00:00
|
|
|
if (str.IsOneByteEqualTo(Vector<const uint8_t>::cast(name))) {
|
2017-09-13 10:56:20 +00:00
|
|
|
*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();
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<FixedArray> new_array =
|
|
|
|
factory->NewFixedArray(length + 2, AllocationType::kOld);
|
2017-09-13 10:56:20 +00:00
|
|
|
cache_.CopyTo(0, *new_array, 0, cache_.length());
|
|
|
|
cache_ = *new_array;
|
|
|
|
Handle<String> str =
|
2019-03-11 19:04:02 +00:00
|
|
|
factory
|
|
|
|
->NewStringFromOneByte(Vector<const uint8_t>::cast(name),
|
|
|
|
AllocationType::kOld)
|
2017-09-13 10:56:20 +00:00
|
|
|
.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
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2019-07-16 21:39:36 +00:00
|
|
|
static bool isValidCpuTraceMarkFunctionName() {
|
|
|
|
return FLAG_expose_cputracemark_as != nullptr &&
|
|
|
|
strlen(FLAG_expose_cputracemark_as) != 0;
|
|
|
|
}
|
|
|
|
|
2013-05-21 12:03:49 +00:00
|
|
|
void Bootstrapper::InitializeOncePerProcess() {
|
2019-09-10 10:12:00 +00:00
|
|
|
v8::RegisterExtension(std::make_unique<GCExtension>(GCFunctionName()));
|
|
|
|
v8::RegisterExtension(std::make_unique<ExternalizeStringExtension>());
|
|
|
|
v8::RegisterExtension(std::make_unique<StatisticsExtension>());
|
|
|
|
v8::RegisterExtension(std::make_unique<TriggerFailureExtension>());
|
|
|
|
v8::RegisterExtension(std::make_unique<IgnitionStatisticsExtension>());
|
2019-07-16 21:39:36 +00:00
|
|
|
if (isValidCpuTraceMarkFunctionName()) {
|
2019-09-10 10:12:00 +00:00
|
|
|
v8::RegisterExtension(
|
|
|
|
std::make_unique<CpuTraceMarkExtension>(FLAG_expose_cputracemark_as));
|
2019-07-16 21:39:36 +00:00
|
|
|
}
|
2019-12-14 08:46:38 +00:00
|
|
|
#ifdef ENABLE_VTUNE_TRACEMARK
|
|
|
|
v8::RegisterExtension(
|
|
|
|
std::make_unique<VTuneDomainSupportExtension>("vtunedomainmark"));
|
|
|
|
#endif // ENABLE_VTUNE_TRACEMARK
|
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
|
|
|
}
|
|
|
|
|
2018-09-06 09:08:10 +00:00
|
|
|
class Genesis {
|
2008-07-03 15:10:15 +00:00
|
|
|
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,
|
2019-02-28 06:54:55 +00:00
|
|
|
v8::DeserializeEmbedderFieldsCallback embedder_fields_deserializer,
|
|
|
|
v8::MicrotaskQueue* microtask_queue);
|
2016-07-07 19:37:05 +00:00
|
|
|
Genesis(Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy,
|
|
|
|
v8::Local<v8::ObjectTemplate> global_proxy_template);
|
2018-09-19 17:03:08 +00:00
|
|
|
~Genesis() = default;
|
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:
|
2018-08-23 15:25:58 +00:00
|
|
|
Handle<NativeContext> 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
|
2020-04-22 09:40:35 +00:00
|
|
|
// context from scratch or using a deserialized one from the context snapshot
|
2010-03-23 11:40:38 +00:00
|
|
|
// 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,
|
2018-12-10 14:45:41 +00:00
|
|
|
Handle<JSFunction> empty_function);
|
2014-09-19 07:36:05 +00:00
|
|
|
void InitializeExperimentalGlobal();
|
2019-01-07 05:08:08 +00:00
|
|
|
void InitializeIteratorFunctions();
|
|
|
|
void InitializeCallSiteBuiltins();
|
2014-10-20 13:33:34 +00:00
|
|
|
|
2019-05-16 10:26:57 +00:00
|
|
|
#define DECLARE_FEATURE_INITIALIZATION(id, descr) void InitializeGlobal_##id();
|
2014-10-20 13:33:34 +00:00
|
|
|
|
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
|
2020-10-29 10:23:57 +00:00
|
|
|
void InitializeGlobal_regexp_linear_flag();
|
2014-10-20 13:33:34 +00:00
|
|
|
|
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);
|
2019-10-22 04:59:35 +00:00
|
|
|
|
|
|
|
bool InstallABunchOfRandomThings();
|
|
|
|
bool InstallExtrasBindings();
|
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);
|
2010-08-25 13:25:54 +00:00
|
|
|
void InitializeNormalizedMapCaches();
|
2011-11-15 23:26:22 +00:00
|
|
|
|
2019-05-16 10:26:57 +00:00
|
|
|
enum ExtensionTraversalState { UNVISITED, VISITED, INSTALLED };
|
2011-11-15 22:48:55 +00:00
|
|
|
|
|
|
|
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);
|
2019-05-16 10:26:57 +00:00
|
|
|
|
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);
|
2019-05-16 10:26:57 +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);
|
|
|
|
|
2019-09-05 11:14:55 +00:00
|
|
|
Handle<Map> CreateInitialMapForArraySubclass(int size,
|
|
|
|
int inobject_properties);
|
|
|
|
|
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_;
|
2018-08-23 15:25:58 +00:00
|
|
|
Handle<NativeContext> 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,
|
2019-02-28 06:54:55 +00:00
|
|
|
v8::DeserializeEmbedderFieldsCallback embedder_fields_deserializer,
|
|
|
|
v8::MicrotaskQueue* microtask_queue) {
|
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,
|
2019-02-28 06:54:55 +00:00
|
|
|
context_snapshot_index, embedder_fields_deserializer,
|
|
|
|
microtask_queue);
|
2017-11-28 16:12:09 +00:00
|
|
|
env = genesis.result();
|
|
|
|
if (env.is_null() || !InstallExtensions(env, extensions)) {
|
|
|
|
return Handle<Context>();
|
|
|
|
}
|
2010-03-23 11:40:38 +00:00
|
|
|
}
|
2018-11-27 08:08:59 +00:00
|
|
|
LogAllMaps();
|
2019-01-22 10:06:28 +00:00
|
|
|
isolate_->heap()->NotifyBootstrapComplete();
|
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>();
|
|
|
|
}
|
2018-11-27 08:08:59 +00:00
|
|
|
LogAllMaps();
|
2016-07-07 19:37:05 +00:00
|
|
|
return scope.CloseAndEscape(global_proxy);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2018-11-27 08:08:59 +00:00
|
|
|
void Bootstrapper::LogAllMaps() {
|
|
|
|
if (!FLAG_trace_maps || isolate_->initialized_from_snapshot()) return;
|
|
|
|
// Log all created Map objects that are on the heap. For snapshots the Map
|
|
|
|
// logging happens during deserialization in order to avoid printing Maps
|
|
|
|
// multiple times during partial deserialization.
|
|
|
|
LOG(isolate_, LogAllMaps());
|
|
|
|
}
|
|
|
|
|
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(
|
2019-07-08 10:56:21 +00:00
|
|
|
env->native_context().GetErrorsThrown());
|
2015-11-06 08:07:52 +00:00
|
|
|
|
2018-07-04 09:10:05 +00:00
|
|
|
ReadOnlyRoots roots(isolate_);
|
2019-03-06 15:00:01 +00:00
|
|
|
Handle<JSGlobalProxy> global_proxy(env->global_proxy(), 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
|
|
|
}
|
2020-10-08 17:35:34 +00:00
|
|
|
DCHECK(global_proxy->IsDetached());
|
2019-02-26 14:31:43 +00:00
|
|
|
|
2020-05-04 17:46:46 +00:00
|
|
|
env->native_context().set_microtask_queue(isolate_, nullptr);
|
2010-03-24 13:24:46 +00:00
|
|
|
}
|
|
|
|
|
2015-08-31 12:52:59 +00:00
|
|
|
namespace {
|
|
|
|
|
2020-11-11 06:18:31 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool IsFunctionMapOrSpecialBuiltin(Handle<Map> map, Builtins::Name builtin_id,
|
|
|
|
Handle<Context> context) {
|
|
|
|
// During bootstrapping some of these maps could be not created yet.
|
|
|
|
return ((*map == context->get(Context::STRICT_FUNCTION_MAP_INDEX)) ||
|
|
|
|
(*map == context->get(
|
|
|
|
Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX)) ||
|
|
|
|
(*map ==
|
|
|
|
context->get(
|
|
|
|
Context::STRICT_FUNCTION_WITH_READONLY_PROTOTYPE_MAP_INDEX)) ||
|
|
|
|
// Check if it's a creation of an empty or Proxy function during
|
|
|
|
// bootstrapping.
|
|
|
|
(builtin_id == Builtins::kEmptyFunction ||
|
|
|
|
builtin_id == Builtins::kProxyConstructor));
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
V8_NOINLINE Handle<JSFunction> CreateFunctionForBuiltin(
|
|
|
|
Isolate* isolate, Handle<String> name, Handle<Map> map,
|
|
|
|
Builtins::Name builtin_id) {
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
Handle<NativeContext> context(isolate->native_context());
|
|
|
|
DCHECK(IsFunctionMapOrSpecialBuiltin(map, builtin_id, context));
|
|
|
|
|
|
|
|
Handle<SharedFunctionInfo> info =
|
|
|
|
factory->NewSharedFunctionInfoForBuiltin(name, builtin_id);
|
|
|
|
info->set_language_mode(LanguageMode::kStrict);
|
|
|
|
|
|
|
|
return Factory::JSFunctionBuilder{isolate, info, context}
|
|
|
|
.set_map(map)
|
|
|
|
.Build();
|
|
|
|
}
|
|
|
|
|
|
|
|
V8_NOINLINE Handle<JSFunction> CreateFunctionForBuiltinWithPrototype(
|
|
|
|
Isolate* isolate, Handle<String> name, Builtins::Name builtin_id,
|
|
|
|
Handle<HeapObject> prototype, InstanceType type, int instance_size,
|
|
|
|
int inobject_properties, MutableMode prototype_mutability) {
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
Handle<NativeContext> context(isolate->native_context());
|
|
|
|
Handle<Map> map =
|
|
|
|
prototype_mutability == MUTABLE
|
|
|
|
? isolate->strict_function_map()
|
|
|
|
: isolate->strict_function_with_readonly_prototype_map();
|
|
|
|
DCHECK(IsFunctionMapOrSpecialBuiltin(map, builtin_id, context));
|
|
|
|
|
|
|
|
Handle<SharedFunctionInfo> info =
|
|
|
|
factory->NewSharedFunctionInfoForBuiltin(name, builtin_id);
|
|
|
|
info->set_language_mode(LanguageMode::kStrict);
|
|
|
|
info->set_expected_nof_properties(inobject_properties);
|
|
|
|
|
|
|
|
Handle<JSFunction> result =
|
|
|
|
Factory::JSFunctionBuilder{isolate, info, context}.set_map(map).Build();
|
|
|
|
|
|
|
|
ElementsKind elements_kind;
|
|
|
|
switch (type) {
|
|
|
|
case JS_ARRAY_TYPE:
|
|
|
|
elements_kind = PACKED_SMI_ELEMENTS;
|
|
|
|
break;
|
|
|
|
case JS_ARGUMENTS_OBJECT_TYPE:
|
|
|
|
elements_kind = PACKED_ELEMENTS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
elements_kind = TERMINAL_FAST_ELEMENTS_KIND;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Handle<Map> initial_map =
|
|
|
|
factory->NewMap(type, instance_size, elements_kind, inobject_properties);
|
|
|
|
// TODO(littledan): Why do we have this is_generator test when
|
|
|
|
// NewFunctionPrototype already handles finding an appropriately
|
|
|
|
// shared prototype?
|
|
|
|
if (!IsResumableFunction(info->kind()) && prototype->IsTheHole(isolate)) {
|
|
|
|
prototype = factory->NewFunctionPrototype(result);
|
|
|
|
}
|
|
|
|
JSFunction::SetInitialMap(result, initial_map, prototype);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
V8_NOINLINE Handle<JSFunction> CreateFunctionForBuiltinWithoutPrototype(
|
|
|
|
Isolate* isolate, Handle<String> name, Builtins::Name builtin_id) {
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
Handle<NativeContext> context(isolate->native_context());
|
|
|
|
Handle<Map> map = isolate->strict_function_without_prototype_map();
|
|
|
|
DCHECK(IsFunctionMapOrSpecialBuiltin(map, builtin_id, context));
|
|
|
|
|
|
|
|
Handle<SharedFunctionInfo> info =
|
|
|
|
factory->NewSharedFunctionInfoForBuiltin(name, builtin_id);
|
|
|
|
info->set_language_mode(LanguageMode::kStrict);
|
|
|
|
|
|
|
|
return Factory::JSFunctionBuilder{isolate, info, context}
|
|
|
|
.set_map(map)
|
|
|
|
.Build();
|
|
|
|
}
|
|
|
|
|
2017-09-15 08:45:45 +00:00
|
|
|
V8_NOINLINE Handle<JSFunction> CreateFunction(
|
|
|
|
Isolate* isolate, Handle<String> name, InstanceType type, int instance_size,
|
2019-04-01 09:07:37 +00:00
|
|
|
int inobject_properties, Handle<HeapObject> prototype,
|
2017-11-08 12:56:08 +00:00
|
|
|
Builtins::Name builtin_id) {
|
2019-10-31 12:22:49 +00:00
|
|
|
DCHECK(Builtins::HasJSLinkage(builtin_id));
|
|
|
|
|
2020-11-11 06:18:31 +00:00
|
|
|
Handle<JSFunction> result = CreateFunctionForBuiltinWithPrototype(
|
|
|
|
isolate, name, builtin_id, prototype, type, instance_size,
|
|
|
|
inobject_properties, IMMUTABLE);
|
2017-11-08 12:56:08 +00:00
|
|
|
|
2018-11-23 09:55:50 +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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-01-07 05:08:08 +00:00
|
|
|
V8_NOINLINE Handle<JSFunction> CreateFunction(
|
|
|
|
Isolate* isolate, const char* name, InstanceType type, int instance_size,
|
2019-04-01 09:07:37 +00:00
|
|
|
int inobject_properties, Handle<HeapObject> prototype,
|
2019-01-07 05:08:08 +00:00
|
|
|
Builtins::Name builtin_id) {
|
|
|
|
return CreateFunction(
|
|
|
|
isolate, isolate->factory()->InternalizeUtf8String(name), type,
|
|
|
|
instance_size, inobject_properties, prototype, builtin_id);
|
|
|
|
}
|
|
|
|
|
2017-09-15 08:45:45 +00:00
|
|
|
V8_NOINLINE Handle<JSFunction> InstallFunction(
|
2018-11-23 14:10:11 +00:00
|
|
|
Isolate* isolate, Handle<JSObject> target, Handle<String> name,
|
2018-05-31 14:14:48 +00:00
|
|
|
InstanceType type, int instance_size, int inobject_properties,
|
2019-04-01 09:07:37 +00:00
|
|
|
Handle<HeapObject> prototype, Builtins::Name call) {
|
2019-10-31 12:22:49 +00:00
|
|
|
DCHECK(Builtins::HasJSLinkage(call));
|
2018-11-23 14:10:11 +00:00
|
|
|
Handle<JSFunction> function = CreateFunction(
|
|
|
|
isolate, name, type, instance_size, inobject_properties, prototype, call);
|
|
|
|
JSObject::AddProperty(isolate, target, name, function, DONT_ENUM);
|
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,
|
2019-04-01 09:07:37 +00:00
|
|
|
Handle<HeapObject> prototype, Builtins::Name call) {
|
2018-11-23 14:10:11 +00:00
|
|
|
return InstallFunction(isolate, target,
|
|
|
|
isolate->factory()->InternalizeUtf8String(name), type,
|
|
|
|
instance_size, inobject_properties, prototype, call);
|
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) {
|
2019-10-31 12:22:49 +00:00
|
|
|
DCHECK(Builtins::HasJSLinkage(call));
|
2020-01-29 14:14:16 +00:00
|
|
|
name = String::Flatten(isolate, name, AllocationType::kOld);
|
2020-11-11 06:18:31 +00:00
|
|
|
Handle<JSFunction> fun =
|
|
|
|
CreateFunctionForBuiltinWithoutPrototype(isolate, name, call);
|
2018-11-23 09:55:50 +00:00
|
|
|
// Make the resulting JSFunction object fast.
|
|
|
|
JSObject::MakePrototypesFast(fun, kStartAtReceiver, isolate);
|
|
|
|
fun->shared().set_native(true);
|
|
|
|
|
2016-04-06 08:37:09 +00:00
|
|
|
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
|
|
|
|
2018-11-23 14:10:11 +00:00
|
|
|
V8_NOINLINE Handle<JSFunction> InstallFunctionWithBuiltinId(
|
|
|
|
Isolate* isolate, Handle<JSObject> base, const char* name,
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::Name call, int len, bool adapt) {
|
2018-11-23 14:10:11 +00:00
|
|
|
Handle<String> internalized_name =
|
|
|
|
isolate->factory()->InternalizeUtf8String(name);
|
2016-04-06 08:37:09 +00:00
|
|
|
Handle<JSFunction> fun =
|
2018-11-23 14:10:11 +00:00
|
|
|
SimpleCreateFunction(isolate, internalized_name, call, len, adapt);
|
|
|
|
JSObject::AddProperty(isolate, base, internalized_name, fun, DONT_ENUM);
|
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, const char* name,
|
|
|
|
Builtins::Name call, int len, bool adapt,
|
2018-11-23 14:10:11 +00:00
|
|
|
PropertyAttributes attrs = DONT_ENUM) {
|
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-11-23 09:55:50 +00:00
|
|
|
Handle<String> internalized_name =
|
|
|
|
isolate->factory()->InternalizeUtf8String(name);
|
2018-11-23 14:10:11 +00:00
|
|
|
Handle<JSFunction> fun =
|
|
|
|
SimpleCreateFunction(isolate, internalized_name, call, len, adapt);
|
|
|
|
JSObject::AddProperty(isolate, base, internalized_name, fun, attrs);
|
|
|
|
return fun;
|
2016-04-06 08:37:09 +00:00
|
|
|
}
|
|
|
|
|
2018-11-23 14:10:11 +00:00
|
|
|
V8_NOINLINE Handle<JSFunction> InstallFunctionAtSymbol(
|
|
|
|
Isolate* isolate, Handle<JSObject> base, Handle<Symbol> symbol,
|
|
|
|
const char* symbol_string, Builtins::Name call, int len, bool adapt,
|
2019-03-07 00:27:04 +00:00
|
|
|
PropertyAttributes attrs = DONT_ENUM) {
|
2018-11-23 14:10:11 +00:00
|
|
|
Handle<String> internalized_symbol =
|
|
|
|
isolate->factory()->InternalizeUtf8String(symbol_string);
|
|
|
|
Handle<JSFunction> fun =
|
|
|
|
SimpleCreateFunction(isolate, internalized_symbol, call, len, adapt);
|
|
|
|
JSObject::AddProperty(isolate, base, symbol, fun, attrs);
|
|
|
|
return fun;
|
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,
|
2018-12-20 01:20:25 +00:00
|
|
|
Builtins::Name call_setter) {
|
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
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
JSObject::DefineAccessor(base, name, getter, setter, DONT_ENUM).Check();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleInstallGetterSetter(Isolate* isolate, Handle<JSObject> base,
|
|
|
|
const char* name, Builtins::Name call_getter,
|
|
|
|
Builtins::Name call_setter) {
|
|
|
|
SimpleInstallGetterSetter(isolate, base,
|
|
|
|
isolate->factory()->InternalizeUtf8String(name),
|
|
|
|
call_getter, call_setter);
|
2016-10-06 13:00:56 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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-10-05 14:32:24 +00:00
|
|
|
isolate, holder, isolate->factory()->InternalizeUtf8String(name), value,
|
2016-12-06 13:21:20 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY));
|
|
|
|
}
|
|
|
|
|
2018-12-20 19:44:56 +00:00
|
|
|
V8_NOINLINE void InstallTrueValuedProperty(Isolate* isolate,
|
|
|
|
Handle<JSObject> holder,
|
|
|
|
const char* name) {
|
|
|
|
JSObject::AddProperty(isolate, holder,
|
|
|
|
isolate->factory()->InternalizeUtf8String(name),
|
|
|
|
isolate->factory()->true_value(), NONE);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
V8_NOINLINE void InstallToStringTag(Isolate* isolate, Handle<JSObject> holder,
|
|
|
|
Handle<String> value) {
|
|
|
|
JSObject::AddProperty(isolate, holder,
|
|
|
|
isolate->factory()->to_string_tag_symbol(), value,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
}
|
|
|
|
|
|
|
|
void InstallToStringTag(Isolate* isolate, Handle<JSObject> holder,
|
|
|
|
const char* value) {
|
|
|
|
InstallToStringTag(isolate, holder,
|
|
|
|
isolate->factory()->InternalizeUtf8String(value));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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
|
2020-11-11 06:18:31 +00:00
|
|
|
Handle<JSFunction> empty_function =
|
|
|
|
CreateFunctionForBuiltin(isolate(), factory()->empty_string(),
|
|
|
|
empty_function_map, Builtins::kEmptyFunction);
|
2018-04-25 09:52:59 +00:00
|
|
|
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);
|
2019-08-12 21:07:13 +00:00
|
|
|
empty_function->shared().set_raw_scope_info(
|
|
|
|
ReadOnlyRoots(isolate()).empty_function_scope_info());
|
2010-03-23 11:40:38 +00:00
|
|
|
empty_function->shared().DontAdaptArguments();
|
2020-01-08 16:47:38 +00:00
|
|
|
empty_function->shared().SetScript(ReadOnlyRoots(isolate()), *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();
|
2020-11-11 06:18:31 +00:00
|
|
|
Handle<JSFunction> function = CreateFunctionForBuiltinWithoutPrototype(
|
|
|
|
isolate(), name, Builtins::kStrictPoisonPillThrower);
|
2015-04-15 17:15:32 +00:00
|
|
|
function->shared().DontAdaptArguments();
|
|
|
|
|
2020-08-18 19:00:37 +00:00
|
|
|
// %ThrowTypeError% must have a name property with an empty string value. Per
|
|
|
|
// spec, ThrowTypeError's name is non-configurable, unlike ordinary functions'
|
|
|
|
// name property. To redefine it to be non-configurable, use
|
|
|
|
// SetOwnPropertyIgnoreAttributes.
|
|
|
|
JSObject::SetOwnPropertyIgnoreAttributes(
|
|
|
|
function, factory()->name_string(), factory()->empty_string(),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY))
|
|
|
|
.Assert();
|
2015-04-15 17:15:32 +00:00
|
|
|
|
|
|
|
// length needs to be non configurable.
|
2019-04-11 10:43:45 +00:00
|
|
|
Handle<Object> value(Smi::FromInt(function->length()), isolate());
|
2019-11-27 14:31:08 +00:00
|
|
|
JSObject::SetOwnPropertyIgnoreAttributes(
|
|
|
|
function, factory()->length_string(), value,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY))
|
2015-04-15 17:15:32 +00:00
|
|
|
.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;
|
2019-01-17 18:02:38 +00:00
|
|
|
int instance_size = JSObject::kHeaderSize + kTaggedSize * 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.
|
2018-11-13 06:16:42 +00:00
|
|
|
Map initial_map = object_fun->initial_map();
|
2017-07-03 13:40:13 +00:00
|
|
|
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();
|
2019-01-17 18:02:38 +00:00
|
|
|
map->set_instance_size(map->instance_size() + kTaggedSize);
|
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.
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<JSObject> iterator_prototype = factory()->NewJSObject(
|
|
|
|
isolate()->object_function(), AllocationType::kOld);
|
2016-09-21 14:17:42 +00:00
|
|
|
|
2018-11-23 09:55:50 +00:00
|
|
|
InstallFunctionAtSymbol(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);
|
|
|
|
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<JSObject> generator_object_prototype = factory()->NewJSObject(
|
|
|
|
isolate()->object_function(), AllocationType::kOld);
|
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);
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<JSObject> generator_function_prototype = factory()->NewJSObject(
|
|
|
|
isolate()->object_function(), AllocationType::kOld);
|
2016-07-19 11:28:43 +00:00
|
|
|
JSObject::ForceSetPrototype(generator_function_prototype, empty);
|
2015-10-16 11:27:14 +00:00
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate(), generator_function_prototype,
|
|
|
|
"GeneratorFunction");
|
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-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate(), generator_object_prototype, "Generator");
|
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);
|
|
|
|
|
2019-09-13 15:20:47 +00:00
|
|
|
// Internal version of async module functions, flagged as non-native such
|
|
|
|
// that they don't show up in Error traces.
|
|
|
|
{
|
|
|
|
Handle<JSFunction> async_module_evaluate_internal =
|
|
|
|
SimpleCreateFunction(isolate(), factory()->next_string(),
|
|
|
|
Builtins::kAsyncModuleEvaluate, 1, false);
|
|
|
|
async_module_evaluate_internal->shared().set_native(false);
|
|
|
|
native_context()->set_async_module_evaluate_internal(
|
|
|
|
*async_module_evaluate_internal);
|
|
|
|
|
|
|
|
Handle<JSFunction> call_async_module_fulfilled =
|
|
|
|
SimpleCreateFunction(isolate(), factory()->empty_string(),
|
|
|
|
Builtins::kCallAsyncModuleFulfilled, 1, false);
|
|
|
|
native_context()->set_call_async_module_fulfilled(
|
|
|
|
*call_async_module_fulfilled);
|
|
|
|
|
|
|
|
Handle<JSFunction> call_async_module_rejected =
|
|
|
|
SimpleCreateFunction(isolate(), factory()->empty_string(),
|
|
|
|
Builtins::kCallAsyncModuleRejected, 1, false);
|
|
|
|
native_context()->set_call_async_module_rejected(
|
|
|
|
*call_async_module_rejected);
|
|
|
|
}
|
|
|
|
|
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
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<JSObject> async_iterator_prototype = factory()->NewJSObject(
|
|
|
|
isolate()->object_function(), AllocationType::kOld);
|
2017-02-24 17:48:49 +00:00
|
|
|
|
2018-11-23 09:55:50 +00:00
|
|
|
InstallFunctionAtSymbol(
|
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);
|
2020-07-16 17:04:32 +00:00
|
|
|
native_context()->set_initial_async_iterator_prototype(
|
|
|
|
*async_iterator_prototype);
|
2017-02-24 17:48:49 +00:00
|
|
|
|
|
|
|
// %AsyncFromSyncIteratorPrototype%
|
|
|
|
// proposal-async-iteration/#sec-%asyncfromsynciteratorprototype%-object
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<JSObject> async_from_sync_iterator_prototype = factory()->NewJSObject(
|
|
|
|
isolate()->object_function(), AllocationType::kOld);
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate(), async_from_sync_iterator_prototype, "next",
|
2020-06-16 04:24:55 +00:00
|
|
|
Builtins::kAsyncFromSyncIteratorPrototypeNext, 1,
|
|
|
|
false);
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate(), async_from_sync_iterator_prototype, "return",
|
|
|
|
Builtins::kAsyncFromSyncIteratorPrototypeReturn, 1,
|
2020-06-16 04:24:55 +00:00
|
|
|
false);
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate(), async_from_sync_iterator_prototype, "throw",
|
|
|
|
Builtins::kAsyncFromSyncIteratorPrototypeThrow, 1,
|
2020-06-16 04:24:55 +00:00
|
|
|
false);
|
2017-02-24 17:48:49 +00:00
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate(), async_from_sync_iterator_prototype,
|
|
|
|
"Async-from-Sync Iterator");
|
2017-02-24 17:48:49 +00:00
|
|
|
|
|
|
|
JSObject::ForceSetPrototype(async_from_sync_iterator_prototype,
|
|
|
|
async_iterator_prototype);
|
|
|
|
|
|
|
|
Handle<Map> async_from_sync_iterator_map = factory()->NewMap(
|
2019-11-15 20:37:49 +00:00
|
|
|
JS_ASYNC_FROM_SYNC_ITERATOR_TYPE, JSAsyncFromSyncIterator::kHeaderSize);
|
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
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<JSObject> async_generator_object_prototype = factory()->NewJSObject(
|
|
|
|
isolate()->object_function(), AllocationType::kOld);
|
|
|
|
Handle<JSObject> async_generator_function_prototype = factory()->NewJSObject(
|
|
|
|
isolate()->object_function(), AllocationType::kOld);
|
[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
|
|
|
|
|
|
|
// %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-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate(), async_generator_function_prototype,
|
|
|
|
"AsyncGeneratorFunction");
|
[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
|
|
|
|
|
|
|
// %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-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate(), async_generator_object_prototype,
|
|
|
|
"AsyncGenerator");
|
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
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<JSObject> async_function_prototype = factory()->NewJSObject(
|
|
|
|
isolate()->object_function(), AllocationType::kOld);
|
2016-07-19 11:28:43 +00:00
|
|
|
JSObject::ForceSetPrototype(async_function_prototype, empty);
|
2016-05-17 00:26:53 +00:00
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate(), async_function_prototype, "AsyncFunction");
|
2016-05-17 00:26:53 +00:00
|
|
|
|
[async] Improve async function handling.
This change introduces new intrinsics used to desugar async functions
in the Parser and the BytecodeGenerator, namely we introduce a new
%_AsyncFunctionEnter intrinsic that constructs the generator object
for the async function (and in the future will also create the outer
promise for the async function). This generator object is internal
and never escapes to user code, plus since async functions don't have
a "prototype" property, we can just a single map here instead of tracking
the prototype/initial_map on every async function. This saves one word
per async function plus one initial_map per async function that was
invoked at least once.
We also introduce two new intrinsics %_AsyncFunctionReject, which
rejects the outer promise with the caught exception, and another
%_AsyncFunctionResolve, which resolves the outer promise with the
right hand side of the `return` statement. These functions also perform
the DevTools part of the job (aka popping from the promise stack and
sending the debug event). This allows us to get rid of the implicit
try-finally from async functions completely; because the finally
block only called to the %AsyncFunctionPromiseRelease builtin, which
was used to inform DevTools.
In essence we now turn an async function like
```js
async function f(x) { return await bar(x); }
```
into something like this (in Parser and BytecodeGenerator respectively):
```
function f(x) {
.generator_object = %_AsyncFunctionEnter(.closure, this);
.promise = %AsyncFunctionCreatePromise();
try {
.tmp = await bar(x);
return %_AsyncFunctionResolve(.promise, .tmp);
} catch (e) {
return %_AsyncFunctionReject(.promise, e);
}
}
```
Overall the bytecode for async functions gets significantly shorter
already (and will get even shorter once we put the outer promise into
the async function generator object). For example the bytecode for a
simple async function
```js
async function f(x) { return await x; }
```
goes from 175 bytes to 110 bytes (a ~38% reduction in size), which
is in particular due to the simplification around the try-finally
removal.
Overall this seems to improve the doxbee-async-es2017-native test by
around 2-3%. On the test case mentioned in v8:8276 we go from
1124ms to 441ms, which corresponds to a 60% reduction in total
execution time!
Tbr: marja@chromium.org
Bug: v8:7253, v8:7522, v8:8276
Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Id29dc92de7490b387ff697860c900cee44c9a7a4
Reviewed-on: https://chromium-review.googlesource.com/c/1269041
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Reviewed-by: Maya Lekova <mslekova@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56502}
2018-10-10 05:54:39 +00:00
|
|
|
Handle<Map> map =
|
|
|
|
Map::Copy(isolate(), isolate()->strict_function_without_prototype_map(),
|
|
|
|
"AsyncFunction");
|
|
|
|
Map::SetPrototype(isolate(), map, async_function_prototype);
|
2017-07-13 09:33:22 +00:00
|
|
|
native_context()->set_async_function_map(*map);
|
|
|
|
|
[async] Improve async function handling.
This change introduces new intrinsics used to desugar async functions
in the Parser and the BytecodeGenerator, namely we introduce a new
%_AsyncFunctionEnter intrinsic that constructs the generator object
for the async function (and in the future will also create the outer
promise for the async function). This generator object is internal
and never escapes to user code, plus since async functions don't have
a "prototype" property, we can just a single map here instead of tracking
the prototype/initial_map on every async function. This saves one word
per async function plus one initial_map per async function that was
invoked at least once.
We also introduce two new intrinsics %_AsyncFunctionReject, which
rejects the outer promise with the caught exception, and another
%_AsyncFunctionResolve, which resolves the outer promise with the
right hand side of the `return` statement. These functions also perform
the DevTools part of the job (aka popping from the promise stack and
sending the debug event). This allows us to get rid of the implicit
try-finally from async functions completely; because the finally
block only called to the %AsyncFunctionPromiseRelease builtin, which
was used to inform DevTools.
In essence we now turn an async function like
```js
async function f(x) { return await bar(x); }
```
into something like this (in Parser and BytecodeGenerator respectively):
```
function f(x) {
.generator_object = %_AsyncFunctionEnter(.closure, this);
.promise = %AsyncFunctionCreatePromise();
try {
.tmp = await bar(x);
return %_AsyncFunctionResolve(.promise, .tmp);
} catch (e) {
return %_AsyncFunctionReject(.promise, e);
}
}
```
Overall the bytecode for async functions gets significantly shorter
already (and will get even shorter once we put the outer promise into
the async function generator object). For example the bytecode for a
simple async function
```js
async function f(x) { return await x; }
```
goes from 175 bytes to 110 bytes (a ~38% reduction in size), which
is in particular due to the simplification around the try-finally
removal.
Overall this seems to improve the doxbee-async-es2017-native test by
around 2-3%. On the test case mentioned in v8:8276 we go from
1124ms to 441ms, which corresponds to a 60% reduction in total
execution time!
Tbr: marja@chromium.org
Bug: v8:7253, v8:7522, v8:8276
Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Id29dc92de7490b387ff697860c900cee44c9a7a4
Reviewed-on: https://chromium-review.googlesource.com/c/1269041
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Reviewed-by: Maya Lekova <mslekova@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56502}
2018-10-10 05:54:39 +00:00
|
|
|
map = Map::Copy(isolate(), isolate()->method_with_name_map(),
|
|
|
|
"AsyncFunction with name");
|
|
|
|
Map::SetPrototype(isolate(), map, async_function_prototype);
|
2017-07-13 09:33:22 +00:00
|
|
|
native_context()->set_async_function_with_name_map(*map);
|
|
|
|
|
[async] Improve async function handling.
This change introduces new intrinsics used to desugar async functions
in the Parser and the BytecodeGenerator, namely we introduce a new
%_AsyncFunctionEnter intrinsic that constructs the generator object
for the async function (and in the future will also create the outer
promise for the async function). This generator object is internal
and never escapes to user code, plus since async functions don't have
a "prototype" property, we can just a single map here instead of tracking
the prototype/initial_map on every async function. This saves one word
per async function plus one initial_map per async function that was
invoked at least once.
We also introduce two new intrinsics %_AsyncFunctionReject, which
rejects the outer promise with the caught exception, and another
%_AsyncFunctionResolve, which resolves the outer promise with the
right hand side of the `return` statement. These functions also perform
the DevTools part of the job (aka popping from the promise stack and
sending the debug event). This allows us to get rid of the implicit
try-finally from async functions completely; because the finally
block only called to the %AsyncFunctionPromiseRelease builtin, which
was used to inform DevTools.
In essence we now turn an async function like
```js
async function f(x) { return await bar(x); }
```
into something like this (in Parser and BytecodeGenerator respectively):
```
function f(x) {
.generator_object = %_AsyncFunctionEnter(.closure, this);
.promise = %AsyncFunctionCreatePromise();
try {
.tmp = await bar(x);
return %_AsyncFunctionResolve(.promise, .tmp);
} catch (e) {
return %_AsyncFunctionReject(.promise, e);
}
}
```
Overall the bytecode for async functions gets significantly shorter
already (and will get even shorter once we put the outer promise into
the async function generator object). For example the bytecode for a
simple async function
```js
async function f(x) { return await x; }
```
goes from 175 bytes to 110 bytes (a ~38% reduction in size), which
is in particular due to the simplification around the try-finally
removal.
Overall this seems to improve the doxbee-async-es2017-native test by
around 2-3%. On the test case mentioned in v8:8276 we go from
1124ms to 441ms, which corresponds to a 60% reduction in total
execution time!
Tbr: marja@chromium.org
Bug: v8:7253, v8:7522, v8:8276
Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Id29dc92de7490b387ff697860c900cee44c9a7a4
Reviewed-on: https://chromium-review.googlesource.com/c/1269041
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Reviewed-by: Maya Lekova <mslekova@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56502}
2018-10-10 05:54:39 +00:00
|
|
|
map = Map::Copy(isolate(), isolate()->method_with_home_object_map(),
|
|
|
|
"AsyncFunction with home object");
|
|
|
|
Map::SetPrototype(isolate(), map, async_function_prototype);
|
2017-07-13 09:33:22 +00:00
|
|
|
native_context()->set_async_function_with_home_object_map(*map);
|
|
|
|
|
[async] Improve async function handling.
This change introduces new intrinsics used to desugar async functions
in the Parser and the BytecodeGenerator, namely we introduce a new
%_AsyncFunctionEnter intrinsic that constructs the generator object
for the async function (and in the future will also create the outer
promise for the async function). This generator object is internal
and never escapes to user code, plus since async functions don't have
a "prototype" property, we can just a single map here instead of tracking
the prototype/initial_map on every async function. This saves one word
per async function plus one initial_map per async function that was
invoked at least once.
We also introduce two new intrinsics %_AsyncFunctionReject, which
rejects the outer promise with the caught exception, and another
%_AsyncFunctionResolve, which resolves the outer promise with the
right hand side of the `return` statement. These functions also perform
the DevTools part of the job (aka popping from the promise stack and
sending the debug event). This allows us to get rid of the implicit
try-finally from async functions completely; because the finally
block only called to the %AsyncFunctionPromiseRelease builtin, which
was used to inform DevTools.
In essence we now turn an async function like
```js
async function f(x) { return await bar(x); }
```
into something like this (in Parser and BytecodeGenerator respectively):
```
function f(x) {
.generator_object = %_AsyncFunctionEnter(.closure, this);
.promise = %AsyncFunctionCreatePromise();
try {
.tmp = await bar(x);
return %_AsyncFunctionResolve(.promise, .tmp);
} catch (e) {
return %_AsyncFunctionReject(.promise, e);
}
}
```
Overall the bytecode for async functions gets significantly shorter
already (and will get even shorter once we put the outer promise into
the async function generator object). For example the bytecode for a
simple async function
```js
async function f(x) { return await x; }
```
goes from 175 bytes to 110 bytes (a ~38% reduction in size), which
is in particular due to the simplification around the try-finally
removal.
Overall this seems to improve the doxbee-async-es2017-native test by
around 2-3%. On the test case mentioned in v8:8276 we go from
1124ms to 441ms, which corresponds to a 60% reduction in total
execution time!
Tbr: marja@chromium.org
Bug: v8:7253, v8:7522, v8:8276
Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Id29dc92de7490b387ff697860c900cee44c9a7a4
Reviewed-on: https://chromium-review.googlesource.com/c/1269041
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Reviewed-by: Maya Lekova <mslekova@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56502}
2018-10-10 05:54:39 +00:00
|
|
|
map = Map::Copy(isolate(), isolate()->method_with_name_and_home_object_map(),
|
|
|
|
"AsyncFunction with name and home object");
|
|
|
|
Map::SetPrototype(isolate(), map, async_function_prototype);
|
2017-07-13 09:33:22 +00:00
|
|
|
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());
|
2018-11-29 12:03:40 +00:00
|
|
|
map->AppendDescriptor(isolate(), &d);
|
2018-01-05 14:40:40 +00:00
|
|
|
}
|
|
|
|
{ // revoke
|
2018-07-17 15:08:58 +00:00
|
|
|
Descriptor d = Descriptor::DataField(
|
|
|
|
isolate(), factory()->revoke_string(),
|
|
|
|
JSProxyRevocableResult::kRevokeIndex, NONE, Representation::Tagged());
|
2018-11-29 12:03:40 +00:00
|
|
|
map->AppendDescriptor(isolate(), &d);
|
2018-01-05 14:40:40 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2020-10-05 09:22:13 +00:00
|
|
|
DescriptorArray descriptors = map->instance_descriptors(kRelaxedLoad);
|
2019-10-11 13:55:05 +00:00
|
|
|
InternalIndex entry = descriptors.SearchWithCache(isolate, *name, *map);
|
2016-12-21 16:40:00 +00:00
|
|
|
Descriptor d = Descriptor::AccessorConstant(name, accessor_pair, attributes);
|
2019-10-11 13:55:05 +00:00
|
|
|
descriptors.Replace(entry, &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-11-23 10:06:32 +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
|
2019-05-16 10:26:57 +00:00
|
|
|
{ // 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.
|
2018-12-25 00:19:47 +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();
|
2019-10-17 15:58:38 +00:00
|
|
|
|
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());
|
2019-08-12 21:07:13 +00:00
|
|
|
Handle<ScopeInfo> scope_info =
|
|
|
|
ReadOnlyRoots(isolate()).global_this_binding_scope_info_handle();
|
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());
|
2018-11-22 10:05:02 +00:00
|
|
|
Handle<Object> proto_template(global_constructor->GetPrototypeTemplate(),
|
2013-02-25 14:46:09 +00:00
|
|
|
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());
|
2020-11-11 06:18:31 +00:00
|
|
|
js_global_object_function = CreateFunctionForBuiltinWithPrototype(
|
|
|
|
isolate(), name, Builtins::kIllegal, prototype, JS_GLOBAL_OBJECT_TYPE,
|
|
|
|
JSGlobalObject::kHeaderSize, 0, MUTABLE);
|
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(
|
2019-08-05 09:09:25 +00:00
|
|
|
isolate(), isolate()->native_context(), js_global_object_constructor,
|
|
|
|
factory()->the_hole_value(), JS_GLOBAL_OBJECT_TYPE);
|
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();
|
2020-11-11 06:18:31 +00:00
|
|
|
global_proxy_function = CreateFunctionForBuiltinWithPrototype(
|
|
|
|
isolate(), name, Builtins::kIllegal, factory()->the_hole_value(),
|
|
|
|
JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::SizeWithEmbedderFields(0), 0,
|
2017-11-08 12:56:08 +00:00
|
|
|
MUTABLE);
|
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(
|
2019-08-05 09:09:25 +00:00
|
|
|
isolate(), isolate()->native_context(), global_constructor,
|
|
|
|
factory()->the_hole_value(), JS_GLOBAL_PROXY_TYPE);
|
2010-03-23 11:40:38 +00:00
|
|
|
}
|
|
|
|
global_proxy_function->initial_map().set_is_access_check_needed(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()) ||
|
2019-09-23 14:49:09 +00:00
|
|
|
native_context()->global_proxy_object() == *global_proxy);
|
|
|
|
native_context()->set_global_proxy_object(*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);
|
2020-11-18 13:59:54 +00:00
|
|
|
if (global_object_from_snapshot->HasDictionaryElements()) {
|
|
|
|
JSObject::NormalizeElements(global_object);
|
|
|
|
}
|
|
|
|
DCHECK_EQ(global_object_from_snapshot->GetElementsKind(),
|
|
|
|
global_object->GetElementsKind());
|
2014-07-01 12:12:34 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-04-20 09:44:59 +00:00
|
|
|
static void InstallError(
|
|
|
|
Isolate* isolate, Handle<JSObject> global, Handle<String> name,
|
|
|
|
int context_index,
|
|
|
|
Builtins::Name error_constructor = Builtins::kErrorConstructor,
|
2020-05-28 07:58:37 +00:00
|
|
|
int error_function_length = 1, int in_object_properties = 2) {
|
2016-07-20 13:02:36 +00:00
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
|
2019-04-11 13:48:20 +00:00
|
|
|
// Most Error objects consist of a message and a stack trace.
|
|
|
|
// Reserve two in-object properties for these.
|
|
|
|
const int kErrorObjectSize =
|
2020-05-28 07:58:37 +00:00
|
|
|
JSObject::kHeaderSize + in_object_properties * kTaggedSize;
|
2020-04-20 09:44:59 +00:00
|
|
|
Handle<JSFunction> error_fun = InstallFunction(
|
2020-05-28 07:58:37 +00:00
|
|
|
isolate, global, name, JS_ERROR_TYPE, kErrorObjectSize,
|
|
|
|
in_object_properties, factory->the_hole_value(), error_constructor);
|
2016-07-20 13:02:36 +00:00
|
|
|
error_fun->shared().DontAdaptArguments();
|
2020-04-20 09:44:59 +00:00
|
|
|
error_fun->shared().set_length(error_function_length);
|
2016-07-20 13:02:36 +00:00
|
|
|
|
|
|
|
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-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate, prototype, "toString",
|
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 {
|
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);
|
2018-11-29 12:03:40 +00:00
|
|
|
initial_map->AppendDescriptor(isolate, &d);
|
2016-07-20 13:02:36 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-07 16:35:03 +00:00
|
|
|
|
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,
|
2018-12-10 14:45:41 +00:00
|
|
|
Handle<JSFunction> empty_function) {
|
2013-10-14 13:25:36 +00:00
|
|
|
// --- N a t i v e C o n t e x t ---
|
2018-11-23 10:06:32 +00:00
|
|
|
native_context()->set_previous(Context());
|
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
|
|
|
|
2019-10-17 15:58:38 +00:00
|
|
|
{ // -- C o n t e x t
|
|
|
|
Handle<Map> map =
|
|
|
|
factory->NewMap(FUNCTION_CONTEXT_TYPE, kVariableSizeSentinel);
|
|
|
|
map->set_native_context(*native_context());
|
|
|
|
native_context()->set_function_context_map(*map);
|
|
|
|
|
|
|
|
map = factory->NewMap(CATCH_CONTEXT_TYPE, kVariableSizeSentinel);
|
|
|
|
map->set_native_context(*native_context());
|
|
|
|
native_context()->set_catch_context_map(*map);
|
|
|
|
|
|
|
|
map = factory->NewMap(WITH_CONTEXT_TYPE, kVariableSizeSentinel);
|
|
|
|
map->set_native_context(*native_context());
|
|
|
|
native_context()->set_with_context_map(*map);
|
|
|
|
|
|
|
|
map = factory->NewMap(DEBUG_EVALUATE_CONTEXT_TYPE, kVariableSizeSentinel);
|
|
|
|
map->set_native_context(*native_context());
|
|
|
|
native_context()->set_debug_evaluate_context_map(*map);
|
|
|
|
|
|
|
|
map = factory->NewMap(BLOCK_CONTEXT_TYPE, kVariableSizeSentinel);
|
|
|
|
map->set_native_context(*native_context());
|
|
|
|
native_context()->set_block_context_map(*map);
|
|
|
|
|
|
|
|
map = factory->NewMap(MODULE_CONTEXT_TYPE, kVariableSizeSentinel);
|
|
|
|
map->set_native_context(*native_context());
|
|
|
|
native_context()->set_module_context_map(*map);
|
|
|
|
|
|
|
|
map = factory->NewMap(AWAIT_CONTEXT_TYPE, kVariableSizeSentinel);
|
|
|
|
map->set_native_context(*native_context());
|
|
|
|
native_context()->set_await_context_map(*map);
|
|
|
|
|
|
|
|
map = factory->NewMap(SCRIPT_CONTEXT_TYPE, kVariableSizeSentinel);
|
|
|
|
map->set_native_context(*native_context());
|
|
|
|
native_context()->set_script_context_map(*map);
|
|
|
|
|
|
|
|
map = factory->NewMap(EVAL_CONTEXT_TYPE, kVariableSizeSentinel);
|
|
|
|
map->set_native_context(*native_context());
|
|
|
|
native_context()->set_eval_context_map(*map);
|
|
|
|
|
|
|
|
Handle<ScriptContextTable> script_context_table =
|
|
|
|
factory->NewScriptContextTable();
|
|
|
|
native_context()->set_script_context_table(*script_context_table);
|
|
|
|
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-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "assign",
|
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,
|
2018-11-23 09:55:50 +00:00
|
|
|
"getOwnPropertyDescriptors",
|
2016-10-31 22:52:55 +00:00
|
|
|
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",
|
2019-06-12 20:55:29 +00:00
|
|
|
Builtins::kObjectPreventExtensions, 1, true);
|
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(
|
2018-11-23 09:55:50 +00:00
|
|
|
isolate_, object_function, "create", Builtins::kObjectCreate, 2, false);
|
2016-12-19 21:36:16 +00:00
|
|
|
native_context()->set_object_create(*object_create);
|
|
|
|
|
2019-07-17 10:11:04 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "defineProperties",
|
|
|
|
Builtins::kObjectDefineProperties, 2, true);
|
2016-04-25 12:24:02 +00:00
|
|
|
|
2019-07-17 10:11:04 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "defineProperty",
|
|
|
|
Builtins::kObjectDefineProperty, 3, true);
|
2016-04-25 12:24:02 +00:00
|
|
|
|
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
|
|
|
|
2019-07-17 10:11:04 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "getPrototypeOf",
|
|
|
|
Builtins::kObjectGetPrototypeOf, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "setPrototypeOf",
|
2019-06-27 06:12:16 +00:00
|
|
|
Builtins::kObjectSetPrototypeOf, 2, true);
|
2016-04-25 11:44:13 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "isExtensible",
|
2019-06-05 16:56:31 +00:00
|
|
|
Builtins::kObjectIsExtensible, 1, true);
|
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
|
|
|
|
2019-07-17 10:11:04 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "isSealed",
|
|
|
|
Builtins::kObjectIsSealed, 1, false);
|
2016-04-25 11:44:13 +00:00
|
|
|
|
2019-07-17 10:11:04 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "keys",
|
|
|
|
Builtins::kObjectKeys, 1, true);
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "entries",
|
2018-02-07 03:43:37 +00:00
|
|
|
Builtins::kObjectEntries, 1, true);
|
2019-06-24 14:22:36 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "fromEntries",
|
|
|
|
Builtins::kObjectFromEntries, 1, false);
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "values",
|
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-11-23 09:55:50 +00:00
|
|
|
Handle<JSFunction> object_to_string = SimpleInstallFunction(
|
|
|
|
isolate_, isolate_->initial_object_prototype(), "toString",
|
|
|
|
Builtins::kObjectPrototypeToString, 0, true);
|
2017-04-14 22:22:40 +00:00
|
|
|
native_context()->set_object_to_string(*object_to_string);
|
2020-03-13 13:14:09 +00:00
|
|
|
Handle<JSFunction> object_value_of = SimpleInstallFunction(
|
|
|
|
isolate_, isolate_->initial_object_prototype(), "valueOf",
|
|
|
|
Builtins::kObjectPrototypeValueOf, 0, true);
|
|
|
|
native_context()->set_object_value_of_function(*object_value_of);
|
2016-10-14 11:24:44 +00:00
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
SimpleInstallGetterSetter(
|
|
|
|
isolate_, isolate_->initial_object_prototype(), factory->proto_string(),
|
|
|
|
Builtins::kObjectPrototypeGetProto, Builtins::kObjectPrototypeSetProto);
|
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-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "apply",
|
2016-01-12 16:43:28 +00:00
|
|
|
Builtins::kFunctionPrototypeApply, 2, false);
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "bind",
|
2016-12-01 21:15:08 +00:00
|
|
|
Builtins::kFastFunctionPrototypeBind, 1, false);
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "call",
|
2016-01-12 16:43:28 +00:00
|
|
|
Builtins::kFunctionPrototypeCall, 1, false);
|
2020-11-02 22:01:19 +00:00
|
|
|
Handle<JSFunction> function_to_string =
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "toString",
|
|
|
|
Builtins::kFunctionPrototypeToString, 0, false);
|
|
|
|
native_context()->set_function_to_string(*function_to_string);
|
2016-01-12 16:43:28 +00:00
|
|
|
|
2016-02-11 11:58:47 +00:00
|
|
|
// Install the @@hasInstance function.
|
2018-11-23 09:55:50 +00:00
|
|
|
Handle<JSFunction> has_instance = InstallFunctionAtSymbol(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, prototype, factory->has_instance_symbol(),
|
|
|
|
"[Symbol.hasInstance]", Builtins::kFunctionPrototypeHasInstance, 1,
|
|
|
|
true,
|
2019-03-07 00:27:04 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY));
|
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
|
|
|
|
2018-12-11 15:27:31 +00:00
|
|
|
Handle<JSFunction> array_prototype_to_string_fun;
|
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(
|
2019-11-15 20:37:49 +00:00
|
|
|
isolate_, global, "Array", JS_ARRAY_TYPE, JSArray::kHeaderSize, 0,
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_->initial_object_prototype(), Builtins::kArrayConstructor);
|
2008-09-16 10:12:32 +00:00
|
|
|
array_function->shared().DontAdaptArguments();
|
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
|
|
|
|
2019-05-16 10:26:57 +00:00
|
|
|
PropertyAttributes attribs =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE);
|
2012-07-18 14:00:58 +00:00
|
|
|
|
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);
|
2018-11-29 12:03:40 +00:00
|
|
|
initial_map->AppendDescriptor(isolate(), &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
|
2019-06-06 11:55:10 +00:00
|
|
|
CacheInitialJSArrayMaps(isolate_, 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
|
2019-04-27 09:06:53 +00:00
|
|
|
// mode and back.
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<JSArray> proto = factory->NewJSArray(0, TERMINAL_FAST_ELEMENTS_KIND,
|
|
|
|
AllocationType::kOld);
|
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
|
|
|
|
2019-07-17 10:11:04 +00:00
|
|
|
SimpleInstallFunction(isolate_, array_function, "isArray",
|
|
|
|
Builtins::kArrayIsArray, 1, true);
|
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-08-08 05:52:45 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "copyWithin",
|
|
|
|
Builtins::kArrayPrototypeCopyWithin, 2, 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-08-28 09:14:58 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "lastIndexOf",
|
|
|
|
Builtins::kArrayPrototypeLastIndexOf, 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);
|
2018-08-23 12:41:58 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "reverse",
|
|
|
|
Builtins::kArrayPrototypeReverse, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "shift",
|
|
|
|
Builtins::kArrayPrototypeShift, 0, false);
|
2018-09-06 05:47:23 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "unshift",
|
|
|
|
Builtins::kArrayPrototypeUnshift, 1, false);
|
2018-11-26 13:29:01 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "slice",
|
|
|
|
Builtins::kArrayPrototypeSlice, 2, false);
|
2018-08-22 13:17:38 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "sort",
|
|
|
|
Builtins::kArrayPrototypeSort, 1, false);
|
2018-11-26 13:29:01 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "splice",
|
|
|
|
Builtins::kArrayPrototypeSplice, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "includes", Builtins::kArrayIncludes,
|
|
|
|
1, false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "indexOf", Builtins::kArrayIndexOf,
|
|
|
|
1, false);
|
2018-10-16 12:52:25 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "join",
|
|
|
|
Builtins::kArrayPrototypeJoin, 1, false);
|
2018-12-20 19:44:56 +00:00
|
|
|
|
|
|
|
{ // Set up iterator-related properties.
|
|
|
|
Handle<JSFunction> keys = InstallFunctionWithBuiltinId(
|
2019-03-07 00:27:04 +00:00
|
|
|
isolate_, proto, "keys", Builtins::kArrayPrototypeKeys, 0, true);
|
2018-12-20 19:44:56 +00:00
|
|
|
native_context()->set_array_keys_iterator(*keys);
|
|
|
|
|
|
|
|
Handle<JSFunction> entries = InstallFunctionWithBuiltinId(
|
2019-03-07 00:27:04 +00:00
|
|
|
isolate_, proto, "entries", Builtins::kArrayPrototypeEntries, 0,
|
|
|
|
true);
|
2018-12-20 19:44:56 +00:00
|
|
|
native_context()->set_array_entries_iterator(*entries);
|
|
|
|
|
|
|
|
Handle<JSFunction> values = InstallFunctionWithBuiltinId(
|
2019-03-07 00:27:04 +00:00
|
|
|
isolate_, proto, "values", Builtins::kArrayPrototypeValues, 0, true);
|
2018-12-20 19:44:56 +00:00
|
|
|
JSObject::AddProperty(isolate_, proto, factory->iterator_symbol(), values,
|
|
|
|
DONT_ENUM);
|
|
|
|
native_context()->set_array_values_iterator(*values);
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<JSFunction> for_each_fun = SimpleInstallFunction(
|
|
|
|
isolate_, proto, "forEach", Builtins::kArrayForEach, 1, false);
|
|
|
|
native_context()->set_array_for_each_iterator(*for_each_fun);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "filter", Builtins::kArrayFilter, 1,
|
|
|
|
false);
|
2019-02-02 02:10:25 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "flat",
|
|
|
|
Builtins::kArrayPrototypeFlat, 0, false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "flatMap",
|
|
|
|
Builtins::kArrayPrototypeFlatMap, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
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);
|
2018-10-16 12:52:25 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "toLocaleString",
|
|
|
|
Builtins::kArrayPrototypeToLocaleString, 0, false);
|
2018-12-11 15:27:31 +00:00
|
|
|
array_prototype_to_string_fun =
|
|
|
|
SimpleInstallFunction(isolate_, proto, "toString",
|
|
|
|
Builtins::kArrayPrototypeToString, 0, false);
|
2018-12-14 05:37:34 +00:00
|
|
|
|
2018-12-20 19:44:56 +00:00
|
|
|
Handle<JSObject> unscopables = factory->NewJSObjectWithNullProto();
|
|
|
|
InstallTrueValuedProperty(isolate_, unscopables, "copyWithin");
|
|
|
|
InstallTrueValuedProperty(isolate_, unscopables, "entries");
|
|
|
|
InstallTrueValuedProperty(isolate_, unscopables, "fill");
|
|
|
|
InstallTrueValuedProperty(isolate_, unscopables, "find");
|
|
|
|
InstallTrueValuedProperty(isolate_, unscopables, "findIndex");
|
2018-12-24 14:13:08 +00:00
|
|
|
InstallTrueValuedProperty(isolate_, unscopables, "flat");
|
|
|
|
InstallTrueValuedProperty(isolate_, unscopables, "flatMap");
|
2018-12-20 19:44:56 +00:00
|
|
|
InstallTrueValuedProperty(isolate_, unscopables, "includes");
|
|
|
|
InstallTrueValuedProperty(isolate_, unscopables, "keys");
|
|
|
|
InstallTrueValuedProperty(isolate_, unscopables, "values");
|
|
|
|
JSObject::MigrateSlowToFast(unscopables, 0, "Bootstrapping");
|
|
|
|
JSObject::AddProperty(
|
|
|
|
isolate_, proto, factory->unscopables_symbol(), unscopables,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
2018-12-14 05:37:34 +00:00
|
|
|
Handle<Map> map(proto->map(), isolate_);
|
|
|
|
Map::SetShouldBeFastPrototypeMap(map, true, isolate_);
|
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 =
|
2019-03-11 19:04:02 +00:00
|
|
|
factory->NewJSObject(isolate_->object_function(), AllocationType::kOld);
|
2016-10-18 02:42:42 +00:00
|
|
|
JSObject::ForceSetPrototype(array_iterator_prototype, iterator_prototype);
|
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate_, array_iterator_prototype,
|
|
|
|
factory->ArrayIterator_string());
|
2016-10-18 02:42:42 +00:00
|
|
|
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate_, array_iterator_prototype, "next",
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kArrayIteratorPrototypeNext, 0,
|
|
|
|
true);
|
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(),
|
2019-11-15 20:37:49 +00:00
|
|
|
JS_ARRAY_ITERATOR_TYPE, JSArrayIterator::kHeaderSize, 0,
|
[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
|
|
|
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(
|
2019-06-24 13:13:34 +00:00
|
|
|
isolate_, global, "Number", JS_PRIMITIVE_WRAPPER_TYPE,
|
2019-11-15 20:37:49 +00:00
|
|
|
JSPrimitiveWrapper::kHeaderSize, 0,
|
|
|
|
isolate_->initial_object_prototype(), Builtins::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%
|
2019-06-24 13:13:34 +00:00
|
|
|
Handle<JSPrimitiveWrapper> prototype = Handle<JSPrimitiveWrapper>::cast(
|
2019-03-11 19:04:02 +00:00
|
|
|
factory->NewJSObject(number_fun, AllocationType::kOld));
|
2019-11-15 10:39:28 +00:00
|
|
|
prototype->set_value(Smi::zero());
|
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-12-20 01:20:25 +00:00
|
|
|
JSObject::AddProperty(isolate_, global_object, "parseFloat",
|
2016-10-07 08:58:43 +00:00
|
|
|
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-12-20 01:20:25 +00:00
|
|
|
JSObject::AddProperty(isolate_, global_object, "parseInt", parse_int_fun,
|
|
|
|
DONT_ENUM);
|
2017-02-27 08:20:45 +00:00
|
|
|
|
|
|
|
// Install Number constants
|
2018-12-20 01:20:25 +00:00
|
|
|
const double kMaxValue = 1.7976931348623157e+308;
|
|
|
|
const double kMinValue = 5e-324;
|
|
|
|
const double kMinSafeInteger = -kMaxSafeInteger;
|
|
|
|
const double kEPS = 2.220446049250313e-16;
|
|
|
|
|
|
|
|
InstallConstant(isolate_, number_fun, "MAX_VALUE",
|
|
|
|
factory->NewNumber(kMaxValue));
|
|
|
|
InstallConstant(isolate_, number_fun, "MIN_VALUE",
|
|
|
|
factory->NewNumber(kMinValue));
|
|
|
|
InstallConstant(isolate_, number_fun, "NaN", factory->nan_value());
|
|
|
|
InstallConstant(isolate_, number_fun, "NEGATIVE_INFINITY",
|
|
|
|
factory->NewNumber(-V8_INFINITY));
|
|
|
|
InstallConstant(isolate_, number_fun, "POSITIVE_INFINITY",
|
|
|
|
factory->infinity_value());
|
|
|
|
InstallConstant(isolate_, number_fun, "MAX_SAFE_INTEGER",
|
|
|
|
factory->NewNumber(kMaxSafeInteger));
|
|
|
|
InstallConstant(isolate_, number_fun, "MIN_SAFE_INTEGER",
|
|
|
|
factory->NewNumber(kMinSafeInteger));
|
|
|
|
InstallConstant(isolate_, number_fun, "EPSILON", factory->NewNumber(kEPS));
|
|
|
|
|
|
|
|
InstallConstant(isolate_, global, "Infinity", factory->infinity_value());
|
|
|
|
InstallConstant(isolate_, global, "NaN", factory->nan_value());
|
|
|
|
InstallConstant(isolate_, global, "undefined", factory->undefined_value());
|
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(
|
2019-06-24 13:13:34 +00:00
|
|
|
isolate_, global, "Boolean", JS_PRIMITIVE_WRAPPER_TYPE,
|
2019-11-15 20:37:49 +00:00
|
|
|
JSPrimitiveWrapper::kHeaderSize, 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%
|
2019-06-24 13:13:34 +00:00
|
|
|
Handle<JSPrimitiveWrapper> prototype = Handle<JSPrimitiveWrapper>::cast(
|
2019-03-11 19:04:02 +00:00
|
|
|
factory->NewJSObject(boolean_fun, AllocationType::kOld));
|
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(
|
2019-06-24 13:13:34 +00:00
|
|
|
isolate_, global, "String", JS_PRIMITIVE_WRAPPER_TYPE,
|
2019-11-15 20:37:49 +00:00
|
|
|
JSPrimitiveWrapper::kHeaderSize, 0,
|
|
|
|
isolate_->initial_object_prototype(), Builtins::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
|
|
|
|
2019-05-16 10:26:57 +00:00
|
|
|
PropertyAttributes attribs =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
|
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->string_length_accessor(), attribs);
|
2018-11-29 12:03:40 +00:00
|
|
|
string_map->AppendDescriptor(isolate(), &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%
|
2019-06-24 13:13:34 +00:00
|
|
|
Handle<JSPrimitiveWrapper> prototype = Handle<JSPrimitiveWrapper>::cast(
|
2019-03-11 19:04:02 +00:00
|
|
|
factory->NewJSObject(string_fun, AllocationType::kOld));
|
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",
|
2019-03-14 13:26:28 +00:00
|
|
|
Builtins::kStringPrototypeAnchor, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "big",
|
2019-03-14 13:26:28 +00:00
|
|
|
Builtins::kStringPrototypeBig, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "blink",
|
2019-03-14 13:26:28 +00:00
|
|
|
Builtins::kStringPrototypeBlink, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "bold",
|
2019-03-14 13:26:28 +00:00
|
|
|
Builtins::kStringPrototypeBold, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
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",
|
2019-03-14 13:26:28 +00:00
|
|
|
Builtins::kStringPrototypeFontcolor, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "fontsize",
|
2019-03-14 13:26:28 +00:00
|
|
|
Builtins::kStringPrototypeFontsize, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "fixed",
|
2019-03-14 13:26:28 +00:00
|
|
|
Builtins::kStringPrototypeFixed, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
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",
|
2019-03-14 13:26:28 +00:00
|
|
|
Builtins::kStringPrototypeItalics, 0, false);
|
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",
|
2019-03-14 13:26:28 +00:00
|
|
|
Builtins::kStringPrototypeLink, 1, false);
|
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);
|
2019-04-25 02:39:22 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "matchAll",
|
|
|
|
Builtins::kStringPrototypeMatchAll, 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",
|
2019-03-14 13:26:28 +00:00
|
|
|
Builtins::kStringPrototypeSmall, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "split",
|
|
|
|
Builtins::kStringPrototypeSplit, 2, false);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "strike",
|
2019-03-14 13:26:28 +00:00
|
|
|
Builtins::kStringPrototypeStrike, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "sub",
|
2019-03-14 13:26:28 +00:00
|
|
|
Builtins::kStringPrototypeSub, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
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",
|
2019-03-14 13:26:28 +00:00
|
|
|
Builtins::kStringPrototypeSup, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
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);
|
2018-10-01 14:34:38 +00:00
|
|
|
|
|
|
|
// Install `String.prototype.trimStart` with `trimLeft` alias.
|
|
|
|
Handle<JSFunction> trim_start_fun =
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "trimStart",
|
|
|
|
Builtins::kStringPrototypeTrimStart, 0, false);
|
2018-12-20 01:20:25 +00:00
|
|
|
JSObject::AddProperty(isolate_, prototype, "trimLeft", trim_start_fun,
|
|
|
|
DONT_ENUM);
|
2018-10-01 14:34:38 +00:00
|
|
|
|
|
|
|
// Install `String.prototype.trimEnd` with `trimRight` alias.
|
|
|
|
Handle<JSFunction> trim_end_fun =
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "trimEnd",
|
|
|
|
Builtins::kStringPrototypeTrimEnd, 0, false);
|
2018-12-20 01:20:25 +00:00
|
|
|
JSObject::AddProperty(isolate_, prototype, "trimRight", trim_end_fun,
|
|
|
|
DONT_ENUM);
|
2018-10-01 14:34:38 +00:00
|
|
|
|
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
|
|
|
|
2019-03-07 00:27:04 +00:00
|
|
|
InstallFunctionAtSymbol(
|
|
|
|
isolate_, prototype, factory->iterator_symbol(), "[Symbol.iterator]",
|
|
|
|
Builtins::kStringPrototypeIterator, 0, true, DONT_ENUM);
|
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 =
|
2019-03-11 19:04:02 +00:00
|
|
|
factory->NewJSObject(isolate_->object_function(), AllocationType::kOld);
|
2016-09-21 14:17:42 +00:00
|
|
|
JSObject::ForceSetPrototype(string_iterator_prototype, iterator_prototype);
|
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate_, string_iterator_prototype, "String Iterator");
|
2016-09-21 14:17:42 +00:00
|
|
|
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate_, string_iterator_prototype, "next",
|
|
|
|
Builtins::kStringIteratorPrototypeNext, 0,
|
2019-03-07 00:27:04 +00:00
|
|
|
true);
|
2016-09-21 14:17:42 +00:00
|
|
|
|
|
|
|
Handle<JSFunction> string_iterator_function = CreateFunction(
|
2018-10-05 14:32:24 +00:00
|
|
|
isolate_, factory->InternalizeUtf8String("StringIterator"),
|
2019-11-15 20:37:49 +00:00
|
|
|
JS_STRING_ITERATOR_TYPE, JSStringIterator::kHeaderSize, 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);
|
2018-10-01 10:57:19 +00:00
|
|
|
native_context()->set_initial_string_iterator_map(
|
2016-09-21 14:17:42 +00:00
|
|
|
string_iterator_function->initial_map());
|
2018-10-01 10:57:19 +00:00
|
|
|
native_context()->set_initial_string_iterator_prototype(
|
|
|
|
*string_iterator_prototype);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2017-06-30 08:54:01 +00:00
|
|
|
{ // --- S y m b o l ---
|
2019-11-15 20:37:49 +00:00
|
|
|
Handle<JSFunction> symbol_fun = InstallFunction(
|
|
|
|
isolate_, global, "Symbol", JS_PRIMITIVE_WRAPPER_TYPE,
|
|
|
|
JSPrimitiveWrapper::kHeaderSize, 0, factory->the_hole_value(),
|
|
|
|
Builtins::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());
|
2019-04-25 02:39:22 +00:00
|
|
|
InstallConstant(isolate_, symbol_fun, "matchAll",
|
|
|
|
factory->match_all_symbol());
|
2018-05-31 14:14:48 +00:00
|
|
|
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
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate_, prototype, "Symbol");
|
2016-07-05 10:03:38 +00:00
|
|
|
|
|
|
|
// Install the Symbol.prototype methods.
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate_, prototype, "toString",
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kSymbolPrototypeToString, 0, true);
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate_, prototype, "valueOf",
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kSymbolPrototypeValueOf, 0, true);
|
2016-07-05 10:03:38 +00:00
|
|
|
|
2019-02-14 10:00:15 +00:00
|
|
|
// Install the Symbol.prototype.description getter.
|
|
|
|
SimpleInstallGetter(isolate_, prototype,
|
|
|
|
factory->InternalizeUtf8String("description"),
|
|
|
|
Builtins::kSymbolPrototypeDescriptionGetter, true);
|
|
|
|
|
2016-07-05 10:03:38 +00:00
|
|
|
// Install the @@toPrimitive function.
|
2018-11-23 10:55:19 +00:00
|
|
|
InstallFunctionAtSymbol(
|
|
|
|
isolate_, prototype, factory->to_primitive_symbol(),
|
|
|
|
"[Symbol.toPrimitive]", Builtins::kSymbolPrototypeToPrimitive, 1, true,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
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(
|
2019-11-15 20:37:49 +00:00
|
|
|
isolate_, global, "Date", JS_DATE_TYPE, JSDate::kHeaderSize, 0,
|
2018-05-31 14:14:48 +00:00
|
|
|
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-12-20 01:20:25 +00:00
|
|
|
JSObject::AddProperty(isolate_, prototype, "toGMTString", to_utc_string,
|
|
|
|
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
|
|
|
|
2018-08-30 20:23:15 +00:00
|
|
|
#ifdef V8_INTL_SUPPORT
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "toLocaleString",
|
|
|
|
Builtins::kDatePrototypeToLocaleString, 0, false);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "toLocaleDateString",
|
|
|
|
Builtins::kDatePrototypeToLocaleDateString, 0, false);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "toLocaleTimeString",
|
|
|
|
Builtins::kDatePrototypeToLocaleTimeString, 0, false);
|
|
|
|
#else
|
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);
|
2018-08-30 20:23:15 +00:00
|
|
|
#endif // V8_INTL_SUPPORT
|
2016-01-12 10:47:27 +00:00
|
|
|
|
|
|
|
// Install the @@toPrimitive function.
|
2018-11-23 10:55:19 +00:00
|
|
|
InstallFunctionAtSymbol(
|
|
|
|
isolate_, prototype, factory->to_primitive_symbol(),
|
|
|
|
"[Symbol.toPrimitive]", Builtins::kDatePrototypeToPrimitive, 1, true,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
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-11-23 14:10:11 +00:00
|
|
|
Handle<JSFunction> promise_all = InstallFunctionWithBuiltinId(
|
2019-03-07 00:27:04 +00:00
|
|
|
isolate_, promise_fun, "all", Builtins::kPromiseAll, 1, true);
|
2018-10-25 20:01:58 +00:00
|
|
|
native_context()->set_promise_all(*promise_all);
|
2017-06-30 08:54:01 +00:00
|
|
|
|
2020-11-03 18:52:31 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate_, promise_fun, "allSettled",
|
|
|
|
Builtins::kPromiseAllSettled, 1, true);
|
|
|
|
|
2020-11-12 00:22:12 +00:00
|
|
|
Handle<JSFunction> promise_any = InstallFunctionWithBuiltinId(
|
|
|
|
isolate_, promise_fun, "any", Builtins::kPromiseAny, 1, true);
|
|
|
|
native_context()->set_promise_any(*promise_any);
|
|
|
|
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate_, promise_fun, "race",
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kPromiseRace, 1, true);
|
2017-07-08 00:43:24 +00:00
|
|
|
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate_, promise_fun, "resolve",
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kPromiseResolveTrampoline, 1, true);
|
2017-06-30 08:54:01 +00:00
|
|
|
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate_, promise_fun, "reject",
|
2019-03-07 00:27:04 +00:00
|
|
|
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
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate_, prototype, factory->Promise_string());
|
2016-12-01 21:09:44 +00:00
|
|
|
|
2018-11-23 14:10:11 +00:00
|
|
|
Handle<JSFunction> promise_then = InstallFunctionWithBuiltinId(
|
2019-03-07 00:27:04 +00:00
|
|
|
isolate_, prototype, "then", 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
|
|
|
|
2019-03-07 00:27:04 +00:00
|
|
|
Handle<JSFunction> promise_catch =
|
|
|
|
InstallFunctionWithBuiltinId(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-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate_, prototype, "finally",
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kPromisePrototypeFinally, 1, true);
|
2018-06-04 19:37:50 +00:00
|
|
|
|
2020-05-04 11:21:32 +00:00
|
|
|
DCHECK(promise_fun->HasFastProperties());
|
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
|
|
|
|
2020-05-04 11:21:32 +00:00
|
|
|
DCHECK(promise_fun->HasFastProperties());
|
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(
|
2019-10-09 16:55:52 +00:00
|
|
|
isolate_, global, "RegExp", JS_REG_EXP_TYPE,
|
2019-11-15 20:37:49 +00:00
|
|
|
JSRegExp::kHeaderSize + JSRegExp::kInObjectFieldCount * kTaggedSize,
|
2017-10-18 20:14:09 +00:00
|
|
|
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());
|
2018-11-19 05:56:01 +00:00
|
|
|
native_context()->set_regexp_prototype(*prototype);
|
2016-10-06 13:00:56 +00:00
|
|
|
|
2016-10-10 13:56:46 +00:00
|
|
|
{
|
2018-12-20 23:13:14 +00:00
|
|
|
Handle<JSFunction> fun =
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "exec",
|
|
|
|
Builtins::kRegExpPrototypeExec, 1, true);
|
2019-07-29 07:55:50 +00:00
|
|
|
native_context()->set_regexp_exec_function(*fun);
|
2018-10-24 05:38:57 +00:00
|
|
|
DCHECK_EQ(JSRegExp::kExecFunctionDescriptorIndex,
|
2019-10-11 13:55:05 +00:00
|
|
|
prototype->map().LastAdded().as_int());
|
2016-10-10 13:56:46 +00:00
|
|
|
}
|
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",
|
2018-12-20 23:13:14 +00:00
|
|
|
Builtins::kRegExpPrototypeCompile, 2, true);
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toString",
|
2018-12-20 23:13:14 +00:00
|
|
|
Builtins::kRegExpPrototypeToString, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "test",
|
2018-12-20 23:13:14 +00:00
|
|
|
Builtins::kRegExpPrototypeTest, 1, true);
|
2016-10-10 13:56:46 +00:00
|
|
|
|
2019-07-29 07:55:50 +00:00
|
|
|
{
|
|
|
|
Handle<JSFunction> fun = InstallFunctionAtSymbol(
|
|
|
|
isolate_, prototype, factory->match_symbol(), "[Symbol.match]",
|
|
|
|
Builtins::kRegExpPrototypeMatch, 1, true);
|
|
|
|
native_context()->set_regexp_match_function(*fun);
|
|
|
|
DCHECK_EQ(JSRegExp::kSymbolMatchFunctionDescriptorIndex,
|
2019-10-11 13:55:05 +00:00
|
|
|
prototype->map().LastAdded().as_int());
|
2019-07-29 07:55:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Handle<JSFunction> fun = InstallFunctionAtSymbol(
|
|
|
|
isolate_, prototype, factory->match_all_symbol(),
|
|
|
|
"[Symbol.matchAll]", Builtins::kRegExpPrototypeMatchAll, 1, true);
|
|
|
|
native_context()->set_regexp_match_all_function(*fun);
|
|
|
|
DCHECK_EQ(JSRegExp::kSymbolMatchAllFunctionDescriptorIndex,
|
2019-10-11 13:55:05 +00:00
|
|
|
prototype->map().LastAdded().as_int());
|
2019-07-29 07:55:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Handle<JSFunction> fun = InstallFunctionAtSymbol(
|
|
|
|
isolate_, prototype, factory->replace_symbol(), "[Symbol.replace]",
|
|
|
|
Builtins::kRegExpPrototypeReplace, 2, false);
|
|
|
|
native_context()->set_regexp_replace_function(*fun);
|
|
|
|
DCHECK_EQ(JSRegExp::kSymbolReplaceFunctionDescriptorIndex,
|
2019-10-11 13:55:05 +00:00
|
|
|
prototype->map().LastAdded().as_int());
|
2019-07-29 07:55:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Handle<JSFunction> fun = InstallFunctionAtSymbol(
|
|
|
|
isolate_, prototype, factory->search_symbol(), "[Symbol.search]",
|
|
|
|
Builtins::kRegExpPrototypeSearch, 1, true);
|
|
|
|
native_context()->set_regexp_search_function(*fun);
|
|
|
|
DCHECK_EQ(JSRegExp::kSymbolSearchFunctionDescriptorIndex,
|
2019-10-11 13:55:05 +00:00
|
|
|
prototype->map().LastAdded().as_int());
|
2019-07-29 07:55:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Handle<JSFunction> fun = InstallFunctionAtSymbol(
|
|
|
|
isolate_, prototype, factory->split_symbol(), "[Symbol.split]",
|
|
|
|
Builtins::kRegExpPrototypeSplit, 2, false);
|
|
|
|
native_context()->set_regexp_split_function(*fun);
|
|
|
|
DCHECK_EQ(JSRegExp::kSymbolSplitFunctionDescriptorIndex,
|
2019-10-11 13:55:05 +00:00
|
|
|
prototype->map().LastAdded().as_int());
|
2019-07-29 07:55:50 +00:00
|
|
|
}
|
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.
|
|
|
|
|
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,
|
2018-12-20 01:20:25 +00:00
|
|
|
Builtins::kRegExpInputSetter);
|
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun, "$_",
|
|
|
|
Builtins::kRegExpInputGetter,
|
|
|
|
Builtins::kRegExpInputSetter);
|
|
|
|
|
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun, "lastMatch",
|
|
|
|
Builtins::kRegExpLastMatchGetter,
|
|
|
|
Builtins::kEmptyFunction);
|
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun, "$&",
|
|
|
|
Builtins::kRegExpLastMatchGetter,
|
|
|
|
Builtins::kEmptyFunction);
|
|
|
|
|
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun, "lastParen",
|
|
|
|
Builtins::kRegExpLastParenGetter,
|
|
|
|
Builtins::kEmptyFunction);
|
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun, "$+",
|
|
|
|
Builtins::kRegExpLastParenGetter,
|
|
|
|
Builtins::kEmptyFunction);
|
|
|
|
|
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun, "leftContext",
|
2016-10-06 13:00:56 +00:00
|
|
|
Builtins::kRegExpLeftContextGetter,
|
2018-12-20 01:20:25 +00:00
|
|
|
Builtins::kEmptyFunction);
|
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun, "$`",
|
2016-10-06 13:00:56 +00:00
|
|
|
Builtins::kRegExpLeftContextGetter,
|
2018-12-20 01:20:25 +00:00
|
|
|
Builtins::kEmptyFunction);
|
2016-10-06 13:00:56 +00:00
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun, "rightContext",
|
2016-10-06 13:00:56 +00:00
|
|
|
Builtins::kRegExpRightContextGetter,
|
2018-12-20 01:20:25 +00:00
|
|
|
Builtins::kEmptyFunction);
|
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun, "$'",
|
2016-10-06 13:00:56 +00:00
|
|
|
Builtins::kRegExpRightContextGetter,
|
2018-12-20 01:20:25 +00:00
|
|
|
Builtins::kEmptyFunction);
|
2016-10-06 13:00:56 +00:00
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
#define INSTALL_CAPTURE_GETTER(i) \
|
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun, "$" #i, \
|
|
|
|
Builtins::kRegExpCapture##i##Getter, \
|
|
|
|
Builtins::kEmptyFunction)
|
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());
|
2018-11-29 12:03:40 +00:00
|
|
|
initial_map->AppendDescriptor(isolate(), &d);
|
2010-03-26 14:19:47 +00:00
|
|
|
|
2019-02-14 14:01:43 +00:00
|
|
|
// Create the last match info.
|
2016-10-14 11:46:43 +00:00
|
|
|
Handle<RegExpMatchInfo> last_match_info = factory->NewRegExpMatchInfo();
|
|
|
|
native_context()->set_regexp_last_match_info(*last_match_info);
|
2017-03-31 18:27:30 +00:00
|
|
|
|
2019-07-11 07:33:33 +00:00
|
|
|
// Install the species protector cell.
|
|
|
|
{
|
|
|
|
Handle<PropertyCell> cell =
|
|
|
|
factory->NewPropertyCell(factory->empty_string());
|
2019-09-26 17:48:59 +00:00
|
|
|
cell->set_value(Smi::FromInt(Protectors::kProtectorValid));
|
2019-07-11 07:33:33 +00:00
|
|
|
native_context()->set_regexp_species_protector(*cell);
|
|
|
|
}
|
|
|
|
|
2020-05-04 11:21:32 +00:00
|
|
|
DCHECK(regexp_fun->HasFastProperties());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2019-04-25 02:39:22 +00:00
|
|
|
{ // --- R e g E x p S t r i n g I t e r a t o r ---
|
|
|
|
Handle<JSObject> iterator_prototype(
|
|
|
|
native_context()->initial_iterator_prototype(), isolate());
|
|
|
|
|
|
|
|
Handle<JSObject> regexp_string_iterator_prototype = factory->NewJSObject(
|
|
|
|
isolate()->object_function(), AllocationType::kOld);
|
|
|
|
JSObject::ForceSetPrototype(regexp_string_iterator_prototype,
|
|
|
|
iterator_prototype);
|
|
|
|
|
|
|
|
InstallToStringTag(isolate(), regexp_string_iterator_prototype,
|
|
|
|
"RegExp String Iterator");
|
|
|
|
|
|
|
|
SimpleInstallFunction(isolate(), regexp_string_iterator_prototype, "next",
|
|
|
|
Builtins::kRegExpStringIteratorPrototypeNext, 0,
|
|
|
|
true);
|
|
|
|
|
|
|
|
Handle<JSFunction> regexp_string_iterator_function = CreateFunction(
|
2019-10-09 16:55:52 +00:00
|
|
|
isolate(), "RegExpStringIterator", JS_REG_EXP_STRING_ITERATOR_TYPE,
|
2019-11-15 20:37:49 +00:00
|
|
|
JSRegExpStringIterator::kHeaderSize, 0,
|
|
|
|
regexp_string_iterator_prototype, Builtins::kIllegal);
|
2019-04-25 02:39:22 +00:00
|
|
|
regexp_string_iterator_function->shared().set_native(false);
|
|
|
|
native_context()->set_initial_regexp_string_iterator_prototype_map(
|
|
|
|
regexp_string_iterator_function->initial_map());
|
|
|
|
}
|
|
|
|
|
2020-04-16 07:43:59 +00:00
|
|
|
// -- E r r o r
|
|
|
|
InstallError(isolate_, global, factory->Error_string(),
|
|
|
|
Context::ERROR_FUNCTION_INDEX);
|
2015-12-09 07:53:19 +00:00
|
|
|
|
2020-11-12 00:22:12 +00:00
|
|
|
// -- A g g r e g a t e E r r o r
|
|
|
|
InstallError(isolate_, global, factory->AggregateError_string(),
|
|
|
|
Context::AGGREGATE_ERROR_FUNCTION_INDEX,
|
|
|
|
Builtins::kAggregateErrorConstructor, 2, 2);
|
|
|
|
|
2020-04-16 07:43:59 +00:00
|
|
|
// -- E v a l E r r o r
|
|
|
|
InstallError(isolate_, global, factory->EvalError_string(),
|
|
|
|
Context::EVAL_ERROR_FUNCTION_INDEX);
|
2015-12-09 07:53:19 +00:00
|
|
|
|
2020-04-16 07:43:59 +00:00
|
|
|
// -- R a n g e E r r o r
|
|
|
|
InstallError(isolate_, global, factory->RangeError_string(),
|
|
|
|
Context::RANGE_ERROR_FUNCTION_INDEX);
|
2015-12-09 07:53:19 +00:00
|
|
|
|
2020-04-16 07:43:59 +00:00
|
|
|
// -- R e f e r e n c e E r r o r
|
|
|
|
InstallError(isolate_, global, factory->ReferenceError_string(),
|
|
|
|
Context::REFERENCE_ERROR_FUNCTION_INDEX);
|
2015-12-09 07:53:19 +00:00
|
|
|
|
2020-04-16 07:43:59 +00:00
|
|
|
// -- S y n t a x E r r o r
|
|
|
|
InstallError(isolate_, global, factory->SyntaxError_string(),
|
|
|
|
Context::SYNTAX_ERROR_FUNCTION_INDEX);
|
2015-12-09 07:53:19 +00:00
|
|
|
|
2020-04-16 07:43:59 +00:00
|
|
|
// -- T y p e E r r o r
|
|
|
|
InstallError(isolate_, global, factory->TypeError_string(),
|
|
|
|
Context::TYPE_ERROR_FUNCTION_INDEX);
|
2015-12-09 07:53:19 +00:00
|
|
|
|
2020-04-16 07:43:59 +00:00
|
|
|
// -- U R I E r r o r
|
|
|
|
InstallError(isolate_, global, factory->URIError_string(),
|
|
|
|
Context::URI_ERROR_FUNCTION_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-11-19 14:40:05 +00:00
|
|
|
// TODO(ishell): microtask queue pointer will be moved from native context
|
|
|
|
// to the embedder data array so we don't need an empty embedder data array.
|
|
|
|
Handle<EmbedderDataArray> embedder_data = factory->NewEmbedderDataArray(0);
|
|
|
|
native_context()->set_embedder_data(*embedder_data);
|
2015-07-13 09:45:43 +00:00
|
|
|
|
2019-06-26 08:53:17 +00:00
|
|
|
{ // -- g l o b a l T h i s
|
|
|
|
Handle<JSGlobalProxy> global_proxy(native_context()->global_proxy(),
|
|
|
|
isolate_);
|
|
|
|
JSObject::AddProperty(isolate_, global, factory->globalThis_string(),
|
|
|
|
global_proxy, DONT_ENUM);
|
|
|
|
}
|
|
|
|
|
2009-04-24 08:13:09 +00:00
|
|
|
{ // -- J S O N
|
2017-06-15 17:56:35 +00:00
|
|
|
Handle<JSObject> json_object =
|
2019-03-11 19:04:02 +00:00
|
|
|
factory->NewJSObject(isolate_->object_function(), AllocationType::kOld);
|
2018-12-20 01:20:25 +00:00
|
|
|
JSObject::AddProperty(isolate_, global, "JSON", 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);
|
2018-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate_, json_object, "JSON");
|
2015-08-14 15:12:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- M a t h
|
2017-06-15 17:56:35 +00:00
|
|
|
Handle<JSObject> math =
|
2019-03-11 19:04:02 +00:00
|
|
|
factory->NewJSObject(isolate_->object_function(), AllocationType::kOld);
|
2018-12-20 01:20:25 +00:00
|
|
|
JSObject::AddProperty(isolate_, global, "Math", 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)));
|
2018-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate_, math, "Math");
|
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
|
|
|
|
2020-11-11 06:18:31 +00:00
|
|
|
Handle<NativeContext> context(isolate()->native_context());
|
|
|
|
Handle<SharedFunctionInfo> info =
|
|
|
|
factory->NewSharedFunctionInfoForBuiltin(name, Builtins::kIllegal);
|
|
|
|
info->set_language_mode(LanguageMode::kStrict);
|
|
|
|
|
|
|
|
Handle<JSFunction> cons =
|
2020-11-11 07:26:28 +00:00
|
|
|
Factory::JSFunctionBuilder{isolate(), info, context}.Build();
|
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
|
|
|
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<JSObject> console = factory->NewJSObject(cons, AllocationType::kOld);
|
2017-04-18 20:50:30 +00:00
|
|
|
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,
|
2019-04-23 19:39:28 +00:00
|
|
|
0, false, NONE);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "error", Builtins::kConsoleError,
|
2019-04-23 19:39:28 +00:00
|
|
|
0, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "info", Builtins::kConsoleInfo, 0,
|
2017-04-25 22:17:24 +00:00
|
|
|
false, NONE);
|
2019-04-23 19:39:28 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "log", Builtins::kConsoleLog, 0,
|
2017-04-25 22:17:24 +00:00
|
|
|
false, NONE);
|
2019-04-23 19:39:28 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "warn", Builtins::kConsoleWarn, 0,
|
2017-04-25 22:17:24 +00:00
|
|
|
false, NONE);
|
2019-11-07 06:14:31 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "dir", Builtins::kConsoleDir, 0,
|
2017-04-25 22:17:24 +00:00
|
|
|
false, NONE);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "dirxml", Builtins::kConsoleDirXml,
|
2019-04-23 19:39:28 +00:00
|
|
|
0, false, NONE);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "table", Builtins::kConsoleTable,
|
2019-11-07 06:14:31 +00:00
|
|
|
0, false, NONE);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "trace", Builtins::kConsoleTrace,
|
2019-04-23 19:39:28 +00:00
|
|
|
0, false, NONE);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "group", Builtins::kConsoleGroup,
|
2019-04-23 19:39:28 +00:00
|
|
|
0, false, NONE);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "groupCollapsed",
|
2019-04-23 19:39:28 +00:00
|
|
|
Builtins::kConsoleGroupCollapsed, 0, false, NONE);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "groupEnd",
|
2019-04-23 19:39:28 +00:00
|
|
|
Builtins::kConsoleGroupEnd, 0, false, NONE);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "clear", Builtins::kConsoleClear,
|
2019-04-23 19:39:28 +00:00
|
|
|
0, false, NONE);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "count", Builtins::kConsoleCount,
|
2019-04-23 19:39:28 +00:00
|
|
|
0, false, NONE);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "countReset",
|
2019-04-23 19:39:28 +00:00
|
|
|
Builtins::kConsoleCountReset, 0, false, NONE);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "assert",
|
2019-04-23 19:39:28 +00:00
|
|
|
Builtins::kFastConsoleAssert, 0, false, NONE);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "profile",
|
2019-04-23 19:39:28 +00:00
|
|
|
Builtins::kConsoleProfile, 0, false, NONE);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "profileEnd",
|
2019-04-23 19:39:28 +00:00
|
|
|
Builtins::kConsoleProfileEnd, 0, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "time", Builtins::kConsoleTime, 0,
|
2017-04-25 22:17:24 +00:00
|
|
|
false, NONE);
|
2018-09-28 15:18:34 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "timeLog",
|
2019-04-23 19:39:28 +00:00
|
|
|
Builtins::kConsoleTimeLog, 0, false, NONE);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "timeEnd",
|
2019-04-23 19:39:28 +00:00
|
|
|
Builtins::kConsoleTimeEnd, 0, false, NONE);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "timeStamp",
|
2019-04-23 19:39:28 +00:00
|
|
|
Builtins::kConsoleTimeStamp, 0, false, NONE);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, console, "context",
|
|
|
|
Builtins::kConsoleContext, 1, true, NONE);
|
2018-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate_, console, "Object");
|
2017-04-18 20:50:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-21 08:35:12 +00:00
|
|
|
#ifdef V8_INTL_SUPPORT
|
2016-12-27 17:10:00 +00:00
|
|
|
{ // -- I n t l
|
2017-06-15 17:56:35 +00:00
|
|
|
Handle<JSObject> intl =
|
2019-03-11 19:04:02 +00:00
|
|
|
factory->NewJSObject(isolate_->object_function(), AllocationType::kOld);
|
2018-12-20 01:20:25 +00:00
|
|
|
JSObject::AddProperty(isolate_, global, "Intl", intl, DONT_ENUM);
|
2016-12-27 17:10:00 +00:00
|
|
|
|
2020-07-30 23:31:27 +00:00
|
|
|
// ecma402 #sec-Intl-toStringTag
|
|
|
|
// The initial value of the @@toStringTag property is the string value
|
|
|
|
// *"Intl"*.
|
|
|
|
InstallToStringTag(isolate_, intl, "Intl");
|
|
|
|
|
2018-10-18 18:29:51 +00:00
|
|
|
SimpleInstallFunction(isolate(), intl, "getCanonicalLocales",
|
|
|
|
Builtins::kIntlGetCanonicalLocales, 1, false);
|
|
|
|
|
2019-02-08 08:14:07 +00:00
|
|
|
{ // -- D a t e T i m e F o r m a t
|
2017-06-30 08:54:01 +00:00
|
|
|
Handle<JSFunction> date_time_format_constructor = InstallFunction(
|
2019-10-09 16:55:52 +00:00
|
|
|
isolate_, intl, "DateTimeFormat", JS_DATE_TIME_FORMAT_TYPE,
|
2019-11-15 20:37:49 +00:00
|
|
|
JSDateTimeFormat::kHeaderSize, 0, factory->the_hole_value(),
|
2018-09-11 09:57:14 +00:00
|
|
|
Builtins::kDateTimeFormatConstructor);
|
|
|
|
date_time_format_constructor->shared().set_length(0);
|
|
|
|
date_time_format_constructor->shared().DontAdaptArguments();
|
|
|
|
InstallWithIntrinsicDefaultProto(
|
|
|
|
isolate_, date_time_format_constructor,
|
|
|
|
Context::INTL_DATE_TIME_FORMAT_FUNCTION_INDEX);
|
|
|
|
|
2018-08-27 16:52:31 +00:00
|
|
|
SimpleInstallFunction(
|
|
|
|
isolate(), date_time_format_constructor, "supportedLocalesOf",
|
|
|
|
Builtins::kDateTimeFormatSupportedLocalesOf, 1, false);
|
|
|
|
|
2017-06-30 08:54:01 +00:00
|
|
|
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
|
|
|
|
2020-05-21 21:56:32 +00:00
|
|
|
InstallToStringTag(isolate_, prototype, "Intl.DateTimeFormat");
|
2018-05-03 00:03:56 +00:00
|
|
|
|
2018-09-24 17:50:39 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "resolvedOptions",
|
|
|
|
Builtins::kDateTimeFormatPrototypeResolvedOptions,
|
|
|
|
0, false);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "formatToParts",
|
2018-05-03 00:03:56 +00:00
|
|
|
Builtins::kDateTimeFormatPrototypeFormatToParts, 1,
|
|
|
|
false);
|
2018-08-18 20:23:13 +00:00
|
|
|
|
2019-03-11 21:40:39 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->format_string(),
|
2018-08-18 20:23:13 +00:00
|
|
|
Builtins::kDateTimeFormatPrototypeFormat, false);
|
2019-09-12 19:53:30 +00:00
|
|
|
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "formatRange",
|
|
|
|
Builtins::kDateTimeFormatPrototypeFormatRange, 2,
|
|
|
|
false);
|
|
|
|
SimpleInstallFunction(
|
|
|
|
isolate_, prototype, "formatRangeToParts",
|
|
|
|
Builtins::kDateTimeFormatPrototypeFormatRangeToParts, 2, false);
|
2017-06-30 08:54:01 +00:00
|
|
|
}
|
|
|
|
|
2019-02-08 08:14:07 +00:00
|
|
|
{ // -- N u m b e r F o r m a t
|
2019-11-15 20:37:49 +00:00
|
|
|
Handle<JSFunction> number_format_constructor = InstallFunction(
|
|
|
|
isolate_, intl, "NumberFormat", JS_NUMBER_FORMAT_TYPE,
|
|
|
|
JSNumberFormat::kHeaderSize, 0, factory->the_hole_value(),
|
|
|
|
Builtins::kNumberFormatConstructor);
|
2018-09-04 18:32:51 +00:00
|
|
|
number_format_constructor->shared().set_length(0);
|
|
|
|
number_format_constructor->shared().DontAdaptArguments();
|
|
|
|
InstallWithIntrinsicDefaultProto(
|
|
|
|
isolate_, number_format_constructor,
|
|
|
|
Context::INTL_NUMBER_FORMAT_FUNCTION_INDEX);
|
2017-06-30 08:54:01 +00:00
|
|
|
|
2018-08-27 16:52:31 +00:00
|
|
|
SimpleInstallFunction(
|
|
|
|
isolate(), number_format_constructor, "supportedLocalesOf",
|
|
|
|
Builtins::kNumberFormatSupportedLocalesOf, 1, false);
|
|
|
|
|
2017-06-30 08:54:01 +00:00
|
|
|
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
|
|
|
|
2020-05-21 21:56:32 +00:00
|
|
|
InstallToStringTag(isolate_, prototype, "Intl.NumberFormat");
|
2018-04-27 19:09:03 +00:00
|
|
|
|
2018-09-11 19:14:49 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "resolvedOptions",
|
|
|
|
Builtins::kNumberFormatPrototypeResolvedOptions, 0,
|
|
|
|
false);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "formatToParts",
|
2018-05-03 00:03:56 +00:00
|
|
|
Builtins::kNumberFormatPrototypeFormatToParts, 1,
|
|
|
|
false);
|
2019-03-11 21:40:39 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->format_string(),
|
2018-07-09 10:36:42 +00:00
|
|
|
Builtins::kNumberFormatPrototypeFormatNumber, false);
|
2017-06-30 08:54:01 +00:00
|
|
|
}
|
|
|
|
|
2019-02-08 08:14:07 +00:00
|
|
|
{ // -- C o l l a t o r
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<JSFunction> collator_constructor = InstallFunction(
|
2019-11-15 20:37:49 +00:00
|
|
|
isolate_, intl, "Collator", JS_COLLATOR_TYPE, JSCollator::kHeaderSize,
|
|
|
|
0, factory->the_hole_value(), Builtins::kCollatorConstructor);
|
2018-08-08 09:23:07 +00:00
|
|
|
collator_constructor->shared().DontAdaptArguments();
|
2018-11-02 06:22:02 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate_, collator_constructor,
|
|
|
|
Context::INTL_COLLATOR_FUNCTION_INDEX);
|
2017-06-30 08:54:01 +00:00
|
|
|
|
2018-08-27 16:52:31 +00:00
|
|
|
SimpleInstallFunction(isolate(), collator_constructor,
|
|
|
|
"supportedLocalesOf",
|
|
|
|
Builtins::kCollatorSupportedLocalesOf, 1, false);
|
|
|
|
|
2017-06-30 08:54:01 +00:00
|
|
|
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
|
|
|
|
2020-05-21 21:56:32 +00:00
|
|
|
InstallToStringTag(isolate_, prototype, "Intl.Collator");
|
2018-08-14 16:19:36 +00:00
|
|
|
|
2018-09-10 21:20:14 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "resolvedOptions",
|
|
|
|
Builtins::kCollatorPrototypeResolvedOptions, 0,
|
|
|
|
false);
|
|
|
|
|
2019-03-11 21:40:39 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->compare_string(),
|
2018-08-14 16:19:36 +00:00
|
|
|
Builtins::kCollatorPrototypeCompare, false);
|
2017-06-30 08:54:01 +00:00
|
|
|
}
|
|
|
|
|
2019-02-08 08:14:07 +00:00
|
|
|
{ // -- V 8 B r e a k I t e r a t o r
|
2018-09-05 02:17:38 +00:00
|
|
|
Handle<JSFunction> v8_break_iterator_constructor = InstallFunction(
|
2019-10-09 16:55:52 +00:00
|
|
|
isolate_, intl, "v8BreakIterator", JS_V8_BREAK_ITERATOR_TYPE,
|
2019-11-15 20:37:49 +00:00
|
|
|
JSV8BreakIterator::kHeaderSize, 0, factory->the_hole_value(),
|
2018-09-05 16:25:38 +00:00
|
|
|
Builtins::kV8BreakIteratorConstructor);
|
2018-09-05 02:17:38 +00:00
|
|
|
v8_break_iterator_constructor->shared().DontAdaptArguments();
|
2017-06-30 08:54:01 +00:00
|
|
|
|
2018-08-27 16:52:31 +00:00
|
|
|
SimpleInstallFunction(
|
2018-09-05 02:17:38 +00:00
|
|
|
isolate_, v8_break_iterator_constructor, "supportedLocalesOf",
|
2018-09-05 16:25:38 +00:00
|
|
|
Builtins::kV8BreakIteratorSupportedLocalesOf, 1, false);
|
2018-08-27 16:52:31 +00:00
|
|
|
|
2017-06-30 08:54:01 +00:00
|
|
|
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
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate_, prototype, factory->Object_string());
|
2018-08-25 10:39:01 +00:00
|
|
|
|
2018-09-05 02:17:38 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "resolvedOptions",
|
2018-09-05 16:25:38 +00:00
|
|
|
Builtins::kV8BreakIteratorPrototypeResolvedOptions,
|
|
|
|
0, false);
|
2018-09-05 02:17:38 +00:00
|
|
|
|
2019-03-11 21:40:39 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->adoptText_string(),
|
2018-09-05 16:25:38 +00:00
|
|
|
Builtins::kV8BreakIteratorPrototypeAdoptText, false);
|
2018-08-25 10:39:01 +00:00
|
|
|
|
2019-03-11 21:40:39 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->first_string(),
|
2018-09-05 16:25:38 +00:00
|
|
|
Builtins::kV8BreakIteratorPrototypeFirst, false);
|
2018-08-28 07:28:31 +00:00
|
|
|
|
2019-03-11 21:40:39 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->next_string(),
|
2018-09-05 16:25:38 +00:00
|
|
|
Builtins::kV8BreakIteratorPrototypeNext, false);
|
2018-08-28 13:37:00 +00:00
|
|
|
|
2019-03-11 21:40:39 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->current_string(),
|
2018-09-05 16:25:38 +00:00
|
|
|
Builtins::kV8BreakIteratorPrototypeCurrent, false);
|
2018-08-28 20:09:39 +00:00
|
|
|
|
2019-03-11 21:40:39 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->breakType_string(),
|
2018-09-05 16:25:38 +00:00
|
|
|
Builtins::kV8BreakIteratorPrototypeBreakType, false);
|
2017-06-30 08:54:01 +00:00
|
|
|
}
|
2018-04-27 19:09:03 +00:00
|
|
|
|
2019-02-08 08:14:07 +00:00
|
|
|
{ // -- P l u r a l R u l e s
|
2019-11-15 20:37:49 +00:00
|
|
|
Handle<JSFunction> plural_rules_constructor = InstallFunction(
|
|
|
|
isolate_, intl, "PluralRules", JS_PLURAL_RULES_TYPE,
|
|
|
|
JSPluralRules::kHeaderSize, 0, factory->the_hole_value(),
|
|
|
|
Builtins::kPluralRulesConstructor);
|
2018-08-06 09:31:26 +00:00
|
|
|
plural_rules_constructor->shared().DontAdaptArguments();
|
2019-09-12 19:47:30 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(
|
|
|
|
isolate_, plural_rules_constructor,
|
|
|
|
Context::INTL_PLURAL_RULES_FUNCTION_INDEX);
|
2018-04-27 19:09:03 +00:00
|
|
|
|
2018-08-27 16:52:31 +00:00
|
|
|
SimpleInstallFunction(isolate(), plural_rules_constructor,
|
|
|
|
"supportedLocalesOf",
|
|
|
|
Builtins::kPluralRulesSupportedLocalesOf, 1, false);
|
|
|
|
|
2018-04-27 19:09:03 +00:00
|
|
|
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
|
|
|
|
2020-05-21 21:56:32 +00:00
|
|
|
InstallToStringTag(isolate_, prototype, "Intl.PluralRules");
|
2018-09-05 20:05:32 +00:00
|
|
|
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "resolvedOptions",
|
|
|
|
Builtins::kPluralRulesPrototypeResolvedOptions, 0,
|
|
|
|
false);
|
2018-09-12 22:55:01 +00:00
|
|
|
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "select",
|
|
|
|
Builtins::kPluralRulesPrototypeSelect, 1, false);
|
2018-04-27 19:09:03 +00:00
|
|
|
}
|
2019-02-08 08:14:07 +00:00
|
|
|
|
2019-09-12 19:47:30 +00:00
|
|
|
{ // -- R e l a t i v e T i m e F o r m a t
|
2019-02-08 08:14:07 +00:00
|
|
|
Handle<JSFunction> relative_time_format_fun = InstallFunction(
|
2019-10-09 16:55:52 +00:00
|
|
|
isolate(), intl, "RelativeTimeFormat", JS_RELATIVE_TIME_FORMAT_TYPE,
|
2019-11-15 20:37:49 +00:00
|
|
|
JSRelativeTimeFormat::kHeaderSize, 0, factory->the_hole_value(),
|
2019-10-09 16:55:52 +00:00
|
|
|
Builtins::kRelativeTimeFormatConstructor);
|
2019-02-08 08:14:07 +00:00
|
|
|
relative_time_format_fun->shared().set_length(0);
|
|
|
|
relative_time_format_fun->shared().DontAdaptArguments();
|
2019-09-12 19:47:30 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(
|
|
|
|
isolate_, relative_time_format_fun,
|
|
|
|
Context::INTL_RELATIVE_TIME_FORMAT_FUNCTION_INDEX);
|
2019-02-08 08:14:07 +00:00
|
|
|
|
|
|
|
SimpleInstallFunction(
|
|
|
|
isolate(), relative_time_format_fun, "supportedLocalesOf",
|
|
|
|
Builtins::kRelativeTimeFormatSupportedLocalesOf, 1, false);
|
|
|
|
|
|
|
|
// Setup %RelativeTimeFormatPrototype%.
|
|
|
|
Handle<JSObject> prototype(
|
|
|
|
JSObject::cast(relative_time_format_fun->instance_prototype()),
|
|
|
|
isolate());
|
|
|
|
|
|
|
|
InstallToStringTag(isolate(), prototype, "Intl.RelativeTimeFormat");
|
|
|
|
|
|
|
|
SimpleInstallFunction(
|
|
|
|
isolate(), prototype, "resolvedOptions",
|
|
|
|
Builtins::kRelativeTimeFormatPrototypeResolvedOptions, 0, false);
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "format",
|
|
|
|
Builtins::kRelativeTimeFormatPrototypeFormat, 2,
|
|
|
|
false);
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "formatToParts",
|
|
|
|
Builtins::kRelativeTimeFormatPrototypeFormatToParts,
|
|
|
|
2, false);
|
|
|
|
}
|
2019-02-14 21:16:40 +00:00
|
|
|
|
|
|
|
{ // -- L i s t F o r m a t
|
2019-11-15 20:37:49 +00:00
|
|
|
Handle<JSFunction> list_format_fun = InstallFunction(
|
|
|
|
isolate(), intl, "ListFormat", JS_LIST_FORMAT_TYPE,
|
|
|
|
JSListFormat::kHeaderSize, 0, factory->the_hole_value(),
|
|
|
|
Builtins::kListFormatConstructor);
|
2019-02-14 21:16:40 +00:00
|
|
|
list_format_fun->shared().set_length(0);
|
|
|
|
list_format_fun->shared().DontAdaptArguments();
|
2019-09-12 19:47:30 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(
|
|
|
|
isolate_, list_format_fun, Context::INTL_LIST_FORMAT_FUNCTION_INDEX);
|
2019-02-14 21:16:40 +00:00
|
|
|
|
|
|
|
SimpleInstallFunction(isolate(), list_format_fun, "supportedLocalesOf",
|
|
|
|
Builtins::kListFormatSupportedLocalesOf, 1, false);
|
|
|
|
|
|
|
|
// Setup %ListFormatPrototype%.
|
|
|
|
Handle<JSObject> prototype(
|
|
|
|
JSObject::cast(list_format_fun->instance_prototype()), isolate());
|
|
|
|
|
|
|
|
InstallToStringTag(isolate(), prototype, "Intl.ListFormat");
|
|
|
|
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "resolvedOptions",
|
|
|
|
Builtins::kListFormatPrototypeResolvedOptions, 0,
|
|
|
|
false);
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "format",
|
|
|
|
Builtins::kListFormatPrototypeFormat, 1, false);
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "formatToParts",
|
|
|
|
Builtins::kListFormatPrototypeFormatToParts, 1,
|
|
|
|
false);
|
|
|
|
}
|
2019-05-10 23:26:36 +00:00
|
|
|
|
|
|
|
{ // -- L o c a l e
|
|
|
|
Handle<JSFunction> locale_fun = InstallFunction(
|
2019-11-15 20:37:49 +00:00
|
|
|
isolate(), intl, "Locale", JS_LOCALE_TYPE, JSLocale::kHeaderSize, 0,
|
2019-05-10 23:26:36 +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%.
|
|
|
|
Handle<JSObject> prototype(
|
|
|
|
JSObject::cast(locale_fun->instance_prototype()), isolate());
|
|
|
|
|
|
|
|
InstallToStringTag(isolate(), prototype, "Intl.Locale");
|
|
|
|
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "toString",
|
|
|
|
Builtins::kLocalePrototypeToString, 0, false);
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "maximize",
|
|
|
|
Builtins::kLocalePrototypeMaximize, 0, false);
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "minimize",
|
|
|
|
Builtins::kLocalePrototypeMinimize, 0, false);
|
|
|
|
// Base locale getters.
|
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->language_string(),
|
|
|
|
Builtins::kLocalePrototypeLanguage, true);
|
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->script_string(),
|
|
|
|
Builtins::kLocalePrototypeScript, true);
|
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->region_string(),
|
|
|
|
Builtins::kLocalePrototypeRegion, true);
|
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->baseName_string(),
|
|
|
|
Builtins::kLocalePrototypeBaseName, true);
|
|
|
|
// Unicode extension getters.
|
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->calendar_string(),
|
|
|
|
Builtins::kLocalePrototypeCalendar, true);
|
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->caseFirst_string(),
|
|
|
|
Builtins::kLocalePrototypeCaseFirst, true);
|
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->collation_string(),
|
|
|
|
Builtins::kLocalePrototypeCollation, true);
|
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->hourCycle_string(),
|
|
|
|
Builtins::kLocalePrototypeHourCycle, true);
|
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->numeric_string(),
|
|
|
|
Builtins::kLocalePrototypeNumeric, true);
|
|
|
|
SimpleInstallGetter(isolate(), prototype,
|
|
|
|
factory->numberingSystem_string(),
|
|
|
|
Builtins::kLocalePrototypeNumberingSystem, true);
|
|
|
|
}
|
2020-04-25 01:11:14 +00:00
|
|
|
|
|
|
|
{ // -- D i s p l a y N a m e s
|
|
|
|
Handle<JSFunction> display_names_fun = InstallFunction(
|
|
|
|
isolate(), intl, "DisplayNames", JS_DISPLAY_NAMES_TYPE,
|
|
|
|
JSDisplayNames::kHeaderSize, 0, factory->the_hole_value(),
|
|
|
|
Builtins::kDisplayNamesConstructor);
|
2020-07-20 23:17:13 +00:00
|
|
|
display_names_fun->shared().set_length(2);
|
2020-04-25 01:11:14 +00:00
|
|
|
display_names_fun->shared().DontAdaptArguments();
|
|
|
|
InstallWithIntrinsicDefaultProto(
|
|
|
|
isolate(), display_names_fun,
|
|
|
|
Context::INTL_DISPLAY_NAMES_FUNCTION_INDEX);
|
|
|
|
|
|
|
|
SimpleInstallFunction(isolate(), display_names_fun, "supportedLocalesOf",
|
|
|
|
Builtins::kDisplayNamesSupportedLocalesOf, 1,
|
|
|
|
false);
|
|
|
|
|
|
|
|
{
|
|
|
|
// Setup %DisplayNamesPrototype%.
|
|
|
|
Handle<JSObject> prototype(
|
|
|
|
JSObject::cast(display_names_fun->instance_prototype()), isolate());
|
|
|
|
|
|
|
|
InstallToStringTag(isolate(), prototype, "Intl.DisplayNames");
|
|
|
|
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "resolvedOptions",
|
|
|
|
Builtins::kDisplayNamesPrototypeResolvedOptions,
|
|
|
|
0, false);
|
|
|
|
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "of",
|
|
|
|
Builtins::kDisplayNamesPrototypeOf, 1, false);
|
|
|
|
}
|
|
|
|
}
|
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_,
|
2018-10-05 14:32:24 +00:00
|
|
|
factory->InternalizeUtf8String(
|
2017-04-06 13:09:38 +00:00
|
|
|
"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 =
|
2019-03-11 19:04:02 +00:00
|
|
|
factory->NewJSObject(isolate_->object_function(), AllocationType::kOld);
|
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);
|
2018-07-18 18:19:55 +00:00
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "notify",
|
2018-09-19 19:23:29 +00:00
|
|
|
Builtins::kAtomicsNotify, 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-11-22 16:02:20 +00:00
|
|
|
JS_TYPED_ARRAY_TYPE, JSTypedArray::kHeaderSize, 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(),
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kTypedArrayPrototypeByteLength, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->byte_offset_string(),
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kTypedArrayPrototypeByteOffset, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->length_string(),
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kTypedArrayPrototypeLength, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->to_string_tag_symbol(),
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kTypedArrayPrototypeToStringTag, true);
|
2016-10-18 02:42:42 +00:00
|
|
|
|
|
|
|
// Install "keys", "values" and "entries" methods on the {prototype}.
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate_, prototype, "entries",
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kTypedArrayPrototypeEntries, 0,
|
|
|
|
true);
|
2017-06-30 13:54:24 +00:00
|
|
|
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate_, prototype, "keys",
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kTypedArrayPrototypeKeys, 0, true);
|
2017-06-30 13:54:24 +00:00
|
|
|
|
2018-11-23 14:10:11 +00:00
|
|
|
Handle<JSFunction> values = InstallFunctionWithBuiltinId(
|
2018-05-31 14:14:48 +00:00
|
|
|
isolate_, prototype, "values", Builtins::kTypedArrayPrototypeValues, 0,
|
2019-03-07 00:27:04 +00:00
|
|
|
true);
|
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-12-11 15:27:31 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "join",
|
|
|
|
Builtins::kTypedArrayPrototypeJoin, 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);
|
2018-12-11 15:27:31 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toLocaleString",
|
|
|
|
Builtins::kTypedArrayPrototypeToLocaleString, 0,
|
|
|
|
false);
|
|
|
|
JSObject::AddProperty(isolate_, prototype, factory->toString_string(),
|
|
|
|
array_prototype_to_string_fun, DONT_ENUM);
|
2016-06-08 07:40:11 +00:00
|
|
|
}
|
|
|
|
|
2019-05-16 10:26:57 +00:00
|
|
|
{// -- T y p e d A r r a y s
|
2018-07-30 15:17:48 +00:00
|
|
|
#define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype) \
|
2015-12-07 16:35:03 +00:00
|
|
|
{ \
|
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
|
|
|
}
|
2019-05-16 10:26:57 +00:00
|
|
|
TYPED_ARRAYS(INSTALL_TYPED_ARRAY)
|
2014-01-24 16:01:15 +00:00
|
|
|
#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
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate_, prototype, "DataView");
|
2016-06-08 07:40:11 +00:00
|
|
|
|
|
|
|
// Install the "buffer", "byteOffset" and "byteLength" getters
|
|
|
|
// on the {prototype}.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->buffer_string(),
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kDataViewPrototypeGetBuffer, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->byte_length_string(),
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kDataViewPrototypeGetByteLength, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->byte_offset_string(),
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kDataViewPrototypeGetByteOffset, false);
|
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);
|
2018-10-01 09:48:52 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getBigInt64",
|
|
|
|
Builtins::kDataViewPrototypeGetBigInt64, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "setBigInt64",
|
|
|
|
Builtins::kDataViewPrototypeSetBigInt64, 2, false);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "getBigUint64",
|
|
|
|
Builtins::kDataViewPrototypeGetBigUint64, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "setBigUint64",
|
|
|
|
Builtins::kDataViewPrototypeSetBigUint64, 2, false);
|
2013-08-20 13:55:52 +00:00
|
|
|
}
|
|
|
|
|
2015-05-26 17:36:48 +00:00
|
|
|
{ // -- M a p
|
2019-11-15 20:37:49 +00:00
|
|
|
Handle<JSFunction> js_map_fun = InstallFunction(
|
|
|
|
isolate_, global, "Map", JS_MAP_TYPE, JSMap::kHeaderSize, 0,
|
|
|
|
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
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate_, prototype, factory->Map_string());
|
2017-05-23 09:06:51 +00:00
|
|
|
|
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);
|
2018-10-24 05:15:20 +00:00
|
|
|
// Check that index of "set" function in JSCollection is correct.
|
|
|
|
DCHECK_EQ(JSCollection::kAddFunctionDescriptorIndex,
|
2019-10-11 13:55:05 +00:00
|
|
|
prototype->map().LastAdded().as_int());
|
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);
|
2019-03-07 00:27:04 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype,
|
|
|
|
factory->InternalizeUtf8String("size"),
|
|
|
|
Builtins::kMapPrototypeGetSize, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
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);
|
2020-05-04 11:21:32 +00:00
|
|
|
|
|
|
|
DCHECK(js_map_fun->HasFastProperties());
|
|
|
|
|
|
|
|
native_context()->set_js_map_map(js_map_fun->initial_map());
|
2015-05-26 17:36:48 +00:00
|
|
|
}
|
2014-08-05 19:37:32 +00:00
|
|
|
|
2018-10-01 09:48:52 +00:00
|
|
|
{ // -- B i g I n t
|
2019-11-15 20:37:49 +00:00
|
|
|
Handle<JSFunction> bigint_fun = InstallFunction(
|
|
|
|
isolate_, global, "BigInt", JS_PRIMITIVE_WRAPPER_TYPE,
|
|
|
|
JSPrimitiveWrapper::kHeaderSize, 0, factory->the_hole_value(),
|
|
|
|
Builtins::kBigIntConstructor);
|
2018-10-01 09:48:52 +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)
|
|
|
|
SimpleInstallFunction(isolate_, bigint_fun, "asUintN",
|
|
|
|
Builtins::kBigIntAsUintN, 2, false);
|
|
|
|
// asIntN(bits, bigint)
|
|
|
|
SimpleInstallFunction(isolate_, bigint_fun, "asIntN",
|
|
|
|
Builtins::kBigIntAsIntN, 2, false);
|
|
|
|
|
|
|
|
// Set up the %BigIntPrototype%.
|
|
|
|
Handle<JSObject> prototype(JSObject::cast(bigint_fun->instance_prototype()),
|
|
|
|
isolate_);
|
|
|
|
JSFunction::SetPrototype(bigint_fun, prototype);
|
|
|
|
|
|
|
|
// Install the properties of the BigInt.prototype.
|
|
|
|
// "constructor" is created implicitly by InstallFunction() above.
|
|
|
|
// toLocaleString([reserved1 [, reserved2]])
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "toLocaleString",
|
|
|
|
Builtins::kBigIntPrototypeToLocaleString, 0, false);
|
|
|
|
// toString([radix])
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "toString",
|
|
|
|
Builtins::kBigIntPrototypeToString, 0, false);
|
|
|
|
// valueOf()
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "valueOf",
|
|
|
|
Builtins::kBigIntPrototypeValueOf, 0, false);
|
|
|
|
// @@toStringTag
|
2018-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate_, prototype, factory->BigInt_string());
|
2018-10-01 09:48:52 +00:00
|
|
|
}
|
|
|
|
|
2015-05-26 17:36:48 +00:00
|
|
|
{ // -- S e t
|
2019-11-15 20:37:49 +00:00
|
|
|
Handle<JSFunction> js_set_fun = InstallFunction(
|
|
|
|
isolate_, global, "Set", JS_SET_TYPE, JSSet::kHeaderSize, 0,
|
|
|
|
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
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate_, prototype, factory->Set_string());
|
2017-06-07 14:22:44 +00:00
|
|
|
|
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);
|
2018-10-24 05:15:20 +00:00
|
|
|
// Check that index of "add" function in JSCollection is correct.
|
|
|
|
DCHECK_EQ(JSCollection::kAddFunctionDescriptorIndex,
|
2019-10-11 13:55:05 +00:00
|
|
|
prototype->map().LastAdded().as_int());
|
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);
|
2019-03-07 00:27:04 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype,
|
|
|
|
factory->InternalizeUtf8String("size"),
|
|
|
|
Builtins::kSetPrototypeGetSize, true);
|
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-10-10 13:29:32 +00:00
|
|
|
native_context()->set_initial_set_prototype(*prototype);
|
2018-01-18 14:53:18 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
InstallSpeciesGetter(isolate_, js_set_fun);
|
2020-05-04 11:21:32 +00:00
|
|
|
|
|
|
|
DCHECK(js_set_fun->HasFastProperties());
|
|
|
|
|
|
|
|
native_context()->set_js_set_map(js_set_fun->initial_map());
|
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);
|
2019-09-17 11:24:41 +00:00
|
|
|
map->SetConstructor(native_context()->object_function());
|
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());
|
2018-11-29 12:03:40 +00:00
|
|
|
map->AppendDescriptor(isolate(), &d);
|
2016-10-13 13:34:50 +00:00
|
|
|
}
|
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
|
2019-05-14 13:17:42 +00:00
|
|
|
// Setup the map for IterResultObjects created from builtins in such a
|
|
|
|
// way that it's exactly the same map as the one produced by object
|
|
|
|
// literals in the form `{value, done}`. This way we have better sharing
|
|
|
|
// of maps (i.e. less polymorphism) and also make it possible to hit the
|
|
|
|
// fast-paths in various builtins (i.e. promises and collections) with
|
|
|
|
// user defined iterators.
|
|
|
|
Handle<Map> map = factory->ObjectLiteralMapFromCache(native_context(), 2);
|
|
|
|
|
|
|
|
// value
|
|
|
|
map = Map::CopyWithField(isolate(), map, factory->value_string(),
|
|
|
|
FieldType::Any(isolate()), NONE,
|
|
|
|
PropertyConstness::kConst,
|
|
|
|
Representation::Tagged(), INSERT_TRANSITION)
|
|
|
|
.ToHandleChecked();
|
|
|
|
|
|
|
|
// done
|
2020-11-12 12:54:53 +00:00
|
|
|
// TODO(ishell): Consider using Representation::HeapObject() here and rely
|
|
|
|
// on the inplace update logic to take care of the case where someone ever
|
|
|
|
// stores a Smi into the done field. The logic works fine but in --jitless
|
|
|
|
// mode FLAG_track_heap_object_fields is off and the logic doesn't handle
|
|
|
|
// generalizations of HeapObject representation properly.
|
2019-05-14 13:17:42 +00:00
|
|
|
map = Map::CopyWithField(isolate(), map, factory->done_string(),
|
|
|
|
FieldType::Any(isolate()), NONE,
|
|
|
|
PropertyConstness::kConst,
|
|
|
|
Representation::Tagged(), INSERT_TRANSITION)
|
|
|
|
.ToHandleChecked();
|
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(
|
2019-11-15 20:37:49 +00:00
|
|
|
isolate_, global, "WeakMap", JS_WEAK_MAP_TYPE, JSWeakMap::kHeaderSize,
|
|
|
|
0, 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-09-14 02:10:39 +00:00
|
|
|
Handle<JSFunction> weakmap_get = SimpleInstallFunction(
|
|
|
|
isolate_, prototype, "get", Builtins::kWeakMapGet, 1, true);
|
|
|
|
native_context()->set_weakmap_get(*weakmap_get);
|
2018-10-24 05:15:20 +00:00
|
|
|
|
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-10-24 05:15:20 +00:00
|
|
|
// Check that index of "set" function in JSWeakCollection is correct.
|
|
|
|
DCHECK_EQ(JSWeakCollection::kAddFunctionDescriptorIndex,
|
2019-10-11 13:55:05 +00:00
|
|
|
prototype->map().LastAdded().as_int());
|
2018-10-24 05:15:20 +00:00
|
|
|
|
2018-01-18 14:53:18 +00:00
|
|
|
native_context()->set_weakmap_set(*weakmap_set);
|
2019-03-07 00:27:04 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "has",
|
|
|
|
Builtins::kWeakMapPrototypeHas, 1, true);
|
2017-07-17 06:44:47 +00:00
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate_, prototype, "WeakMap");
|
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(
|
2019-11-15 20:37:49 +00:00
|
|
|
isolate_, global, "WeakSet", JS_WEAK_SET_TYPE, JSWeakSet::kHeaderSize,
|
|
|
|
0, 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);
|
2019-03-07 00:27:04 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "has",
|
|
|
|
Builtins::kWeakSetPrototypeHas, 1, true);
|
2018-10-24 05:15:20 +00:00
|
|
|
|
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-10-24 05:15:20 +00:00
|
|
|
// Check that index of "add" function in JSWeakCollection is correct.
|
|
|
|
DCHECK_EQ(JSWeakCollection::kAddFunctionDescriptorIndex,
|
2019-10-11 13:55:05 +00:00
|
|
|
prototype->map().LastAdded().as_int());
|
2018-10-24 05:15:20 +00:00
|
|
|
|
2018-01-18 14:53:18 +00:00
|
|
|
native_context()->set_weakset_add(*weakset_add);
|
2017-07-17 08:18:14 +00:00
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate_, prototype,
|
|
|
|
factory->InternalizeUtf8String("WeakSet"));
|
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();
|
2020-11-11 06:18:31 +00:00
|
|
|
Handle<JSFunction> proxy_function = CreateFunctionForBuiltin(
|
|
|
|
isolate(), name, proxy_function_map, Builtins::kProxyConstructor);
|
2016-03-21 19:39:16 +00:00
|
|
|
|
2018-08-02 08:22:11 +00:00
|
|
|
isolate_->proxy_map()->SetConstructor(*proxy_function);
|
|
|
|
|
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-11-23 14:10:11 +00:00
|
|
|
JSObject::AddProperty(isolate_, global, name, proxy_function, DONT_ENUM);
|
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);
|
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 =
|
2019-03-11 19:04:02 +00:00
|
|
|
factory->NewJSObject(isolate_->object_function(), AllocationType::kOld);
|
2018-06-19 09:00:37 +00:00
|
|
|
JSObject::AddProperty(isolate_, global, reflect_string, reflect, DONT_ENUM);
|
2020-07-30 19:14:25 +00:00
|
|
|
InstallToStringTag(isolate_, reflect, reflect_string);
|
2016-03-21 19:39:16 +00:00
|
|
|
|
2020-05-06 08:59:46 +00:00
|
|
|
SimpleInstallFunction(isolate_, reflect, "defineProperty",
|
|
|
|
Builtins::kReflectDefineProperty, 3, true);
|
2016-03-21 19:39:16 +00:00
|
|
|
|
2020-05-06 08:59:46 +00:00
|
|
|
SimpleInstallFunction(isolate_, reflect, "deleteProperty",
|
|
|
|
Builtins::kReflectDeleteProperty, 2, true);
|
2016-03-21 19:39:16 +00:00
|
|
|
|
2018-11-23 09:55:50 +00:00
|
|
|
Handle<JSFunction> apply = SimpleInstallFunction(
|
|
|
|
isolate_, reflect, "apply", Builtins::kReflectApply, 3, false);
|
2016-03-21 19:39:16 +00:00
|
|
|
native_context()->set_reflect_apply(*apply);
|
|
|
|
|
2018-11-23 09:55:50 +00:00
|
|
|
Handle<JSFunction> construct = SimpleInstallFunction(
|
|
|
|
isolate_, reflect, "construct", Builtins::kReflectConstruct, 2, false);
|
2016-03-21 19:39:16 +00:00
|
|
|
native_context()->set_reflect_construct(*construct);
|
|
|
|
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate_, reflect, "get", Builtins::kReflectGet, 2,
|
|
|
|
false);
|
|
|
|
SimpleInstallFunction(isolate_, reflect, "getOwnPropertyDescriptor",
|
2016-03-21 19:39:16 +00:00
|
|
|
Builtins::kReflectGetOwnPropertyDescriptor, 2, true);
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate_, reflect, "getPrototypeOf",
|
2016-03-21 19:39:16 +00:00
|
|
|
Builtins::kReflectGetPrototypeOf, 1, true);
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate_, reflect, "has", Builtins::kReflectHas, 2,
|
|
|
|
true);
|
|
|
|
SimpleInstallFunction(isolate_, reflect, "isExtensible",
|
2016-03-21 19:39:16 +00:00
|
|
|
Builtins::kReflectIsExtensible, 1, true);
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate_, reflect, "ownKeys",
|
2016-03-21 19:39:16 +00:00
|
|
|
Builtins::kReflectOwnKeys, 1, true);
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate_, reflect, "preventExtensions",
|
2016-03-21 19:39:16 +00:00
|
|
|
Builtins::kReflectPreventExtensions, 1, true);
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate_, reflect, "set", Builtins::kReflectSet, 3,
|
|
|
|
false);
|
|
|
|
SimpleInstallFunction(isolate_, reflect, "setPrototypeOf",
|
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 =
|
2019-11-15 20:37:49 +00:00
|
|
|
factory->NewMap(JS_BOUND_FUNCTION_TYPE, JSBoundFunction::kHeaderSize,
|
2017-10-18 20:14:09 +00:00
|
|
|
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);
|
2018-11-29 12:03:40 +00:00
|
|
|
map->AppendDescriptor(isolate(), &d);
|
2015-12-27 06:30:53 +00:00
|
|
|
}
|
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);
|
2018-11-29 12:03:40 +00:00
|
|
|
map->AppendDescriptor(isolate(), &d);
|
2015-12-27 06:30:53 +00:00
|
|
|
}
|
|
|
|
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();
|
2020-11-11 06:18:31 +00:00
|
|
|
Handle<JSFunction> function = CreateFunctionForBuiltinWithPrototype(
|
|
|
|
isolate(), arguments_string, Builtins::kIllegal,
|
|
|
|
isolate()->initial_object_prototype(), JS_ARGUMENTS_OBJECT_TYPE,
|
|
|
|
JSSloppyArgumentsObject::kSize, 2, MUTABLE);
|
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());
|
2018-11-29 12:03:40 +00:00
|
|
|
map->AppendDescriptor(isolate(), &d);
|
2014-07-07 13:27:37 +00:00
|
|
|
}
|
|
|
|
{ // callee
|
2018-07-17 15:08:58 +00:00
|
|
|
Descriptor d =
|
|
|
|
Descriptor::DataField(isolate(), factory->callee_string(),
|
|
|
|
JSSloppyArgumentsObject::kCalleeIndex,
|
|
|
|
DONT_ENUM, Representation::Tagged());
|
2018-11-29 12:03:40 +00:00
|
|
|
map->AppendDescriptor(isolate(), &d);
|
2014-07-07 13:27:37 +00:00
|
|
|
}
|
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 =
|
2019-05-16 10:26:57 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
|
2011-03-17 20:28:41 +00:00
|
|
|
|
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.
|
2019-10-09 16:55:52 +00:00
|
|
|
Handle<Map> map =
|
|
|
|
factory->NewMap(JS_ARGUMENTS_OBJECT_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());
|
2018-11-29 12:03:40 +00:00
|
|
|
map->AppendDescriptor(isolate(), &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);
|
2018-11-29 12:03:40 +00:00
|
|
|
map->AppendDescriptor(isolate(), &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
|
|
|
|
2020-04-22 00:42:18 +00:00
|
|
|
// Initialize features from more mature to less mature, because less mature
|
|
|
|
// features may depend on more mature features having been initialized
|
|
|
|
// already.
|
2020-04-21 21:57:57 +00:00
|
|
|
HARMONY_SHIPPING(FEATURE_INITIALIZE_GLOBAL)
|
2020-04-22 00:42:18 +00:00
|
|
|
HARMONY_STAGED(FEATURE_INITIALIZE_GLOBAL)
|
|
|
|
HARMONY_INPROGRESS(FEATURE_INITIALIZE_GLOBAL)
|
2014-10-20 13:33:34 +00:00
|
|
|
#undef FEATURE_INITIALIZE_GLOBAL
|
2020-10-29 10:23:57 +00:00
|
|
|
InitializeGlobal_regexp_linear_flag();
|
2014-09-19 07:36:05 +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 =
|
2020-11-10 11:22:49 +00:00
|
|
|
Factory::JSFunctionBuilder{isolate, function_info, context}.Build();
|
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
|
|
|
}
|
|
|
|
|
2019-01-07 05:08:08 +00:00
|
|
|
void Genesis::InitializeIteratorFunctions() {
|
|
|
|
Isolate* isolate = isolate_;
|
2015-10-19 11:36:00 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2015-08-21 06:44:17 +00:00
|
|
|
HandleScope scope(isolate);
|
2018-08-23 15:25:58 +00:00
|
|
|
Handle<NativeContext> native_context = isolate->native_context();
|
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
|
|
|
|
2019-01-07 05:08:08 +00:00
|
|
|
{ // -- G e n e r a t o r
|
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);
|
2019-01-07 05:08:08 +00:00
|
|
|
Handle<JSFunction> generator_function_function = CreateFunction(
|
|
|
|
isolate, "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
|
|
|
}
|
|
|
|
|
2019-01-07 05:08:08 +00:00
|
|
|
{ // -- A s y n c G e n e r a t o r
|
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
|
|
|
|
2019-01-07 05:08:08 +00:00
|
|
|
Handle<JSFunction> async_generator_function_function = CreateFunction(
|
|
|
|
isolate, "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
|
2017-06-30 10:32:50 +00:00
|
|
|
// Setup %SetIteratorPrototype%.
|
|
|
|
Handle<JSObject> prototype =
|
2019-03-11 19:04:02 +00:00
|
|
|
factory->NewJSObject(isolate->object_function(), AllocationType::kOld);
|
2017-06-30 10:32:50 +00:00
|
|
|
JSObject::ForceSetPrototype(prototype, iterator_prototype);
|
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate, prototype, factory->SetIterator_string());
|
2017-06-30 10:32:50 +00:00
|
|
|
|
2017-07-06 10:39:28 +00:00
|
|
|
// Install the next function on the {prototype}.
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate, prototype, "next",
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kSetIteratorPrototypeNext, 0, true);
|
2018-10-10 13:29:32 +00:00
|
|
|
native_context->set_initial_set_iterator_prototype(*prototype);
|
2017-07-06 10:39:28 +00:00
|
|
|
|
2017-06-30 10:32:50 +00:00
|
|
|
// Setup SetIterator constructor.
|
2019-11-15 20:37:49 +00:00
|
|
|
Handle<JSFunction> set_iterator_function = CreateFunction(
|
|
|
|
isolate, "SetIterator", JS_SET_VALUE_ITERATOR_TYPE,
|
|
|
|
JSSetIterator::kHeaderSize, 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
|
2017-06-30 10:32:50 +00:00
|
|
|
// Setup %MapIteratorPrototype%.
|
|
|
|
Handle<JSObject> prototype =
|
2019-03-11 19:04:02 +00:00
|
|
|
factory->NewJSObject(isolate->object_function(), AllocationType::kOld);
|
2017-06-30 10:32:50 +00:00
|
|
|
JSObject::ForceSetPrototype(prototype, iterator_prototype);
|
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate, prototype, factory->MapIterator_string());
|
2017-06-30 10:32:50 +00:00
|
|
|
|
2017-07-06 10:39:28 +00:00
|
|
|
// Install the next function on the {prototype}.
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate, prototype, "next",
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kMapIteratorPrototypeNext, 0, true);
|
2018-10-10 13:29:32 +00:00
|
|
|
native_context->set_initial_map_iterator_prototype(*prototype);
|
2017-07-06 10:39:28 +00:00
|
|
|
|
2017-06-30 10:32:50 +00:00
|
|
|
// Setup MapIterator constructor.
|
2019-11-15 20:37:49 +00:00
|
|
|
Handle<JSFunction> map_iterator_function = CreateFunction(
|
|
|
|
isolate, "MapIterator", JS_MAP_KEY_ITERATOR_TYPE,
|
|
|
|
JSMapIterator::kHeaderSize, 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
|
|
|
|
2019-01-07 05:08:08 +00:00
|
|
|
Handle<JSFunction> async_function_constructor = CreateFunction(
|
|
|
|
isolate, "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
|
|
|
|
[async] Improve async function handling.
This change introduces new intrinsics used to desugar async functions
in the Parser and the BytecodeGenerator, namely we introduce a new
%_AsyncFunctionEnter intrinsic that constructs the generator object
for the async function (and in the future will also create the outer
promise for the async function). This generator object is internal
and never escapes to user code, plus since async functions don't have
a "prototype" property, we can just a single map here instead of tracking
the prototype/initial_map on every async function. This saves one word
per async function plus one initial_map per async function that was
invoked at least once.
We also introduce two new intrinsics %_AsyncFunctionReject, which
rejects the outer promise with the caught exception, and another
%_AsyncFunctionResolve, which resolves the outer promise with the
right hand side of the `return` statement. These functions also perform
the DevTools part of the job (aka popping from the promise stack and
sending the debug event). This allows us to get rid of the implicit
try-finally from async functions completely; because the finally
block only called to the %AsyncFunctionPromiseRelease builtin, which
was used to inform DevTools.
In essence we now turn an async function like
```js
async function f(x) { return await bar(x); }
```
into something like this (in Parser and BytecodeGenerator respectively):
```
function f(x) {
.generator_object = %_AsyncFunctionEnter(.closure, this);
.promise = %AsyncFunctionCreatePromise();
try {
.tmp = await bar(x);
return %_AsyncFunctionResolve(.promise, .tmp);
} catch (e) {
return %_AsyncFunctionReject(.promise, e);
}
}
```
Overall the bytecode for async functions gets significantly shorter
already (and will get even shorter once we put the outer promise into
the async function generator object). For example the bytecode for a
simple async function
```js
async function f(x) { return await x; }
```
goes from 175 bytes to 110 bytes (a ~38% reduction in size), which
is in particular due to the simplification around the try-finally
removal.
Overall this seems to improve the doxbee-async-es2017-native test by
around 2-3%. On the test case mentioned in v8:8276 we go from
1124ms to 441ms, which corresponds to a 60% reduction in total
execution time!
Tbr: marja@chromium.org
Bug: v8:7253, v8:7522, v8:8276
Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Id29dc92de7490b387ff697860c900cee44c9a7a4
Reviewed-on: https://chromium-review.googlesource.com/c/1269041
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Reviewed-by: Maya Lekova <mslekova@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56502}
2018-10-10 05:54:39 +00:00
|
|
|
// Async functions don't have a prototype, but they use generator objects
|
|
|
|
// under the hood to model the suspend/resume (in await). Instead of using
|
|
|
|
// the "prototype" / initial_map machinery (like for (async) generators),
|
|
|
|
// there's one global (per native context) map here that is used for the
|
|
|
|
// async function generator objects. These objects never escape to user
|
|
|
|
// JavaScript anyways.
|
2018-10-11 08:35:56 +00:00
|
|
|
Handle<Map> async_function_object_map = factory->NewMap(
|
2019-11-15 20:37:49 +00:00
|
|
|
JS_ASYNC_FUNCTION_OBJECT_TYPE, JSAsyncFunctionObject::kHeaderSize);
|
[async] Improve async function handling.
This change introduces new intrinsics used to desugar async functions
in the Parser and the BytecodeGenerator, namely we introduce a new
%_AsyncFunctionEnter intrinsic that constructs the generator object
for the async function (and in the future will also create the outer
promise for the async function). This generator object is internal
and never escapes to user code, plus since async functions don't have
a "prototype" property, we can just a single map here instead of tracking
the prototype/initial_map on every async function. This saves one word
per async function plus one initial_map per async function that was
invoked at least once.
We also introduce two new intrinsics %_AsyncFunctionReject, which
rejects the outer promise with the caught exception, and another
%_AsyncFunctionResolve, which resolves the outer promise with the
right hand side of the `return` statement. These functions also perform
the DevTools part of the job (aka popping from the promise stack and
sending the debug event). This allows us to get rid of the implicit
try-finally from async functions completely; because the finally
block only called to the %AsyncFunctionPromiseRelease builtin, which
was used to inform DevTools.
In essence we now turn an async function like
```js
async function f(x) { return await bar(x); }
```
into something like this (in Parser and BytecodeGenerator respectively):
```
function f(x) {
.generator_object = %_AsyncFunctionEnter(.closure, this);
.promise = %AsyncFunctionCreatePromise();
try {
.tmp = await bar(x);
return %_AsyncFunctionResolve(.promise, .tmp);
} catch (e) {
return %_AsyncFunctionReject(.promise, e);
}
}
```
Overall the bytecode for async functions gets significantly shorter
already (and will get even shorter once we put the outer promise into
the async function generator object). For example the bytecode for a
simple async function
```js
async function f(x) { return await x; }
```
goes from 175 bytes to 110 bytes (a ~38% reduction in size), which
is in particular due to the simplification around the try-finally
removal.
Overall this seems to improve the doxbee-async-es2017-native test by
around 2-3%. On the test case mentioned in v8:8276 we go from
1124ms to 441ms, which corresponds to a 60% reduction in total
execution time!
Tbr: marja@chromium.org
Bug: v8:7253, v8:7522, v8:8276
Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Id29dc92de7490b387ff697860c900cee44c9a7a4
Reviewed-on: https://chromium-review.googlesource.com/c/1269041
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Reviewed-by: Maya Lekova <mslekova@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56502}
2018-10-10 05:54:39 +00:00
|
|
|
native_context->set_async_function_object_map(*async_function_object_map);
|
2015-10-16 11:27:14 +00:00
|
|
|
}
|
2019-01-07 05:08:08 +00:00
|
|
|
}
|
2016-07-22 10:12:24 +00:00
|
|
|
|
2019-01-07 05:08:08 +00:00
|
|
|
void Genesis::InitializeCallSiteBuiltins() {
|
|
|
|
Factory* factory = isolate()->factory();
|
|
|
|
HandleScope scope(isolate());
|
|
|
|
// -- C a l l S i t e
|
|
|
|
// Builtin functions for CallSite.
|
2016-07-22 10:12:24 +00:00
|
|
|
|
2019-01-07 05:08:08 +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-08-02 09:29:14 +00:00
|
|
|
|
2019-01-07 05:08:08 +00:00
|
|
|
Handle<JSFunction> callsite_fun = CreateFunction(
|
|
|
|
isolate(), "CallSite", JS_OBJECT_TYPE, JSObject::kHeaderSize, 0,
|
|
|
|
factory->the_hole_value(), Builtins::kUnsupportedThrower);
|
|
|
|
callsite_fun->shared().DontAdaptArguments();
|
|
|
|
isolate()->native_context()->set_callsite_function(*callsite_fun);
|
2016-08-01 14:26:53 +00:00
|
|
|
|
2019-01-07 05:08:08 +00:00
|
|
|
// Setup CallSite.prototype.
|
|
|
|
Handle<JSObject> prototype(JSObject::cast(callsite_fun->instance_prototype()),
|
|
|
|
isolate());
|
|
|
|
|
|
|
|
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},
|
|
|
|
{"getPromiseIndex", Builtins::kCallSitePrototypeGetPromiseIndex},
|
|
|
|
{"getScriptNameOrSourceURL",
|
|
|
|
Builtins::kCallSitePrototypeGetScriptNameOrSourceURL},
|
|
|
|
{"getThis", Builtins::kCallSitePrototypeGetThis},
|
|
|
|
{"getTypeName", Builtins::kCallSitePrototypeGetTypeName},
|
|
|
|
{"isAsync", Builtins::kCallSitePrototypeIsAsync},
|
|
|
|
{"isConstructor", Builtins::kCallSitePrototypeIsConstructor},
|
|
|
|
{"isEval", Builtins::kCallSitePrototypeIsEval},
|
|
|
|
{"isNative", Builtins::kCallSitePrototypeIsNative},
|
|
|
|
{"isPromiseAll", Builtins::kCallSitePrototypeIsPromiseAll},
|
|
|
|
{"isToplevel", Builtins::kCallSitePrototypeIsToplevel},
|
|
|
|
{"toString", Builtins::kCallSitePrototypeToString}};
|
|
|
|
|
|
|
|
PropertyAttributes attrs =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
|
|
|
|
|
|
|
|
Handle<JSFunction> fun;
|
|
|
|
for (const FunctionInfo& info : infos) {
|
|
|
|
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() {}
|
|
|
|
|
2018-09-21 14:31:18 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_regexp_sequence)
|
2019-09-13 15:20:47 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_top_level_await)
|
2020-04-22 16:57:57 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_logical_assignment)
|
2020-10-14 19:12:37 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_import_assertions)
|
2015-09-16 18:01:38 +00:00
|
|
|
|
2019-02-01 02:10:39 +00:00
|
|
|
#ifdef V8_INTL_SUPPORT
|
2019-12-19 00:17:17 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_intl_displaynames_date_types)
|
2019-06-06 20:03:12 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_intl_dateformat_day_period)
|
2019-02-01 02:10:39 +00:00
|
|
|
#endif // V8_INTL_SUPPORT
|
|
|
|
|
[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
|
|
|
|
|
2020-07-20 13:27:14 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_atomics_waitasync() {
|
|
|
|
if (!FLAG_harmony_atomics_waitasync) return;
|
|
|
|
SimpleInstallFunction(isolate(), isolate()->atomics_object(), "waitAsync",
|
|
|
|
Builtins::kAtomicsWaitAsync, 4, true);
|
|
|
|
}
|
|
|
|
|
2015-05-22 13:43:38 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_sharedarraybuffer() {
|
2020-07-29 17:34:21 +00:00
|
|
|
if (!FLAG_harmony_sharedarraybuffer) return;
|
2015-05-22 13:43:38 +00:00
|
|
|
|
2018-06-20 10:10:43 +00:00
|
|
|
Handle<JSGlobalObject> global(native_context()->global_object(), isolate());
|
2016-04-13 18:21:30 +00:00
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
JSObject::AddProperty(isolate_, global, "SharedArrayBuffer",
|
|
|
|
isolate()->shared_array_buffer_fun(), DONT_ENUM);
|
2020-09-21 20:35:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Genesis::InitializeGlobal_harmony_atomics() {
|
|
|
|
if (!FLAG_harmony_atomics) return;
|
|
|
|
|
|
|
|
Handle<JSGlobalObject> global(native_context()->global_object(), isolate());
|
2016-04-13 18:21:30 +00:00
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
JSObject::AddProperty(isolate_, global, "Atomics",
|
|
|
|
isolate()->atomics_object(), DONT_ENUM);
|
|
|
|
InstallToStringTag(isolate_, isolate()->atomics_object(), "Atomics");
|
2015-05-22 13:43:38 +00:00
|
|
|
}
|
|
|
|
|
2018-10-09 12:08:23 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_weak_refs() {
|
|
|
|
if (!FLAG_harmony_weak_refs) return;
|
|
|
|
|
|
|
|
Factory* factory = isolate()->factory();
|
|
|
|
Handle<JSGlobalObject> global(native_context()->global_object(), isolate());
|
|
|
|
|
|
|
|
{
|
2020-02-24 19:47:48 +00:00
|
|
|
// Create %FinalizationRegistry%
|
2020-04-21 19:12:03 +00:00
|
|
|
Handle<JSFunction> finalization_registry_fun = InstallFunction(
|
|
|
|
isolate(), global, factory->FinalizationRegistry_string(),
|
|
|
|
JS_FINALIZATION_REGISTRY_TYPE, JSFinalizationRegistry::kHeaderSize, 0,
|
|
|
|
factory->the_hole_value(), Builtins::kFinalizationRegistryConstructor);
|
2019-07-23 10:07:49 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(
|
2020-02-24 19:47:48 +00:00
|
|
|
isolate(), finalization_registry_fun,
|
|
|
|
Context::JS_FINALIZATION_REGISTRY_FUNCTION_INDEX);
|
2018-10-09 12:08:23 +00:00
|
|
|
|
2020-02-24 19:47:48 +00:00
|
|
|
finalization_registry_fun->shared().DontAdaptArguments();
|
|
|
|
finalization_registry_fun->shared().set_length(1);
|
2018-10-09 12:08:23 +00:00
|
|
|
|
2020-04-21 19:12:03 +00:00
|
|
|
Handle<JSObject> finalization_registry_prototype(
|
|
|
|
JSObject::cast(finalization_registry_fun->instance_prototype()),
|
|
|
|
isolate());
|
2018-10-09 12:08:23 +00:00
|
|
|
|
2020-02-24 19:47:48 +00:00
|
|
|
InstallToStringTag(isolate(), finalization_registry_prototype,
|
2020-04-21 19:12:03 +00:00
|
|
|
factory->FinalizationRegistry_string());
|
2018-10-09 12:08:23 +00:00
|
|
|
|
2020-02-24 19:47:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), finalization_registry_prototype,
|
|
|
|
"register", Builtins::kFinalizationRegistryRegister,
|
|
|
|
2, false);
|
2018-11-05 14:21:02 +00:00
|
|
|
|
2020-02-24 19:47:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), finalization_registry_prototype,
|
|
|
|
"unregister",
|
|
|
|
Builtins::kFinalizationRegistryUnregister, 1, false);
|
2020-04-16 02:44:07 +00:00
|
|
|
|
|
|
|
// The cleanupSome function is created but not exposed, as it is used
|
|
|
|
// internally by InvokeFinalizationRegistryCleanupFromTask.
|
|
|
|
//
|
|
|
|
// It is exposed by FLAG_harmony_weak_refs_with_cleanup_some.
|
|
|
|
Handle<JSFunction> cleanup_some_fun = SimpleCreateFunction(
|
|
|
|
isolate(), factory->InternalizeUtf8String("cleanupSome"),
|
|
|
|
Builtins::kFinalizationRegistryPrototypeCleanupSome, 0, false);
|
|
|
|
native_context()->set_finalization_registry_cleanup_some(*cleanup_some_fun);
|
2018-10-09 12:08:23 +00:00
|
|
|
}
|
|
|
|
{
|
2018-12-17 08:15:02 +00:00
|
|
|
// Create %WeakRef%
|
2020-04-21 19:12:03 +00:00
|
|
|
Handle<JSFunction> weak_ref_fun = InstallFunction(
|
|
|
|
isolate(), global, factory->WeakRef_string(), JS_WEAK_REF_TYPE,
|
|
|
|
JSWeakRef::kHeaderSize, 0, factory->the_hole_value(),
|
|
|
|
Builtins::kWeakRefConstructor);
|
2019-07-23 10:07:49 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate(), weak_ref_fun,
|
|
|
|
Context::JS_WEAK_REF_FUNCTION_INDEX);
|
2018-12-17 08:15:02 +00:00
|
|
|
|
|
|
|
weak_ref_fun->shared().DontAdaptArguments();
|
|
|
|
weak_ref_fun->shared().set_length(1);
|
|
|
|
|
2020-04-21 19:12:03 +00:00
|
|
|
Handle<JSObject> weak_ref_prototype(
|
|
|
|
JSObject::cast(weak_ref_fun->instance_prototype()), isolate());
|
2018-12-17 08:15:02 +00:00
|
|
|
|
2020-04-21 19:12:03 +00:00
|
|
|
InstallToStringTag(isolate(), weak_ref_prototype,
|
|
|
|
factory->WeakRef_string());
|
|
|
|
|
|
|
|
SimpleInstallFunction(isolate(), weak_ref_prototype, "deref",
|
2020-08-26 14:27:44 +00:00
|
|
|
Builtins::kWeakRefDeref, 0, true);
|
2018-10-09 12:08:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-08 23:16:14 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_weak_refs_with_cleanup_some() {
|
|
|
|
if (!FLAG_harmony_weak_refs_with_cleanup_some) return;
|
|
|
|
DCHECK(FLAG_harmony_weak_refs);
|
|
|
|
|
|
|
|
Handle<JSFunction> finalization_registry_fun =
|
|
|
|
isolate()->js_finalization_registry_fun();
|
|
|
|
Handle<JSObject> finalization_registry_prototype(
|
|
|
|
JSObject::cast(finalization_registry_fun->instance_prototype()),
|
|
|
|
isolate());
|
|
|
|
|
2020-04-16 02:44:07 +00:00
|
|
|
JSObject::AddProperty(isolate(), finalization_registry_prototype,
|
|
|
|
factory()->InternalizeUtf8String("cleanupSome"),
|
|
|
|
isolate()->finalization_registry_cleanup_some(),
|
|
|
|
DONT_ENUM);
|
2020-04-08 23:16:14 +00:00
|
|
|
}
|
|
|
|
|
2019-09-05 11:14:55 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_regexp_match_indices() {
|
|
|
|
if (!FLAG_harmony_regexp_match_indices) return;
|
|
|
|
|
|
|
|
// Add indices accessor to JSRegExpResult's initial map.
|
|
|
|
Handle<Map> initial_map(native_context()->regexp_result_map(), isolate());
|
|
|
|
Descriptor d = Descriptor::AccessorConstant(
|
|
|
|
factory()->indices_string(), factory()->regexp_result_indices_accessor(),
|
|
|
|
NONE);
|
|
|
|
Map::EnsureDescriptorSlack(isolate(), initial_map, 1);
|
|
|
|
initial_map->AppendDescriptor(isolate(), &d);
|
|
|
|
}
|
|
|
|
|
2019-11-05 15:42:22 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_string_replaceall() {
|
|
|
|
if (!FLAG_harmony_string_replaceall) return;
|
|
|
|
|
|
|
|
Handle<JSFunction> string_fun(native_context()->string_function(), isolate());
|
|
|
|
Handle<JSObject> string_prototype(
|
|
|
|
JSObject::cast(string_fun->instance_prototype()), isolate());
|
|
|
|
|
|
|
|
SimpleInstallFunction(isolate(), string_prototype, "replaceAll",
|
|
|
|
Builtins::kStringPrototypeReplaceAll, 2, true);
|
|
|
|
}
|
|
|
|
|
2020-10-29 10:23:57 +00:00
|
|
|
void Genesis::InitializeGlobal_regexp_linear_flag() {
|
|
|
|
if (!FLAG_enable_experimental_regexp_engine) return;
|
|
|
|
|
|
|
|
Handle<JSFunction> regexp_fun(native_context()->regexp_function(), isolate());
|
|
|
|
Handle<JSObject> regexp_prototype(
|
|
|
|
JSObject::cast(regexp_fun->instance_prototype()), isolate());
|
|
|
|
SimpleInstallGetter(isolate(), regexp_prototype,
|
|
|
|
isolate()->factory()->linear_string(),
|
|
|
|
Builtins::kRegExpPrototypeLinearGetter, true);
|
|
|
|
|
|
|
|
// Store regexp prototype map again after change.
|
|
|
|
native_context()->set_regexp_prototype_map(regexp_prototype->map());
|
|
|
|
}
|
|
|
|
|
2018-05-15 20:50:46 +00:00
|
|
|
#ifdef V8_INTL_SUPPORT
|
2019-03-22 01:20:33 +00:00
|
|
|
|
2018-10-05 01:57:05 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_intl_segmenter() {
|
|
|
|
if (!FLAG_harmony_intl_segmenter) return;
|
|
|
|
Handle<JSObject> intl = Handle<JSObject>::cast(
|
|
|
|
JSReceiver::GetProperty(
|
|
|
|
isolate(),
|
|
|
|
Handle<JSReceiver>(native_context()->global_object(), isolate()),
|
|
|
|
factory()->InternalizeUtf8String("Intl"))
|
|
|
|
.ToHandleChecked());
|
|
|
|
|
|
|
|
Handle<JSFunction> segmenter_fun = InstallFunction(
|
2019-11-15 20:37:49 +00:00
|
|
|
isolate(), intl, "Segmenter", JS_SEGMENTER_TYPE, JSSegmenter::kHeaderSize,
|
|
|
|
0, factory()->the_hole_value(), Builtins::kSegmenterConstructor);
|
2018-10-05 01:57:05 +00:00
|
|
|
segmenter_fun->shared().set_length(0);
|
|
|
|
segmenter_fun->shared().DontAdaptArguments();
|
2019-09-12 19:47:30 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate_, segmenter_fun,
|
|
|
|
Context::INTL_SEGMENTER_FUNCTION_INDEX);
|
2018-10-05 01:57:05 +00:00
|
|
|
|
|
|
|
SimpleInstallFunction(isolate(), segmenter_fun, "supportedLocalesOf",
|
|
|
|
Builtins::kSegmenterSupportedLocalesOf, 1, false);
|
|
|
|
|
2018-10-18 07:59:28 +00:00
|
|
|
{
|
|
|
|
// Setup %SegmenterPrototype%.
|
|
|
|
Handle<JSObject> prototype(
|
|
|
|
JSObject::cast(segmenter_fun->instance_prototype()), isolate());
|
2018-10-05 01:57:05 +00:00
|
|
|
|
2020-07-29 15:06:31 +00:00
|
|
|
// #sec-intl.segmenter.prototype-@@tostringtag
|
|
|
|
//
|
|
|
|
// Intl.Segmenter.prototype [ @@toStringTag ]
|
|
|
|
//
|
|
|
|
// The initial value of the @@toStringTag property is the String value
|
|
|
|
// "Intl.Segmenter".
|
2018-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate(), prototype, "Intl.Segmenter");
|
2018-10-05 01:57:05 +00:00
|
|
|
|
2018-10-18 07:59:28 +00:00
|
|
|
SimpleInstallFunction(isolate(), prototype, "resolvedOptions",
|
|
|
|
Builtins::kSegmenterPrototypeResolvedOptions, 0,
|
|
|
|
false);
|
|
|
|
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "segment",
|
|
|
|
Builtins::kSegmenterPrototypeSegment, 1, false);
|
|
|
|
}
|
|
|
|
|
2020-07-29 15:06:31 +00:00
|
|
|
{
|
|
|
|
// Setup %SegmentsPrototype%.
|
|
|
|
Handle<JSObject> prototype = factory()->NewJSObject(
|
|
|
|
isolate()->object_function(), AllocationType::kOld);
|
|
|
|
|
|
|
|
Handle<String> name_string =
|
|
|
|
Name::ToFunctionName(isolate(), isolate()->factory()->Segments_string())
|
|
|
|
.ToHandleChecked();
|
|
|
|
Handle<JSFunction> segments_fun = CreateFunction(
|
|
|
|
isolate(), name_string, JS_SEGMENTS_TYPE, JSSegments::kHeaderSize, 0,
|
|
|
|
prototype, Builtins::kIllegal);
|
|
|
|
segments_fun->shared().set_native(false);
|
|
|
|
segments_fun->shared().set_length(0);
|
|
|
|
segments_fun->shared().DontAdaptArguments();
|
|
|
|
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "containing",
|
|
|
|
Builtins::kSegmentsPrototypeContaining, 1, false);
|
|
|
|
|
|
|
|
InstallFunctionAtSymbol(
|
|
|
|
isolate_, prototype, factory()->iterator_symbol(), "[Symbol.iterator]",
|
|
|
|
Builtins::kSegmentsPrototypeIterator, 0, true, DONT_ENUM);
|
|
|
|
|
|
|
|
Handle<Map> segments_map(segments_fun->initial_map(), isolate());
|
|
|
|
native_context()->set_intl_segments_map(*segments_map);
|
|
|
|
}
|
|
|
|
|
2018-10-18 07:59:28 +00:00
|
|
|
{
|
|
|
|
// Setup %SegmentIteratorPrototype%.
|
|
|
|
Handle<JSObject> iterator_prototype(
|
|
|
|
native_context()->initial_iterator_prototype(), isolate());
|
|
|
|
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<JSObject> prototype = factory()->NewJSObject(
|
|
|
|
isolate()->object_function(), AllocationType::kOld);
|
2018-10-18 07:59:28 +00:00
|
|
|
JSObject::ForceSetPrototype(prototype, iterator_prototype);
|
|
|
|
|
2020-07-29 15:06:31 +00:00
|
|
|
// #sec-%segmentiteratorprototype%.@@tostringtag
|
|
|
|
//
|
|
|
|
// %SegmentIteratorPrototype% [ @@toStringTag ]
|
|
|
|
//
|
|
|
|
// The initial value of the @@toStringTag property is the String value
|
|
|
|
// "Segmenter String Iterator".
|
|
|
|
InstallToStringTag(isolate(), prototype, "Segmenter String Iterator");
|
2018-10-18 07:59:28 +00:00
|
|
|
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "next",
|
|
|
|
Builtins::kSegmentIteratorPrototypeNext, 0, false);
|
|
|
|
|
|
|
|
// Setup SegmentIterator constructor.
|
2018-10-30 07:16:10 +00:00
|
|
|
Handle<String> name_string =
|
2019-03-11 21:40:39 +00:00
|
|
|
Name::ToFunctionName(isolate(),
|
|
|
|
isolate()->factory()->SegmentIterator_string())
|
2018-10-30 07:16:10 +00:00
|
|
|
.ToHandleChecked();
|
|
|
|
Handle<JSFunction> segment_iterator_fun = CreateFunction(
|
2019-10-09 16:55:52 +00:00
|
|
|
isolate(), name_string, JS_SEGMENT_ITERATOR_TYPE,
|
2019-11-15 20:37:49 +00:00
|
|
|
JSSegmentIterator::kHeaderSize, 0, prototype, Builtins::kIllegal);
|
2018-10-18 07:59:28 +00:00
|
|
|
segment_iterator_fun->shared().set_native(false);
|
|
|
|
|
|
|
|
Handle<Map> segment_iterator_map(segment_iterator_fun->initial_map(),
|
|
|
|
isolate());
|
|
|
|
native_context()->set_intl_segment_iterator_map(*segment_iterator_map);
|
|
|
|
}
|
2018-10-05 01:57: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.
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<JSObject> prototype = factory()->NewJSObject(
|
|
|
|
isolate()->object_function(), AllocationType::kOld);
|
2018-12-20 01:20:25 +00:00
|
|
|
InstallToStringTag(isolate(), prototype, name);
|
2016-01-01 07:12:48 +00:00
|
|
|
|
|
|
|
// 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:
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate(), array_buffer_fun, "isView",
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kArrayBufferIsView, 1, true);
|
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(),
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kArrayBufferPrototypeGetByteLength, false);
|
2018-01-10 23:52:53 +00:00
|
|
|
|
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,
|
2019-03-07 00:27:04 +00:00
|
|
|
false);
|
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;
|
|
|
|
}
|
|
|
|
|
2019-10-22 04:59:35 +00:00
|
|
|
// TODO(jgruber): Refactor this into some kind of meaningful organization. There
|
|
|
|
// is likely no reason remaining for these objects to be installed here. For
|
|
|
|
// example, global object setup done in this function could likely move to
|
|
|
|
// InitializeGlobal.
|
|
|
|
bool Genesis::InstallABunchOfRandomThings() {
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(isolate());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
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());
|
2018-12-08 02:59:17 +00:00
|
|
|
JSObject string_function_prototype =
|
2017-02-10 09:38:50 +00:00
|
|
|
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-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate(), global_object, "decodeURI",
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kGlobalDecodeURI, 1, false);
|
2016-05-27 09:56:04 +00:00
|
|
|
|
|
|
|
// Install Global.decodeURIComponent.
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate(), global_object, "decodeURIComponent",
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kGlobalDecodeURIComponent, 1, false);
|
2016-05-27 09:56:04 +00:00
|
|
|
|
2016-05-17 10:54:14 +00:00
|
|
|
// Install Global.encodeURI.
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate(), global_object, "encodeURI",
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kGlobalEncodeURI, 1, false);
|
2016-05-17 10:54:14 +00:00
|
|
|
|
|
|
|
// Install Global.encodeURIComponent.
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate(), global_object, "encodeURIComponent",
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kGlobalEncodeURIComponent, 1, false);
|
2016-05-17 10:54:14 +00:00
|
|
|
|
2016-06-01 04:24:32 +00:00
|
|
|
// Install Global.escape.
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate(), global_object, "escape",
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kGlobalEscape, 1, false);
|
2016-06-01 04:24:32 +00:00
|
|
|
|
|
|
|
// Install Global.unescape.
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate(), global_object, "unescape",
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kGlobalUnescape, 1, false);
|
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(
|
2018-11-23 09:55:50 +00:00
|
|
|
isolate(), global_object, "eval", 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-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate(), global_object, "isFinite",
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kGlobalIsFinite, 1, true);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
|
|
|
// Install Global.isNaN
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate(), global_object, "isNaN",
|
2019-03-07 00:27:04 +00:00
|
|
|
Builtins::kGlobalIsNaN, 1, true);
|
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.
|
2018-12-25 00:19:47 +00:00
|
|
|
Object length = proto->length();
|
2017-03-22 13:37:25 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
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());
|
2018-11-29 12:03:40 +00:00
|
|
|
map->AppendDescriptor(isolate(), &d);
|
2016-01-20 19:04:06 +00:00
|
|
|
}
|
|
|
|
{ // set
|
2018-07-17 15:08:58 +00:00
|
|
|
Descriptor d =
|
|
|
|
Descriptor::DataField(isolate(), factory()->set_string(),
|
|
|
|
JSAccessorPropertyDescriptor::kSetIndex, NONE,
|
|
|
|
Representation::Tagged());
|
2018-11-29 12:03:40 +00:00
|
|
|
map->AppendDescriptor(isolate(), &d);
|
2016-01-20 19:04:06 +00:00
|
|
|
}
|
|
|
|
{ // 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());
|
2018-11-29 12:03:40 +00:00
|
|
|
map->AppendDescriptor(isolate(), &d);
|
2016-01-20 19:04:06 +00:00
|
|
|
}
|
|
|
|
{ // 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());
|
2018-11-29 12:03:40 +00:00
|
|
|
map->AppendDescriptor(isolate(), &d);
|
2016-01-20 19:04:06 +00:00
|
|
|
}
|
|
|
|
|
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());
|
2018-11-29 12:03:40 +00:00
|
|
|
map->AppendDescriptor(isolate(), &d);
|
2016-01-20 19:04:06 +00:00
|
|
|
}
|
|
|
|
{ // 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());
|
2018-11-29 12:03:40 +00:00
|
|
|
map->AppendDescriptor(isolate(), &d);
|
2016-01-20 19:04:06 +00:00
|
|
|
}
|
|
|
|
{ // 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());
|
2018-11-29 12:03:40 +00:00
|
|
|
map->AppendDescriptor(isolate(), &d);
|
2016-01-20 19:04:06 +00:00
|
|
|
}
|
|
|
|
{ // 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());
|
2018-11-29 12:03:40 +00:00
|
|
|
map->AppendDescriptor(isolate(), &d);
|
2016-01-20 19:04:06 +00:00
|
|
|
}
|
|
|
|
|
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.
|
2019-09-05 11:14:55 +00:00
|
|
|
// Add additional slack to the initial map in case regexp_match_indices
|
|
|
|
// are enabled to account for the additional descriptor.
|
|
|
|
Handle<Map> initial_map = CreateInitialMapForArraySubclass(
|
|
|
|
JSRegExpResult::kSize, JSRegExpResult::kInObjectPropertyCount);
|
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());
|
2018-11-29 12:03:40 +00:00
|
|
|
initial_map->AppendDescriptor(isolate(), &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());
|
2018-11-29 12:03:40 +00:00
|
|
|
initial_map->AppendDescriptor(isolate(), &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());
|
2018-11-29 12:03:40 +00:00
|
|
|
initial_map->AppendDescriptor(isolate(), &d);
|
2017-12-15 12:33:39 +00:00
|
|
|
}
|
|
|
|
|
2019-09-05 11:14:55 +00:00
|
|
|
// Private internal only fields. All of the remaining fields have special
|
|
|
|
// symbols to prevent their use in Javascript.
|
|
|
|
{
|
|
|
|
PropertyAttributes attribs = DONT_ENUM;
|
2019-11-20 15:13:43 +00:00
|
|
|
|
|
|
|
// cached_indices_or_regexp descriptor.
|
2019-09-05 11:14:55 +00:00
|
|
|
{
|
|
|
|
Descriptor d = Descriptor::DataField(
|
|
|
|
isolate(),
|
2019-11-20 15:13:43 +00:00
|
|
|
factory()->regexp_result_cached_indices_or_regexp_symbol(),
|
|
|
|
JSRegExpResult::kCachedIndicesOrRegExpIndex, attribs,
|
2019-09-05 11:14:55 +00:00
|
|
|
Representation::Tagged());
|
|
|
|
initial_map->AppendDescriptor(isolate(), &d);
|
|
|
|
}
|
|
|
|
|
|
|
|
// names descriptor.
|
|
|
|
{
|
|
|
|
Descriptor d = Descriptor::DataField(
|
|
|
|
isolate(), factory()->regexp_result_names_symbol(),
|
|
|
|
JSRegExpResult::kNamesIndex, attribs, Representation::Tagged());
|
2019-11-20 15:13:43 +00:00
|
|
|
initial_map->AppendDescriptor(isolate(), &d);
|
|
|
|
}
|
|
|
|
|
|
|
|
// regexp_input_index descriptor.
|
|
|
|
{
|
|
|
|
Descriptor d = Descriptor::DataField(
|
|
|
|
isolate(), factory()->regexp_result_regexp_input_symbol(),
|
|
|
|
JSRegExpResult::kRegExpInputIndex, attribs,
|
|
|
|
Representation::Tagged());
|
|
|
|
initial_map->AppendDescriptor(isolate(), &d);
|
|
|
|
}
|
|
|
|
|
|
|
|
// regexp_last_index descriptor.
|
|
|
|
{
|
|
|
|
Descriptor d = Descriptor::DataField(
|
|
|
|
isolate(), factory()->regexp_result_regexp_last_index_symbol(),
|
|
|
|
JSRegExpResult::kRegExpLastIndex, attribs,
|
|
|
|
Representation::Tagged());
|
2019-09-05 11:14:55 +00:00
|
|
|
initial_map->AppendDescriptor(isolate(), &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
|
|
|
}
|
|
|
|
|
2019-09-05 11:14:55 +00:00
|
|
|
// Create a constructor for JSRegExpResultIndices (a variant of Array that
|
|
|
|
// predefines the groups property).
|
|
|
|
{
|
|
|
|
// JSRegExpResultIndices initial map.
|
|
|
|
Handle<Map> initial_map = CreateInitialMapForArraySubclass(
|
|
|
|
JSRegExpResultIndices::kSize,
|
|
|
|
JSRegExpResultIndices::kInObjectPropertyCount);
|
|
|
|
|
|
|
|
// groups descriptor.
|
|
|
|
{
|
|
|
|
Descriptor d = Descriptor::DataField(
|
|
|
|
isolate(), factory()->groups_string(),
|
|
|
|
JSRegExpResultIndices::kGroupsIndex, NONE, Representation::Tagged());
|
|
|
|
initial_map->AppendDescriptor(isolate(), &d);
|
2019-10-11 13:55:05 +00:00
|
|
|
DCHECK_EQ(initial_map->LastAdded().as_int(),
|
2019-09-05 11:14:55 +00:00
|
|
|
JSRegExpResultIndices::kGroupsDescriptorIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
native_context()->set_regexp_result_indices_map(*initial_map);
|
|
|
|
}
|
|
|
|
|
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);
|
2018-11-29 12:03:40 +00:00
|
|
|
map->AppendDescriptor(isolate(), &d);
|
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()->fast_aliased_arguments_map(),
|
|
|
|
isolate());
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::EnsureDescriptorSlack(isolate(), map, 1);
|
2018-11-29 12:03:40 +00:00
|
|
|
map->AppendDescriptor(isolate(), &d);
|
2015-07-02 14:38:37 +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()->slow_aliased_arguments_map(),
|
|
|
|
isolate());
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::EnsureDescriptorSlack(isolate(), map, 1);
|
2018-11-29 12:03:40 +00:00
|
|
|
map->AppendDescriptor(isolate(), &d);
|
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()->strict_arguments_map(), isolate());
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::EnsureDescriptorSlack(isolate(), map, 1);
|
2018-11-29 12:03:40 +00:00
|
|
|
map->AppendDescriptor(isolate(), &d);
|
2014-08-25 09:12:22 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-20 13:27:14 +00:00
|
|
|
{
|
|
|
|
Handle<OrderedHashSet> promises =
|
|
|
|
OrderedHashSet::Allocate(isolate(), 0).ToHandleChecked();
|
|
|
|
native_context()->set_atomics_waitasync_promises(*promises);
|
|
|
|
}
|
2014-08-25 09:12:22 +00:00
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-10-22 04:59:35 +00:00
|
|
|
bool Genesis::InstallExtrasBindings() {
|
2015-08-14 18:47:46 +00:00
|
|
|
HandleScope scope(isolate());
|
|
|
|
|
2019-02-26 10:39:00 +00:00
|
|
|
Handle<JSObject> extras_binding = factory()->NewJSObjectWithNullProto();
|
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-07-13 09:45:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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);
|
2019-02-04 09:04:04 +00:00
|
|
|
SaveAndSwitchContext saved_context(isolate_, *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) {
|
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();
|
2018-08-16 15:44:10 +00:00
|
|
|
Handle<String> name = isolate->factory()->stackTraceLimit_string();
|
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
|
2020-03-30 16:15:05 +00:00
|
|
|
// translated to Wasm to work correctly.
|
2017-09-04 12:15:18 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
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_gc ||
|
|
|
|
InstallExtension(isolate, "v8/gc", &extension_states)) &&
|
|
|
|
(!FLAG_expose_externalize_string ||
|
|
|
|
InstallExtension(isolate, "v8/externalize", &extension_states)) &&
|
2019-03-07 17:26:16 +00:00
|
|
|
(!TracingFlags::is_gc_stats_enabled() ||
|
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)) &&
|
2019-07-16 21:39:36 +00:00
|
|
|
(!isValidCpuTraceMarkFunctionName() ||
|
|
|
|
InstallExtension(isolate, "v8/cpumark", &extension_states)) &&
|
2019-12-14 08:46:38 +00:00
|
|
|
#ifdef ENABLE_VTUNE_TRACEMARK
|
|
|
|
(!FLAG_enable_vtune_domain_support ||
|
|
|
|
InstallExtension(isolate, "v8/vtunedomain", &extension_states)) &&
|
|
|
|
#endif // ENABLE_VTUNE_TRACEMARK
|
2016-04-27 11:10:41 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
2019-05-16 10:26:57 +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
|
|
|
}
|
2019-05-16 10:26:57 +00:00
|
|
|
return Utils::ApiCheck(false, "v8::Context::New()",
|
2014-01-16 13:18:28 +00:00
|
|
|
"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,
|
2019-05-16 10:26:57 +00:00
|
|
|
"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++) {
|
2019-05-16 10:26:57 +00:00
|
|
|
if (!InstallExtension(isolate, extension->dependencies()[i],
|
2013-02-15 09:27:10 +00:00
|
|
|
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) {
|
2019-03-06 15:00:01 +00:00
|
|
|
Handle<JSObject> global_proxy(native_context()->global_proxy(), isolate());
|
|
|
|
Handle<JSObject> global_object(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());
|
2018-11-22 10:05:02 +00:00
|
|
|
if (!proxy_constructor->GetPrototypeTemplate().IsUndefined(isolate())) {
|
2014-07-01 12:12:34 +00:00
|
|
|
Handle<ObjectTemplateInfo> global_object_data(
|
2018-11-22 10:05:02 +00:00
|
|
|
ObjectTemplateInfo::cast(proxy_constructor->GetPrototypeTemplate()),
|
2018-06-20 10:10:43 +00:00
|
|
|
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
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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())
|
2019-05-16 10:26:57 +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);
|
2019-01-14 13:27:52 +00:00
|
|
|
Handle<JSObject> instantiated_template;
|
|
|
|
if (!maybe_obj.ToHandle(&instantiated_template)) {
|
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;
|
|
|
|
}
|
2019-01-14 13:27:52 +00:00
|
|
|
TransferObject(instantiated_template, object);
|
2008-07-03 15:10:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-14 13:27:52 +00:00
|
|
|
static bool PropertyAlreadyExists(Isolate* isolate, Handle<JSObject> to,
|
|
|
|
Handle<Name> key) {
|
|
|
|
LookupIterator it(isolate, to, key, LookupIterator::OWN_SKIP_INTERCEPTOR);
|
|
|
|
CHECK_NE(LookupIterator::ACCESS_CHECK, it.state());
|
|
|
|
return it.IsFound();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
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()) {
|
2020-10-05 09:22:13 +00:00
|
|
|
Handle<DescriptorArray> descs = Handle<DescriptorArray>(
|
|
|
|
from->map().instance_descriptors(kRelaxedLoad), isolate());
|
2019-10-11 13:55:05 +00:00
|
|
|
for (InternalIndex i : from->map().IterateOwnDescriptors()) {
|
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());
|
2019-01-14 13:27:52 +00:00
|
|
|
// If the property is already there we skip it.
|
|
|
|
if (PropertyAlreadyExists(isolate(), to, key)) continue;
|
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());
|
2019-04-27 09:06:53 +00:00
|
|
|
DCHECK_EQ(kAccessor, details.kind());
|
|
|
|
Handle<Name> key(descs->GetKey(i), isolate());
|
|
|
|
// If the property is already there we skip it.
|
|
|
|
if (PropertyAlreadyExists(isolate(), to, key)) continue;
|
|
|
|
HandleScope inner(isolate());
|
|
|
|
DCHECK(!to->HasFastProperties());
|
|
|
|
// Add to dictionary.
|
|
|
|
Handle<Object> value(descs->GetStrongValue(i), isolate());
|
|
|
|
PropertyDetails d(kAccessor, details.attributes(),
|
|
|
|
PropertyCellType::kMutable);
|
|
|
|
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(
|
2020-11-13 14:53:45 +00:00
|
|
|
JSGlobalObject::cast(*from).global_dictionary(kAcquireLoad), 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++) {
|
2019-10-16 12:24:54 +00:00
|
|
|
InternalIndex index(Smi::ToInt(indices->get(i)));
|
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());
|
2019-01-14 13:27:52 +00:00
|
|
|
// If the property is already there we skip it.
|
|
|
|
if (PropertyAlreadyExists(isolate(), to, key)) continue;
|
2016-12-05 20:17:13 +00:00
|
|
|
// 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++) {
|
2019-10-16 12:24:54 +00:00
|
|
|
InternalIndex key_index(Smi::ToInt(key_indices->get(i)));
|
2018-12-25 00:19:47 +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());
|
|
|
|
Handle<Name> key(Name::cast(raw_key), isolate());
|
2019-01-14 13:27:52 +00:00
|
|
|
// If the property is already there we skip it.
|
|
|
|
if (PropertyAlreadyExists(isolate(), to, key)) continue;
|
2016-12-05 20:17:13 +00:00
|
|
|
// 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).
|
2019-04-01 09:07:37 +00:00
|
|
|
Handle<HeapObject> 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
|
|
|
}
|
|
|
|
|
2019-09-05 11:14:55 +00:00
|
|
|
Handle<Map> Genesis::CreateInitialMapForArraySubclass(int size,
|
|
|
|
int inobject_properties) {
|
|
|
|
// Find global.Array.prototype to inherit from.
|
|
|
|
Handle<JSFunction> array_constructor(native_context()->array_function(),
|
|
|
|
isolate());
|
|
|
|
Handle<JSObject> array_prototype(native_context()->initial_array_prototype(),
|
|
|
|
isolate());
|
|
|
|
|
|
|
|
// Add initial map.
|
|
|
|
Handle<Map> initial_map = factory()->NewMap(
|
|
|
|
JS_ARRAY_TYPE, size, TERMINAL_FAST_ELEMENTS_KIND, inobject_properties);
|
|
|
|
initial_map->SetConstructor(*array_constructor);
|
|
|
|
|
|
|
|
// Set prototype on map.
|
|
|
|
initial_map->set_has_non_instance_prototype(false);
|
|
|
|
Map::SetPrototype(isolate(), initial_map, array_prototype);
|
|
|
|
|
|
|
|
// Update map with length accessor from Array.
|
|
|
|
static constexpr int kTheLengthAccessor = 1;
|
|
|
|
Map::EnsureDescriptorSlack(isolate(), initial_map,
|
|
|
|
inobject_properties + kTheLengthAccessor);
|
|
|
|
|
|
|
|
// length descriptor.
|
|
|
|
{
|
|
|
|
JSFunction array_function = native_context()->array_function();
|
|
|
|
Handle<DescriptorArray> array_descriptors(
|
2020-10-05 09:22:13 +00:00
|
|
|
array_function.initial_map().instance_descriptors(kRelaxedLoad),
|
|
|
|
isolate());
|
2019-09-05 11:14:55 +00:00
|
|
|
Handle<String> length = factory()->length_string();
|
2019-10-11 13:55:05 +00:00
|
|
|
InternalIndex old = array_descriptors->SearchWithCache(
|
|
|
|
isolate(), *length, array_function.initial_map());
|
|
|
|
DCHECK(old.is_found());
|
2019-09-05 11:14:55 +00:00
|
|
|
Descriptor d = Descriptor::AccessorConstant(
|
|
|
|
length, handle(array_descriptors->GetStrongValue(old), isolate()),
|
|
|
|
array_descriptors->GetDetails(old).attributes());
|
|
|
|
initial_map->AppendDescriptor(isolate(), &d);
|
|
|
|
}
|
|
|
|
return initial_map;
|
|
|
|
}
|
|
|
|
|
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,
|
2019-02-28 06:54:55 +00:00
|
|
|
v8::DeserializeEmbedderFieldsCallback embedder_fields_deserializer,
|
|
|
|
v8::MicrotaskQueue* microtask_queue)
|
2015-07-06 07:09:07 +00:00
|
|
|
: isolate_(isolate), active_(isolate->bootstrapper()) {
|
2018-11-30 12:14:42 +00:00
|
|
|
RuntimeCallTimerScope rcs_timer(isolate, RuntimeCallCounterId::kGenesis);
|
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.
|
2018-12-25 00:19:47 +00:00
|
|
|
Object size = isolate->heap()->serialized_global_proxy_sizes().get(
|
2016-12-16 12:40:38 +00:00
|
|
|
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.
|
2018-08-23 15:25:58 +00:00
|
|
|
DCHECK(native_context_.is_null());
|
|
|
|
if (isolate->initialized_from_snapshot()) {
|
|
|
|
Handle<Context> context;
|
|
|
|
if (Snapshot::NewContextFromSnapshot(isolate, global_proxy,
|
|
|
|
context_snapshot_index,
|
|
|
|
embedder_fields_deserializer)
|
|
|
|
.ToHandle(&context)) {
|
|
|
|
native_context_ = Handle<NativeContext>::cast(context);
|
|
|
|
}
|
2013-06-28 13:40:41 +00:00
|
|
|
}
|
|
|
|
|
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 {
|
2019-10-22 04:59:35 +00:00
|
|
|
DCHECK(native_context().is_null());
|
|
|
|
|
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-09-24 13:25:07 +00:00
|
|
|
MathRandom::InitializeContext(isolate, native_context());
|
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);
|
2018-12-10 14:45:41 +00:00
|
|
|
InitializeGlobal(global_object, empty_function);
|
2010-08-25 13:25:54 +00:00
|
|
|
InitializeNormalizedMapCaches();
|
2019-01-07 05:08:08 +00:00
|
|
|
InitializeIteratorFunctions();
|
|
|
|
InitializeCallSiteBuiltins();
|
2015-07-13 09:45:43 +00:00
|
|
|
|
2019-10-22 04:59:35 +00:00
|
|
|
if (!InstallABunchOfRandomThings()) return;
|
|
|
|
if (!InstallExtrasBindings()) return;
|
2016-06-27 12:49:51 +00:00
|
|
|
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();
|
2019-01-14 13:27:52 +00:00
|
|
|
PrintF("[Initializing context from scratch took %0.3f ms]\n", ms);
|
2017-07-14 09:22:07 +00:00
|
|
|
}
|
2010-03-23 11:40:38 +00:00
|
|
|
}
|
2008-08-14 13:41:48 +00:00
|
|
|
|
2020-09-29 13:40:21 +00:00
|
|
|
// TODO(v8:10391): The reason is that the NativeContext::microtask_queue
|
|
|
|
// serialization is not actually supported, and therefore the field is
|
|
|
|
// serialized as raw data instead of being serialized as ExternalReference.
|
|
|
|
// As a result, when V8 heap sandbox is enabled, the external pointer entry
|
|
|
|
// is not allocated for microtask queue field during deserialization, so we
|
|
|
|
// allocate it manually here.
|
|
|
|
native_context()->AllocateExternalPointerEntries(isolate);
|
|
|
|
|
2019-02-28 06:54:55 +00:00
|
|
|
native_context()->set_microtask_queue(
|
2020-05-04 17:46:46 +00:00
|
|
|
isolate, microtask_queue ? static_cast<MicrotaskQueue*>(microtask_queue)
|
|
|
|
: isolate->default_microtask_queue());
|
2018-11-27 08:32:53 +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.
|
2019-05-16 10:26:57 +00:00
|
|
|
if (!isolate->serializer_enabled()) {
|
|
|
|
InitializeExperimentalGlobal();
|
|
|
|
|
|
|
|
// Store String.prototype's map again in case it has been changed by
|
|
|
|
// experimental natives.
|
|
|
|
Handle<JSFunction> string_function(native_context()->string_function(),
|
|
|
|
isolate);
|
|
|
|
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-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
|
|
|
}
|
|
|
|
|
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-11-22 10:05:02 +00:00
|
|
|
ObjectTemplateInfo::cast(global_constructor->GetPrototypeTemplate()),
|
2018-06-20 10:10:43 +00:00
|
|
|
isolate);
|
2017-02-22 10:13:24 +00:00
|
|
|
Handle<JSObject> global_object =
|
2019-05-16 10:26:57 +00:00
|
|
|
ApiNatives::InstantiateRemoteObject(global_object_template)
|
|
|
|
.ToHandleChecked();
|
2017-02-22 10:13:24 +00:00
|
|
|
|
|
|
|
// (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);
|
[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);
|
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.
|
2019-05-16 10:26:57 +00:00
|
|
|
int Bootstrapper::ArchiveSpacePerThread() { 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.
|
2019-05-16 10:26:57 +00:00
|
|
|
void Bootstrapper::FreeThreadResources() { DCHECK(!IsActive()); }
|
2009-01-26 18:09:46 +00:00
|
|
|
|
2015-06-01 22:46:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|