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"
|
2021-06-09 15:52:22 +00:00
|
|
|
#include "src/logging/runtime-call-stats-scope.h"
|
2021-11-24 14:56:56 +00:00
|
|
|
#include "src/objects/instance-type.h"
|
2020-11-18 12:15:16 +00:00
|
|
|
#include "src/objects/objects.h"
|
2022-05-20 09:53:14 +00:00
|
|
|
#include "src/sandbox/testing.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"
|
2022-05-28 03:39:27 +00:00
|
|
|
#include "src/objects/js-atomics-synchronization.h"
|
2018-09-04 18:32:51 +00:00
|
|
|
#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"
|
2022-04-25 22:41:09 +00:00
|
|
|
#include "src/objects/js-shadow-realm.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
|
2021-08-04 07:36:35 +00:00
|
|
|
#include "src/codegen/script-details.h"
|
2022-06-21 16:17:39 +00:00
|
|
|
#include "src/objects/js-shared-array.h"
|
2022-02-23 00:36:17 +00:00
|
|
|
#include "src/objects/js-struct.h"
|
2021-10-07 21:22:29 +00:00
|
|
|
#include "src/objects/js-temporal-objects-inl.h"
|
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"
|
2021-03-05 09:45:31 +00:00
|
|
|
#include "src/objects/swiss-name-dictionary-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"
|
2020-07-08 09:48:27 +00:00
|
|
|
#include "src/zone/zone-hashmap.h"
|
2015-08-27 14:42:36 +00:00
|
|
|
|
2021-03-05 11:40:31 +00:00
|
|
|
#if V8_ENABLE_WEBASSEMBLY
|
|
|
|
#include "src/wasm/wasm-js.h"
|
|
|
|
#endif // V8_ENABLE_WEBASSEMBLY
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-06-17 15:43:55 +00:00
|
|
|
bool SourceCodeCache::Lookup(Isolate* isolate, base::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));
|
2020-11-24 13:21:10 +00:00
|
|
|
if (str.IsOneByteEqualTo(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;
|
|
|
|
}
|
|
|
|
|
2021-06-17 15:43:55 +00:00
|
|
|
void SourceCodeCache::Add(Isolate* isolate, base::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
|
2021-06-17 15:43:55 +00:00
|
|
|
->NewStringFromOneByte(base::Vector<const uint8_t>::cast(name),
|
2019-03-11 19:04:02 +00:00
|
|
|
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();
|
2022-02-08 14:48:01 +00:00
|
|
|
void InitializeConsole(Handle<JSObject> extras_binding);
|
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
|
|
|
|
2022-04-20 13:37:05 +00:00
|
|
|
void InitializeGlobal_experimental_web_snapshots();
|
|
|
|
|
2021-07-20 07:20:42 +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,
|
2021-01-18 17:01:02 +00:00
|
|
|
ElementsKind elements_kind,
|
2021-11-24 14:56:56 +00:00
|
|
|
InstanceType constructor_type,
|
2021-05-06 10:43:37 +00:00
|
|
|
int rab_gsab_initial_map_index);
|
2021-07-16 12:10:29 +00:00
|
|
|
void InitializeMapCaches();
|
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();
|
2020-12-01 07:31:00 +00:00
|
|
|
ExtensionStates(const ExtensionStates&) = delete;
|
|
|
|
ExtensionStates& operator=(const ExtensionStates&) = delete;
|
2011-11-15 22:48:55 +00:00
|
|
|
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 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);
|
2021-09-17 14:15:49 +00:00
|
|
|
bool ConfigureGlobalObject(
|
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-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() {
|
2021-01-12 14:54:10 +00:00
|
|
|
if (!FLAG_log_maps || isolate_->initialized_from_snapshot()) return;
|
2018-11-27 08:08:59 +00:00
|
|
|
// 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());
|
|
|
|
}
|
|
|
|
|
2015-08-31 12:52:59 +00:00
|
|
|
namespace {
|
|
|
|
|
2020-11-11 06:18:31 +00:00
|
|
|
#ifdef DEBUG
|
2021-06-14 09:18:22 +00:00
|
|
|
bool IsFunctionMapOrSpecialBuiltin(Handle<Map> map, Builtin builtin,
|
2020-11-11 06:18:31 +00:00
|
|
|
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.
|
2021-06-14 09:18:22 +00:00
|
|
|
(builtin == Builtin::kEmptyFunction ||
|
|
|
|
builtin == Builtin::kProxyConstructor));
|
2020-11-11 06:18:31 +00:00
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
2021-06-07 15:24:12 +00:00
|
|
|
V8_NOINLINE Handle<JSFunction> CreateFunctionForBuiltin(Isolate* isolate,
|
|
|
|
Handle<String> name,
|
|
|
|
Handle<Map> map,
|
2021-06-14 09:18:22 +00:00
|
|
|
Builtin builtin) {
|
2020-11-11 06:18:31 +00:00
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
Handle<NativeContext> context(isolate->native_context());
|
2021-06-14 09:18:22 +00:00
|
|
|
DCHECK(IsFunctionMapOrSpecialBuiltin(map, builtin, context));
|
2020-11-11 06:18:31 +00:00
|
|
|
|
|
|
|
Handle<SharedFunctionInfo> info =
|
2021-06-14 09:18:22 +00:00
|
|
|
factory->NewSharedFunctionInfoForBuiltin(name, builtin);
|
2020-11-11 06:18:31 +00:00
|
|
|
info->set_language_mode(LanguageMode::kStrict);
|
|
|
|
|
|
|
|
return Factory::JSFunctionBuilder{isolate, info, context}
|
|
|
|
.set_map(map)
|
|
|
|
.Build();
|
|
|
|
}
|
|
|
|
|
|
|
|
V8_NOINLINE Handle<JSFunction> CreateFunctionForBuiltinWithPrototype(
|
2021-06-14 09:18:22 +00:00
|
|
|
Isolate* isolate, Handle<String> name, Builtin builtin,
|
2020-11-11 06:18:31 +00:00
|
|
|
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();
|
2021-06-14 09:18:22 +00:00
|
|
|
DCHECK(IsFunctionMapOrSpecialBuiltin(map, builtin, context));
|
2020-11-11 06:18:31 +00:00
|
|
|
|
|
|
|
Handle<SharedFunctionInfo> info =
|
2021-06-14 09:18:22 +00:00
|
|
|
factory->NewSharedFunctionInfoForBuiltin(name, builtin);
|
2020-11-11 06:18:31 +00:00
|
|
|
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);
|
2022-02-22 23:56:17 +00:00
|
|
|
if (type == JS_FUNCTION_TYPE) {
|
|
|
|
DCHECK_EQ(instance_size, JSFunction::kSizeWithPrototype);
|
|
|
|
// Since we are creating an initial map for JSFunction objects with
|
|
|
|
// prototype slot, set the respective bit.
|
|
|
|
initial_map->set_has_prototype_slot(true);
|
|
|
|
}
|
2020-11-11 06:18:31 +00:00
|
|
|
// 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);
|
|
|
|
}
|
2021-03-16 10:37:32 +00:00
|
|
|
JSFunction::SetInitialMap(isolate, result, initial_map, prototype);
|
2020-11-11 06:18:31 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
V8_NOINLINE Handle<JSFunction> CreateFunctionForBuiltinWithoutPrototype(
|
2021-06-14 09:18:22 +00:00
|
|
|
Isolate* isolate, Handle<String> name, Builtin builtin) {
|
2020-11-11 06:18:31 +00:00
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
Handle<NativeContext> context(isolate->native_context());
|
|
|
|
Handle<Map> map = isolate->strict_function_without_prototype_map();
|
2021-06-14 09:18:22 +00:00
|
|
|
DCHECK(IsFunctionMapOrSpecialBuiltin(map, builtin, context));
|
2020-11-11 06:18:31 +00:00
|
|
|
|
|
|
|
Handle<SharedFunctionInfo> info =
|
2021-06-14 09:18:22 +00:00
|
|
|
factory->NewSharedFunctionInfoForBuiltin(name, builtin);
|
2020-11-11 06:18:31 +00:00
|
|
|
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,
|
2021-06-14 09:18:22 +00:00
|
|
|
int inobject_properties, Handle<HeapObject> prototype, Builtin builtin) {
|
|
|
|
DCHECK(Builtins::HasJSLinkage(builtin));
|
2019-10-31 12:22:49 +00:00
|
|
|
|
2020-11-11 06:18:31 +00:00
|
|
|
Handle<JSFunction> result = CreateFunctionForBuiltinWithPrototype(
|
2021-06-14 09:18:22 +00:00
|
|
|
isolate, name, builtin, prototype, type, instance_size,
|
2020-11-11 06:18:31 +00:00
|
|
|
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,
|
2021-06-14 09:18:22 +00:00
|
|
|
int inobject_properties, Handle<HeapObject> prototype, Builtin builtin) {
|
|
|
|
return CreateFunction(isolate,
|
|
|
|
isolate->factory()->InternalizeUtf8String(name), type,
|
|
|
|
instance_size, inobject_properties, prototype, builtin);
|
2019-01-07 05:08:08 +00:00
|
|
|
}
|
|
|
|
|
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,
|
2021-06-07 15:24:12 +00:00
|
|
|
Handle<HeapObject> prototype, Builtin 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,
|
2021-06-07 15:24:12 +00:00
|
|
|
Handle<HeapObject> prototype, Builtin 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
|
|
|
}
|
|
|
|
|
2022-05-28 03:39:27 +00:00
|
|
|
V8_NOINLINE Handle<JSFunction> CreateSharedObjectConstructor(
|
|
|
|
Isolate* isolate, Handle<String> name, InstanceType type, int instance_size,
|
2022-06-21 16:17:39 +00:00
|
|
|
ElementsKind element_kind, Builtin builtin) {
|
2022-05-28 03:39:27 +00:00
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
Handle<SharedFunctionInfo> info = factory->NewSharedFunctionInfoForBuiltin(
|
|
|
|
name, builtin, FunctionKind::kNormalFunction);
|
|
|
|
info->set_language_mode(LanguageMode::kStrict);
|
|
|
|
Handle<JSFunction> constructor =
|
|
|
|
Factory::JSFunctionBuilder{isolate, info, isolate->native_context()}
|
|
|
|
.set_map(isolate->strict_function_map())
|
|
|
|
.Build();
|
|
|
|
constexpr int in_object_properties = 0;
|
|
|
|
Handle<Map> instance_map =
|
2022-06-21 16:17:39 +00:00
|
|
|
factory->NewMap(type, instance_size, element_kind, in_object_properties,
|
|
|
|
AllocationType::kSharedMap);
|
2022-05-28 03:39:27 +00:00
|
|
|
// Shared objects have fixed layout ahead of time, so there's no slack.
|
|
|
|
instance_map->SetInObjectUnusedPropertyFields(0);
|
|
|
|
// Shared objects are not extensible and have a null prototype.
|
|
|
|
instance_map->set_is_extensible(false);
|
|
|
|
JSFunction::SetInitialMap(isolate, constructor, instance_map,
|
|
|
|
factory->null_value());
|
|
|
|
// The constructor itself is not a shared object, so the shared map should not
|
|
|
|
// point to it.
|
|
|
|
instance_map->set_constructor_or_back_pointer(*factory->null_value());
|
|
|
|
return constructor;
|
|
|
|
}
|
|
|
|
|
2021-11-24 14:56:56 +00:00
|
|
|
// This sets a constructor instance type on the constructor map which will be
|
|
|
|
// used in IsXxxConstructor() predicates. Having such predicates helps figuring
|
|
|
|
// out if a protector cell should be invalidated. If there are no protector
|
|
|
|
// cell checks required for constructor, this function must not be used.
|
|
|
|
// Note, this function doesn't create a copy of the constructor's map. So it's
|
|
|
|
// better to set constructor instance type after all the properties are added
|
|
|
|
// to the constructor and thus the map is already guaranteed to be unique.
|
|
|
|
V8_NOINLINE void SetConstructorInstanceType(Isolate* isolate,
|
|
|
|
Handle<JSFunction> constructor,
|
|
|
|
InstanceType constructor_type) {
|
2021-01-18 17:01:02 +00:00
|
|
|
DCHECK(InstanceTypeChecker::IsJSFunction(constructor_type));
|
2021-11-24 14:56:56 +00:00
|
|
|
DCHECK_NE(constructor_type, JS_FUNCTION_TYPE);
|
|
|
|
|
|
|
|
Map map = constructor->map();
|
|
|
|
|
|
|
|
// Check we don't accidentally change one of the existing maps.
|
|
|
|
DCHECK_NE(map, *isolate->strict_function_map());
|
|
|
|
DCHECK_NE(map, *isolate->strict_function_with_readonly_prototype_map());
|
|
|
|
// Constructor function map is always a root map, and thus we don't have to
|
|
|
|
// deal with updating the whole transition tree.
|
|
|
|
DCHECK(map.GetBackPointer().IsUndefined(isolate));
|
|
|
|
DCHECK_EQ(JS_FUNCTION_TYPE, map.instance_type());
|
|
|
|
|
|
|
|
map.set_instance_type(constructor_type);
|
2021-01-18 17:01:02 +00:00
|
|
|
}
|
|
|
|
|
2017-09-15 08:45:45 +00:00
|
|
|
V8_NOINLINE Handle<JSFunction> SimpleCreateFunction(Isolate* isolate,
|
|
|
|
Handle<String> name,
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin 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) {
|
2021-09-07 14:51:40 +00:00
|
|
|
fun->shared().set_internal_formal_parameter_count(JSParameterCount(len));
|
2016-04-06 08:37:09 +00:00
|
|
|
} 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(
|
2021-06-07 15:24:12 +00:00
|
|
|
Isolate* isolate, Handle<JSObject> base, const char* name, Builtin 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;
|
|
|
|
}
|
|
|
|
|
2018-11-23 14:10:11 +00:00
|
|
|
V8_NOINLINE Handle<JSFunction> InstallFunctionAtSymbol(
|
|
|
|
Isolate* isolate, Handle<JSObject> base, Handle<Symbol> symbol,
|
2021-06-07 15:24:12 +00:00
|
|
|
const char* symbol_string, Builtin 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,
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin call_getter,
|
|
|
|
Builtin 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,
|
2021-06-07 15:24:12 +00:00
|
|
|
const char* name, Builtin call_getter,
|
|
|
|
Builtin call_setter) {
|
2018-12-20 01:20:25 +00:00
|
|
|
SimpleInstallGetterSetter(isolate, base,
|
|
|
|
isolate->factory()->InternalizeUtf8String(name),
|
|
|
|
call_getter, call_setter);
|
2016-10-06 13:00:56 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 15:24:12 +00:00
|
|
|
V8_NOINLINE Handle<JSFunction> SimpleInstallGetter(Isolate* isolate,
|
|
|
|
Handle<JSObject> base,
|
|
|
|
Handle<Name> name,
|
|
|
|
Handle<Name> property_name,
|
|
|
|
Builtin 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,
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin 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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
factory->species_symbol(), Builtin::kReturnReceiver,
|
2017-01-04 23:19:27 +00:00
|
|
|
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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
empty_function_map, Builtin::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(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate(), name, Builtin::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);
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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,
|
2021-06-07 15:24:12 +00:00
|
|
|
inobject_properties, factory->null_value(), Builtin::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);
|
|
|
|
|
2021-11-13 00:46:48 +00:00
|
|
|
{
|
|
|
|
Handle<Map> map = Map::Copy(
|
|
|
|
isolate(), handle(object_function_prototype->map(), isolate()),
|
|
|
|
"EmptyObjectPrototype");
|
|
|
|
map->set_is_prototype_map(true);
|
|
|
|
// Ban re-setting Object.prototype.__proto__ to prevent Proxy security bug
|
|
|
|
map->set_is_immutable_proto(true);
|
|
|
|
object_function_prototype->set_map(*map);
|
|
|
|
}
|
2017-07-03 13:40:13 +00:00
|
|
|
|
|
|
|
// 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);
|
2020-12-16 13:50:35 +00:00
|
|
|
object_function_prototype->map().set_instance_type(JS_OBJECT_PROTOTYPE_TYPE);
|
2017-07-03 13:40:13 +00:00
|
|
|
{
|
|
|
|
// 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.
|
|
|
|
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
|
|
|
|
|
2022-05-12 19:30:38 +00:00
|
|
|
Handle<JSFunction> SimpleInstallFunction(Isolate* isolate,
|
|
|
|
Handle<JSObject> base,
|
|
|
|
const char* name, Builtin call,
|
|
|
|
int len, bool adapt,
|
|
|
|
PropertyAttributes attrs) {
|
|
|
|
// Although function name does not have to be internalized the property name
|
|
|
|
// will be internalized during property addition anyway, so do it here now.
|
|
|
|
Handle<String> internalized_name =
|
|
|
|
isolate->factory()->InternalizeUtf8String(name);
|
|
|
|
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
|
|
|
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]",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kReturnReceiver, 0, true);
|
2016-09-21 14:17:42 +00:00
|
|
|
native_context()->set_initial_iterator_prototype(*iterator_prototype);
|
2020-12-16 13:50:35 +00:00
|
|
|
CHECK_NE(iterator_prototype->map().ptr(),
|
|
|
|
isolate_->initial_object_prototype()->map().ptr());
|
|
|
|
iterator_prototype->map().set_instance_type(JS_ITERATOR_PROTOTYPE_TYPE);
|
2016-09-21 14:17:42 +00:00
|
|
|
|
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);
|
2021-04-29 08:59:15 +00:00
|
|
|
JSObject::ForceSetPrototype(isolate(), 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);
|
2021-04-29 08:59:15 +00:00
|
|
|
JSObject::ForceSetPrototype(isolate(), 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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kGeneratorPrototypeNext, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), generator_object_prototype, "return",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kGeneratorPrototypeReturn, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), generator_object_prototype, "throw",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kAsyncModuleEvaluate, 1, false);
|
2019-09-13 15:20:47 +00:00
|
|
|
async_module_evaluate_internal->shared().set_native(false);
|
|
|
|
native_context()->set_async_module_evaluate_internal(
|
|
|
|
*async_module_evaluate_internal);
|
|
|
|
}
|
|
|
|
|
2015-10-16 11:27:14 +00:00
|
|
|
// Create maps for generator functions and their prototypes. Store those
|
|
|
|
// maps in the native context. The "prototype" property descriptor is
|
|
|
|
// writable, non-enumerable, and non-configurable (as per ES6 draft
|
|
|
|
// 04-14-15, section 25.2.4.3).
|
|
|
|
// Generator functions do not have "caller" or "arguments" accessors.
|
2017-07-13 09:33:22 +00:00
|
|
|
Handle<Map> map;
|
2018-06-19 09:00:37 +00:00
|
|
|
map = CreateNonConstructorMap(isolate(), isolate()->strict_function_map(),
|
2017-07-13 09:33:22 +00:00
|
|
|
generator_function_prototype,
|
|
|
|
"GeneratorFunction");
|
|
|
|
native_context()->set_generator_function_map(*map);
|
|
|
|
|
2018-06-19 09:00:37 +00:00
|
|
|
map = CreateNonConstructorMap(
|
|
|
|
isolate(), isolate()->strict_function_with_name_map(),
|
|
|
|
generator_function_prototype, "GeneratorFunction with name");
|
2017-07-13 09:33:22 +00:00
|
|
|
native_context()->set_generator_function_with_name_map(*map);
|
|
|
|
|
2018-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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
"[Symbol.asyncIterator]", Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kAsyncFromSyncIteratorPrototypeNext, 1, false);
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate(), async_from_sync_iterator_prototype, "return",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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
|
|
|
|
2021-04-29 08:59:15 +00:00
|
|
|
JSObject::ForceSetPrototype(isolate(), async_from_sync_iterator_prototype,
|
2017-02-24 17:48:49 +00:00
|
|
|
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
|
2021-04-29 08:59:15 +00:00
|
|
|
JSObject::ForceSetPrototype(isolate(), async_generator_function_prototype,
|
|
|
|
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
|
|
|
|
|
|
|
// 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%
|
2021-04-29 08:59:15 +00:00
|
|
|
JSObject::ForceSetPrototype(isolate(), async_generator_object_prototype,
|
[async-iteration] implement AsyncGenerator
- Introduce new struct AsyncGeneratorRequest, which holds
information pertinent to resuming execution of an
AsyncGenerator, such as the Promise associated with the async
generator request. It is intended to be used as a singly
linked list, and holds a pointer to the next item in te queue.
- Introduce JSAsyncGeneratorObject (subclass of
JSGeneratorObject), which includes several new internal fields
(`queue` which contains a singly linked list of
AsyncGeneratorRequest objects, and `await_input` which
contains the sent value from an Await expression (This is
necessary to prevent function.sent (used by yield*) from
having the sent value observably overwritten during
execution).
- Modify SuspendGenerator to accept a set of Flags, which
indicate whether the suspend is for a Yield or Await, and
whether it takes place on an async generator or ES6
generator.
- Introduce interpreter intrinsics and TF intrinsic lowering for
accessing the await input of an async generator
- Modify the JSGeneratorStore operator to understand whether or
not it's suspending for a normal yield, or an AsyncGenerator
Await. This ensures appropriate registers are stored.
- Add versions of ResumeGeneratorTrampoline which store the
input value in a different field depending on wether it's an
AsyncGenerator Await resume, or an ordinary resume. Also modifies
whether debug code will assert that the generator object is a
JSGeneratorObject or a JSAsyncGeneratorObject depending on the
resume type.
BUG=v8:5855
R=bmeurer@chromium.org, rmcilroy@chromium.org, jgruber@chromium.org,
littledan@chromium.org, neis@chromium.org
TBR=marja@chromium.org
Change-Id: I9d58df1d344465fc937fe7eed322424204497187
Reviewed-on: https://chromium-review.googlesource.com/446961
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44240}
2017-03-29 13:41:45 +00:00
|
|
|
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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kAsyncGeneratorPrototypeNext, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), async_generator_object_prototype, "return",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kAsyncGeneratorPrototypeReturn, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), async_generator_object_prototype, "throw",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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-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);
|
2021-04-29 08:59:15 +00:00
|
|
|
JSObject::ForceSetPrototype(isolate(), 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);
|
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) {
|
2021-03-05 11:23:36 +00:00
|
|
|
DescriptorArray descriptors = map->instance_descriptors(isolate);
|
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
|
|
|
}
|
2022-04-13 19:32:45 +00:00
|
|
|
|
|
|
|
void InitializeJSArrayMaps(Isolate* isolate, Handle<Context> native_context,
|
|
|
|
Handle<Map> initial_map) {
|
|
|
|
// Replace all of the cached initial array maps in the native context with
|
|
|
|
// the appropriate transitioned elements kind maps.
|
|
|
|
Handle<Map> current_map = initial_map;
|
|
|
|
ElementsKind kind = current_map->elements_kind();
|
|
|
|
DCHECK_EQ(GetInitialFastElementsKind(), kind);
|
|
|
|
DCHECK_EQ(PACKED_SMI_ELEMENTS, kind);
|
|
|
|
DCHECK_EQ(Context::ArrayMapIndex(kind),
|
|
|
|
Context::JS_ARRAY_PACKED_SMI_ELEMENTS_MAP_INDEX);
|
|
|
|
native_context->set(Context::ArrayMapIndex(kind), *current_map,
|
|
|
|
UPDATE_WRITE_BARRIER, kReleaseStore);
|
|
|
|
for (int i = GetSequenceIndexFromFastElementsKind(kind) + 1;
|
|
|
|
i < kFastElementsKindCount; ++i) {
|
|
|
|
Handle<Map> new_map;
|
|
|
|
ElementsKind next_kind = GetFastElementsKindFromSequenceIndex(i);
|
|
|
|
Map maybe_elements_transition = current_map->ElementsTransitionMap(
|
|
|
|
isolate, ConcurrencyMode::kSynchronous);
|
|
|
|
if (!maybe_elements_transition.is_null()) {
|
|
|
|
new_map = handle(maybe_elements_transition, isolate);
|
|
|
|
} else {
|
|
|
|
new_map = Map::CopyAsElementsKind(isolate, current_map, next_kind,
|
|
|
|
INSERT_TRANSITION);
|
|
|
|
}
|
|
|
|
DCHECK_EQ(next_kind, new_map->elements_kind());
|
|
|
|
native_context->set(Context::ArrayMapIndex(next_kind), *new_map,
|
|
|
|
UPDATE_WRITE_BARRIER, kReleaseStore);
|
|
|
|
current_map = new_map;
|
|
|
|
}
|
|
|
|
}
|
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
|
2021-06-18 16:39:11 +00:00
|
|
|
{
|
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(),
|
2022-05-31 08:02:41 +00:00
|
|
|
UPDATE_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 =
|
2022-02-07 15:10:10 +00:00
|
|
|
ScriptContextTable::Extend(isolate(), script_contexts, context);
|
2015-06-12 12:34:10 +00:00
|
|
|
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(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate(), name, Builtin::kIllegal, prototype, JS_GLOBAL_OBJECT_TYPE,
|
2020-11-11 06:18:31 +00:00
|
|
|
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(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate(), name, Builtin::kIllegal, factory()->the_hole_value(),
|
2020-11-11 06:18:31 +00:00
|
|
|
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
|
|
|
|
2021-09-17 14:15:49 +00:00
|
|
|
// Set the global object as the (hidden) __proto__ of the global proxy after
|
|
|
|
// ConfigureGlobalObject
|
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());
|
2021-04-29 08:59:15 +00:00
|
|
|
JSObject::ForceSetPrototype(isolate(), global_proxy, global_object);
|
2016-12-13 11:24:24 +00:00
|
|
|
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);
|
2021-05-12 11:36:30 +00:00
|
|
|
isolate->native_context()->set(context_index, *function, UPDATE_WRITE_BARRIER,
|
|
|
|
kReleaseStore);
|
2015-12-07 16:35:03 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 15:24:12 +00:00
|
|
|
static void InstallError(Isolate* isolate, Handle<JSObject> global,
|
|
|
|
Handle<String> name, int context_index,
|
|
|
|
Builtin error_constructor = Builtin::kErrorConstructor,
|
2022-05-19 23:35:56 +00:00
|
|
|
int error_function_length = 1) {
|
2016-07-20 13:02:36 +00:00
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
|
2022-05-19 23:35:56 +00:00
|
|
|
// Most Error objects consist of a message, a stack trace, and possibly a
|
|
|
|
// cause. Reserve three in-object properties for these.
|
|
|
|
const int in_object_properties = 3;
|
2019-04-11 13:48:20 +00:00
|
|
|
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);
|
2021-06-18 08:54:13 +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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kErrorPrototypeToString, 0, true);
|
2016-08-03 12:20:39 +00:00
|
|
|
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();
|
2022-02-04 19:59:03 +00:00
|
|
|
CHECK(JSReceiver::SetPrototype(isolate, error_fun, global_error, false,
|
2017-10-25 18:07:04 +00:00
|
|
|
kThrowOnError)
|
2016-07-20 13:02:36 +00:00
|
|
|
.FromMaybe(false));
|
2022-02-04 19:59:03 +00:00
|
|
|
CHECK(JSReceiver::SetPrototype(isolate, prototype,
|
2016-07-20 13:02:36 +00:00
|
|
|
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 ---
|
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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectAssign, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "getOwnPropertyDescriptor",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectGetOwnPropertyDescriptor, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function,
|
2018-11-23 09:55:50 +00:00
|
|
|
"getOwnPropertyDescriptors",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectGetOwnPropertyDescriptors, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "getOwnPropertyNames",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectGetOwnPropertyNames, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "getOwnPropertySymbols",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectGetOwnPropertySymbols, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, object_function, "is", Builtin::kObjectIs,
|
2018-05-31 14:14:48 +00:00
|
|
|
2, true);
|
|
|
|
SimpleInstallFunction(isolate_, object_function, "preventExtensions",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectPreventExtensions, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "seal",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectSeal, 1, false);
|
2016-04-25 11:44:13 +00:00
|
|
|
|
2021-08-26 12:17:28 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "create",
|
|
|
|
Builtin::kObjectCreate, 2, false);
|
2016-12-19 21:36:16 +00:00
|
|
|
|
2019-07-17 10:11:04 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "defineProperties",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectDefineProperties, 2, true);
|
2016-04-25 12:24:02 +00:00
|
|
|
|
2019-07-17 10:11:04 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "defineProperty",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectDefineProperty, 3, true);
|
2016-04-25 12:24:02 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "freeze",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectFreeze, 1, false);
|
2016-04-25 11:44:13 +00:00
|
|
|
|
2019-07-17 10:11:04 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "getPrototypeOf",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectGetPrototypeOf, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "setPrototypeOf",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectSetPrototypeOf, 2, true);
|
2016-04-25 11:44:13 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "isExtensible",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectIsExtensible, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "isFrozen",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectIsFrozen, 1, false);
|
2016-04-25 11:44:13 +00:00
|
|
|
|
2019-07-17 10:11:04 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "isSealed",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectIsSealed, 1, false);
|
2016-04-25 11:44:13 +00:00
|
|
|
|
2019-07-17 10:11:04 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "keys",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectKeys, 1, true);
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "entries",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectEntries, 1, true);
|
2019-06-24 14:22:36 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "fromEntries",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectFromEntries, 1, false);
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate_, object_function, "values",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
"__defineGetter__", Builtin::kObjectDefineGetter, 2,
|
2016-04-29 10:14:42 +00:00
|
|
|
true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, isolate_->initial_object_prototype(),
|
2021-06-07 15:24:12 +00:00
|
|
|
"__defineSetter__", Builtin::kObjectDefineSetter, 2,
|
2016-04-29 10:14:42 +00:00
|
|
|
true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, isolate_->initial_object_prototype(),
|
|
|
|
"hasOwnProperty",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectPrototypeHasOwnProperty, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, isolate_->initial_object_prototype(),
|
2021-06-07 15:24:12 +00:00
|
|
|
"__lookupGetter__", Builtin::kObjectLookupGetter, 1,
|
2016-04-29 10:14:42 +00:00
|
|
|
true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, isolate_->initial_object_prototype(),
|
2021-06-07 15:24:12 +00:00
|
|
|
"__lookupSetter__", Builtin::kObjectLookupSetter, 1,
|
2016-04-29 10:14:42 +00:00
|
|
|
true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, isolate_->initial_object_prototype(),
|
|
|
|
"isPrototypeOf",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectPrototypePropertyIsEnumerable, 1, false);
|
2018-11-23 09:55:50 +00:00
|
|
|
Handle<JSFunction> object_to_string = SimpleInstallFunction(
|
|
|
|
isolate_, isolate_->initial_object_prototype(), "toString",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectPrototypeValueOf, 0, true);
|
2020-03-13 13:14:09 +00:00
|
|
|
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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectPrototypeGetProto, Builtin::kObjectPrototypeSetProto);
|
2017-12-19 19:42:59 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, isolate_->initial_object_prototype(),
|
|
|
|
"toLocaleString",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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,
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kFunctionConstructor);
|
2017-07-07 09:24:57 +00:00
|
|
|
// Function instances are sloppy by default.
|
2021-04-27 10:36:45 +00:00
|
|
|
function_fun->set_prototype_or_initial_map(*isolate_->sloppy_function_map(),
|
|
|
|
kReleaseStore);
|
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);
|
2022-02-25 18:27:19 +00:00
|
|
|
native_context()->set_function_prototype(*prototype);
|
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);
|
Collect receiver to feedback for prototype.apply
When a function is invoked by prototype.apply, it may undergo following transformation in the JSCallReducer:
receiver.apply(this, args) ->
this.receiver(...args) Since the new target (also the receiver of apply()) is not collected to the feedback slot, further speculative optimization on the new target is not available if the new target
is not a heapconstant.
With this CL, the receiver will be collected to the feedback instead of the target if the target is a prototype.apply. It may improve the performance of the following usecase by ~80%.
function reduceArray(func, arr, r) {
for (var i = 0, len = arr.length; i < len; i++) {
r = func.apply(null, r, arr[i]);
}
return r;
}
var a = 0; for (var i = 0; i < 10000000; i++) {
a += reduceArray(Math.imul, [5,6,2,3,7,6,8,3,7,9,2,5,], 1);
}
console.log(a);
This CL also improves the runTime score of JetStream2/richards-wasm by ~45% in default, ~60% with --turbo-inline-js-wasm-calls.
Change-Id: I542eb8d3fcb592f4e0993af93ba1af70e89c3982
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2639813
Commit-Queue: Fanchen Kong <fanchen.kong@intel.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74413}
2021-03-25 22:56:46 +00:00
|
|
|
Handle<JSFunction> function_prototype_apply =
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "apply",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kFunctionPrototypeApply, 2, false);
|
Collect receiver to feedback for prototype.apply
When a function is invoked by prototype.apply, it may undergo following transformation in the JSCallReducer:
receiver.apply(this, args) ->
this.receiver(...args) Since the new target (also the receiver of apply()) is not collected to the feedback slot, further speculative optimization on the new target is not available if the new target
is not a heapconstant.
With this CL, the receiver will be collected to the feedback instead of the target if the target is a prototype.apply. It may improve the performance of the following usecase by ~80%.
function reduceArray(func, arr, r) {
for (var i = 0, len = arr.length; i < len; i++) {
r = func.apply(null, r, arr[i]);
}
return r;
}
var a = 0; for (var i = 0; i < 10000000; i++) {
a += reduceArray(Math.imul, [5,6,2,3,7,6,8,3,7,9,2,5,], 1);
}
console.log(a);
This CL also improves the runTime score of JetStream2/richards-wasm by ~45% in default, ~60% with --turbo-inline-js-wasm-calls.
Change-Id: I542eb8d3fcb592f4e0993af93ba1af70e89c3982
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2639813
Commit-Queue: Fanchen Kong <fanchen.kong@intel.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74413}
2021-03-25 22:56:46 +00:00
|
|
|
native_context()->set_function_prototype_apply(*function_prototype_apply);
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "bind",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kFastFunctionPrototypeBind, 1, false);
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "call",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kFunctionPrototypeCall, 1, false);
|
2020-11-02 22:01:19 +00:00
|
|
|
Handle<JSFunction> function_to_string =
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "toString",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kFunctionPrototypeToString, 0, false);
|
2020-11-02 22:01:19 +00:00
|
|
|
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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
"[Symbol.hasInstance]", Builtin::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);
|
|
|
|
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 ---
|
2021-11-24 14:56:56 +00:00
|
|
|
Handle<JSFunction> array_function = InstallFunction(
|
2019-11-15 20:37:49 +00:00
|
|
|
isolate_, global, "Array", JS_ARRAY_TYPE, JSArray::kHeaderSize, 0,
|
2021-11-24 14:56:56 +00:00
|
|
|
isolate_->initial_object_prototype(), Builtin::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
|
|
|
|
2022-05-13 09:19:09 +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
|
|
|
|
2022-04-13 19:32:45 +00:00
|
|
|
// Create the initial array map for Array.prototype which is required by
|
|
|
|
// the used ArrayConstructorStub.
|
|
|
|
// This is repeated after properly instantiating the Array.prototype.
|
|
|
|
InitializeJSArrayMaps(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
|
|
|
|
2022-04-13 19:32:45 +00:00
|
|
|
InitializeJSArrayMaps(isolate_, native_context(),
|
|
|
|
|
|
|
|
handle(array_function->initial_map(), isolate_));
|
|
|
|
|
2019-07-17 10:11:04 +00:00
|
|
|
SimpleInstallFunction(isolate_, array_function, "isArray",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kArrayIsArray, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, array_function, "from", Builtin::kArrayFrom,
|
|
|
|
1, false);
|
|
|
|
SimpleInstallFunction(isolate_, array_function, "of", Builtin::kArrayOf, 0,
|
2018-02-08 17:27:59 +00:00
|
|
|
false);
|
2021-11-24 14:56:56 +00:00
|
|
|
SetConstructorInstanceType(isolate_, array_function,
|
|
|
|
JS_ARRAY_CONSTRUCTOR_TYPE);
|
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
|
|
|
|
2022-05-03 17:53:19 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "at", Builtin::kArrayPrototypeAt, 1,
|
|
|
|
true);
|
2021-07-15 09:53:20 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "concat",
|
|
|
|
Builtin::kArrayPrototypeConcat, 1, false);
|
2018-08-08 05:52:45 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "copyWithin",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kArrayPrototypeCopyWithin, 2, false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "fill", Builtin::kArrayPrototypeFill,
|
|
|
|
1, false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "find", Builtin::kArrayPrototypeFind,
|
|
|
|
1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "findIndex",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kArrayPrototypeFindIndex, 1, false);
|
2018-08-28 09:14:58 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "lastIndexOf",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kArrayPrototypeLastIndexOf, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "pop", Builtin::kArrayPrototypePop,
|
2018-05-31 14:14:48 +00:00
|
|
|
0, false);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "push", Builtin::kArrayPrototypePush,
|
|
|
|
1, false);
|
2018-08-23 12:41:58 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "reverse",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kArrayPrototypeReverse, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "shift",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kArrayPrototypeShift, 0, false);
|
2018-09-06 05:47:23 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "unshift",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kArrayPrototypeUnshift, 1, false);
|
2018-11-26 13:29:01 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "slice",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kArrayPrototypeSlice, 2, false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "sort", Builtin::kArrayPrototypeSort,
|
|
|
|
1, false);
|
2018-11-26 13:29:01 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "splice",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kArrayPrototypeSplice, 2, false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "includes", Builtin::kArrayIncludes,
|
2018-05-31 14:14:48 +00:00
|
|
|
1, false);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "indexOf", Builtin::kArrayIndexOf, 1,
|
|
|
|
false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "join", Builtin::kArrayPrototypeJoin,
|
2018-05-31 14:14:48 +00:00
|
|
|
1, false);
|
2018-12-20 19:44:56 +00:00
|
|
|
|
|
|
|
{ // Set up iterator-related properties.
|
|
|
|
Handle<JSFunction> keys = InstallFunctionWithBuiltinId(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_, proto, "keys", Builtin::kArrayPrototypeKeys, 0, true);
|
2018-12-20 19:44:56 +00:00
|
|
|
native_context()->set_array_keys_iterator(*keys);
|
|
|
|
|
|
|
|
Handle<JSFunction> entries = InstallFunctionWithBuiltinId(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_, proto, "entries", Builtin::kArrayPrototypeEntries, 0, true);
|
2018-12-20 19:44:56 +00:00
|
|
|
native_context()->set_array_entries_iterator(*entries);
|
|
|
|
|
|
|
|
Handle<JSFunction> values = InstallFunctionWithBuiltinId(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_, proto, "values", Builtin::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(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_, proto, "forEach", Builtin::kArrayForEach, 1, false);
|
2018-12-20 19:44:56 +00:00
|
|
|
native_context()->set_array_for_each_iterator(*for_each_fun);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "filter", Builtin::kArrayFilter, 1,
|
2018-05-31 14:14:48 +00:00
|
|
|
false);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "flat", Builtin::kArrayPrototypeFlat,
|
|
|
|
0, false);
|
2019-02-02 02:10:25 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "flatMap",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kArrayPrototypeFlatMap, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "map", Builtin::kArrayMap, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "every", Builtin::kArrayEvery, 1,
|
2018-05-31 14:14:48 +00:00
|
|
|
false);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "some", Builtin::kArraySome, 1,
|
2017-06-26 10:03:43 +00:00
|
|
|
false);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "reduce", Builtin::kArrayReduce, 1,
|
2018-05-31 14:14:48 +00:00
|
|
|
false);
|
|
|
|
SimpleInstallFunction(isolate_, proto, "reduceRight",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kArrayReduceRight, 1, false);
|
2018-10-16 12:52:25 +00:00
|
|
|
SimpleInstallFunction(isolate_, proto, "toLocaleString",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kArrayPrototypeToLocaleString, 0, false);
|
2018-12-11 15:27:31 +00:00
|
|
|
array_prototype_to_string_fun =
|
|
|
|
SimpleInstallFunction(isolate_, proto, "toString",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kArrayPrototypeToString, 0, false);
|
2018-12-14 05:37:34 +00:00
|
|
|
|
2018-12-20 19:44:56 +00:00
|
|
|
Handle<JSObject> unscopables = factory->NewJSObjectWithNullProto();
|
2022-05-03 17:53:19 +00:00
|
|
|
InstallTrueValuedProperty(isolate_, unscopables, "at");
|
2018-12-20 19:44:56 +00:00
|
|
|
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);
|
2021-04-29 08:59:15 +00:00
|
|
|
JSObject::ForceSetPrototype(isolate(), array_iterator_prototype,
|
|
|
|
iterator_prototype);
|
2020-12-16 13:50:35 +00:00
|
|
|
CHECK_NE(array_iterator_prototype->map().ptr(),
|
|
|
|
isolate_->initial_object_prototype()->map().ptr());
|
|
|
|
array_iterator_prototype->map().set_instance_type(
|
|
|
|
JS_ARRAY_ITERATOR_PROTOTYPE_TYPE);
|
2016-10-18 02:42:42 +00:00
|
|
|
|
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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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,
|
2021-06-07 15:24:12 +00:00
|
|
|
array_iterator_prototype, Builtin::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,
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_->initial_object_prototype(), Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kNumberPrototypeToExponential, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toFixed",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kNumberPrototypeToFixed, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toPrecision",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kNumberPrototypeToPrecision, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toString",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kNumberPrototypeToString, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "valueOf",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kNumberPrototypeValueOf, 0, true);
|
2016-07-05 10:03:38 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toLocaleString",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kNumberIsFinite, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, number_fun, "isInteger",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kNumberIsInteger, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, number_fun, "isNaN", Builtin::kNumberIsNaN,
|
2016-09-07 10:14:19 +00:00
|
|
|
1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, number_fun, "isSafeInteger",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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);
|
[console] Proper type conversions in console builtins.
This updates the following set of console builtins in V8 to match the
Console Standard (https://console.spec.whatwg.org) with respect to
(potentially side effecting) type conversions:
- console.debug
- console.error
- console.info
- console.log
- console.trace
- console.warn
- console.group
- console.groupCollapsed
- console.assert
The V8 implementation only performs the type conversions and updates
the arguments in-place with the results from the %String% constructor,
%parseInt%, or %parseFloat% invocations. The actual formatting is
still left completely to the debugger front-end.
To give a concrete example, the following code
```js
const msgFmt = {
toString() { return 'Message %i' }
};
console.log('LOG: %s`, msgFmt, 42);
```
sends the following parameters to the debugger front-end
```js
["LOG: %s", "Message %i", 42]
```
and it's then the job of the front-end to perform the actual string
substitutions.
It's also worth calling out that the console builtins are only
concerned with %s, %f, %d, and %i formatting specifiers, since
these are the only ones that trigger type conversions, and %o, %O,
and %c can only be implemented in a meaningful way at a higher
level.
Fixed: chromium:1277944
Bug: chromium:1282076
Doc: https://bit.ly/v8-proper-console-type-conversions
Spec: https://console.spec.whatwg.org
Change-Id: I0996680811aa96236bd0d879e4a11101629ef1a7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3352118
Reviewed-by: Kim-Anh Tran <kimanh@chromium.org>
Auto-Submit: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78432}
2021-12-22 11:25:21 +00:00
|
|
|
native_context()->set_global_parse_float_fun(*parse_float_fun);
|
2016-10-18 12:44:48 +00:00
|
|
|
|
|
|
|
// Install Number.parseInt and Global.parseInt.
|
|
|
|
Handle<JSFunction> parse_int_fun = SimpleInstallFunction(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_, number_fun, "parseInt", Builtin::kNumberParseInt, 2, true);
|
2018-12-20 01:20:25 +00:00
|
|
|
JSObject::AddProperty(isolate_, global_object, "parseInt", parse_int_fun,
|
|
|
|
DONT_ENUM);
|
[console] Proper type conversions in console builtins.
This updates the following set of console builtins in V8 to match the
Console Standard (https://console.spec.whatwg.org) with respect to
(potentially side effecting) type conversions:
- console.debug
- console.error
- console.info
- console.log
- console.trace
- console.warn
- console.group
- console.groupCollapsed
- console.assert
The V8 implementation only performs the type conversions and updates
the arguments in-place with the results from the %String% constructor,
%parseInt%, or %parseFloat% invocations. The actual formatting is
still left completely to the debugger front-end.
To give a concrete example, the following code
```js
const msgFmt = {
toString() { return 'Message %i' }
};
console.log('LOG: %s`, msgFmt, 42);
```
sends the following parameters to the debugger front-end
```js
["LOG: %s", "Message %i", 42]
```
and it's then the job of the front-end to perform the actual string
substitutions.
It's also worth calling out that the console builtins are only
concerned with %s, %f, %d, and %i formatting specifiers, since
these are the only ones that trigger type conversions, and %o, %O,
and %c can only be implemented in a meaningful way at a higher
level.
Fixed: chromium:1277944
Bug: chromium:1282076
Doc: https://bit.ly/v8-proper-console-type-conversions
Spec: https://console.spec.whatwg.org
Change-Id: I0996680811aa96236bd0d879e4a11101629ef1a7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3352118
Reviewed-by: Kim-Anh Tran <kimanh@chromium.org>
Auto-Submit: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78432}
2021-12-22 11:25:21 +00:00
|
|
|
native_context()->set_global_parse_int_fun(*parse_int_fun);
|
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 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,
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_->initial_object_prototype(), Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kBooleanPrototypeToString, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "valueOf",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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,
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_->initial_object_prototype(), Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringFromCodePoint, 1, false);
|
2016-06-27 13:47:35 +00:00
|
|
|
|
2017-10-19 12:55:32 +00:00
|
|
|
// Install the String.raw function.
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, string_fun, "raw", Builtin::kStringRaw, 1,
|
2018-05-31 14:14:48 +00:00
|
|
|
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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeAnchor, 1, false);
|
2022-05-03 17:53:19 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "at",
|
|
|
|
Builtin::kStringPrototypeAt, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "big",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeBig, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "blink",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeBlink, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "bold",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeBold, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "charAt",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeCharAt, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "charCodeAt",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeCharCodeAt, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "codePointAt",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeCodePointAt, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "concat",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeConcat, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "endsWith",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeEndsWith, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "fontcolor",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeFontcolor, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "fontsize",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeFontsize, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "fixed",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeFixed, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "includes",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeIncludes, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "indexOf",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeIndexOf, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "italics",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeItalics, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "lastIndexOf",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeLastIndexOf, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "link",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeLink, 1, false);
|
2018-07-27 00:14:24 +00:00
|
|
|
#ifdef V8_INTL_SUPPORT
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "localeCompare",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeLocaleCompare, 1, false);
|
2018-07-27 00:14:24 +00:00
|
|
|
#else
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "localeCompare",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeMatch, 1, true);
|
2019-04-25 02:39:22 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "matchAll",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeNormalizeIntl, 0, false);
|
2017-03-31 21:27:30 +00:00
|
|
|
#else
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "normalize",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypePadEnd, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "padStart",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypePadStart, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "repeat",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeRepeat, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "replace",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeReplace, 2, true);
|
2021-03-11 20:03:33 +00:00
|
|
|
SimpleInstallFunction(isolate(), prototype, "replaceAll",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeReplaceAll, 2, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "search",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeSearch, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "slice",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeSlice, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "small",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeSmall, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "split",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeSplit, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "strike",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeStrike, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "sub",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeSub, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "substr",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeSubstr, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "substring",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeSubstring, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "sup",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeSup, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "startsWith",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeStartsWith, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toString",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeToString, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "trim",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeToLocaleLowerCase, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toLocaleUpperCase",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeToLocaleUpperCase, 0, false);
|
2018-07-26 22:08:25 +00:00
|
|
|
#ifdef V8_INTL_SUPPORT
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "toLowerCase",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeToLowerCaseIntl, 0, true);
|
2018-07-26 22:08:25 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toUpperCase",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeToUpperCaseIntl, 0, false);
|
2018-07-26 22:08:25 +00:00
|
|
|
#else
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toLowerCase",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeToLowerCase, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toUpperCase",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kStringPrototypeToUpperCase, 0, false);
|
2017-06-29 03:01:13 +00:00
|
|
|
#endif
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "valueOf",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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]",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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);
|
2021-04-29 08:59:15 +00:00
|
|
|
JSObject::ForceSetPrototype(isolate(), string_iterator_prototype,
|
|
|
|
iterator_prototype);
|
2020-12-16 13:50:35 +00:00
|
|
|
CHECK_NE(string_iterator_prototype->map().ptr(),
|
|
|
|
isolate_->initial_object_prototype()->map().ptr());
|
|
|
|
string_iterator_prototype->map().set_instance_type(
|
|
|
|
JS_STRING_ITERATOR_PROTOTYPE_TYPE);
|
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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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,
|
2021-06-07 15:24:12 +00:00
|
|
|
string_iterator_prototype, Builtin::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 ---
|
2021-06-07 15:24:12 +00:00
|
|
|
Handle<JSFunction> symbol_fun =
|
|
|
|
InstallFunction(isolate_, global, "Symbol", JS_PRIMITIVE_WRAPPER_TYPE,
|
|
|
|
JSPrimitiveWrapper::kHeaderSize, 0,
|
|
|
|
factory->the_hole_value(), Builtin::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.
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, symbol_fun, "for", Builtin::kSymbolFor, 1,
|
2016-12-06 13:21:20 +00:00
|
|
|
false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, symbol_fun, "keyFor",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kSymbolPrototypeToString, 0, true);
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate_, prototype, "valueOf",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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"),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kSymbolPrototypeDescriptionGetter, true);
|
2019-02-14 10:00:15 +00:00
|
|
|
|
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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
"[Symbol.toPrimitive]", Builtin::kSymbolPrototypeToPrimitive, 1, true,
|
2018-11-23 10:55:19 +00:00
|
|
|
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,
|
2021-06-07 15:24:12 +00:00
|
|
|
factory->the_hole_value(), Builtin::kDateConstructor);
|
2018-05-31 14:14:48 +00:00
|
|
|
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.
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, date_fun, "now", Builtin::kDateNow, 0,
|
2018-05-31 14:14:48 +00:00
|
|
|
false);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, date_fun, "parse", Builtin::kDateParse, 1,
|
2018-05-31 14:14:48 +00:00
|
|
|
false);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, date_fun, "UTC", Builtin::kDateUTC, 7,
|
2018-05-31 14:14:48 +00:00
|
|
|
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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeToString, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toDateString",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeToDateString, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toTimeString",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeToTimeString, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toISOString",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeGetDate, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setDate",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeSetDate, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getDay",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeGetDay, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getFullYear",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeGetFullYear, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setFullYear",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeSetFullYear, 3, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getHours",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeGetHours, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setHours",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeSetHours, 4, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getMilliseconds",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeGetMilliseconds, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setMilliseconds",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeSetMilliseconds, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getMinutes",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeGetMinutes, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setMinutes",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeSetMinutes, 3, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getMonth",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeGetMonth, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setMonth",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeSetMonth, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getSeconds",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeGetSeconds, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setSeconds",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeSetSeconds, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getTime",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeGetTime, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setTime",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeSetTime, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getTimezoneOffset",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeGetTimezoneOffset, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getUTCDate",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeGetUTCDate, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setUTCDate",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeSetUTCDate, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getUTCDay",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeGetUTCDay, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getUTCFullYear",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeGetUTCFullYear, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setUTCFullYear",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeSetUTCFullYear, 3, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getUTCHours",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeGetUTCHours, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setUTCHours",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeSetUTCHours, 4, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getUTCMilliseconds",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeGetUTCMilliseconds, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setUTCMilliseconds",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeSetUTCMilliseconds, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getUTCMinutes",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeGetUTCMinutes, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setUTCMinutes",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeSetUTCMinutes, 3, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getUTCMonth",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeGetUTCMonth, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setUTCMonth",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeSetUTCMonth, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getUTCSeconds",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeGetUTCSeconds, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setUTCSeconds",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeSetUTCSeconds, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "valueOf",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeValueOf, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getYear",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeGetYear, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setYear",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeSetYear, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toJSON",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeToLocaleString, 0, false);
|
2018-08-30 20:23:15 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toLocaleDateString",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeToLocaleDateString, 0, false);
|
2018-08-30 20:23:15 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toLocaleTimeString",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeToLocaleTimeString, 0, false);
|
2018-08-30 20:23:15 +00:00
|
|
|
#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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeToString, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toLocaleDateString",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDatePrototypeToDateString, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toLocaleTimeString",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
"[Symbol.toPrimitive]", Builtin::kDatePrototypeToPrimitive, 1, true,
|
2018-11-23 10:55:19 +00:00
|
|
|
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
|
2021-11-24 14:56:56 +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(),
|
2021-11-24 14:56:56 +00:00
|
|
|
Builtin::kPromiseConstructor);
|
2018-05-31 14:14:48 +00:00
|
|
|
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_);
|
2021-09-07 14:51:40 +00:00
|
|
|
shared->set_internal_formal_parameter_count(JSParameterCount(1));
|
2016-12-01 21:09:44 +00:00
|
|
|
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(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_, promise_fun, "all", Builtin::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
|
|
|
|
2022-03-13 04:52:15 +00:00
|
|
|
Handle<JSFunction> promise_all_settled =
|
|
|
|
InstallFunctionWithBuiltinId(isolate_, promise_fun, "allSettled",
|
|
|
|
Builtin::kPromiseAllSettled, 1, true);
|
|
|
|
native_context()->set_promise_all_settled(*promise_all_settled);
|
2020-11-03 18:52:31 +00:00
|
|
|
|
2020-11-12 00:22:12 +00:00
|
|
|
Handle<JSFunction> promise_any = InstallFunctionWithBuiltinId(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_, promise_fun, "any", Builtin::kPromiseAny, 1, true);
|
2020-11-12 00:22:12 +00:00
|
|
|
native_context()->set_promise_any(*promise_any);
|
|
|
|
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate_, promise_fun, "race",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kPromiseRace, 1, true);
|
2017-07-08 00:43:24 +00:00
|
|
|
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate_, promise_fun, "resolve",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kPromiseResolveTrampoline, 1, true);
|
2017-06-30 08:54:01 +00:00
|
|
|
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate_, promise_fun, "reject",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kPromiseReject, 1, true);
|
2017-06-30 08:54:01 +00:00
|
|
|
|
2021-11-24 14:56:56 +00:00
|
|
|
SetConstructorInstanceType(isolate_, promise_fun,
|
|
|
|
JS_PROMISE_CONSTRUCTOR_TYPE);
|
|
|
|
|
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(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_, prototype, "then", Builtin::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
|
|
|
|
2020-12-12 00:55:31 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate_, prototype, "catch",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kPromisePrototypeCatch, 1, true);
|
2016-12-06 18:42:49 +00:00
|
|
|
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate_, prototype, "finally",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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_);
|
2020-12-16 13:50:35 +00:00
|
|
|
CHECK_NE(prototype->map().ptr(),
|
|
|
|
isolate_->initial_object_prototype()->map().ptr());
|
|
|
|
prototype->map().set_instance_type(JS_PROMISE_PROTOTYPE_TYPE);
|
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.
|
2021-11-24 14:56:56 +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(),
|
2021-11-24 14:56:56 +00:00
|
|
|
Builtin::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);
|
2018-05-31 14:14:48 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(regexp_fun->shared(), isolate_);
|
2021-09-07 14:51:40 +00:00
|
|
|
shared->set_internal_formal_parameter_count(JSParameterCount(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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpPrototypeDotAllGetter, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->flags_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpPrototypeFlagsGetter, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->global_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpPrototypeGlobalGetter, true);
|
2021-08-19 08:26:08 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->hasIndices_string(),
|
2021-07-20 22:15:27 +00:00
|
|
|
Builtin::kRegExpPrototypeHasIndicesGetter, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->ignoreCase_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpPrototypeIgnoreCaseGetter, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->multiline_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpPrototypeMultilineGetter, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->source_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpPrototypeSourceGetter, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->sticky_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpPrototypeStickyGetter, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->unicode_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpPrototypeUnicodeGetter, true);
|
2016-10-10 13:06:24 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "compile",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpPrototypeCompile, 2, true);
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toString",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpPrototypeToString, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "test",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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]",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpPrototypeMatch, 1, true);
|
2019-07-29 07:55:50 +00:00
|
|
|
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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
"[Symbol.matchAll]", Builtin::kRegExpPrototypeMatchAll, 1, true);
|
2019-07-29 07:55:50 +00:00
|
|
|
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]",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpPrototypeReplace, 2, false);
|
2019-07-29 07:55:50 +00:00
|
|
|
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]",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpPrototypeSearch, 1, true);
|
2019-07-29 07:55:50 +00:00
|
|
|
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]",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpPrototypeSplit, 2, false);
|
2019-07-29 07:55:50 +00:00
|
|
|
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_);
|
2020-12-16 13:50:35 +00:00
|
|
|
CHECK_NE((*prototype_map).ptr(),
|
|
|
|
isolate_->initial_object_prototype()->map().ptr());
|
|
|
|
prototype_map->set_instance_type(JS_REG_EXP_PROTOTYPE_TYPE);
|
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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpInputGetter,
|
|
|
|
Builtin::kRegExpInputSetter);
|
2018-12-20 01:20:25 +00:00
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun, "$_",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpInputGetter,
|
|
|
|
Builtin::kRegExpInputSetter);
|
2018-12-20 01:20:25 +00:00
|
|
|
|
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun, "lastMatch",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpLastMatchGetter,
|
|
|
|
Builtin::kEmptyFunction);
|
2018-12-20 01:20:25 +00:00
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun, "$&",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpLastMatchGetter,
|
|
|
|
Builtin::kEmptyFunction);
|
2018-12-20 01:20:25 +00:00
|
|
|
|
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun, "lastParen",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpLastParenGetter,
|
|
|
|
Builtin::kEmptyFunction);
|
2018-12-20 01:20:25 +00:00
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun, "$+",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpLastParenGetter,
|
|
|
|
Builtin::kEmptyFunction);
|
2018-12-20 01:20:25 +00:00
|
|
|
|
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun, "leftContext",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpLeftContextGetter,
|
|
|
|
Builtin::kEmptyFunction);
|
2018-12-20 01:20:25 +00:00
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun, "$`",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpLeftContextGetter,
|
|
|
|
Builtin::kEmptyFunction);
|
2016-10-06 13:00:56 +00:00
|
|
|
|
2018-12-20 01:20:25 +00:00
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun, "rightContext",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpRightContextGetter,
|
|
|
|
Builtin::kEmptyFunction);
|
2018-12-20 01:20:25 +00:00
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun, "$'",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpRightContextGetter,
|
|
|
|
Builtin::kEmptyFunction);
|
2016-10-06 13:00:56 +00:00
|
|
|
|
2021-06-07 15:24:12 +00:00
|
|
|
#define INSTALL_CAPTURE_GETTER(i) \
|
|
|
|
SimpleInstallGetterSetter(isolate_, regexp_fun, "$" #i, \
|
|
|
|
Builtin::kRegExpCapture##i##Getter, \
|
|
|
|
Builtin::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
|
|
|
|
}
|
2021-11-24 14:56:56 +00:00
|
|
|
SetConstructorInstanceType(isolate_, regexp_fun,
|
|
|
|
JS_REG_EXP_CONSTRUCTOR_TYPE);
|
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.
|
2021-02-12 12:41:33 +00:00
|
|
|
Handle<PropertyCell> cell = factory->NewProtector();
|
|
|
|
native_context()->set_regexp_species_protector(*cell);
|
2019-07-11 07:33:33 +00:00
|
|
|
|
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);
|
2021-04-29 08:59:15 +00:00
|
|
|
JSObject::ForceSetPrototype(isolate(), regexp_string_iterator_prototype,
|
2019-04-25 02:39:22 +00:00
|
|
|
iterator_prototype);
|
|
|
|
|
|
|
|
InstallToStringTag(isolate(), regexp_string_iterator_prototype,
|
|
|
|
"RegExp String Iterator");
|
|
|
|
|
|
|
|
SimpleInstallFunction(isolate(), regexp_string_iterator_prototype, "next",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpStringIteratorPrototypeNext, 0, true);
|
2019-04-25 02:39:22 +00:00
|
|
|
|
|
|
|
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,
|
2021-06-07 15:24:12 +00:00
|
|
|
regexp_string_iterator_prototype, Builtin::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,
|
2022-05-19 23:35:56 +00:00
|
|
|
Builtin::kAggregateErrorConstructor, 2);
|
2020-11-12 00:22:12 +00:00
|
|
|
|
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);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, json_object, "parse", Builtin::kJsonParse,
|
2018-05-31 14:14:48 +00:00
|
|
|
2, false);
|
|
|
|
SimpleInstallFunction(isolate_, json_object, "stringify",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, math, "abs", Builtin::kMathAbs, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "acos", Builtin::kMathAcos, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "acosh", Builtin::kMathAcosh, 1,
|
2018-05-31 14:14:48 +00:00
|
|
|
true);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, math, "asin", Builtin::kMathAsin, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "asinh", Builtin::kMathAsinh, 1,
|
2018-05-31 14:14:48 +00:00
|
|
|
true);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, math, "atan", Builtin::kMathAtan, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "atanh", Builtin::kMathAtanh, 1,
|
2018-05-31 14:14:48 +00:00
|
|
|
true);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, math, "atan2", Builtin::kMathAtan2, 2,
|
2018-05-31 14:14:48 +00:00
|
|
|
true);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, math, "ceil", Builtin::kMathCeil, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "cbrt", Builtin::kMathCbrt, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "expm1", Builtin::kMathExpm1, 1,
|
2018-05-31 14:14:48 +00:00
|
|
|
true);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, math, "clz32", Builtin::kMathClz32, 1,
|
2018-05-31 14:14:48 +00:00
|
|
|
true);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, math, "cos", Builtin::kMathCos, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "cosh", Builtin::kMathCosh, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "exp", Builtin::kMathExp, 1, true);
|
2021-08-26 12:17:28 +00:00
|
|
|
SimpleInstallFunction(isolate_, math, "floor", Builtin::kMathFloor, 1,
|
|
|
|
true);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, math, "fround", Builtin::kMathFround, 1,
|
2018-05-31 14:14:48 +00:00
|
|
|
true);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, math, "hypot", Builtin::kMathHypot, 2,
|
2018-05-31 14:14:48 +00:00
|
|
|
false);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, math, "imul", Builtin::kMathImul, 2, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "log", Builtin::kMathLog, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "log1p", Builtin::kMathLog1p, 1,
|
2018-05-31 14:14:48 +00:00
|
|
|
true);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, math, "log2", Builtin::kMathLog2, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "log10", Builtin::kMathLog10, 1,
|
2018-05-31 14:14:48 +00:00
|
|
|
true);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, math, "max", Builtin::kMathMax, 2, false);
|
|
|
|
SimpleInstallFunction(isolate_, math, "min", Builtin::kMathMin, 2, false);
|
2021-08-26 12:17:28 +00:00
|
|
|
SimpleInstallFunction(isolate_, math, "pow", Builtin::kMathPow, 2, true);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, math, "random", Builtin::kMathRandom, 0,
|
2018-05-31 14:14:48 +00:00
|
|
|
true);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, math, "round", Builtin::kMathRound, 1,
|
2018-05-31 14:14:48 +00:00
|
|
|
true);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, math, "sign", Builtin::kMathSign, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "sin", Builtin::kMathSin, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "sinh", Builtin::kMathSinh, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "sqrt", Builtin::kMathSqrt, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "tan", Builtin::kMathTan, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "tanh", Builtin::kMathTanh, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, math, "trunc", Builtin::kMathTrunc, 1,
|
2018-05-31 14:14:48 +00:00
|
|
|
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-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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kIntlGetCanonicalLocales, 1, false);
|
2018-10-18 18:29:51 +00:00
|
|
|
|
2022-03-08 06:13:14 +00:00
|
|
|
SimpleInstallFunction(isolate(), intl, "supportedValuesOf",
|
|
|
|
Builtin::kIntlSupportedValuesOf, 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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDateTimeFormatConstructor);
|
2018-09-11 09:57:14 +00:00
|
|
|
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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDateTimeFormatSupportedLocalesOf, 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(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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDateTimeFormatPrototypeResolvedOptions, 0,
|
|
|
|
false);
|
2018-09-24 17:50:39 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "formatToParts",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDateTimeFormatPrototypeFormatToParts, 1,
|
2018-05-03 00:03:56 +00:00
|
|
|
false);
|
2018-08-18 20:23:13 +00:00
|
|
|
|
2019-03-11 21:40:39 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->format_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDateTimeFormatPrototypeFormat, false);
|
2019-09-12 19:53:30 +00:00
|
|
|
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "formatRange",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDateTimeFormatPrototypeFormatRange, 2,
|
2019-09-12 19:53:30 +00:00
|
|
|
false);
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "formatRangeToParts",
|
|
|
|
Builtin::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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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
|
|
|
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate(), number_format_constructor,
|
|
|
|
"supportedLocalesOf",
|
|
|
|
Builtin::kNumberFormatSupportedLocalesOf, 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(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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kNumberFormatPrototypeResolvedOptions, 0,
|
2018-09-11 19:14:49 +00:00
|
|
|
false);
|
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "formatToParts",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kNumberFormatPrototypeFormatToParts, 1,
|
2018-05-03 00:03:56 +00:00
|
|
|
false);
|
2019-03-11 21:40:39 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->format_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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,
|
2021-06-07 15:24:12 +00:00
|
|
|
0, factory->the_hole_value(), Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kCollatorSupportedLocalesOf, 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(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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kCollatorPrototypeResolvedOptions, 0,
|
2018-09-10 21:20:14 +00:00
|
|
|
false);
|
|
|
|
|
2019-03-11 21:40:39 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->compare_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kV8BreakIteratorPrototypeResolvedOptions,
|
2018-09-05 16:25:38 +00:00
|
|
|
0, false);
|
2018-09-05 02:17:38 +00:00
|
|
|
|
2019-03-11 21:40:39 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->adoptText_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kV8BreakIteratorPrototypeAdoptText, false);
|
2018-08-25 10:39:01 +00:00
|
|
|
|
2019-03-11 21:40:39 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->first_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kV8BreakIteratorPrototypeFirst, false);
|
2018-08-28 07:28:31 +00:00
|
|
|
|
2019-03-11 21:40:39 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->next_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kV8BreakIteratorPrototypeNext, false);
|
2018-08-28 13:37:00 +00:00
|
|
|
|
2019-03-11 21:40:39 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->current_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kV8BreakIteratorPrototypeCurrent, false);
|
2018-08-28 20:09:39 +00:00
|
|
|
|
2019-03-11 21:40:39 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->breakType_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kPluralRulesSupportedLocalesOf, 1, false);
|
2018-08-27 16:52:31 +00:00
|
|
|
|
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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kPluralRulesPrototypeResolvedOptions, 0,
|
2018-09-05 20:05:32 +00:00
|
|
|
false);
|
2018-09-12 22:55:01 +00:00
|
|
|
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "select",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRelativeTimeFormatSupportedLocalesOf, 1, false);
|
2019-02-08 08:14:07 +00:00
|
|
|
|
|
|
|
// Setup %RelativeTimeFormatPrototype%.
|
|
|
|
Handle<JSObject> prototype(
|
|
|
|
JSObject::cast(relative_time_format_fun->instance_prototype()),
|
|
|
|
isolate());
|
|
|
|
|
|
|
|
InstallToStringTag(isolate(), prototype, "Intl.RelativeTimeFormat");
|
|
|
|
|
|
|
|
SimpleInstallFunction(
|
|
|
|
isolate(), prototype, "resolvedOptions",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRelativeTimeFormatPrototypeResolvedOptions, 0, false);
|
2019-02-08 08:14:07 +00:00
|
|
|
SimpleInstallFunction(isolate(), prototype, "format",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRelativeTimeFormatPrototypeFormat, 2,
|
2019-02-08 08:14:07 +00:00
|
|
|
false);
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "formatToParts",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRelativeTimeFormatPrototypeFormatToParts,
|
2019-02-08 08:14:07 +00:00
|
|
|
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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kListFormatSupportedLocalesOf, 1, false);
|
2019-02-14 21:16:40 +00:00
|
|
|
|
|
|
|
// Setup %ListFormatPrototype%.
|
|
|
|
Handle<JSObject> prototype(
|
|
|
|
JSObject::cast(list_format_fun->instance_prototype()), isolate());
|
|
|
|
|
|
|
|
InstallToStringTag(isolate(), prototype, "Intl.ListFormat");
|
|
|
|
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "resolvedOptions",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kListFormatPrototypeResolvedOptions, 0,
|
2019-02-14 21:16:40 +00:00
|
|
|
false);
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "format",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kListFormatPrototypeFormat, 1, false);
|
2019-02-14 21:16:40 +00:00
|
|
|
SimpleInstallFunction(isolate(), prototype, "formatToParts",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kListFormatPrototypeFormatToParts, 1,
|
2019-02-14 21:16:40 +00:00
|
|
|
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,
|
2021-06-07 15:24:12 +00:00
|
|
|
factory->the_hole_value(), Builtin::kLocaleConstructor);
|
2019-05-10 23:26:36 +00:00
|
|
|
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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kLocalePrototypeToString, 0, false);
|
2019-05-10 23:26:36 +00:00
|
|
|
SimpleInstallFunction(isolate(), prototype, "maximize",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kLocalePrototypeMaximize, 0, false);
|
2019-05-10 23:26:36 +00:00
|
|
|
SimpleInstallFunction(isolate(), prototype, "minimize",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kLocalePrototypeMinimize, 0, false);
|
2019-05-10 23:26:36 +00:00
|
|
|
// Base locale getters.
|
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->language_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kLocalePrototypeLanguage, true);
|
2019-05-10 23:26:36 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->script_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kLocalePrototypeScript, true);
|
2019-05-10 23:26:36 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->region_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kLocalePrototypeRegion, true);
|
2019-05-10 23:26:36 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->baseName_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kLocalePrototypeBaseName, true);
|
2019-05-10 23:26:36 +00:00
|
|
|
// Unicode extension getters.
|
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->calendar_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kLocalePrototypeCalendar, true);
|
2019-05-10 23:26:36 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->caseFirst_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kLocalePrototypeCaseFirst, true);
|
2019-05-10 23:26:36 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->collation_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kLocalePrototypeCollation, true);
|
2019-05-10 23:26:36 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->hourCycle_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kLocalePrototypeHourCycle, true);
|
2019-05-10 23:26:36 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->numeric_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kLocalePrototypeNumeric, true);
|
2019-05-10 23:26:36 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype,
|
|
|
|
factory->numberingSystem_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kLocalePrototypeNumberingSystem, true);
|
2022-03-08 06:13:14 +00:00
|
|
|
|
|
|
|
// Intl Locale Info functions
|
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->calendars_string(),
|
|
|
|
Builtin::kLocalePrototypeCalendars, true);
|
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->collations_string(),
|
|
|
|
Builtin::kLocalePrototypeCollations, true);
|
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->hourCycles_string(),
|
|
|
|
Builtin::kLocalePrototypeHourCycles, true);
|
|
|
|
SimpleInstallGetter(isolate(), prototype,
|
|
|
|
factory->numberingSystems_string(),
|
|
|
|
Builtin::kLocalePrototypeNumberingSystems, true);
|
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->textInfo_string(),
|
|
|
|
Builtin::kLocalePrototypeTextInfo, true);
|
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->timeZones_string(),
|
|
|
|
Builtin::kLocalePrototypeTimeZones, true);
|
|
|
|
SimpleInstallGetter(isolate(), prototype, factory->weekInfo_string(),
|
|
|
|
Builtin::kLocalePrototypeWeekInfo, true);
|
2019-05-10 23:26:36 +00:00
|
|
|
}
|
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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDisplayNamesSupportedLocalesOf, 1, false);
|
2020-04-25 01:11:14 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
// Setup %DisplayNamesPrototype%.
|
|
|
|
Handle<JSObject> prototype(
|
|
|
|
JSObject::cast(display_names_fun->instance_prototype()), isolate());
|
|
|
|
|
|
|
|
InstallToStringTag(isolate(), prototype, "Intl.DisplayNames");
|
|
|
|
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "resolvedOptions",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDisplayNamesPrototypeResolvedOptions, 0,
|
|
|
|
false);
|
2020-04-25 01:11:14 +00:00
|
|
|
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "of",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDisplayNamesPrototypeOf, 1, false);
|
2020-04-25 01:11:14 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-08 05:10:44 +00:00
|
|
|
|
|
|
|
{ // -- S e g m e n t e r
|
|
|
|
Handle<JSFunction> segmenter_fun = InstallFunction(
|
|
|
|
isolate(), intl, "Segmenter", JS_SEGMENTER_TYPE,
|
|
|
|
JSSegmenter::kHeaderSize, 0, factory->the_hole_value(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kSegmenterConstructor);
|
2020-12-08 05:10:44 +00:00
|
|
|
segmenter_fun->shared().set_length(0);
|
|
|
|
segmenter_fun->shared().DontAdaptArguments();
|
|
|
|
InstallWithIntrinsicDefaultProto(isolate_, segmenter_fun,
|
|
|
|
Context::INTL_SEGMENTER_FUNCTION_INDEX);
|
|
|
|
SimpleInstallFunction(isolate(), segmenter_fun, "supportedLocalesOf",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kSegmenterSupportedLocalesOf, 1, false);
|
2020-12-08 05:10:44 +00:00
|
|
|
{
|
|
|
|
// Setup %SegmenterPrototype%.
|
|
|
|
Handle<JSObject> prototype(
|
|
|
|
JSObject::cast(segmenter_fun->instance_prototype()), isolate());
|
|
|
|
// #sec-intl.segmenter.prototype-@@tostringtag
|
|
|
|
//
|
|
|
|
// Intl.Segmenter.prototype [ @@toStringTag ]
|
|
|
|
//
|
|
|
|
// The initial value of the @@toStringTag property is the String value
|
|
|
|
// "Intl.Segmenter".
|
|
|
|
InstallToStringTag(isolate(), prototype, "Intl.Segmenter");
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "resolvedOptions",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kSegmenterPrototypeResolvedOptions, 0,
|
2020-12-08 05:10:44 +00:00
|
|
|
false);
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "segment",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kSegmenterPrototypeSegment, 1, false);
|
2020-12-08 05:10:44 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
// Setup %SegmentsPrototype%.
|
|
|
|
Handle<JSObject> prototype = factory->NewJSObject(
|
|
|
|
isolate()->object_function(), AllocationType::kOld);
|
|
|
|
Handle<String> name_string =
|
|
|
|
Name::ToFunctionName(isolate(), factory->Segments_string())
|
|
|
|
.ToHandleChecked();
|
|
|
|
Handle<JSFunction> segments_fun = CreateFunction(
|
|
|
|
isolate(), name_string, JS_SEGMENTS_TYPE, JSSegments::kHeaderSize,
|
2021-06-07 15:24:12 +00:00
|
|
|
0, prototype, Builtin::kIllegal);
|
2020-12-08 05:10:44 +00:00
|
|
|
segments_fun->shared().set_native(false);
|
|
|
|
segments_fun->shared().set_length(0);
|
|
|
|
segments_fun->shared().DontAdaptArguments();
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "containing",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kSegmentsPrototypeContaining, 1, false);
|
2020-12-08 05:10:44 +00:00
|
|
|
InstallFunctionAtSymbol(isolate_, prototype, factory->iterator_symbol(),
|
|
|
|
"[Symbol.iterator]",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kSegmentsPrototypeIterator, 0, true,
|
2020-12-08 05:10:44 +00:00
|
|
|
DONT_ENUM);
|
|
|
|
Handle<Map> segments_map(segments_fun->initial_map(), isolate());
|
|
|
|
native_context()->set_intl_segments_map(*segments_map);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// Setup %SegmentIteratorPrototype%.
|
|
|
|
Handle<JSObject> iterator_prototype(
|
|
|
|
native_context()->initial_iterator_prototype(), isolate());
|
|
|
|
Handle<JSObject> prototype = factory->NewJSObject(
|
|
|
|
isolate()->object_function(), AllocationType::kOld);
|
2021-04-29 08:59:15 +00:00
|
|
|
JSObject::ForceSetPrototype(isolate(), prototype, iterator_prototype);
|
2020-12-08 05:10:44 +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");
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "next",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kSegmentIteratorPrototypeNext, 0, false);
|
2020-12-08 05:10:44 +00:00
|
|
|
// Setup SegmentIterator constructor.
|
|
|
|
Handle<String> name_string =
|
|
|
|
Name::ToFunctionName(isolate(), factory->SegmentIterator_string())
|
|
|
|
.ToHandleChecked();
|
|
|
|
Handle<JSFunction> segment_iterator_fun = CreateFunction(
|
|
|
|
isolate(), name_string, JS_SEGMENT_ITERATOR_TYPE,
|
2021-06-07 15:24:12 +00:00
|
|
|
JSSegmentIterator::kHeaderSize, 0, prototype, Builtin::kIllegal);
|
2020-12-08 05:10:44 +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);
|
|
|
|
}
|
|
|
|
}
|
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"),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kArrayBufferConstructor_DoNotInitialize, 1, false);
|
2017-04-06 13:09:38 +00:00
|
|
|
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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kAtomicsLoad, 2, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "store",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kAtomicsStore, 3, true);
|
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "add", Builtin::kAtomicsAdd,
|
|
|
|
3, true);
|
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "sub", Builtin::kAtomicsSub,
|
|
|
|
3, true);
|
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "and", Builtin::kAtomicsAnd,
|
|
|
|
3, true);
|
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "or", Builtin::kAtomicsOr,
|
|
|
|
3, true);
|
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "xor", Builtin::kAtomicsXor,
|
2018-05-31 14:14:48 +00:00
|
|
|
3, true);
|
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "exchange",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kAtomicsExchange, 3, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "compareExchange",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kAtomicsCompareExchange, 4, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "isLockFree",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kAtomicsIsLockFree, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "wait",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kAtomicsWait, 4, true);
|
2021-03-11 20:03:33 +00:00
|
|
|
SimpleInstallFunction(isolate(), atomics_object, "waitAsync",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kAtomicsWaitAsync, 4, true);
|
2018-07-18 18:19:55 +00:00
|
|
|
SimpleInstallFunction(isolate_, atomics_object, "notify",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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,
|
2021-06-07 15:24:12 +00:00
|
|
|
factory->the_hole_value(), Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayOf, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, typed_array_fun, "from",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeBuffer, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->byte_length_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeByteLength, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->byte_offset_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeByteOffset, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->length_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeLength, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->to_string_tag_symbol(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeEntries, 0, true);
|
2017-06-30 13:54:24 +00:00
|
|
|
|
2018-11-23 14:10:11 +00:00
|
|
|
InstallFunctionWithBuiltinId(isolate_, prototype, "keys",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeKeys, 0, true);
|
2017-06-30 13:54:24 +00:00
|
|
|
|
2018-11-23 14:10:11 +00:00
|
|
|
Handle<JSFunction> values = InstallFunctionWithBuiltinId(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_, prototype, "values", Builtin::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
|
2022-05-03 17:53:19 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "at",
|
|
|
|
Builtin::kTypedArrayPrototypeAt, 1, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "copyWithin",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeCopyWithin, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "every",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeEvery, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "fill",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeFill, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "filter",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeFilter, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "find",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeFind, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "findIndex",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeFindIndex, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "forEach",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeForEach, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "includes",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeIncludes, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "indexOf",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeIndexOf, 1, false);
|
2018-12-11 15:27:31 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "join",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeJoin, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "lastIndexOf",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeLastIndexOf, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "map",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeMap, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "reverse",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeReverse, 0, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "reduce",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeReduce, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "reduceRight",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeReduceRight, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "set",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeSet, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "slice",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeSlice, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "some",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeSome, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "sort",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeSort, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "subarray",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeSubArray, 2, false);
|
2018-12-11 15:27:31 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "toLocaleString",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kTypedArrayPrototypeToLocaleString, 0,
|
2018-12-11 15:27:31 +00:00
|
|
|
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
|
2021-05-06 10:43:37 +00:00
|
|
|
#define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype) \
|
|
|
|
{ \
|
|
|
|
Handle<JSFunction> fun = InstallTypedArray( \
|
|
|
|
#Type "Array", TYPE##_ELEMENTS, TYPE##_TYPED_ARRAY_CONSTRUCTOR_TYPE, \
|
|
|
|
Context::RAB_GSAB_##TYPE##_ARRAY_MAP_INDEX); \
|
|
|
|
InstallWithIntrinsicDefaultProto(isolate_, fun, \
|
|
|
|
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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDataViewPrototypeGetBuffer, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->byte_length_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDataViewPrototypeGetByteLength, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype, factory->byte_offset_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDataViewPrototypeGetByteOffset, false);
|
2016-09-02 18:31:41 +00:00
|
|
|
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getInt8",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDataViewPrototypeGetInt8, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setInt8",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDataViewPrototypeSetInt8, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getUint8",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDataViewPrototypeGetUint8, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setUint8",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDataViewPrototypeSetUint8, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getInt16",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDataViewPrototypeGetInt16, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setInt16",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDataViewPrototypeSetInt16, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getUint16",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDataViewPrototypeGetUint16, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setUint16",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDataViewPrototypeSetUint16, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getInt32",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDataViewPrototypeGetInt32, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setInt32",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDataViewPrototypeSetInt32, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getUint32",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDataViewPrototypeGetUint32, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setUint32",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDataViewPrototypeSetUint32, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getFloat32",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDataViewPrototypeGetFloat32, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setFloat32",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDataViewPrototypeSetFloat32, 2, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getFloat64",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDataViewPrototypeGetFloat64, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setFloat64",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDataViewPrototypeSetFloat64, 2, false);
|
2018-10-01 09:48:52 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getBigInt64",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDataViewPrototypeGetBigInt64, 1, false);
|
2018-10-01 09:48:52 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setBigInt64",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDataViewPrototypeSetBigInt64, 2, false);
|
2018-10-01 09:48:52 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "getBigUint64",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kDataViewPrototypeGetBigUint64, 1, false);
|
2018-10-01 09:48:52 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "setBigUint64",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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,
|
2021-06-07 15:24:12 +00:00
|
|
|
factory->the_hole_value(), Builtin::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(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_, prototype, "get", Builtin::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(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_, prototype, "set", Builtin::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(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_, prototype, "has", Builtin::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(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_, prototype, "delete", Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kMapPrototypeClear, 0, true);
|
|
|
|
Handle<JSFunction> entries = SimpleInstallFunction(
|
|
|
|
isolate_, prototype, "entries", Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kMapPrototypeForEach, 1, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "keys",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kMapPrototypeKeys, 0, true);
|
2019-03-07 00:27:04 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype,
|
|
|
|
factory->InternalizeUtf8String("size"),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kMapPrototypeGetSize, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "values",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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
|
2021-06-07 15:24:12 +00:00
|
|
|
Handle<JSFunction> bigint_fun =
|
|
|
|
InstallFunction(isolate_, global, "BigInt", JS_PRIMITIVE_WRAPPER_TYPE,
|
|
|
|
JSPrimitiveWrapper::kHeaderSize, 0,
|
|
|
|
factory->the_hole_value(), Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kBigIntAsUintN, 2, false);
|
2018-10-01 09:48:52 +00:00
|
|
|
// asIntN(bits, bigint)
|
|
|
|
SimpleInstallFunction(isolate_, bigint_fun, "asIntN",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kBigIntAsIntN, 2, false);
|
2018-10-01 09:48:52 +00:00
|
|
|
|
|
|
|
// 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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kBigIntPrototypeToLocaleString, 0, false);
|
2018-10-01 09:48:52 +00:00
|
|
|
// toString([radix])
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "toString",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kBigIntPrototypeToString, 0, false);
|
2018-10-01 09:48:52 +00:00
|
|
|
// valueOf()
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "valueOf",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kBigIntPrototypeValueOf, 0, false);
|
2018-10-01 09:48:52 +00:00
|
|
|
// @@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,
|
2021-06-07 15:24:12 +00:00
|
|
|
factory->the_hole_value(), Builtin::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(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_, prototype, "has", Builtin::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(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_, prototype, "add", Builtin::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(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_, prototype, "delete", Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kSetPrototypeClear, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "entries",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kSetPrototypeEntries, 0, true);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "forEach",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kSetPrototypeForEach, 1, false);
|
2019-03-07 00:27:04 +00:00
|
|
|
SimpleInstallGetter(isolate_, prototype,
|
|
|
|
factory->InternalizeUtf8String("size"),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kSetPrototypeGetSize, true);
|
2017-07-06 10:39:28 +00:00
|
|
|
Handle<JSFunction> values = SimpleInstallFunction(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_, prototype, "values", Builtin::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());
|
2020-12-16 13:50:35 +00:00
|
|
|
CHECK_NE(prototype->map().ptr(),
|
|
|
|
isolate_->initial_object_prototype()->map().ptr());
|
|
|
|
prototype->map().set_instance_type(JS_SET_PROTOTYPE_TYPE);
|
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
|
|
|
|
map = Map::CopyWithField(isolate(), map, factory->done_string(),
|
|
|
|
FieldType::Any(isolate()), NONE,
|
|
|
|
PropertyConstness::kConst,
|
2021-07-13 14:45:55 +00:00
|
|
|
Representation::HeapObject(), INSERT_TRANSITION)
|
2019-05-14 13:17:42 +00:00
|
|
|
.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,
|
2021-06-07 15:24:12 +00:00
|
|
|
0, factory->the_hole_value(), Builtin::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
|
|
|
|
2021-06-16 11:00:48 +00:00
|
|
|
Handle<JSFunction> weakmap_delete =
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "delete",
|
|
|
|
Builtin::kWeakMapPrototypeDelete, 1, true);
|
|
|
|
native_context()->set_weakmap_delete(*weakmap_delete);
|
|
|
|
|
2018-09-14 02:10:39 +00:00
|
|
|
Handle<JSFunction> weakmap_get = SimpleInstallFunction(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_, prototype, "get", Builtin::kWeakMapGet, 1, true);
|
2018-09-14 02:10:39 +00:00
|
|
|
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(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_, prototype, "set", Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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,
|
2021-06-07 15:24:12 +00:00
|
|
|
0, factory->the_hole_value(), Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kWeakSetPrototypeDelete, 1, true);
|
2019-03-07 00:27:04 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "has",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kWeakSetPrototypeHas, 1, true);
|
2018-10-24 05:15:20 +00:00
|
|
|
|
2018-01-18 14:53:18 +00:00
|
|
|
Handle<JSFunction> weakset_add = SimpleInstallFunction(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_, prototype, "add", Builtin::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(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate(), name, proxy_function_map, Builtin::kProxyConstructor);
|
2016-03-21 19:39:16 +00:00
|
|
|
|
2018-08-02 08:22:11 +00:00
|
|
|
isolate_->proxy_map()->SetConstructor(*proxy_function);
|
|
|
|
|
2021-09-07 14:51:40 +00:00
|
|
|
proxy_function->shared().set_internal_formal_parameter_count(
|
|
|
|
JSParameterCount(2));
|
2016-03-21 19:39:16 +00:00
|
|
|
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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kReflectDefineProperty, 3, true);
|
2016-03-21 19:39:16 +00:00
|
|
|
|
2020-05-06 08:59:46 +00:00
|
|
|
SimpleInstallFunction(isolate_, reflect, "deleteProperty",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kReflectDeleteProperty, 2, true);
|
2016-03-21 19:39:16 +00:00
|
|
|
|
2018-11-23 09:55:50 +00:00
|
|
|
Handle<JSFunction> apply = SimpleInstallFunction(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_, reflect, "apply", Builtin::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(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate_, reflect, "construct", Builtin::kReflectConstruct, 2, false);
|
2016-03-21 19:39:16 +00:00
|
|
|
native_context()->set_reflect_construct(*construct);
|
|
|
|
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate_, reflect, "get", Builtin::kReflectGet, 2,
|
2018-11-23 09:55:50 +00:00
|
|
|
false);
|
|
|
|
SimpleInstallFunction(isolate_, reflect, "getOwnPropertyDescriptor",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kReflectGetOwnPropertyDescriptor, 2, true);
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate_, reflect, "getPrototypeOf",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kReflectGetPrototypeOf, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, reflect, "has", Builtin::kReflectHas, 2,
|
2018-11-23 09:55:50 +00:00
|
|
|
true);
|
|
|
|
SimpleInstallFunction(isolate_, reflect, "isExtensible",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kReflectIsExtensible, 1, true);
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate_, reflect, "ownKeys",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kReflectOwnKeys, 1, true);
|
2018-11-23 09:55:50 +00:00
|
|
|
SimpleInstallFunction(isolate_, reflect, "preventExtensions",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kReflectPreventExtensions, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, reflect, "set", Builtin::kReflectSet, 3,
|
2018-11-23 09:55:50 +00:00
|
|
|
false);
|
|
|
|
SimpleInstallFunction(isolate_, reflect, "setPrototypeOf",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kReflectSetPrototypeOf, 2, true);
|
2016-03-21 19:39:16 +00:00
|
|
|
}
|
|
|
|
|
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
|
2022-05-13 09:19:09 +00:00
|
|
|
static_assert(
|
2022-02-25 18:27:19 +00:00
|
|
|
JSFunctionOrBoundFunctionOrWrappedFunction::kLengthDescriptorIndex ==
|
|
|
|
0);
|
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
|
2022-05-13 09:19:09 +00:00
|
|
|
static_assert(
|
2022-02-25 18:27:19 +00:00
|
|
|
JSFunctionOrBoundFunctionOrWrappedFunction::kNameDescriptorIndex ==
|
|
|
|
1);
|
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);
|
|
|
|
}
|
|
|
|
|
2021-03-07 15:00:51 +00:00
|
|
|
{ // -- F i n a l i z a t i o n R e g i s t r y
|
|
|
|
Handle<JSFunction> finalization_registry_fun = InstallFunction(
|
|
|
|
isolate_, global, factory->FinalizationRegistry_string(),
|
|
|
|
JS_FINALIZATION_REGISTRY_TYPE, JSFinalizationRegistry::kHeaderSize, 0,
|
2021-06-07 15:24:12 +00:00
|
|
|
factory->the_hole_value(), Builtin::kFinalizationRegistryConstructor);
|
2021-03-07 15:00:51 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(
|
|
|
|
isolate_, finalization_registry_fun,
|
|
|
|
Context::JS_FINALIZATION_REGISTRY_FUNCTION_INDEX);
|
|
|
|
|
|
|
|
finalization_registry_fun->shared().DontAdaptArguments();
|
|
|
|
finalization_registry_fun->shared().set_length(1);
|
|
|
|
|
|
|
|
Handle<JSObject> finalization_registry_prototype(
|
|
|
|
JSObject::cast(finalization_registry_fun->instance_prototype()),
|
|
|
|
isolate());
|
|
|
|
|
|
|
|
InstallToStringTag(isolate_, finalization_registry_prototype,
|
|
|
|
factory->FinalizationRegistry_string());
|
|
|
|
|
|
|
|
SimpleInstallFunction(isolate_, finalization_registry_prototype, "register",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kFinalizationRegistryRegister, 2, false);
|
2021-03-07 15:00:51 +00:00
|
|
|
|
|
|
|
SimpleInstallFunction(isolate_, finalization_registry_prototype,
|
|
|
|
"unregister",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kFinalizationRegistryUnregister, 1, false);
|
2021-03-07 15:00:51 +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"),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kFinalizationRegistryPrototypeCleanupSome, 0, false);
|
2021-03-07 15:00:51 +00:00
|
|
|
native_context()->set_finalization_registry_cleanup_some(*cleanup_some_fun);
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- W e a k R e f
|
|
|
|
Handle<JSFunction> weak_ref_fun = InstallFunction(
|
|
|
|
isolate_, global, "WeakRef", JS_WEAK_REF_TYPE, JSWeakRef::kHeaderSize,
|
2021-06-07 15:24:12 +00:00
|
|
|
0, factory->the_hole_value(), Builtin::kWeakRefConstructor);
|
2021-03-07 15:00:51 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate_, weak_ref_fun,
|
|
|
|
Context::JS_WEAK_REF_FUNCTION_INDEX);
|
|
|
|
|
|
|
|
weak_ref_fun->shared().DontAdaptArguments();
|
|
|
|
weak_ref_fun->shared().set_length(1);
|
|
|
|
|
|
|
|
Handle<JSObject> weak_ref_prototype(
|
|
|
|
JSObject::cast(weak_ref_fun->instance_prototype()), isolate());
|
|
|
|
|
|
|
|
InstallToStringTag(isolate_, weak_ref_prototype, factory->WeakRef_string());
|
|
|
|
|
|
|
|
SimpleInstallFunction(isolate_, weak_ref_prototype, "deref",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kWeakRefDeref, 0, true);
|
2021-03-07 15:00:51 +00:00
|
|
|
}
|
|
|
|
|
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(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate(), arguments_string, Builtin::kIllegal,
|
2020-11-11 06:18:31 +00:00
|
|
|
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.
|
2021-06-07 15:24:12 +00:00
|
|
|
Handle<JSFunction> context_extension_fun = CreateFunction(
|
|
|
|
isolate_, factory->empty_string(), JS_CONTEXT_EXTENSION_OBJECT_TYPE,
|
|
|
|
JSObject::kHeaderSize, 0, factory->the_hole_value(), Builtin::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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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
|
|
|
}
|
2021-06-18 16:39:11 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2017-11-28 08:35:49 +00:00
|
|
|
Handle<JSFunction> Genesis::InstallTypedArray(const char* name,
|
2021-01-18 17:01:02 +00:00
|
|
|
ElementsKind elements_kind,
|
2021-11-24 14:56:56 +00:00
|
|
|
InstanceType constructor_type,
|
2021-05-06 10:43:37 +00:00
|
|
|
int rab_gsab_initial_map_index) {
|
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
|
|
|
|
2021-11-24 14:56:56 +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(),
|
2021-11-24 14:56:56 +00:00
|
|
|
Builtin::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);
|
|
|
|
|
2022-02-04 19:59:03 +00:00
|
|
|
CHECK(JSObject::SetPrototype(isolate(), 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);
|
|
|
|
|
2021-11-24 14:56:56 +00:00
|
|
|
// TODO(v8:11256, ishell): given the granularity of typed array contructor
|
|
|
|
// protectors, consider creating only one constructor instance type for all
|
|
|
|
// typed array constructors.
|
|
|
|
SetConstructorInstanceType(isolate_, result, constructor_type);
|
|
|
|
|
2017-11-28 08:35:49 +00:00
|
|
|
// Setup prototype object.
|
|
|
|
DCHECK(result->prototype().IsJSObject());
|
|
|
|
Handle<JSObject> prototype(JSObject::cast(result->prototype()), isolate());
|
|
|
|
|
2022-02-04 19:59:03 +00:00
|
|
|
CHECK(JSObject::SetPrototype(isolate(), prototype, typed_array_prototype,
|
|
|
|
false, kDontThrow)
|
2016-06-08 07:40:11 +00:00
|
|
|
.FromJust());
|
2017-11-28 08:35:49 +00:00
|
|
|
|
2020-12-16 15:41:50 +00:00
|
|
|
CHECK_NE(prototype->map().ptr(),
|
|
|
|
isolate_->initial_object_prototype()->map().ptr());
|
|
|
|
prototype->map().set_instance_type(JS_TYPED_ARRAY_PROTOTYPE_TYPE);
|
|
|
|
|
2017-11-28 08:35:49 +00:00
|
|
|
InstallConstant(isolate(), prototype, "BYTES_PER_ELEMENT", bytes_per_element);
|
2021-05-06 10:43:37 +00:00
|
|
|
|
|
|
|
// RAB / GSAB backed TypedArrays don't have separate constructors, but they
|
|
|
|
// have their own maps. Create the corresponding map here.
|
|
|
|
Handle<Map> rab_gsab_initial_map = factory()->NewMap(
|
|
|
|
JS_TYPED_ARRAY_TYPE, JSTypedArray::kSizeWithEmbedderFields,
|
|
|
|
GetCorrespondingRabGsabElementsKind(elements_kind), 0);
|
2022-03-21 13:01:45 +00:00
|
|
|
rab_gsab_initial_map->SetConstructor(*result);
|
|
|
|
|
2021-05-12 11:36:30 +00:00
|
|
|
native_context()->set(rab_gsab_initial_map_index, *rab_gsab_initial_map,
|
|
|
|
UPDATE_WRITE_BARRIER, kReleaseStore);
|
2021-05-06 10:43:37 +00:00
|
|
|
Map::SetPrototype(isolate(), rab_gsab_initial_map, prototype);
|
|
|
|
|
2017-11-28 08:35:49 +00:00
|
|
|
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();
|
2022-04-20 13:37:05 +00:00
|
|
|
InitializeGlobal_experimental_web_snapshots();
|
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.
|
2021-06-17 15:43:55 +00:00
|
|
|
base::Vector<const char> name = base::CStrVector(extension->name());
|
2015-05-12 14:00:47 +00:00
|
|
|
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 =
|
2021-08-17 08:52:17 +00:00
|
|
|
Compiler::GetSharedFunctionInfoForScriptWithExtension(
|
|
|
|
isolate, source, ScriptDetails(script_name), extension,
|
|
|
|
ScriptCompiler::kNoCompileOptions, 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();
|
2021-10-18 08:25:43 +00:00
|
|
|
Handle<FixedArray> host_defined_options =
|
|
|
|
isolate->factory()->empty_fixed_array();
|
|
|
|
return !Execution::TryCallScript(isolate, fun, receiver, host_defined_options,
|
|
|
|
Execution::MessageHandling::kKeepPending,
|
|
|
|
nullptr)
|
2017-01-17 13:01:03 +00:00
|
|
|
.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,
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kGeneratorFunctionConstructor);
|
2015-12-10 17:27:44 +00:00
|
|
|
generator_function_function->set_prototype_or_initial_map(
|
2021-04-27 10:36:45 +00:00
|
|
|
native_context->generator_function_map(), kReleaseStore);
|
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
|
|
|
|
2021-04-29 08:59:15 +00:00
|
|
|
JSObject::ForceSetPrototype(isolate, generator_function_function,
|
2016-07-19 11:28:43 +00:00
|
|
|
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,
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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(
|
2021-04-27 10:36:45 +00:00
|
|
|
native_context->async_generator_function_map(), kReleaseStore);
|
[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->shared().DontAdaptArguments();
|
|
|
|
async_generator_function_function->shared().set_length(1);
|
|
|
|
InstallWithIntrinsicDefaultProto(
|
|
|
|
isolate, async_generator_function_function,
|
|
|
|
Context::ASYNC_GENERATOR_FUNCTION_FUNCTION_INDEX);
|
|
|
|
|
2021-04-29 08:59:15 +00:00
|
|
|
JSObject::ForceSetPrototype(isolate, 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
|
|
|
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);
|
2021-04-29 08:59:15 +00:00
|
|
|
JSObject::ForceSetPrototype(isolate, prototype, iterator_prototype);
|
2017-06-30 10:32:50 +00:00
|
|
|
|
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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kSetIteratorPrototypeNext, 0, true);
|
2018-10-10 13:29:32 +00:00
|
|
|
native_context->set_initial_set_iterator_prototype(*prototype);
|
2020-12-16 13:50:35 +00:00
|
|
|
CHECK_NE(prototype->map().ptr(),
|
|
|
|
isolate_->initial_object_prototype()->map().ptr());
|
|
|
|
prototype->map().set_instance_type(JS_SET_ITERATOR_PROTOTYPE_TYPE);
|
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,
|
2021-06-07 15:24:12 +00:00
|
|
|
JSSetIterator::kHeaderSize, 0, prototype, Builtin::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);
|
2021-04-29 08:59:15 +00:00
|
|
|
JSObject::ForceSetPrototype(isolate, prototype, iterator_prototype);
|
2017-06-30 10:32:50 +00:00
|
|
|
|
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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kMapIteratorPrototypeNext, 0, true);
|
2018-10-10 13:29:32 +00:00
|
|
|
native_context->set_initial_map_iterator_prototype(*prototype);
|
2020-12-16 13:50:35 +00:00
|
|
|
CHECK_NE(prototype->map().ptr(),
|
|
|
|
isolate_->initial_object_prototype()->map().ptr());
|
|
|
|
prototype->map().set_instance_type(JS_MAP_ITERATOR_PROTOTYPE_TYPE);
|
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,
|
2021-06-07 15:24:12 +00:00
|
|
|
JSMapIterator::kHeaderSize, 0, prototype, Builtin::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,
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kAsyncFunctionConstructor);
|
2017-05-26 17:19:03 +00:00
|
|
|
async_function_constructor->set_prototype_or_initial_map(
|
2021-04-27 10:36:45 +00:00
|
|
|
native_context->async_function_map(), kReleaseStore);
|
2017-01-20 19:36:28 +00:00
|
|
|
async_function_constructor->shared().DontAdaptArguments();
|
|
|
|
async_function_constructor->shared().set_length(1);
|
2021-07-21 17:19:39 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(
|
|
|
|
isolate, async_function_constructor,
|
|
|
|
Context::ASYNC_FUNCTION_FUNCTION_INDEX);
|
|
|
|
|
2017-06-19 15:17:22 +00:00
|
|
|
native_context->set_async_function_constructor(*async_function_constructor);
|
2021-04-29 08:59:15 +00:00
|
|
|
JSObject::ForceSetPrototype(isolate, async_function_constructor,
|
2017-01-20 19:36:28 +00:00
|
|
|
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,
|
2021-06-07 15:24:12 +00:00
|
|
|
factory->the_hole_value(), Builtin::kUnsupportedThrower);
|
2019-01-07 05:08:08 +00:00
|
|
|
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;
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin id;
|
2019-01-07 05:08:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
FunctionInfo infos[] = {
|
2021-06-07 15:24:12 +00:00
|
|
|
{"getColumnNumber", Builtin::kCallSitePrototypeGetColumnNumber},
|
2020-11-23 19:23:15 +00:00
|
|
|
{"getEnclosingColumnNumber",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kCallSitePrototypeGetEnclosingColumnNumber},
|
2020-11-23 19:23:15 +00:00
|
|
|
{"getEnclosingLineNumber",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kCallSitePrototypeGetEnclosingLineNumber},
|
|
|
|
{"getEvalOrigin", Builtin::kCallSitePrototypeGetEvalOrigin},
|
|
|
|
{"getFileName", Builtin::kCallSitePrototypeGetFileName},
|
|
|
|
{"getFunction", Builtin::kCallSitePrototypeGetFunction},
|
|
|
|
{"getFunctionName", Builtin::kCallSitePrototypeGetFunctionName},
|
|
|
|
{"getLineNumber", Builtin::kCallSitePrototypeGetLineNumber},
|
|
|
|
{"getMethodName", Builtin::kCallSitePrototypeGetMethodName},
|
|
|
|
{"getPosition", Builtin::kCallSitePrototypeGetPosition},
|
|
|
|
{"getPromiseIndex", Builtin::kCallSitePrototypeGetPromiseIndex},
|
2019-01-07 05:08:08 +00:00
|
|
|
{"getScriptNameOrSourceURL",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kCallSitePrototypeGetScriptNameOrSourceURL},
|
2022-05-02 18:26:25 +00:00
|
|
|
{"getScriptHash", Builtin::kCallSitePrototypeGetScriptHash},
|
2021-06-07 15:24:12 +00:00
|
|
|
{"getThis", Builtin::kCallSitePrototypeGetThis},
|
|
|
|
{"getTypeName", Builtin::kCallSitePrototypeGetTypeName},
|
|
|
|
{"isAsync", Builtin::kCallSitePrototypeIsAsync},
|
|
|
|
{"isConstructor", Builtin::kCallSitePrototypeIsConstructor},
|
|
|
|
{"isEval", Builtin::kCallSitePrototypeIsEval},
|
|
|
|
{"isNative", Builtin::kCallSitePrototypeIsNative},
|
|
|
|
{"isPromiseAll", Builtin::kCallSitePrototypeIsPromiseAll},
|
|
|
|
{"isToplevel", Builtin::kCallSitePrototypeIsToplevel},
|
|
|
|
{"toString", Builtin::kCallSitePrototypeToString}};
|
2019-01-07 05:08:08 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-02-08 14:48:01 +00:00
|
|
|
void Genesis::InitializeConsole(Handle<JSObject> extras_binding) {
|
|
|
|
HandleScope scope(isolate());
|
|
|
|
Factory* factory = isolate_->factory();
|
|
|
|
|
|
|
|
// -- C o n s o l e
|
|
|
|
Handle<String> name = factory->console_string();
|
|
|
|
|
|
|
|
Handle<NativeContext> context(isolate_->native_context());
|
|
|
|
Handle<JSGlobalObject> global(context->global_object(), isolate());
|
|
|
|
Handle<SharedFunctionInfo> info =
|
|
|
|
factory->NewSharedFunctionInfoForBuiltin(name, Builtin::kIllegal);
|
|
|
|
info->set_language_mode(LanguageMode::kStrict);
|
|
|
|
|
|
|
|
Handle<JSFunction> cons =
|
|
|
|
Factory::JSFunctionBuilder{isolate(), info, context}.Build();
|
|
|
|
Handle<JSObject> empty = factory->NewJSObject(isolate_->object_function());
|
|
|
|
JSFunction::SetPrototype(cons, empty);
|
|
|
|
|
|
|
|
Handle<JSObject> console = factory->NewJSObject(cons, AllocationType::kOld);
|
|
|
|
DCHECK(console->IsJSObject());
|
|
|
|
|
|
|
|
JSObject::AddProperty(isolate_, extras_binding, name, console, DONT_ENUM);
|
|
|
|
// TODO(v8:11989): remove this in the next release
|
|
|
|
JSObject::AddProperty(isolate_, global, name, console, DONT_ENUM);
|
|
|
|
|
|
|
|
SimpleInstallFunction(isolate_, console, "debug", Builtin::kConsoleDebug, 0,
|
|
|
|
false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "error", Builtin::kConsoleError, 0,
|
|
|
|
false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "info", Builtin::kConsoleInfo, 0,
|
|
|
|
false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "log", Builtin::kConsoleLog, 0,
|
|
|
|
false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "warn", Builtin::kConsoleWarn, 0,
|
|
|
|
false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "dir", Builtin::kConsoleDir, 0,
|
|
|
|
false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "dirxml", Builtin::kConsoleDirXml, 0,
|
|
|
|
false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "table", Builtin::kConsoleTable, 0,
|
|
|
|
false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "trace", Builtin::kConsoleTrace, 0,
|
|
|
|
false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "group", Builtin::kConsoleGroup, 0,
|
|
|
|
false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "groupCollapsed",
|
|
|
|
Builtin::kConsoleGroupCollapsed, 0, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "groupEnd",
|
|
|
|
Builtin::kConsoleGroupEnd, 0, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "clear", Builtin::kConsoleClear, 0,
|
|
|
|
false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "count", Builtin::kConsoleCount, 0,
|
|
|
|
false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "countReset",
|
|
|
|
Builtin::kConsoleCountReset, 0, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "assert",
|
|
|
|
Builtin::kFastConsoleAssert, 0, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "profile", Builtin::kConsoleProfile,
|
|
|
|
0, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "profileEnd",
|
|
|
|
Builtin::kConsoleProfileEnd, 0, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "time", Builtin::kConsoleTime, 0,
|
|
|
|
false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "timeLog", Builtin::kConsoleTimeLog,
|
|
|
|
0, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "timeEnd", Builtin::kConsoleTimeEnd,
|
|
|
|
0, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "timeStamp",
|
|
|
|
Builtin::kConsoleTimeStamp, 0, false, NONE);
|
|
|
|
SimpleInstallFunction(isolate_, console, "context", Builtin::kConsoleContext,
|
|
|
|
1, true, NONE);
|
|
|
|
InstallToStringTag(isolate_, console, "Object");
|
|
|
|
}
|
|
|
|
|
2014-10-20 13:33:34 +00:00
|
|
|
#define EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(id) \
|
|
|
|
void Genesis::InitializeGlobal_##id() {}
|
|
|
|
|
2020-10-14 19:12:37 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_import_assertions)
|
2021-02-17 23:40:14 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_class_static_blocks)
|
2015-09-16 18:01:38 +00:00
|
|
|
|
2019-02-01 02:10:39 +00:00
|
|
|
#ifdef V8_INTL_SUPPORT
|
2021-03-19 21:52:32 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_intl_best_fit_matcher)
|
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
|
|
|
|
|
2022-05-23 23:49:27 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_change_array_by_copy() {
|
|
|
|
if (!FLAG_harmony_change_array_by_copy) return;
|
|
|
|
|
|
|
|
{
|
|
|
|
Handle<JSFunction> array_function(native_context()->array_function(),
|
|
|
|
isolate());
|
|
|
|
Handle<JSObject> array_prototype(
|
|
|
|
JSObject::cast(array_function->instance_prototype()), isolate());
|
|
|
|
|
|
|
|
SimpleInstallFunction(isolate_, array_prototype, "toReversed",
|
|
|
|
Builtin::kArrayPrototypeToReversed, 0, true);
|
2022-06-24 21:19:38 +00:00
|
|
|
SimpleInstallFunction(isolate_, array_prototype, "toSpliced",
|
|
|
|
Builtin::kArrayPrototypeToSpliced, 2, false);
|
2022-06-01 00:06:42 +00:00
|
|
|
SimpleInstallFunction(isolate_, array_prototype, "with",
|
|
|
|
Builtin::kArrayPrototypeWith, 2, true);
|
2022-05-23 23:49:27 +00:00
|
|
|
|
|
|
|
Handle<JSObject> unscopables = Handle<JSObject>::cast(
|
|
|
|
JSObject::GetProperty(isolate(), array_prototype,
|
|
|
|
isolate()->factory()->unscopables_symbol())
|
|
|
|
.ToHandleChecked());
|
|
|
|
|
|
|
|
InstallTrueValuedProperty(isolate_, unscopables, "toReversed");
|
2022-06-24 21:19:38 +00:00
|
|
|
InstallTrueValuedProperty(isolate_, unscopables, "toSpliced");
|
2022-05-23 23:49:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Handle<JSObject> prototype(native_context()->typed_array_prototype(),
|
|
|
|
isolate());
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "toReversed",
|
|
|
|
Builtin::kTypedArrayPrototypeToReversed, 0, true);
|
2022-06-01 00:06:42 +00:00
|
|
|
SimpleInstallFunction(isolate_, prototype, "with",
|
|
|
|
Builtin::kTypedArrayPrototypeWith, 2, true);
|
2022-05-23 23:49:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-18 15:59:17 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_shadow_realm() {
|
|
|
|
if (!FLAG_harmony_shadow_realm) return;
|
2022-03-25 14:59:28 +00:00
|
|
|
Factory* factory = isolate()->factory();
|
2022-01-18 15:59:17 +00:00
|
|
|
// -- S h a d o w R e a l m
|
|
|
|
// #sec-shadowrealm-objects
|
|
|
|
Handle<JSGlobalObject> global(native_context()->global_object(), isolate());
|
2022-03-25 14:59:28 +00:00
|
|
|
Handle<JSFunction> shadow_realm_fun =
|
|
|
|
InstallFunction(isolate_, global, "ShadowRealm", JS_SHADOW_REALM_TYPE,
|
|
|
|
JSShadowRealm::kHeaderSize, 0, factory->the_hole_value(),
|
|
|
|
Builtin::kShadowRealmConstructor);
|
2022-01-18 15:59:17 +00:00
|
|
|
shadow_realm_fun->shared().set_length(0);
|
|
|
|
shadow_realm_fun->shared().DontAdaptArguments();
|
|
|
|
|
|
|
|
// Setup %ShadowRealmPrototype%.
|
|
|
|
Handle<JSObject> prototype(
|
|
|
|
JSObject::cast(shadow_realm_fun->instance_prototype()), isolate());
|
|
|
|
|
2022-03-25 14:59:28 +00:00
|
|
|
InstallToStringTag(isolate_, prototype, factory->ShadowRealm_string());
|
2022-01-18 15:59:17 +00:00
|
|
|
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "evaluate",
|
|
|
|
Builtin::kShadowRealmPrototypeEvaluate, 1, true);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "importValue",
|
|
|
|
Builtin::kShadowRealmPrototypeImportValue, 2, true);
|
2022-02-25 18:27:19 +00:00
|
|
|
|
|
|
|
{ // --- W r a p p e d F u n c t i o n
|
2022-03-25 14:59:28 +00:00
|
|
|
Handle<Map> map = factory->NewMap(JS_WRAPPED_FUNCTION_TYPE,
|
|
|
|
JSWrappedFunction::kHeaderSize,
|
|
|
|
TERMINAL_FAST_ELEMENTS_KIND, 0);
|
2022-02-25 18:27:19 +00:00
|
|
|
map->SetConstructor(native_context()->object_function());
|
|
|
|
map->set_is_callable(true);
|
|
|
|
Handle<JSObject> empty_function(native_context()->function_prototype(),
|
|
|
|
isolate());
|
|
|
|
Map::SetPrototype(isolate(), map, empty_function);
|
|
|
|
|
2022-03-25 14:59:28 +00:00
|
|
|
PropertyAttributes roc_attribs =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
|
|
|
|
Map::EnsureDescriptorSlack(isolate_, map, 2);
|
|
|
|
{ // length
|
2022-05-13 09:19:09 +00:00
|
|
|
static_assert(
|
2022-03-25 14:59:28 +00:00
|
|
|
JSFunctionOrBoundFunctionOrWrappedFunction::kLengthDescriptorIndex ==
|
|
|
|
0);
|
|
|
|
Descriptor d = Descriptor::AccessorConstant(
|
|
|
|
factory->length_string(), factory->wrapped_function_length_accessor(),
|
|
|
|
roc_attribs);
|
|
|
|
map->AppendDescriptor(isolate(), &d);
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // name
|
2022-05-13 09:19:09 +00:00
|
|
|
static_assert(
|
2022-03-25 14:59:28 +00:00
|
|
|
JSFunctionOrBoundFunctionOrWrappedFunction::kNameDescriptorIndex ==
|
|
|
|
1);
|
|
|
|
Descriptor d = Descriptor::AccessorConstant(
|
|
|
|
factory->name_string(), factory->wrapped_function_name_accessor(),
|
|
|
|
roc_attribs);
|
|
|
|
map->AppendDescriptor(isolate(), &d);
|
|
|
|
}
|
|
|
|
|
2022-02-25 18:27:19 +00:00
|
|
|
native_context()->set_wrapped_function_map(*map);
|
|
|
|
}
|
2022-04-20 14:29:28 +00:00
|
|
|
|
|
|
|
// Internal steps of ShadowRealmImportValue
|
|
|
|
{
|
|
|
|
Handle<JSFunction> shadow_realm_import_value_rejected =
|
|
|
|
SimpleCreateFunction(isolate(), factory->empty_string(),
|
|
|
|
Builtin::kShadowRealmImportValueRejected, 1,
|
|
|
|
false);
|
|
|
|
shadow_realm_import_value_rejected->shared().set_native(false);
|
|
|
|
native_context()->set_shadow_realm_import_value_rejected(
|
|
|
|
*shadow_realm_import_value_rejected);
|
|
|
|
}
|
2022-01-18 15:59:17 +00:00
|
|
|
}
|
|
|
|
|
2022-02-23 00:36:17 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_struct() {
|
|
|
|
if (!FLAG_harmony_struct) return;
|
|
|
|
|
|
|
|
Handle<JSGlobalObject> global(native_context()->global_object(), isolate());
|
|
|
|
Handle<String> name =
|
|
|
|
isolate()->factory()->InternalizeUtf8String("SharedStructType");
|
|
|
|
Handle<JSFunction> shared_struct_type_fun = CreateFunctionForBuiltin(
|
|
|
|
isolate(), name, isolate()->strict_function_with_readonly_prototype_map(),
|
|
|
|
Builtin::kSharedStructTypeConstructor);
|
|
|
|
JSObject::MakePrototypesFast(shared_struct_type_fun, kStartAtReceiver,
|
|
|
|
isolate());
|
|
|
|
shared_struct_type_fun->shared().set_native(true);
|
|
|
|
shared_struct_type_fun->shared().DontAdaptArguments();
|
|
|
|
shared_struct_type_fun->shared().set_length(1);
|
|
|
|
JSObject::AddProperty(isolate(), global, "SharedStructType",
|
|
|
|
shared_struct_type_fun, DONT_ENUM);
|
2022-05-28 03:39:27 +00:00
|
|
|
|
2022-06-21 16:17:39 +00:00
|
|
|
{ // SharedArray
|
|
|
|
Handle<String> shared_array_str =
|
|
|
|
isolate()->factory()->InternalizeUtf8String("SharedArray");
|
|
|
|
Handle<JSFunction> shared_array_fun = CreateSharedObjectConstructor(
|
|
|
|
isolate(), shared_array_str, JS_SHARED_ARRAY_TYPE,
|
|
|
|
JSSharedArray::kHeaderSize, SHARED_ARRAY_ELEMENTS,
|
|
|
|
Builtin::kSharedArrayConstructor);
|
|
|
|
shared_array_fun->shared().set_internal_formal_parameter_count(
|
|
|
|
JSParameterCount(0));
|
|
|
|
shared_array_fun->shared().set_length(0);
|
|
|
|
|
|
|
|
// Add the length accessor.
|
|
|
|
Handle<DescriptorArray> descriptors =
|
|
|
|
isolate()->factory()->NewDescriptorArray(1, 0,
|
|
|
|
AllocationType::kSharedOld);
|
|
|
|
Descriptor descriptor = Descriptor::AccessorConstant(
|
|
|
|
isolate()->shared_isolate()->factory()->length_string(),
|
|
|
|
isolate()->shared_isolate()->factory()->shared_array_length_accessor(),
|
|
|
|
ALL_ATTRIBUTES_MASK);
|
|
|
|
descriptors->Set(InternalIndex(0), &descriptor);
|
|
|
|
shared_array_fun->initial_map().InitializeDescriptors(isolate(),
|
|
|
|
*descriptors);
|
|
|
|
|
|
|
|
// Install SharedArray constructor.
|
|
|
|
JSObject::AddProperty(isolate(), global, "SharedArray", shared_array_fun,
|
|
|
|
DONT_ENUM);
|
|
|
|
}
|
|
|
|
|
2022-05-28 03:39:27 +00:00
|
|
|
{ // Atomics.Mutex
|
2022-07-14 23:59:14 +00:00
|
|
|
// TODO(syg): Make a single canonical copy of the map.
|
2022-05-28 03:39:27 +00:00
|
|
|
Handle<String> mutex_str =
|
|
|
|
isolate()->factory()->InternalizeUtf8String("Mutex");
|
|
|
|
Handle<JSFunction> mutex_fun = CreateSharedObjectConstructor(
|
|
|
|
isolate(), mutex_str, JS_ATOMICS_MUTEX_TYPE,
|
2022-06-21 16:17:39 +00:00
|
|
|
JSAtomicsMutex::kHeaderSize, TERMINAL_FAST_ELEMENTS_KIND,
|
|
|
|
Builtin::kAtomicsMutexConstructor);
|
2022-05-28 03:39:27 +00:00
|
|
|
mutex_fun->shared().set_internal_formal_parameter_count(
|
|
|
|
JSParameterCount(0));
|
|
|
|
mutex_fun->shared().set_length(0);
|
|
|
|
native_context()->set_js_atomics_mutex_map(mutex_fun->initial_map());
|
|
|
|
JSObject::AddProperty(isolate(), isolate()->atomics_object(), mutex_str,
|
|
|
|
mutex_fun, DONT_ENUM);
|
|
|
|
|
|
|
|
SimpleInstallFunction(isolate(), mutex_fun, "lock",
|
|
|
|
Builtin::kAtomicsMutexLock, 2, true);
|
|
|
|
SimpleInstallFunction(isolate(), mutex_fun, "tryLock",
|
|
|
|
Builtin::kAtomicsMutexTryLock, 2, true);
|
|
|
|
}
|
2022-02-23 00:36:17 +00:00
|
|
|
}
|
|
|
|
|
2021-07-24 08:22:43 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_array_find_last() {
|
|
|
|
if (!FLAG_harmony_array_find_last) return;
|
|
|
|
|
|
|
|
{
|
|
|
|
Handle<JSFunction> array_function(native_context()->array_function(),
|
|
|
|
isolate());
|
|
|
|
Handle<JSObject> array_prototype(
|
|
|
|
JSObject::cast(array_function->instance_prototype()), isolate());
|
|
|
|
|
|
|
|
SimpleInstallFunction(isolate_, array_prototype, "findLast",
|
|
|
|
Builtin::kArrayPrototypeFindLast, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, array_prototype, "findLastIndex",
|
|
|
|
Builtin::kArrayPrototypeFindLastIndex, 1, false);
|
|
|
|
|
|
|
|
Handle<JSObject> unscopables = Handle<JSObject>::cast(
|
|
|
|
JSObject::GetProperty(isolate(), array_prototype,
|
|
|
|
isolate()->factory()->unscopables_symbol())
|
|
|
|
.ToHandleChecked());
|
|
|
|
|
|
|
|
InstallTrueValuedProperty(isolate_, unscopables, "findLast");
|
|
|
|
InstallTrueValuedProperty(isolate_, unscopables, "findLastIndex");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Handle<JSObject> prototype(native_context()->typed_array_prototype(),
|
|
|
|
isolate());
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "findLast",
|
|
|
|
Builtin::kTypedArrayPrototypeFindLast, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, prototype, "findLastIndex",
|
|
|
|
Builtin::kTypedArrayPrototypeFindLastIndex, 1, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-26 16:33:08 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_array_grouping() {
|
|
|
|
if (!FLAG_harmony_array_grouping) return;
|
|
|
|
|
|
|
|
Handle<JSFunction> array_function(native_context()->array_function(),
|
|
|
|
isolate());
|
|
|
|
Handle<JSObject> array_prototype(
|
|
|
|
JSObject::cast(array_function->instance_prototype()), isolate());
|
|
|
|
|
2022-06-07 14:52:24 +00:00
|
|
|
SimpleInstallFunction(isolate_, array_prototype, "group",
|
|
|
|
Builtin::kArrayPrototypeGroup, 1, false);
|
|
|
|
SimpleInstallFunction(isolate_, array_prototype, "groupToMap",
|
|
|
|
Builtin::kArrayPrototypeGroupToMap, 1, false);
|
2022-01-26 16:33:08 +00:00
|
|
|
|
|
|
|
Handle<JSObject> unscopables = Handle<JSObject>::cast(
|
|
|
|
JSObject::GetProperty(isolate(), array_prototype,
|
|
|
|
isolate()->factory()->unscopables_symbol())
|
|
|
|
.ToHandleChecked());
|
|
|
|
|
2022-06-07 14:52:24 +00:00
|
|
|
InstallTrueValuedProperty(isolate_, unscopables, "group");
|
|
|
|
InstallTrueValuedProperty(isolate_, unscopables, "groupToMap");
|
2022-01-26 16:33:08 +00:00
|
|
|
}
|
|
|
|
|
2021-05-31 07:59:52 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_object_has_own() {
|
|
|
|
if (!FLAG_harmony_object_has_own) return;
|
|
|
|
|
|
|
|
Handle<JSFunction> object_function = isolate_->object_function();
|
|
|
|
SimpleInstallFunction(isolate_, object_function, "hasOwn",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kObjectHasOwn, 2, true);
|
2021-05-31 07:59:52 +00:00
|
|
|
}
|
|
|
|
|
2015-05-22 13:43:38 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_sharedarraybuffer() {
|
(reland) [api] Add API callback setter for the SAB origin trial
This reland patch:
https://chromium-review.googlesource.com/c/v8/v8/+/2867473
(See patchset 1)
The problem was blink injecting interceptor into the window object. It
observes "observation" and "mutations" on this object. When it happens
to the initial empty document, the IPC DidAccessInitialDocument() is
sent and modify the state of the browser process. Causing two tests to
fail.
The diff (See patchset 1..2) includes:
1. Use JSObject::HasRealNamedProperty instead of JsObject::HasProperty.
This skips the interceptor and do not walk the prototype chain.
2. Invert JSObject::HasRealNamedProperty() with
IsSharedArrayBufferConstructorEnabled(), just in case. This avoid
observing the object when not needed.
Original patch description:
---
This change makes it possible to enable SharedArrayBuffer per Context,
controlling whether it should be enabled or not with a callback. The
previous implementation of the reverse origin trial for
SharedArrayBuffer was broken, since the feature could only be enabled
globally per process, and only if the feature flag is set early enough
in the v8 initialization. This does not play well with how origin
trials work.
The implementation is similar to the callbacks that already exist for
the origin trials for WebAssembly simd and exceptions.
SharedArrayBuffer is still controlled by the flag
harmony_sharedarraybuffer. If that flag is disabled, then
SharedArrayBuffer is disabled unconditionally. On top of that, this CL
introduces a new flag for enabling SharedArrayBuffer per context. If
that flag is set, a callback is used to determine whether
SharedArrayBuffer should be enabled.
Note that this only controls whether the SharedArrayBuffer constructor
should be exposed on the global object or not. It is always possible
to construct a SharedArrayBuffer using
new WebAssembly.Memory({
shared:true, initial:0, maximum:0 }).buffer.constructor;
There are few things which I do not like of this approach, but I did
not have better ideas:
1. The complex logic of dobule flag + callback. However, this seemed
the best way to me to not break embedders which rely on that flag
being enabled by default.
2. The fact that what actually matters is just whether the callback
returns `true` once. It would be good to check that the callback gives
a consistent return value, or to provide a better API that cannot be
missunderstood.
Bug: chromium:923807,chromium:1071424,chromium:1138860
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2867473
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Antonio Sartori <antoniosartori@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74378}
---
Bug: chromium:923807,chromium:1071424,chromium:1138860,chromium:1206187
Change-Id: Ibc6b4f8c0e0827178b7f0cbe4b942444bbbe6216
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2880215
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Lutz Vahl <vahl@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Auto-Submit: Arthur Sonzogni <arthursonzogni@chromium.org>
Commit-Queue: Hannes Payer <hpayer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74441}
2021-05-07 11:12:11 +00:00
|
|
|
if (!FLAG_harmony_sharedarraybuffer ||
|
|
|
|
FLAG_enable_sharedarraybuffer_per_context) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kRegExpPrototypeLinearGetter, true);
|
2020-10-29 10:23:57 +00:00
|
|
|
|
|
|
|
// Store regexp prototype map again after change.
|
|
|
|
native_context()->set_regexp_prototype_map(regexp_prototype->map());
|
|
|
|
}
|
|
|
|
|
2021-07-20 07:20:42 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_rab_gsab() {
|
|
|
|
if (!FLAG_harmony_rab_gsab) return;
|
|
|
|
Handle<JSObject> array_buffer_prototype(
|
|
|
|
JSObject::cast(native_context()->array_buffer_fun().instance_prototype()),
|
|
|
|
isolate());
|
|
|
|
SimpleInstallGetter(isolate(), array_buffer_prototype,
|
|
|
|
factory()->max_byte_length_string(),
|
|
|
|
Builtin::kArrayBufferPrototypeGetMaxByteLength, false);
|
|
|
|
SimpleInstallGetter(isolate(), array_buffer_prototype,
|
|
|
|
factory()->resizable_string(),
|
|
|
|
Builtin::kArrayBufferPrototypeGetResizable, false);
|
|
|
|
SimpleInstallFunction(isolate(), array_buffer_prototype, "resize",
|
|
|
|
Builtin::kArrayBufferPrototypeResize, 1, true);
|
2022-07-12 18:26:56 +00:00
|
|
|
SimpleInstallFunction(isolate(), array_buffer_prototype, "transfer",
|
|
|
|
Builtin::kArrayBufferPrototypeTransfer, 0, false);
|
2021-07-20 07:20:42 +00:00
|
|
|
|
|
|
|
Handle<JSObject> shared_array_buffer_prototype(
|
|
|
|
JSObject::cast(
|
|
|
|
native_context()->shared_array_buffer_fun().instance_prototype()),
|
|
|
|
isolate());
|
|
|
|
SimpleInstallGetter(isolate(), shared_array_buffer_prototype,
|
|
|
|
factory()->max_byte_length_string(),
|
|
|
|
Builtin::kSharedArrayBufferPrototypeGetMaxByteLength,
|
|
|
|
false);
|
|
|
|
SimpleInstallGetter(isolate(), shared_array_buffer_prototype,
|
|
|
|
factory()->growable_string(),
|
|
|
|
Builtin::kSharedArrayBufferPrototypeGetGrowable, false);
|
|
|
|
SimpleInstallFunction(isolate(), shared_array_buffer_prototype, "grow",
|
|
|
|
Builtin::kSharedArrayBufferPrototypeGrow, 1, true);
|
|
|
|
}
|
|
|
|
|
2021-10-07 21:22:29 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_temporal() {
|
|
|
|
if (!FLAG_harmony_temporal) return;
|
|
|
|
// -- T e m p o r a l
|
|
|
|
// #sec-temporal-objects
|
|
|
|
Handle<JSObject> temporal =
|
|
|
|
factory()->NewJSObject(isolate_->object_function(), AllocationType::kOld);
|
|
|
|
Handle<JSGlobalObject> global(native_context()->global_object(), isolate());
|
|
|
|
JSObject::AddProperty(isolate_, global, "Temporal", temporal, DONT_ENUM);
|
|
|
|
|
|
|
|
// The initial value of the @@toStringTag property is the string value
|
|
|
|
// *"Temporal"*.
|
|
|
|
// https://github.com/tc39/proposal-temporal/issues/1539
|
|
|
|
InstallToStringTag(isolate_, temporal, "Temporal");
|
|
|
|
|
|
|
|
{ // -- N o w
|
|
|
|
// #sec-temporal-now-object
|
|
|
|
Handle<JSObject> now = factory()->NewJSObject(isolate_->object_function(),
|
|
|
|
AllocationType::kOld);
|
|
|
|
JSObject::AddProperty(isolate_, temporal, "Now", now, DONT_ENUM);
|
2022-01-06 03:32:26 +00:00
|
|
|
InstallToStringTag(isolate_, now, "Temporal.Now");
|
2021-10-07 21:22:29 +00:00
|
|
|
|
|
|
|
// Note: There are NO Temporal.Now.plainTime
|
|
|
|
// See https://github.com/tc39/proposal-temporal/issues/1540
|
|
|
|
#define NOW_LIST(V) \
|
|
|
|
V(timeZone, TimeZone, 0) \
|
|
|
|
V(instant, Instant, 0) \
|
|
|
|
V(plainDateTime, PlainDateTime, 1) \
|
|
|
|
V(plainDateTimeISO, PlainDateTimeISO, 0) \
|
|
|
|
V(zonedDateTime, ZonedDateTime, 1) \
|
|
|
|
V(zonedDateTimeISO, ZonedDateTimeISO, 0) \
|
|
|
|
V(plainDate, PlainDate, 1) \
|
|
|
|
V(plainDateISO, PlainDateISO, 0) \
|
|
|
|
V(plainTimeISO, PlainTimeISO, 0)
|
|
|
|
|
|
|
|
#define INSTALL_NOW_FUNC(p, N, n) \
|
|
|
|
SimpleInstallFunction(isolate(), now, #p, Builtin::kTemporalNow##N, n, false);
|
|
|
|
|
|
|
|
NOW_LIST(INSTALL_NOW_FUNC)
|
|
|
|
#undef INSTALL_NOW_FUNC
|
|
|
|
#undef NOW_LIST
|
|
|
|
}
|
|
|
|
#define INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(N, U, NUM_ARGS) \
|
|
|
|
Handle<JSFunction> obj_func = InstallFunction( \
|
|
|
|
isolate(), temporal, #N, JS_TEMPORAL_##U##_TYPE, \
|
|
|
|
JSTemporal##N::kHeaderSize, 0, factory()->the_hole_value(), \
|
|
|
|
Builtin::kTemporal##N##Constructor); \
|
|
|
|
obj_func->shared().set_length(NUM_ARGS); \
|
|
|
|
obj_func->shared().DontAdaptArguments(); \
|
|
|
|
InstallWithIntrinsicDefaultProto(isolate_, obj_func, \
|
|
|
|
Context::JS_TEMPORAL_##U##_FUNCTION_INDEX); \
|
|
|
|
Handle<JSObject> prototype(JSObject::cast(obj_func->instance_prototype()), \
|
|
|
|
isolate()); \
|
|
|
|
InstallToStringTag(isolate(), prototype, "Temporal." #N);
|
|
|
|
|
|
|
|
#define INSTALL_TEMPORAL_FUNC(T, name, N, arg) \
|
|
|
|
SimpleInstallFunction(isolate(), obj_func, #name, Builtin::kTemporal##T##N, \
|
|
|
|
arg, false);
|
|
|
|
|
|
|
|
{ // -- P l a i n D a t e
|
|
|
|
// #sec-temporal-plaindate-objects
|
|
|
|
// #sec-temporal.plaindate
|
|
|
|
INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(PlainDate, PLAIN_DATE, 3)
|
|
|
|
INSTALL_TEMPORAL_FUNC(PlainDate, from, From, 1)
|
|
|
|
INSTALL_TEMPORAL_FUNC(PlainDate, compare, Compare, 2)
|
|
|
|
|
|
|
|
#ifdef V8_INTL_SUPPORT
|
|
|
|
#define PLAIN_DATE_GETTER_LIST_INTL(V) \
|
|
|
|
V(era, Era) \
|
|
|
|
V(eraYear, EraYear)
|
|
|
|
#else
|
|
|
|
#define PLAIN_DATE_GETTER_LIST_INTL(V)
|
|
|
|
#endif // V8_INTL_SUPPORT
|
|
|
|
|
|
|
|
#define PLAIN_DATE_GETTER_LIST(V) \
|
|
|
|
PLAIN_DATE_GETTER_LIST_INTL(V) \
|
|
|
|
V(calendar, Calendar) \
|
|
|
|
V(year, Year) \
|
|
|
|
V(month, Month) \
|
|
|
|
V(monthCode, MonthCode) \
|
|
|
|
V(day, Day) \
|
|
|
|
V(dayOfWeek, DayOfWeek) \
|
|
|
|
V(dayOfYear, DayOfYear) \
|
|
|
|
V(weekOfYear, WeekOfYear) \
|
|
|
|
V(daysInWeek, DaysInWeek) \
|
|
|
|
V(daysInMonth, DaysInMonth) \
|
|
|
|
V(daysInYear, DaysInYear) \
|
|
|
|
V(monthsInYear, MonthsInYear) \
|
|
|
|
V(inLeapYear, InLeapYear)
|
|
|
|
|
|
|
|
#define INSTALL_PLAIN_DATE_GETTER_FUNC(p, N) \
|
|
|
|
SimpleInstallGetter(isolate(), prototype, isolate_->factory()->p##_string(), \
|
|
|
|
Builtin::kTemporalPlainDatePrototype##N, true);
|
|
|
|
|
|
|
|
PLAIN_DATE_GETTER_LIST(INSTALL_PLAIN_DATE_GETTER_FUNC)
|
|
|
|
#undef PLAIN_DATE_GETTER_LIST
|
|
|
|
#undef PLAIN_DATE_GETTER_LIST_INTL
|
|
|
|
#undef INSTALL_PLAIN_DATE_GETTER_FUNC
|
|
|
|
|
|
|
|
#define PLAIN_DATE_FUNC_LIST(V) \
|
|
|
|
V(toPlainYearMonth, ToPlainYearMonth, 0) \
|
|
|
|
V(toPlainMonthDay, ToPlainMonthDay, 0) \
|
|
|
|
V(getISOFiels, GetISOFields, 0) \
|
|
|
|
V(add, Add, 1) \
|
|
|
|
V(subtract, Subtract, 1) \
|
|
|
|
V(with, With, 1) \
|
|
|
|
V(withCalendar, WithCalendar, 1) \
|
|
|
|
V(until, Until, 1) \
|
|
|
|
V(since, Since, 1) \
|
|
|
|
V(equals, Equals, 1) \
|
|
|
|
V(getISOFields, GetISOFields, 0) \
|
2022-05-19 23:48:12 +00:00
|
|
|
V(toLocaleString, ToLocaleString, 0) \
|
2021-10-07 21:22:29 +00:00
|
|
|
V(toPlainDateTime, ToPlainDateTime, 0) \
|
|
|
|
V(toZonedDateTime, ToZonedDateTime, 1) \
|
|
|
|
V(toString, ToString, 0) \
|
|
|
|
V(toJSON, ToJSON, 0) \
|
|
|
|
V(valueOf, ValueOf, 0)
|
|
|
|
|
|
|
|
#define INSTALL_PLAIN_DATE_FUNC(p, N, min) \
|
|
|
|
SimpleInstallFunction(isolate(), prototype, #p, \
|
|
|
|
Builtin::kTemporalPlainDatePrototype##N, min, false);
|
|
|
|
PLAIN_DATE_FUNC_LIST(INSTALL_PLAIN_DATE_FUNC)
|
|
|
|
#undef PLAIN_DATE_FUNC_LIST
|
|
|
|
#undef INSTALL_PLAIN_DATE_FUNC
|
|
|
|
}
|
|
|
|
{ // -- P l a i n T i m e
|
|
|
|
// #sec-temporal-plaintime-objects
|
|
|
|
// #sec-temporal.plaintime
|
|
|
|
INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(PlainTime, PLAIN_TIME, 0)
|
|
|
|
INSTALL_TEMPORAL_FUNC(PlainTime, from, From, 1)
|
|
|
|
INSTALL_TEMPORAL_FUNC(PlainTime, compare, Compare, 2)
|
|
|
|
|
|
|
|
#define PLAIN_TIME_GETTER_LIST(V) \
|
|
|
|
V(calendar, Calendar) \
|
|
|
|
V(hour, Hour) \
|
|
|
|
V(minute, Minute) \
|
|
|
|
V(second, Second) \
|
|
|
|
V(millisecond, Millisecond) \
|
|
|
|
V(microsecond, Microsecond) \
|
|
|
|
V(nanosecond, Nanosecond)
|
|
|
|
|
|
|
|
#define INSTALL_PLAIN_TIME_GETTER_FUNC(p, N) \
|
|
|
|
SimpleInstallGetter(isolate(), prototype, isolate_->factory()->p##_string(), \
|
|
|
|
Builtin::kTemporalPlainTimePrototype##N, true);
|
|
|
|
|
|
|
|
PLAIN_TIME_GETTER_LIST(INSTALL_PLAIN_TIME_GETTER_FUNC)
|
|
|
|
#undef PLAIN_TIME_GETTER_LIST
|
|
|
|
#undef INSTALL_PLAIN_TIME_GETTER_FUNC
|
|
|
|
|
|
|
|
#define PLAIN_TIME_FUNC_LIST(V) \
|
|
|
|
V(add, Add, 1) \
|
|
|
|
V(subtract, Subtract, 1) \
|
|
|
|
V(with, With, 1) \
|
|
|
|
V(until, Until, 1) \
|
|
|
|
V(since, Since, 1) \
|
|
|
|
V(round, Round, 1) \
|
|
|
|
V(equals, Equals, 1) \
|
|
|
|
V(toPlainDateTime, ToPlainDateTime, 1) \
|
|
|
|
V(toZonedDateTime, ToZonedDateTime, 1) \
|
|
|
|
V(getISOFields, GetISOFields, 0) \
|
2022-05-19 23:48:12 +00:00
|
|
|
V(toLocaleString, ToLocaleString, 0) \
|
2021-10-07 21:22:29 +00:00
|
|
|
V(toString, ToString, 0) \
|
|
|
|
V(toJSON, ToJSON, 0) \
|
|
|
|
V(valueOf, ValueOf, 0)
|
|
|
|
|
|
|
|
#define INSTALL_PLAIN_TIME_FUNC(p, N, min) \
|
|
|
|
SimpleInstallFunction(isolate(), prototype, #p, \
|
|
|
|
Builtin::kTemporalPlainTimePrototype##N, min, false);
|
|
|
|
PLAIN_TIME_FUNC_LIST(INSTALL_PLAIN_TIME_FUNC)
|
|
|
|
#undef PLAIN_TIME_FUNC_LIST
|
|
|
|
#undef INSTALL_PLAIN_TIME_FUNC
|
|
|
|
}
|
|
|
|
{ // -- P l a i n D a t e T i m e
|
|
|
|
// #sec-temporal-plaindatetime-objects
|
|
|
|
// #sec-temporal.plaindatetime
|
|
|
|
INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(PlainDateTime, PLAIN_DATE_TIME, 3)
|
|
|
|
INSTALL_TEMPORAL_FUNC(PlainDateTime, from, From, 1)
|
|
|
|
INSTALL_TEMPORAL_FUNC(PlainDateTime, compare, Compare, 2)
|
|
|
|
|
|
|
|
#ifdef V8_INTL_SUPPORT
|
|
|
|
#define PLAIN_DATE_TIME_GETTER_LIST_INTL(V) \
|
|
|
|
V(era, Era) \
|
|
|
|
V(eraYear, EraYear)
|
|
|
|
#else
|
|
|
|
#define PLAIN_DATE_TIME_GETTER_LIST_INTL(V)
|
|
|
|
#endif // V8_INTL_SUPPORT
|
|
|
|
|
|
|
|
#define PLAIN_DATE_TIME_GETTER_LIST(V) \
|
|
|
|
PLAIN_DATE_TIME_GETTER_LIST_INTL(V) \
|
|
|
|
V(calendar, Calendar) \
|
|
|
|
V(year, Year) \
|
|
|
|
V(month, Month) \
|
|
|
|
V(monthCode, MonthCode) \
|
|
|
|
V(day, Day) \
|
|
|
|
V(hour, Hour) \
|
|
|
|
V(minute, Minute) \
|
|
|
|
V(second, Second) \
|
|
|
|
V(millisecond, Millisecond) \
|
|
|
|
V(microsecond, Microsecond) \
|
|
|
|
V(nanosecond, Nanosecond) \
|
|
|
|
V(dayOfWeek, DayOfWeek) \
|
|
|
|
V(dayOfYear, DayOfYear) \
|
|
|
|
V(weekOfYear, WeekOfYear) \
|
|
|
|
V(daysInWeek, DaysInWeek) \
|
|
|
|
V(daysInMonth, DaysInMonth) \
|
|
|
|
V(daysInYear, DaysInYear) \
|
|
|
|
V(monthsInYear, MonthsInYear) \
|
|
|
|
V(inLeapYear, InLeapYear)
|
|
|
|
|
|
|
|
#define INSTALL_PLAIN_DATE_TIME_GETTER_FUNC(p, N) \
|
|
|
|
SimpleInstallGetter(isolate(), prototype, isolate_->factory()->p##_string(), \
|
|
|
|
Builtin::kTemporalPlainDateTimePrototype##N, true);
|
|
|
|
|
|
|
|
PLAIN_DATE_TIME_GETTER_LIST(INSTALL_PLAIN_DATE_TIME_GETTER_FUNC)
|
|
|
|
#undef PLAIN_DATE_TIME_GETTER_LIST
|
|
|
|
#undef PLAIN_DATE_TIME_GETTER_LIST_INTL
|
|
|
|
#undef INSTALL_PLAIN_DATE_TIME_GETTER_FUNC
|
|
|
|
|
|
|
|
#define PLAIN_DATE_TIME_FUNC_LIST(V) \
|
|
|
|
V(with, With, 1) \
|
|
|
|
V(withPlainTime, WithPlainTime, 0) \
|
|
|
|
V(withPlainDate, WithPlainDate, 1) \
|
|
|
|
V(withCalendar, WithCalendar, 1) \
|
|
|
|
V(add, Add, 1) \
|
|
|
|
V(subtract, Subtract, 1) \
|
|
|
|
V(until, Until, 1) \
|
|
|
|
V(since, Since, 1) \
|
|
|
|
V(round, Round, 1) \
|
|
|
|
V(equals, Equals, 1) \
|
2022-05-19 23:48:12 +00:00
|
|
|
V(toLocaleString, ToLocaleString, 0) \
|
2021-10-07 21:22:29 +00:00
|
|
|
V(toJSON, ToJSON, 0) \
|
|
|
|
V(toString, ToString, 0) \
|
|
|
|
V(valueOf, ValueOf, 0) \
|
|
|
|
V(toZonedDateTime, ToZonedDateTime, 1) \
|
|
|
|
V(toPlainDate, ToPlainDate, 0) \
|
|
|
|
V(toPlainYearMonth, ToPlainYearMonth, 0) \
|
|
|
|
V(toPlainMonthDay, ToPlainMonthDay, 0) \
|
|
|
|
V(toPlainTime, ToPlainTime, 0) \
|
|
|
|
V(getISOFields, GetISOFields, 0)
|
|
|
|
|
|
|
|
#define INSTALL_PLAIN_DATE_TIME_FUNC(p, N, min) \
|
|
|
|
SimpleInstallFunction(isolate(), prototype, #p, \
|
|
|
|
Builtin::kTemporalPlainDateTimePrototype##N, min, \
|
|
|
|
false);
|
|
|
|
PLAIN_DATE_TIME_FUNC_LIST(INSTALL_PLAIN_DATE_TIME_FUNC)
|
|
|
|
#undef PLAIN_DATE_TIME_FUNC_LIST
|
|
|
|
#undef INSTALL_PLAIN_DATE_TIME_FUNC
|
|
|
|
}
|
|
|
|
{ // -- Z o n e d D a t e T i m e
|
|
|
|
// #sec-temporal-zoneddatetime-objects
|
|
|
|
// #sec-temporal.zoneddatetime
|
|
|
|
INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(ZonedDateTime, ZONED_DATE_TIME, 2)
|
|
|
|
INSTALL_TEMPORAL_FUNC(ZonedDateTime, from, From, 1)
|
|
|
|
INSTALL_TEMPORAL_FUNC(ZonedDateTime, compare, Compare, 2)
|
|
|
|
|
|
|
|
#ifdef V8_INTL_SUPPORT
|
|
|
|
#define ZONED_DATE_TIME_GETTER_LIST_INTL(V) \
|
|
|
|
V(era, Era) \
|
|
|
|
V(eraYear, EraYear)
|
|
|
|
#else
|
|
|
|
#define ZONED_DATE_TIME_GETTER_LIST_INTL(V)
|
|
|
|
#endif // V8_INTL_SUPPORT
|
|
|
|
|
|
|
|
#define ZONED_DATE_TIME_GETTER_LIST(V) \
|
|
|
|
ZONED_DATE_TIME_GETTER_LIST_INTL(V) \
|
|
|
|
V(calendar, Calendar) \
|
|
|
|
V(timeZone, TimeZone) \
|
|
|
|
V(year, Year) \
|
|
|
|
V(month, Month) \
|
|
|
|
V(monthCode, MonthCode) \
|
|
|
|
V(day, Day) \
|
|
|
|
V(hour, Hour) \
|
|
|
|
V(minute, Minute) \
|
|
|
|
V(second, Second) \
|
|
|
|
V(millisecond, Millisecond) \
|
|
|
|
V(microsecond, Microsecond) \
|
|
|
|
V(nanosecond, Nanosecond) \
|
|
|
|
V(epochSeconds, EpochSeconds) \
|
|
|
|
V(epochMilliseconds, EpochMilliseconds) \
|
|
|
|
V(epochMicroseconds, EpochMicroseconds) \
|
|
|
|
V(epochNanoseconds, EpochNanoseconds) \
|
|
|
|
V(dayOfWeek, DayOfWeek) \
|
|
|
|
V(dayOfYear, DayOfYear) \
|
|
|
|
V(weekOfYear, WeekOfYear) \
|
|
|
|
V(hoursInDay, HoursInDay) \
|
|
|
|
V(daysInWeek, DaysInWeek) \
|
|
|
|
V(daysInMonth, DaysInMonth) \
|
|
|
|
V(daysInYear, DaysInYear) \
|
|
|
|
V(monthsInYear, MonthsInYear) \
|
|
|
|
V(inLeapYear, InLeapYear) \
|
|
|
|
V(offsetNanoseconds, OffsetNanoseconds) \
|
|
|
|
V(offset, Offset)
|
|
|
|
|
|
|
|
#define INSTALL_ZONED_DATE_TIME_GETTER_FUNC(p, N) \
|
|
|
|
SimpleInstallGetter(isolate(), prototype, isolate_->factory()->p##_string(), \
|
|
|
|
Builtin::kTemporalZonedDateTimePrototype##N, true);
|
|
|
|
|
|
|
|
ZONED_DATE_TIME_GETTER_LIST(INSTALL_ZONED_DATE_TIME_GETTER_FUNC)
|
|
|
|
#undef ZONED_DATE_TIME_GETTER_LIST
|
|
|
|
#undef ZONED_DATE_TIME_GETTER_LIST_INTL
|
|
|
|
#undef INSTALL_ZONED_DATE_TIME_GETTER_FUNC
|
|
|
|
|
|
|
|
#define ZONED_DATE_TIME_FUNC_LIST(V) \
|
|
|
|
V(with, With, 1) \
|
|
|
|
V(withPlainTime, WithPlainTime, 0) \
|
|
|
|
V(withPlainDate, WithPlainDate, 1) \
|
|
|
|
V(withTimeZone, WithTimeZone, 1) \
|
|
|
|
V(withCalendar, WithCalendar, 1) \
|
|
|
|
V(add, Add, 1) \
|
|
|
|
V(subtract, Subtract, 1) \
|
|
|
|
V(until, Until, 1) \
|
|
|
|
V(since, Since, 1) \
|
|
|
|
V(round, Round, 1) \
|
|
|
|
V(equals, Equals, 1) \
|
2022-05-19 23:48:12 +00:00
|
|
|
V(toLocaleString, ToLocaleString, 0) \
|
2021-10-07 21:22:29 +00:00
|
|
|
V(toString, ToString, 0) \
|
|
|
|
V(toJSON, ToJSON, 0) \
|
|
|
|
V(valueOf, ValueOf, 0) \
|
|
|
|
V(startOfDay, StartOfDay, 0) \
|
|
|
|
V(toInstant, ToInstant, 0) \
|
|
|
|
V(toPlainDate, ToPlainDate, 0) \
|
|
|
|
V(toPlainTime, ToPlainTime, 0) \
|
|
|
|
V(toPlainDateTime, ToPlainDateTime, 0) \
|
|
|
|
V(toPlainYearMonth, ToPlainYearMonth, 0) \
|
|
|
|
V(toPlainMonthDay, ToPlainMonthDay, 0) \
|
|
|
|
V(getISOFields, GetISOFields, 0)
|
|
|
|
|
|
|
|
#define INSTALL_ZONED_DATE_TIME_FUNC(p, N, min) \
|
|
|
|
SimpleInstallFunction(isolate(), prototype, #p, \
|
|
|
|
Builtin::kTemporalZonedDateTimePrototype##N, min, \
|
|
|
|
false);
|
|
|
|
ZONED_DATE_TIME_FUNC_LIST(INSTALL_ZONED_DATE_TIME_FUNC)
|
|
|
|
#undef ZONED_DATE_TIME_FUNC_LIST
|
|
|
|
#undef INSTALL_ZONED_DATE_TIME_FUNC
|
|
|
|
}
|
|
|
|
{ // -- D u r a t i o n
|
|
|
|
// #sec-temporal-duration-objects
|
|
|
|
// #sec-temporal.duration
|
|
|
|
INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(Duration, DURATION, 0)
|
|
|
|
INSTALL_TEMPORAL_FUNC(Duration, from, From, 1)
|
|
|
|
INSTALL_TEMPORAL_FUNC(Duration, compare, Compare, 2)
|
|
|
|
|
|
|
|
#define DURATION_GETTER_LIST(V) \
|
|
|
|
V(years, Years) \
|
|
|
|
V(months, Months) \
|
|
|
|
V(weeks, Weeks) \
|
|
|
|
V(days, Days) \
|
|
|
|
V(hours, Hours) \
|
|
|
|
V(minutes, Minutes) \
|
|
|
|
V(seconds, Seconds) \
|
|
|
|
V(milliseconds, Milliseconds) \
|
|
|
|
V(microseconds, Microseconds) \
|
|
|
|
V(nanoseconds, Nanoseconds) \
|
|
|
|
V(sign, Sign) \
|
|
|
|
V(blank, Blank)
|
|
|
|
|
|
|
|
#define INSTALL_DURATION_GETTER_FUNC(p, N) \
|
|
|
|
SimpleInstallGetter(isolate(), prototype, isolate_->factory()->p##_string(), \
|
|
|
|
Builtin::kTemporalDurationPrototype##N, true);
|
|
|
|
|
|
|
|
DURATION_GETTER_LIST(INSTALL_DURATION_GETTER_FUNC)
|
|
|
|
#undef DURATION_GETTER_LIST
|
|
|
|
#undef INSTALL_DURATION_GETTER_FUNC
|
|
|
|
|
2022-05-19 23:48:12 +00:00
|
|
|
#define DURATION_FUNC_LIST(V) \
|
|
|
|
V(with, With, 1) \
|
|
|
|
V(negated, Negated, 0) \
|
|
|
|
V(abs, Abs, 0) \
|
|
|
|
V(add, Add, 1) \
|
|
|
|
V(subtract, Subtract, 1) \
|
|
|
|
V(round, Round, 1) \
|
|
|
|
V(total, Total, 1) \
|
|
|
|
V(toLocaleString, ToLocaleString, 0) \
|
|
|
|
V(toString, ToString, 0) \
|
|
|
|
V(toJSON, ToJSON, 0) \
|
2021-10-07 21:22:29 +00:00
|
|
|
V(valueOf, ValueOf, 0)
|
|
|
|
|
|
|
|
#define INSTALL_DURATION_FUNC(p, N, min) \
|
|
|
|
SimpleInstallFunction(isolate(), prototype, #p, \
|
|
|
|
Builtin::kTemporalDurationPrototype##N, min, false);
|
|
|
|
DURATION_FUNC_LIST(INSTALL_DURATION_FUNC)
|
|
|
|
#undef DURATION_FUNC_LIST
|
|
|
|
#undef INSTALL_DURATION_FUNC
|
|
|
|
}
|
|
|
|
{ // -- I n s t a n t
|
|
|
|
// #sec-temporal-instant-objects
|
|
|
|
// #sec-temporal.instant
|
|
|
|
INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(Instant, INSTANT, 1)
|
|
|
|
INSTALL_TEMPORAL_FUNC(Instant, from, From, 1)
|
|
|
|
INSTALL_TEMPORAL_FUNC(Instant, compare, Compare, 2)
|
|
|
|
INSTALL_TEMPORAL_FUNC(Instant, fromEpochSeconds, FromEpochSeconds, 1)
|
|
|
|
INSTALL_TEMPORAL_FUNC(Instant, fromEpochMilliseconds, FromEpochMilliseconds,
|
|
|
|
1)
|
|
|
|
INSTALL_TEMPORAL_FUNC(Instant, fromEpochMicroseconds, FromEpochMicroseconds,
|
|
|
|
1)
|
|
|
|
INSTALL_TEMPORAL_FUNC(Instant, fromEpochNanoseconds, FromEpochNanoseconds,
|
|
|
|
1)
|
|
|
|
|
|
|
|
#define INSTANT_GETTER_LIST(V) \
|
|
|
|
V(epochSeconds, EpochSeconds) \
|
|
|
|
V(epochMilliseconds, EpochMilliseconds) \
|
|
|
|
V(epochMicroseconds, EpochMicroseconds) \
|
|
|
|
V(epochNanoseconds, EpochNanoseconds)
|
|
|
|
|
|
|
|
#define INSTALL_INSTANT_GETTER_FUNC(p, N) \
|
|
|
|
SimpleInstallGetter(isolate(), prototype, isolate_->factory()->p##_string(), \
|
|
|
|
Builtin::kTemporalInstantPrototype##N, true);
|
|
|
|
|
|
|
|
INSTANT_GETTER_LIST(INSTALL_INSTANT_GETTER_FUNC)
|
|
|
|
#undef INSTANT_GETTER_LIST
|
|
|
|
#undef INSTALL_INSTANT_GETTER_FUNC
|
|
|
|
|
|
|
|
#define INSTANT_FUNC_LIST(V) \
|
|
|
|
V(add, Add, 1) \
|
|
|
|
V(subtract, Subtract, 1) \
|
|
|
|
V(until, Until, 1) \
|
|
|
|
V(since, Since, 1) \
|
|
|
|
V(round, Round, 1) \
|
|
|
|
V(equals, Equals, 1) \
|
2022-05-19 23:48:12 +00:00
|
|
|
V(toLocaleString, ToLocaleString, 0) \
|
2021-10-07 21:22:29 +00:00
|
|
|
V(toString, ToString, 0) \
|
|
|
|
V(toJSON, ToJSON, 0) \
|
|
|
|
V(valueOf, ValueOf, 0) \
|
|
|
|
V(toZonedDateTime, ToZonedDateTime, 1) \
|
|
|
|
V(toZonedDateTimeISO, ToZonedDateTimeISO, 1)
|
|
|
|
|
|
|
|
#define INSTALL_INSTANT_FUNC(p, N, min) \
|
|
|
|
SimpleInstallFunction(isolate(), prototype, #p, \
|
|
|
|
Builtin::kTemporalInstantPrototype##N, min, false);
|
|
|
|
INSTANT_FUNC_LIST(INSTALL_INSTANT_FUNC)
|
|
|
|
#undef INSTANT_FUNC_LIST
|
|
|
|
#undef INSTALL_INSTANT_FUNC
|
|
|
|
}
|
|
|
|
{ // -- P l a i n Y e a r M o n t h
|
|
|
|
// #sec-temporal-plainyearmonth-objects
|
|
|
|
// #sec-temporal.plainyearmonth
|
|
|
|
INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(PlainYearMonth, PLAIN_YEAR_MONTH, 2)
|
|
|
|
INSTALL_TEMPORAL_FUNC(PlainYearMonth, from, From, 1)
|
|
|
|
INSTALL_TEMPORAL_FUNC(PlainYearMonth, compare, Compare, 2)
|
|
|
|
|
|
|
|
#ifdef V8_INTL_SUPPORT
|
|
|
|
#define PLAIN_YEAR_MONTH_GETTER_LIST_INTL(V) \
|
|
|
|
V(era, Era) \
|
|
|
|
V(eraYear, EraYear)
|
|
|
|
#else
|
|
|
|
#define PLAIN_YEAR_MONTH_GETTER_LIST_INTL(V)
|
|
|
|
#endif // V8_INTL_SUPPORT
|
|
|
|
|
|
|
|
#define PLAIN_YEAR_MONTH_GETTER_LIST(V) \
|
|
|
|
PLAIN_YEAR_MONTH_GETTER_LIST_INTL(V) \
|
|
|
|
V(calendar, Calendar) \
|
|
|
|
V(year, Year) \
|
|
|
|
V(month, Month) \
|
|
|
|
V(monthCode, MonthCode) \
|
|
|
|
V(daysInYear, DaysInYear) \
|
|
|
|
V(daysInMonth, DaysInMonth) \
|
|
|
|
V(monthsInYear, MonthsInYear) \
|
|
|
|
V(inLeapYear, InLeapYear)
|
|
|
|
|
|
|
|
#define INSTALL_PLAIN_YEAR_MONTH_GETTER_FUNC(p, N) \
|
|
|
|
SimpleInstallGetter(isolate(), prototype, isolate_->factory()->p##_string(), \
|
|
|
|
Builtin::kTemporalPlainYearMonthPrototype##N, true);
|
|
|
|
|
|
|
|
PLAIN_YEAR_MONTH_GETTER_LIST(INSTALL_PLAIN_YEAR_MONTH_GETTER_FUNC)
|
|
|
|
#undef PLAIN_YEAR_MONTH_GETTER_LIST
|
|
|
|
#undef PLAIN_YEAR_MONTH_GETTER_LIST_INTL
|
|
|
|
#undef INSTALL_PLAIN_YEAR_MONTH_GETTER_FUNC
|
|
|
|
|
2022-05-19 23:48:12 +00:00
|
|
|
#define PLAIN_YEAR_MONTH_FUNC_LIST(V) \
|
|
|
|
V(with, With, 1) \
|
|
|
|
V(add, Add, 1) \
|
|
|
|
V(subtract, Subtract, 1) \
|
|
|
|
V(until, Until, 1) \
|
|
|
|
V(since, Since, 1) \
|
|
|
|
V(equals, Equals, 1) \
|
|
|
|
V(toLocaleString, ToLocaleString, 0) \
|
|
|
|
V(toString, ToString, 0) \
|
|
|
|
V(toJSON, ToJSON, 0) \
|
|
|
|
V(valueOf, ValueOf, 0) \
|
|
|
|
V(toPlainDate, ToPlainDate, 1) \
|
2021-10-07 21:22:29 +00:00
|
|
|
V(getISOFields, GetISOFields, 0)
|
|
|
|
|
|
|
|
#define INSTALL_PLAIN_YEAR_MONTH_FUNC(p, N, min) \
|
|
|
|
SimpleInstallFunction(isolate(), prototype, #p, \
|
|
|
|
Builtin::kTemporalPlainYearMonthPrototype##N, min, \
|
|
|
|
false);
|
|
|
|
PLAIN_YEAR_MONTH_FUNC_LIST(INSTALL_PLAIN_YEAR_MONTH_FUNC)
|
|
|
|
#undef PLAIN_YEAR_MONTH_FUNC_LIST
|
|
|
|
#undef INSTALL_PLAIN_YEAR_MONTH_FUNC
|
|
|
|
}
|
|
|
|
{ // -- P l a i n M o n t h D a y
|
|
|
|
// #sec-temporal-plainmonthday-objects
|
|
|
|
// #sec-temporal.plainmonthday
|
|
|
|
INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(PlainMonthDay, PLAIN_MONTH_DAY, 2)
|
|
|
|
INSTALL_TEMPORAL_FUNC(PlainMonthDay, from, From, 1)
|
|
|
|
// Notice there are no Temporal.PlainMonthDay.compare in the spec.
|
|
|
|
|
|
|
|
#define PLAIN_MONTH_DAY_GETTER_LIST(V) \
|
|
|
|
V(calendar, Calendar) \
|
|
|
|
V(monthCode, MonthCode) \
|
|
|
|
V(day, Day)
|
|
|
|
|
|
|
|
#define INSTALL_PLAIN_MONTH_DAY_GETTER_FUNC(p, N) \
|
|
|
|
SimpleInstallGetter(isolate(), prototype, isolate_->factory()->p##_string(), \
|
|
|
|
Builtin::kTemporalPlainMonthDayPrototype##N, true);
|
|
|
|
|
|
|
|
PLAIN_MONTH_DAY_GETTER_LIST(INSTALL_PLAIN_MONTH_DAY_GETTER_FUNC)
|
|
|
|
#undef PLAIN_MONTH_DAY_GETTER_LIST
|
|
|
|
#undef INSTALL_PLAIN_MONTH_DAY_GETTER_FUNC
|
|
|
|
|
2022-05-19 23:48:12 +00:00
|
|
|
#define PLAIN_MONTH_DAY_FUNC_LIST(V) \
|
|
|
|
V(with, With, 1) \
|
|
|
|
V(equals, Equals, 1) \
|
|
|
|
V(toLocaleString, ToLocaleString, 0) \
|
|
|
|
V(toString, ToString, 0) \
|
|
|
|
V(toJSON, ToJSON, 0) \
|
|
|
|
V(valueOf, ValueOf, 0) \
|
|
|
|
V(toPlainDate, ToPlainDate, 1) \
|
2021-10-07 21:22:29 +00:00
|
|
|
V(getISOFields, GetISOFields, 0)
|
|
|
|
|
|
|
|
#define INSTALL_PLAIN_MONTH_DAY_FUNC(p, N, min) \
|
|
|
|
SimpleInstallFunction(isolate(), prototype, #p, \
|
|
|
|
Builtin::kTemporalPlainMonthDayPrototype##N, min, \
|
|
|
|
false);
|
|
|
|
PLAIN_MONTH_DAY_FUNC_LIST(INSTALL_PLAIN_MONTH_DAY_FUNC)
|
|
|
|
#undef PLAIN_MONTH_DAY_FUNC_LIST
|
|
|
|
#undef INSTALL_PLAIN_MONTH_DAY_FUNC
|
|
|
|
}
|
|
|
|
{ // -- T i m e Z o n e
|
|
|
|
// #sec-temporal-timezone-objects
|
|
|
|
// #sec-temporal.timezone
|
|
|
|
INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(TimeZone, TIME_ZONE, 1)
|
|
|
|
INSTALL_TEMPORAL_FUNC(TimeZone, from, From, 1)
|
|
|
|
|
|
|
|
// #sec-get-temporal.timezone.prototype.id
|
|
|
|
SimpleInstallGetter(isolate(), prototype, factory()->id_string(),
|
|
|
|
Builtin::kTemporalTimeZonePrototypeId, true);
|
|
|
|
|
|
|
|
#define TIME_ZONE_FUNC_LIST(V) \
|
|
|
|
V(getOffsetNanosecondsFor, GetOffsetNanosecondsFor, 1) \
|
|
|
|
V(getOffsetStringFor, GetOffsetStringFor, 1) \
|
|
|
|
V(getPlainDateTimeFor, GetPlainDateTimeFor, 1) \
|
|
|
|
V(getInstantFor, GetInstantFor, 1) \
|
|
|
|
V(getPossibleInstantsFor, GetPossibleInstantsFor, 1) \
|
|
|
|
V(getNextTransition, GetNextTransition, 1) \
|
|
|
|
V(getPreviousTransition, GetPreviousTransition, 1) \
|
|
|
|
V(toString, ToString, 0) \
|
|
|
|
V(toJSON, ToJSON, 0)
|
|
|
|
|
|
|
|
#define INSTALL_TIME_ZONE_FUNC(p, N, min) \
|
|
|
|
SimpleInstallFunction(isolate(), prototype, #p, \
|
|
|
|
Builtin::kTemporalTimeZonePrototype##N, min, false);
|
|
|
|
TIME_ZONE_FUNC_LIST(INSTALL_TIME_ZONE_FUNC)
|
|
|
|
#undef TIME_ZONE_FUNC_LIST
|
|
|
|
#undef INSTALL_TIME_ZONE_FUNC
|
|
|
|
}
|
|
|
|
{ // -- C a l e n d a r
|
|
|
|
// #sec-temporal-calendar-objects
|
|
|
|
// #sec-temporal.calendar
|
|
|
|
INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(Calendar, CALENDAR, 1)
|
|
|
|
INSTALL_TEMPORAL_FUNC(Calendar, from, From, 1)
|
|
|
|
|
|
|
|
// #sec-get-temporal.calendar.prototype.id
|
|
|
|
SimpleInstallGetter(isolate(), prototype, factory()->id_string(),
|
|
|
|
Builtin::kTemporalCalendarPrototypeId, true);
|
|
|
|
|
|
|
|
#ifdef V8_INTL_SUPPORT
|
|
|
|
#define CALENDAR_FUNC_LIST_INTL(V) \
|
|
|
|
V(era, Era, 1) \
|
|
|
|
V(eraYear, EraYear, 1)
|
|
|
|
#else
|
|
|
|
#define CALENDAR_FUNC_LIST_INTL(V)
|
|
|
|
#endif // V8_INTL_SUPPORT
|
|
|
|
|
|
|
|
#define CALENDAR_FUNC_LIST(V) \
|
|
|
|
CALENDAR_FUNC_LIST_INTL(V) \
|
|
|
|
V(dateFromFields, DateFromFields, 1) \
|
|
|
|
V(yearMonthFromFields, YearMonthFromFields, 1) \
|
|
|
|
V(monthDayFromFields, MonthDayFromFields, 1) \
|
|
|
|
V(dateAdd, DateAdd, 2) \
|
|
|
|
V(dateUntil, DateUntil, 2) \
|
|
|
|
V(year, Year, 1) \
|
|
|
|
V(month, Month, 1) \
|
|
|
|
V(monthCode, MonthCode, 1) \
|
|
|
|
V(day, Day, 1) \
|
|
|
|
V(dayOfWeek, DayOfWeek, 1) \
|
|
|
|
V(dayOfYear, DayOfYear, 1) \
|
|
|
|
V(weekOfYear, WeekOfYear, 1) \
|
|
|
|
V(daysInWeek, DaysInWeek, 1) \
|
|
|
|
V(daysInMonth, DaysInMonth, 1) \
|
|
|
|
V(daysInYear, DaysInYear, 1) \
|
|
|
|
V(monthsInYear, MonthsInYear, 1) \
|
|
|
|
V(inLeapYear, InLeapYear, 1) \
|
|
|
|
V(fields, Fields, 1) \
|
|
|
|
V(mergeFields, MergeFields, 2) \
|
|
|
|
V(toString, ToString, 0) \
|
|
|
|
V(toJSON, ToJSON, 0)
|
|
|
|
|
|
|
|
#define INSTALL_CALENDAR_FUNC(p, N, min) \
|
|
|
|
SimpleInstallFunction(isolate(), prototype, #p, \
|
|
|
|
Builtin::kTemporalCalendarPrototype##N, min, false);
|
|
|
|
CALENDAR_FUNC_LIST(INSTALL_CALENDAR_FUNC)
|
|
|
|
#undef CALENDAR_FUNC_LIST
|
|
|
|
#undef CALENDAR_FUNC_LIST_INTL
|
|
|
|
#undef INSTALL_CALENDAE_FUNC
|
|
|
|
}
|
|
|
|
#undef INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE
|
|
|
|
#undef INSTALL_TEMPORAL_FUNC
|
2022-01-06 03:32:26 +00:00
|
|
|
|
2022-05-25 00:53:42 +00:00
|
|
|
{ // -- D a t e
|
|
|
|
// #sec-date.prototype.totemporalinstant
|
|
|
|
Handle<JSFunction> date_func(native_context()->date_function(), isolate());
|
|
|
|
// Setup %DatePrototype%.
|
|
|
|
Handle<JSObject> date_prototype(
|
|
|
|
JSObject::cast(date_func->instance_prototype()), isolate());
|
|
|
|
|
|
|
|
// Install the Date.prototype.toTemporalInstant().
|
|
|
|
SimpleInstallFunction(isolate_, date_prototype, "toTemporalInstant",
|
|
|
|
Builtin::kDatePrototypeToTemporalInstant, 0, false);
|
|
|
|
}
|
|
|
|
|
2022-03-08 05:24:38 +00:00
|
|
|
// The StringListFromIterable functions is created but not
|
|
|
|
// exposed, as it is used internally by CalendarFields.
|
|
|
|
{
|
|
|
|
Handle<JSFunction> func = SimpleCreateFunction(
|
|
|
|
isolate_,
|
|
|
|
factory()->InternalizeUtf8String("StringFixedArrayFromIterable"),
|
|
|
|
Builtin::kStringFixedArrayFromIterable, 1, false);
|
|
|
|
native_context()->set_string_fixed_array_from_iterable(*func);
|
|
|
|
}
|
2022-01-06 03:32:26 +00:00
|
|
|
// The TemporalInsantFixedArrayFromIterable functions is created but not
|
|
|
|
// exposed, as it is used internally by GetPossibleInstantsFor.
|
|
|
|
{
|
|
|
|
Handle<JSFunction> func = SimpleCreateFunction(
|
|
|
|
isolate_,
|
|
|
|
factory()->InternalizeUtf8String(
|
|
|
|
"TemporalInstantFixedArrayFromIterable"),
|
|
|
|
Builtin::kTemporalInstantFixedArrayFromIterable, 1, false);
|
|
|
|
native_context()->set_temporal_instant_fixed_array_from_iterable(*func);
|
|
|
|
}
|
2021-10-07 21:22:29 +00:00
|
|
|
}
|
|
|
|
|
2021-05-06 01:16:34 +00:00
|
|
|
#ifdef V8_INTL_SUPPORT
|
|
|
|
|
2022-03-04 02:53:18 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_intl_number_format_v3() {
|
|
|
|
if (!FLAG_harmony_intl_number_format_v3) return;
|
|
|
|
|
2022-03-05 05:45:04 +00:00
|
|
|
{
|
2022-07-28 18:02:54 +00:00
|
|
|
Handle<JSFunction> number_format_constructor =
|
|
|
|
isolate()->intl_number_format_function();
|
2022-03-04 02:53:18 +00:00
|
|
|
|
2022-03-05 05:45:04 +00:00
|
|
|
Handle<JSObject> prototype(
|
|
|
|
JSObject::cast(number_format_constructor->prototype()), isolate());
|
2022-03-04 02:53:18 +00:00
|
|
|
|
2022-03-05 05:45:04 +00:00
|
|
|
SimpleInstallFunction(isolate(), prototype, "formatRange",
|
|
|
|
Builtin::kNumberFormatPrototypeFormatRange, 2, false);
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "formatRangeToParts",
|
|
|
|
Builtin::kNumberFormatPrototypeFormatRangeToParts, 2,
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
{
|
2022-07-28 18:02:54 +00:00
|
|
|
Handle<JSFunction> plural_rules_constructor =
|
|
|
|
isolate()->intl_plural_rules_function();
|
2022-03-05 05:45:04 +00:00
|
|
|
|
|
|
|
Handle<JSObject> prototype(
|
|
|
|
JSObject::cast(plural_rules_constructor->prototype()), isolate());
|
|
|
|
|
|
|
|
SimpleInstallFunction(isolate(), prototype, "selectRange",
|
|
|
|
Builtin::kPluralRulesPrototypeSelectRange, 2, false);
|
|
|
|
}
|
2021-05-06 01:16:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // V8_INTL_SUPPORT
|
|
|
|
|
2022-04-20 13:37:05 +00:00
|
|
|
void Genesis::InitializeGlobal_experimental_web_snapshots() {
|
|
|
|
if (!FLAG_experimental_web_snapshots) return;
|
|
|
|
|
|
|
|
Handle<JSGlobalObject> global(native_context()->global_object(), isolate());
|
|
|
|
Handle<JSObject> web_snapshot_object =
|
|
|
|
factory()->NewJSObject(isolate_->object_function(), AllocationType::kOld);
|
|
|
|
JSObject::AddProperty(isolate_, global, "WebSnapshot", web_snapshot_object,
|
|
|
|
DONT_ENUM);
|
|
|
|
InstallToStringTag(isolate_, web_snapshot_object, "WebSnapshot");
|
|
|
|
SimpleInstallFunction(isolate_, web_snapshot_object, "serialize",
|
|
|
|
Builtin::kWebSnapshotSerialize, 2, false);
|
|
|
|
SimpleInstallFunction(isolate_, web_snapshot_object, "deserialize",
|
|
|
|
Builtin::kWebSnapshotDeserialize, 2, false);
|
|
|
|
}
|
|
|
|
|
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,
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kArrayBufferIsView, 1, true);
|
2018-01-10 23:52:53 +00:00
|
|
|
|
2021-07-19 08:00:16 +00:00
|
|
|
// Install the "byteLength" getter on the {prototype}.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype, factory()->byte_length_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kArrayBufferPrototypeGetByteLength, false);
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallFunction(isolate(), prototype, "slice",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kArrayBufferPrototypeSlice, 2, true);
|
2018-01-10 23:52:53 +00:00
|
|
|
break;
|
2016-01-01 07:12:48 +00:00
|
|
|
|
2018-01-10 23:52:53 +00:00
|
|
|
case SHARED_ARRAY_BUFFER:
|
2021-07-19 08:00:16 +00:00
|
|
|
// Install the "byteLength" getter on the {prototype}.
|
2018-05-31 14:14:48 +00:00
|
|
|
SimpleInstallGetter(isolate(), prototype, factory()->byte_length_string(),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kSharedArrayBufferPrototypeGetByteLength,
|
2019-03-07 00:27:04 +00:00
|
|
|
false);
|
2021-07-16 12:26:21 +00:00
|
|
|
SimpleInstallFunction(isolate(), prototype, "slice",
|
|
|
|
Builtin::kSharedArrayBufferPrototypeSlice, 2, true);
|
2021-07-19 08:00:16 +00:00
|
|
|
break;
|
2018-01-10 23:52:53 +00:00
|
|
|
}
|
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
|
|
|
|
2021-01-01 10:59:44 +00:00
|
|
|
auto fast_template_instantiations_cache =
|
|
|
|
isolate()->factory()->NewFixedArrayWithHoles(
|
|
|
|
TemplateInfo::kFastTemplateInstantiationsCacheSize);
|
2016-07-28 17:16:33 +00:00
|
|
|
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
|
|
|
|
2021-02-08 15:39:00 +00:00
|
|
|
auto wasm_debug_maps = isolate()->factory()->empty_fixed_array();
|
|
|
|
native_context()->set_wasm_debug_maps(*wasm_debug_maps);
|
2021-01-19 14:05:14 +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());
|
2022-02-25 18:27:19 +00:00
|
|
|
native_context()->set_object_function_prototype(
|
|
|
|
JSObject::cast(object_function->initial_map().prototype()));
|
2017-04-27 14:48:32 +00:00
|
|
|
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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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(
|
2021-06-07 15:24:12 +00:00
|
|
|
isolate(), global_object, "eval", Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::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
|
|
|
|
2019-09-05 11:14:55 +00:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-20 22:15:27 +00:00
|
|
|
// Set up the map for RegExp results objects for regexps with the /d flag.
|
|
|
|
Handle<Map> initial_with_indices_map =
|
|
|
|
Map::Copy(isolate(), initial_map, "JSRegExpResult with indices");
|
|
|
|
initial_with_indices_map->set_instance_size(
|
|
|
|
JSRegExpResultWithIndices::kSize);
|
|
|
|
DCHECK_EQ(initial_with_indices_map->GetInObjectProperties(),
|
|
|
|
JSRegExpResultWithIndices::kInObjectPropertyCount);
|
|
|
|
|
|
|
|
// indices descriptor
|
|
|
|
{
|
|
|
|
Descriptor d =
|
|
|
|
Descriptor::DataField(isolate(), factory()->indices_string(),
|
|
|
|
JSRegExpResultWithIndices::kIndicesIndex, NONE,
|
|
|
|
Representation::Tagged());
|
|
|
|
Map::EnsureDescriptorSlack(isolate(), initial_with_indices_map, 1);
|
|
|
|
initial_with_indices_map->AppendDescriptor(isolate(), &d);
|
|
|
|
}
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_regexp_result_map(*initial_map);
|
2021-07-20 22:15:27 +00:00
|
|
|
native_context()->set_regexp_result_with_indices_map(
|
|
|
|
*initial_with_indices_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",
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kIsTraceCategoryEnabled, 1, true);
|
2018-07-18 18:08:21 +00:00
|
|
|
|
|
|
|
// binding.trace(phase, category, name, id, data)
|
2021-06-07 15:24:12 +00:00
|
|
|
SimpleInstallFunction(isolate(), extras_binding, "trace", Builtin::kTrace, 5,
|
2018-07-18 18:08:21 +00:00
|
|
|
true);
|
|
|
|
|
2022-02-08 14:48:01 +00:00
|
|
|
InitializeConsole(extras_binding);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-07-16 12:10:29 +00:00
|
|
|
void Genesis::InitializeMapCaches() {
|
|
|
|
{
|
|
|
|
Handle<NormalizedMapCache> cache = NormalizedMapCache::New(isolate());
|
|
|
|
native_context()->set_normalized_map_cache(*cache);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Handle<WeakFixedArray> cache = factory()->NewWeakFixedArray(
|
|
|
|
JSObject::kMapCacheSize, AllocationType::kOld);
|
|
|
|
|
|
|
|
DisallowGarbageCollection no_gc;
|
|
|
|
native_context()->set_map_cache(*cache);
|
|
|
|
Map initial = native_context()->object_function().initial_map();
|
2022-01-17 13:46:27 +00:00
|
|
|
cache->Set(0, HeapObjectReference::Weak(initial));
|
2021-07-16 12:10:29 +00:00
|
|
|
cache->Set(initial.GetInObjectProperties(),
|
2022-01-17 13:46:27 +00:00
|
|
|
HeapObjectReference::Weak(initial));
|
2021-07-16 12:10:29 +00:00
|
|
|
}
|
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
|
|
|
|
2021-03-05 11:40:31 +00:00
|
|
|
#if V8_ENABLE_WEBASSEMBLY
|
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
|
|
|
}
|
2021-03-05 11:40:31 +00:00
|
|
|
#endif // V8_ENABLE_WEBASSEMBLY
|
2015-08-27 14:42:36 +00:00
|
|
|
|
2022-05-20 09:53:14 +00:00
|
|
|
#ifdef V8_EXPOSE_MEMORY_CORRUPTION_API
|
|
|
|
if (GetProcessWideSandbox()->is_initialized()) {
|
2022-06-08 09:07:29 +00:00
|
|
|
SandboxTesting::InstallMemoryCorruptionApi(isolate);
|
2022-05-20 09:53:14 +00:00
|
|
|
}
|
|
|
|
#endif // V8_EXPOSE_MEMORY_CORRUPTION_API
|
|
|
|
|
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)) &&
|
2022-03-09 14:23:25 +00:00
|
|
|
(!(FLAG_expose_statistics || 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)) &&
|
2021-06-04 22:52:29 +00:00
|
|
|
(!FLAG_expose_ignition_statistics ||
|
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
|
|
|
}
|
2022-04-06 11:37:57 +00:00
|
|
|
if (!CompileExtension(isolate, extension)) {
|
2021-01-18 12:58:30 +00:00
|
|
|
// If this failed, it either threw an exception, or the isolate is
|
|
|
|
// terminating.
|
|
|
|
DCHECK(isolate->has_pending_exception() ||
|
|
|
|
(isolate->has_scheduled_exception() &&
|
2022-05-09 09:28:47 +00:00
|
|
|
isolate->is_execution_terminating()));
|
2022-04-06 11:37:57 +00:00
|
|
|
if (isolate->has_pending_exception()) {
|
|
|
|
// 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.
|
|
|
|
base::OS::PrintError("Error installing extension '%s'.\n",
|
|
|
|
current->extension()->name());
|
|
|
|
isolate->clear_pending_exception();
|
|
|
|
}
|
|
|
|
return false;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2022-04-06 11:37:57 +00:00
|
|
|
|
|
|
|
DCHECK(!isolate->has_pending_exception() &&
|
|
|
|
!isolate->has_scheduled_exception());
|
2011-11-15 22:48:55 +00:00
|
|
|
extension_states->set_state(current, INSTALLED);
|
2022-04-06 11:37:57 +00:00
|
|
|
return true;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 14:15:49 +00:00
|
|
|
bool Genesis::ConfigureGlobalObject(
|
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
|
|
|
|
2021-04-29 08:59:15 +00:00
|
|
|
JSObject::ForceSetPrototype(isolate(), 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>(
|
2021-03-05 11:23:36 +00:00
|
|
|
from->map().instance_descriptors(isolate()), 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);
|
2021-09-24 22:31:55 +00:00
|
|
|
if (details.location() == PropertyLocation::kField) {
|
2021-11-11 22:26:35 +00:00
|
|
|
if (details.kind() == PropertyKind::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);
|
2022-02-05 00:14:33 +00:00
|
|
|
Handle<Object> value = JSObject::FastPropertyAt(
|
|
|
|
isolate(), 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 {
|
2021-11-11 22:26:35 +00:00
|
|
|
DCHECK_EQ(PropertyKind::kAccessor, details.kind());
|
2017-01-12 16:37:12 +00:00
|
|
|
UNREACHABLE();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2017-01-12 16:37:12 +00:00
|
|
|
|
|
|
|
} else {
|
2021-09-24 22:31:55 +00:00
|
|
|
DCHECK_EQ(PropertyLocation::kDescriptor, details.location());
|
2021-11-11 22:26:35 +00:00
|
|
|
DCHECK_EQ(PropertyKind::kAccessor, details.kind());
|
2019-04-27 09:06:53 +00:00
|
|
|
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());
|
2021-11-11 22:26:35 +00:00
|
|
|
PropertyDetails d(PropertyKind::kAccessor, details.attributes(),
|
2019-04-27 09:06:53 +00:00
|
|
|
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();
|
2022-02-14 08:58:10 +00:00
|
|
|
if (details.kind() == PropertyKind::kData) {
|
|
|
|
JSObject::AddProperty(isolate(), to, key, value, details.attributes());
|
|
|
|
} else {
|
|
|
|
DCHECK_EQ(PropertyKind::kAccessor, details.kind());
|
|
|
|
DCHECK(!to->HasFastProperties());
|
|
|
|
PropertyDetails d(PropertyKind::kAccessor, details.attributes(),
|
|
|
|
PropertyCellType::kMutable);
|
|
|
|
JSObject::SetNormalizedProperty(to, key, value, d);
|
|
|
|
}
|
2015-06-01 16:24:59 +00:00
|
|
|
}
|
2020-11-18 12:15:16 +00:00
|
|
|
|
2021-03-25 23:14:31 +00:00
|
|
|
} else if (V8_ENABLE_SWISS_NAME_DICTIONARY_BOOL) {
|
2020-11-18 12:15:16 +00:00
|
|
|
// Copy all keys and values in enumeration order.
|
2021-03-05 09:45:31 +00:00
|
|
|
Handle<SwissNameDictionary> properties = Handle<SwissNameDictionary>(
|
|
|
|
from->property_dictionary_swiss(), isolate());
|
2020-11-18 12:15:16 +00:00
|
|
|
ReadOnlyRoots roots(isolate());
|
2021-03-05 09:45:31 +00:00
|
|
|
for (InternalIndex entry : properties->IterateEntriesOrdered()) {
|
2020-11-18 12:15:16 +00:00
|
|
|
Object raw_key;
|
|
|
|
if (!properties->ToKey(roots, entry, &raw_key)) continue;
|
|
|
|
|
|
|
|
DCHECK(raw_key.IsName());
|
|
|
|
Handle<Name> key(Name::cast(raw_key), isolate());
|
|
|
|
// If the property is already there we skip it.
|
|
|
|
if (PropertyAlreadyExists(isolate(), to, key)) continue;
|
|
|
|
// Set the property.
|
|
|
|
Handle<Object> value =
|
|
|
|
Handle<Object>(properties->ValueAt(entry), isolate());
|
|
|
|
DCHECK(!value->IsCell());
|
|
|
|
DCHECK(!value->IsTheHole(isolate()));
|
|
|
|
PropertyDetails details = properties->DetailsAt(entry);
|
2021-11-11 22:26:35 +00:00
|
|
|
DCHECK_EQ(PropertyKind::kData, details.kind());
|
2020-11-18 12:15:16 +00:00
|
|
|
JSObject::AddProperty(isolate(), to, key, value, details.attributes());
|
|
|
|
}
|
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);
|
2021-11-11 22:26:35 +00:00
|
|
|
DCHECK_EQ(PropertyKind::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());
|
2021-04-29 08:59:15 +00:00
|
|
|
JSObject::ForceSetPrototype(isolate(), 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(
|
2021-03-05 11:23:36 +00:00
|
|
|
array_function.initial_map().instance_descriptors(isolate()),
|
2020-10-05 09:22:13 +00:00
|
|
|
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()) {
|
2021-04-12 14:38:06 +00:00
|
|
|
RCS_SCOPE(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());
|
2014-07-01 12:12:34 +00:00
|
|
|
|
2021-09-17 14:15:49 +00:00
|
|
|
// If no global proxy template was passed in, simply use the global in the
|
|
|
|
// snapshot. If a global proxy template was passed in it's used to recreate
|
2022-02-14 08:58:10 +00:00
|
|
|
// the global object and its prototype chain, and the data and the accessor
|
|
|
|
// properties from the deserialized global are copied onto it.
|
2021-09-17 14:15:49 +00:00
|
|
|
if (context_snapshot_index == 0 && !global_proxy_template.IsEmpty()) {
|
2016-12-08 12:44:29 +00:00
|
|
|
Handle<JSGlobalObject> global_object =
|
|
|
|
CreateNewGlobals(global_proxy_template, global_proxy);
|
|
|
|
HookUpGlobalObject(global_object);
|
2021-09-17 14:15:49 +00:00
|
|
|
if (!ConfigureGlobalObject(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
|
|
|
}
|
2021-09-17 14:15:49 +00:00
|
|
|
DCHECK_EQ(global_proxy->native_context(), *native_context());
|
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);
|
2021-07-16 12:10:29 +00:00
|
|
|
InitializeMapCaches();
|
2018-12-10 14:45:41 +00:00
|
|
|
InitializeGlobal(global_object, empty_function);
|
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;
|
2021-09-17 14:15:49 +00:00
|
|
|
if (!ConfigureGlobalObject(global_proxy_template)) return;
|
2016-06-27 12:49:51 +00:00
|
|
|
|
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
|
|
|
|
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.
|
2021-04-29 08:59:15 +00:00
|
|
|
JSObject::ForceSetPrototype(isolate, 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
|