2014-03-31 12:01:02 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/bootstrapper.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/accessors.h"
|
2015-02-04 13:01:34 +00:00
|
|
|
#include "src/api-natives.h"
|
2016-06-21 07:01:59 +00:00
|
|
|
#include "src/base/ieee754.h"
|
2014-06-20 08:40:11 +00:00
|
|
|
#include "src/code-stubs.h"
|
2016-08-23 12:35:20 +00:00
|
|
|
#include "src/compiler.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/extensions/externalize-string-extension.h"
|
|
|
|
#include "src/extensions/free-buffer-extension.h"
|
|
|
|
#include "src/extensions/gc-extension.h"
|
2016-04-27 11:10:41 +00:00
|
|
|
#include "src/extensions/ignition-statistics-extension.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/extensions/statistics-extension.h"
|
|
|
|
#include "src/extensions/trigger-failure-extension.h"
|
2015-08-21 06:44:17 +00:00
|
|
|
#include "src/heap/heap.h"
|
2015-09-01 09:25:19 +00:00
|
|
|
#include "src/isolate-inl.h"
|
2015-03-27 15:28:55 +00:00
|
|
|
#include "src/snapshot/natives.h"
|
|
|
|
#include "src/snapshot/snapshot.h"
|
2015-08-27 14:42:36 +00:00
|
|
|
#include "src/wasm/wasm-js.h"
|
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
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
|
|
|
|
2015-04-30 15:10:43 +00:00
|
|
|
template <class Source>
|
|
|
|
Handle<String> Bootstrapper::SourceLookup(int index) {
|
|
|
|
DCHECK(0 <= index && index < Source::GetBuiltinsCount());
|
2013-02-15 09:27:10 +00:00
|
|
|
Heap* heap = isolate_->heap();
|
2016-06-06 12:58:10 +00:00
|
|
|
if (Source::GetSourceCache(heap)->get(index)->IsUndefined(isolate_)) {
|
2012-01-30 12:25:29 +00:00
|
|
|
// We can use external strings for the natives.
|
2015-04-30 15:10:43 +00:00
|
|
|
Vector<const char> source = Source::GetScriptSource(index);
|
2012-01-30 12:25:29 +00:00
|
|
|
NativesExternalStringResource* resource =
|
2015-02-09 09:04:45 +00:00
|
|
|
new NativesExternalStringResource(source.start(), source.length());
|
2016-05-19 12:28:30 +00:00
|
|
|
Handle<ExternalOneByteString> source_code =
|
|
|
|
isolate_->factory()->NewNativeSourceString(resource);
|
2014-10-02 09:39:13 +00:00
|
|
|
// Mark this external string with a special map.
|
2016-05-19 12:28:30 +00:00
|
|
|
DCHECK(source_code->is_short());
|
2015-08-14 18:47:46 +00:00
|
|
|
Source::GetSourceCache(heap)->set(index, *source_code);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2015-08-14 18:47:46 +00:00
|
|
|
Handle<Object> cached_source(Source::GetSourceCache(heap)->get(index),
|
|
|
|
isolate_);
|
2008-07-03 15:10:15 +00:00
|
|
|
return Handle<String>::cast(cached_source);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-30 15:10:43 +00:00
|
|
|
template Handle<String> Bootstrapper::SourceLookup<Natives>(int index);
|
|
|
|
template Handle<String> Bootstrapper::SourceLookup<ExperimentalNatives>(
|
|
|
|
int index);
|
2015-08-20 00:01:07 +00:00
|
|
|
template Handle<String> Bootstrapper::SourceLookup<ExperimentalExtraNatives>(
|
|
|
|
int index);
|
2015-05-08 08:44:47 +00:00
|
|
|
template Handle<String> Bootstrapper::SourceLookup<ExtraNatives>(int index);
|
2015-04-30 15:10:43 +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() {
|
|
|
|
bool flag_given = FLAG_expose_gc_as != NULL && strlen(FLAG_expose_gc_as) != 0;
|
|
|
|
return flag_given ? FLAG_expose_gc_as : "gc";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Extension* Bootstrapper::free_buffer_extension_ = NULL;
|
|
|
|
v8::Extension* Bootstrapper::gc_extension_ = NULL;
|
|
|
|
v8::Extension* Bootstrapper::externalize_string_extension_ = NULL;
|
|
|
|
v8::Extension* Bootstrapper::statistics_extension_ = NULL;
|
|
|
|
v8::Extension* Bootstrapper::trigger_failure_extension_ = NULL;
|
2016-04-27 11:10:41 +00:00
|
|
|
v8::Extension* Bootstrapper::ignition_statistics_extension_ = NULL;
|
2014-01-17 10:52:00 +00:00
|
|
|
|
2013-05-21 12:03:49 +00:00
|
|
|
void Bootstrapper::InitializeOncePerProcess() {
|
2014-01-17 10:52:00 +00:00
|
|
|
free_buffer_extension_ = new FreeBufferExtension;
|
|
|
|
v8::RegisterExtension(free_buffer_extension_);
|
|
|
|
gc_extension_ = new GCExtension(GCFunctionName());
|
|
|
|
v8::RegisterExtension(gc_extension_);
|
|
|
|
externalize_string_extension_ = new ExternalizeStringExtension;
|
|
|
|
v8::RegisterExtension(externalize_string_extension_);
|
|
|
|
statistics_extension_ = new StatisticsExtension;
|
|
|
|
v8::RegisterExtension(statistics_extension_);
|
|
|
|
trigger_failure_extension_ = new TriggerFailureExtension;
|
|
|
|
v8::RegisterExtension(trigger_failure_extension_);
|
2016-04-27 11:10:41 +00:00
|
|
|
ignition_statistics_extension_ = new IgnitionStatisticsExtension;
|
|
|
|
v8::RegisterExtension(ignition_statistics_extension_);
|
2014-01-17 10:52:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Bootstrapper::TearDownExtensions() {
|
|
|
|
delete free_buffer_extension_;
|
2014-08-26 13:07:18 +00:00
|
|
|
free_buffer_extension_ = NULL;
|
2014-01-17 10:52:00 +00:00
|
|
|
delete gc_extension_;
|
2014-08-26 13:07:18 +00:00
|
|
|
gc_extension_ = NULL;
|
2014-01-17 10:52:00 +00:00
|
|
|
delete externalize_string_extension_;
|
2014-08-26 13:07:18 +00:00
|
|
|
externalize_string_extension_ = NULL;
|
2014-01-17 10:52:00 +00:00
|
|
|
delete statistics_extension_;
|
2014-08-26 13:07:18 +00:00
|
|
|
statistics_extension_ = NULL;
|
2014-01-17 10:52:00 +00:00
|
|
|
delete trigger_failure_extension_;
|
2014-08-26 13:07:18 +00:00
|
|
|
trigger_failure_extension_ = NULL;
|
2016-04-27 11:10:41 +00:00
|
|
|
delete ignition_statistics_extension_;
|
|
|
|
ignition_statistics_extension_ = NULL;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-30 15:10:43 +00:00
|
|
|
void DeleteNativeSources(Object* maybe_array) {
|
|
|
|
if (maybe_array->IsFixedArray()) {
|
|
|
|
FixedArray* array = FixedArray::cast(maybe_array);
|
2016-06-06 12:58:10 +00:00
|
|
|
Isolate* isolate = array->GetIsolate();
|
2015-04-30 15:10:43 +00:00
|
|
|
for (int i = 0; i < array->length(); i++) {
|
|
|
|
Object* natives_source = array->get(i);
|
2016-06-06 12:58:10 +00:00
|
|
|
if (!natives_source->IsUndefined(isolate)) {
|
2015-02-09 09:04:45 +00:00
|
|
|
const NativesExternalStringResource* resource =
|
|
|
|
reinterpret_cast<const NativesExternalStringResource*>(
|
|
|
|
ExternalOneByteString::cast(natives_source)->resource());
|
|
|
|
delete resource;
|
|
|
|
}
|
2009-12-11 10:40:01 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-30 15:10:43 +00:00
|
|
|
}
|
2009-12-11 10:40:01 +00:00
|
|
|
|
2015-04-30 15:10:43 +00:00
|
|
|
|
|
|
|
void Bootstrapper::TearDown() {
|
2015-08-14 18:47:46 +00:00
|
|
|
DeleteNativeSources(Natives::GetSourceCache(isolate_->heap()));
|
|
|
|
DeleteNativeSources(ExperimentalNatives::GetSourceCache(isolate_->heap()));
|
|
|
|
DeleteNativeSources(ExtraNatives::GetSourceCache(isolate_->heap()));
|
2015-08-20 00:01:07 +00:00
|
|
|
DeleteNativeSources(
|
|
|
|
ExperimentalExtraNatives::GetSourceCache(isolate_->heap()));
|
|
|
|
|
2013-09-11 08:39:38 +00:00
|
|
|
extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Genesis BASE_EMBEDDED {
|
|
|
|
public:
|
2015-07-06 07:09:07 +00:00
|
|
|
Genesis(Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy,
|
|
|
|
v8::Local<v8::ObjectTemplate> global_proxy_template,
|
2016-06-15 15:38:40 +00:00
|
|
|
v8::ExtensionConfiguration* extensions, size_t context_snapshot_index,
|
2016-02-02 07:25:30 +00:00
|
|
|
GlobalContextType context_type);
|
2016-07-07 19:37:05 +00:00
|
|
|
Genesis(Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy,
|
|
|
|
v8::Local<v8::ObjectTemplate> global_proxy_template);
|
2010-03-23 11:40:38 +00:00
|
|
|
~Genesis() { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-04-14 08:01:19 +00:00
|
|
|
Isolate* isolate() const { return isolate_; }
|
|
|
|
Factory* factory() const { return isolate_->factory(); }
|
|
|
|
Heap* heap() const { return isolate_->heap(); }
|
|
|
|
|
2013-03-18 17:36:47 +00:00
|
|
|
Handle<Context> result() { return result_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2016-07-07 19:37:05 +00:00
|
|
|
Handle<JSGlobalProxy> global_proxy() { return global_proxy_; }
|
|
|
|
|
2013-03-18 17:36:47 +00:00
|
|
|
private:
|
2012-08-17 09:03:08 +00:00
|
|
|
Handle<Context> native_context() { return native_context_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
// Creates some basic objects. Used for creating a context from scratch.
|
|
|
|
void CreateRoots();
|
|
|
|
// Creates the empty function. Used for creating a context from scratch.
|
2011-04-14 08:01:19 +00:00
|
|
|
Handle<JSFunction> CreateEmptyFunction(Isolate* isolate);
|
2011-03-17 20:28:17 +00:00
|
|
|
// Creates the ThrowTypeError function. ECMA 5th Ed. 13.2.3
|
2015-04-09 22:40:16 +00:00
|
|
|
Handle<JSFunction> GetRestrictedFunctionPropertiesThrower();
|
|
|
|
Handle<JSFunction> GetStrictArgumentsPoisonFunction();
|
2015-04-15 17:15:32 +00:00
|
|
|
Handle<JSFunction> GetThrowTypeErrorIntrinsic(Builtins::Name builtin_name);
|
2011-03-17 20:28:17 +00:00
|
|
|
|
|
|
|
void CreateStrictModeFunctionMaps(Handle<JSFunction> empty);
|
2016-04-06 08:37:09 +00:00
|
|
|
void CreateIteratorMaps(Handle<JSFunction> empty);
|
2016-05-17 00:26:53 +00:00
|
|
|
void CreateAsyncFunctionMaps(Handle<JSFunction> empty);
|
2016-03-21 19:39:16 +00:00
|
|
|
void CreateJSProxyMaps();
|
2012-02-20 08:42:18 +00:00
|
|
|
|
|
|
|
// Make the "arguments" and "caller" properties throw a TypeError on access.
|
2016-05-25 17:00:28 +00:00
|
|
|
void AddRestrictedFunctionProperties(Handle<JSFunction> empty);
|
2012-02-20 08:42:18 +00:00
|
|
|
|
2015-01-14 16:42:15 +00:00
|
|
|
// Creates the global objects using the global proxy and the template passed
|
|
|
|
// in through the API. We call this regardless of whether we are building a
|
2010-03-23 11:40:38 +00:00
|
|
|
// context from scratch or using a deserialized one from the partial snapshot
|
|
|
|
// but in the latter case we don't use the objects it produces directly, as
|
|
|
|
// we have to used the deserialized ones that are linked together with the
|
|
|
|
// rest of the context snapshot.
|
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);
|
2010-03-23 11:40:38 +00:00
|
|
|
// Hooks the given global proxy into the context. If the context was created
|
|
|
|
// by deserialization then this will unhook the global proxy that was
|
|
|
|
// deserialized, leaving the GC to pick it up.
|
2015-11-02 14:57:59 +00:00
|
|
|
void HookUpGlobalProxy(Handle<JSGlobalObject> global_object,
|
2010-03-23 11:40:38 +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);
|
2015-06-12 12:34:10 +00:00
|
|
|
// The native context has a ScriptContextTable that store declarative bindings
|
|
|
|
// made in script scopes. Add a "this" binding to that table pointing to the
|
|
|
|
// global proxy.
|
|
|
|
void InstallGlobalThisBinding();
|
2010-03-23 11:40:38 +00:00
|
|
|
// New context initialization. Used for creating a context from scratch.
|
2015-11-02 14:57:59 +00:00
|
|
|
void InitializeGlobal(Handle<JSGlobalObject> global_object,
|
2015-07-13 09:45:43 +00:00
|
|
|
Handle<JSFunction> empty_function,
|
2016-02-02 07:25:30 +00:00
|
|
|
GlobalContextType context_type);
|
2014-09-19 07:36:05 +00:00
|
|
|
void InitializeExperimentalGlobal();
|
2015-10-16 11:27:14 +00:00
|
|
|
// Depending on the situation, expose and/or get rid of the utils object.
|
2016-02-02 07:25:30 +00:00
|
|
|
void ConfigureUtilsObject(GlobalContextType context_type);
|
2014-10-20 13:33:34 +00:00
|
|
|
|
|
|
|
#define DECLARE_FEATURE_INITIALIZATION(id, descr) \
|
|
|
|
void InitializeGlobal_##id();
|
|
|
|
|
2014-11-04 16:05:27 +00:00
|
|
|
HARMONY_INPROGRESS(DECLARE_FEATURE_INITIALIZATION)
|
|
|
|
HARMONY_STAGED(DECLARE_FEATURE_INITIALIZATION)
|
|
|
|
HARMONY_SHIPPING(DECLARE_FEATURE_INITIALIZATION)
|
2014-10-20 13:33:34 +00:00
|
|
|
#undef DECLARE_FEATURE_INITIALIZATION
|
|
|
|
|
2016-01-01 07:12:48 +00:00
|
|
|
Handle<JSFunction> InstallArrayBuffer(Handle<JSObject> target,
|
2016-07-07 19:42:15 +00:00
|
|
|
const char* name, Builtins::Name call,
|
|
|
|
BuiltinFunctionId id);
|
2015-05-12 14:00:47 +00:00
|
|
|
Handle<JSFunction> InstallInternalArray(Handle<JSObject> target,
|
2013-02-15 15:20:05 +00:00
|
|
|
const char* name,
|
|
|
|
ElementsKind elements_kind);
|
2016-02-02 07:25:30 +00:00
|
|
|
bool InstallNatives(GlobalContextType context_type);
|
2013-04-16 14:16:30 +00:00
|
|
|
|
2015-07-28 09:29:34 +00:00
|
|
|
void InstallTypedArray(const char* name, ElementsKind elements_kind,
|
|
|
|
Handle<JSFunction>* fun);
|
2011-04-15 12:31:03 +00:00
|
|
|
bool InstallExperimentalNatives();
|
2015-05-08 08:44:47 +00:00
|
|
|
bool InstallExtraNatives();
|
2015-08-20 00:01:07 +00:00
|
|
|
bool InstallExperimentalExtraNatives();
|
2015-08-12 14:22:07 +00:00
|
|
|
bool InstallDebuggerNatives();
|
2010-12-14 18:53:48 +00:00
|
|
|
void InstallBuiltinFunctionIds();
|
2015-06-03 17:58:29 +00:00
|
|
|
void InstallExperimentalBuiltinFunctionIds();
|
2010-08-25 13:25:54 +00:00
|
|
|
void InitializeNormalizedMapCaches();
|
2011-11-15 23:26:22 +00:00
|
|
|
|
2011-11-15 22:48:55 +00:00
|
|
|
enum ExtensionTraversalState {
|
|
|
|
UNVISITED, VISITED, INSTALLED
|
|
|
|
};
|
|
|
|
|
|
|
|
class ExtensionStates {
|
2012-02-23 09:12:57 +00:00
|
|
|
public:
|
2011-11-15 22:48:55 +00:00
|
|
|
ExtensionStates();
|
|
|
|
ExtensionTraversalState get_state(RegisteredExtension* extension);
|
|
|
|
void set_state(RegisteredExtension* extension,
|
|
|
|
ExtensionTraversalState state);
|
2012-02-23 09:12:57 +00:00
|
|
|
private:
|
2016-06-09 17:58:10 +00:00
|
|
|
base::HashMap map_;
|
2011-11-15 23:26:22 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(ExtensionStates);
|
2011-11-15 22:48:55 +00:00
|
|
|
};
|
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
// Used both for deserialized and from-scratch contexts to add the extensions
|
|
|
|
// provided.
|
2012-08-17 09:03:08 +00:00
|
|
|
static bool InstallExtensions(Handle<Context> native_context,
|
2010-03-23 11:40:38 +00:00
|
|
|
v8::ExtensionConfiguration* extensions);
|
2014-01-16 13:18:28 +00:00
|
|
|
static bool InstallAutoExtensions(Isolate* isolate,
|
|
|
|
ExtensionStates* extension_states);
|
|
|
|
static bool InstallRequestedExtensions(Isolate* isolate,
|
|
|
|
v8::ExtensionConfiguration* extensions,
|
|
|
|
ExtensionStates* extension_states);
|
2013-02-15 09:27:10 +00:00
|
|
|
static bool InstallExtension(Isolate* isolate,
|
|
|
|
const char* name,
|
2011-11-15 22:48:55 +00:00
|
|
|
ExtensionStates* extension_states);
|
2013-02-15 09:27:10 +00:00
|
|
|
static bool InstallExtension(Isolate* isolate,
|
|
|
|
v8::RegisteredExtension* current,
|
2011-11-15 22:48:55 +00:00
|
|
|
ExtensionStates* extension_states);
|
2014-01-16 13:18:28 +00:00
|
|
|
static bool InstallSpecialObjects(Handle<Context> native_context);
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
bool ConfigureApiObject(Handle<JSObject> object,
|
|
|
|
Handle<ObjectTemplateInfo> object_template);
|
2014-07-01 12:12:34 +00:00
|
|
|
bool ConfigureGlobalObjects(
|
2015-07-06 07:09:07 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> global_proxy_template);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Migrates all properties from the 'from' object to the 'to'
|
|
|
|
// object and overrides the prototype in 'to' with the one from
|
|
|
|
// 'from'.
|
|
|
|
void TransferObject(Handle<JSObject> from, Handle<JSObject> to);
|
|
|
|
void TransferNamedProperties(Handle<JSObject> from, Handle<JSObject> to);
|
|
|
|
void TransferIndexedProperties(Handle<JSObject> from, Handle<JSObject> to);
|
|
|
|
|
|
|
|
void MakeFunctionInstancePrototypeWritable();
|
|
|
|
|
2012-07-18 15:38:58 +00:00
|
|
|
void SetStrictFunctionInstanceDescriptor(Handle<Map> map,
|
2014-06-13 12:19:04 +00:00
|
|
|
FunctionMode function_mode);
|
2011-03-17 20:28:17 +00:00
|
|
|
|
2015-05-21 06:15:33 +00:00
|
|
|
static bool CallUtilsFunction(Isolate* isolate, const char* name);
|
|
|
|
|
2015-05-12 14:00:47 +00:00
|
|
|
static bool CompileExtension(Isolate* isolate, v8::Extension* extension);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-03-18 17:36:47 +00:00
|
|
|
Isolate* isolate_;
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<Context> result_;
|
2013-03-18 17:36:47 +00:00
|
|
|
Handle<Context> native_context_;
|
2016-07-07 19:37:05 +00:00
|
|
|
Handle<JSGlobalProxy> global_proxy_;
|
2011-03-17 20:28:17 +00:00
|
|
|
|
2013-05-10 12:59:20 +00:00
|
|
|
// Function maps. Function maps are created initially with a read only
|
|
|
|
// prototype for the processing of JS builtins. Later the function maps are
|
|
|
|
// replaced in order to make prototype writable. These are the final, writable
|
|
|
|
// prototype, maps.
|
2014-03-11 14:41:22 +00:00
|
|
|
Handle<Map> sloppy_function_map_writable_prototype_;
|
|
|
|
Handle<Map> strict_function_map_writable_prototype_;
|
2015-04-15 17:15:32 +00:00
|
|
|
Handle<JSFunction> strict_poison_function_;
|
|
|
|
Handle<JSFunction> restricted_function_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
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void Bootstrapper::Iterate(ObjectVisitor* 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,
|
|
|
|
GlobalContextType context_type) {
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(isolate_);
|
2015-07-13 09:45:43 +00:00
|
|
|
Genesis genesis(isolate_, maybe_global_proxy, global_proxy_template,
|
2016-06-15 15:38:40 +00:00
|
|
|
extensions, context_snapshot_index, context_type);
|
2013-04-10 09:34:37 +00:00
|
|
|
Handle<Context> env = genesis.result();
|
2016-06-27 12:49:51 +00:00
|
|
|
if (env.is_null() || !InstallExtensions(env, extensions)) {
|
2013-04-10 09:34:37 +00:00
|
|
|
return Handle<Context>();
|
2010-03-23 11:40:38 +00:00
|
|
|
}
|
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_);
|
|
|
|
Genesis genesis(isolate_, maybe_global_proxy, global_proxy_template);
|
|
|
|
Handle<JSGlobalProxy> global_proxy = genesis.global_proxy();
|
|
|
|
if (global_proxy.is_null()) return Handle<JSGlobalProxy>();
|
|
|
|
return scope.CloseAndEscape(global_proxy);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
void Bootstrapper::DetachGlobal(Handle<Context> env) {
|
2015-11-06 08:07:52 +00:00
|
|
|
env->GetIsolate()->counters()->errors_thrown_per_context()->AddSample(
|
|
|
|
env->GetErrorsThrown());
|
|
|
|
|
2011-04-14 08:01:19 +00:00
|
|
|
Factory* factory = env->GetIsolate()->factory();
|
2012-08-28 11:25:08 +00:00
|
|
|
Handle<JSGlobalProxy> global_proxy(JSGlobalProxy::cast(env->global_proxy()));
|
|
|
|
global_proxy->set_native_context(*factory->null_value());
|
2016-07-19 11:28:43 +00:00
|
|
|
JSObject::ForceSetPrototype(global_proxy, factory->null_value());
|
2015-02-24 20:50:06 +00:00
|
|
|
global_proxy->map()->SetConstructor(*factory->null_value());
|
2015-02-05 09:35:47 +00:00
|
|
|
if (FLAG_track_detached_contexts) {
|
|
|
|
env->GetIsolate()->AddDetachedContext(env);
|
|
|
|
}
|
2010-03-24 13:24:46 +00:00
|
|
|
}
|
|
|
|
|
2015-08-31 12:52:59 +00:00
|
|
|
namespace {
|
|
|
|
|
2015-12-14 15:11:55 +00:00
|
|
|
void InstallFunction(Handle<JSObject> target, Handle<Name> property_name,
|
|
|
|
Handle<JSFunction> function, Handle<String> function_name,
|
|
|
|
PropertyAttributes attributes = DONT_ENUM) {
|
2015-12-08 16:04:08 +00:00
|
|
|
JSObject::AddProperty(target, property_name, function, attributes);
|
|
|
|
if (target->IsJSGlobalObject()) {
|
|
|
|
function->shared()->set_instance_class_name(*function_name);
|
|
|
|
}
|
|
|
|
function->shared()->set_native(true);
|
2015-12-14 15:11:55 +00:00
|
|
|
}
|
|
|
|
|
2016-04-06 08:37:09 +00:00
|
|
|
void InstallFunction(Handle<JSObject> target, Handle<JSFunction> function,
|
|
|
|
Handle<Name> name,
|
|
|
|
PropertyAttributes attributes = DONT_ENUM) {
|
2015-12-14 15:11:55 +00:00
|
|
|
Handle<String> name_string = Name::ToFunctionName(name).ToHandleChecked();
|
|
|
|
InstallFunction(target, name, function, name_string, attributes);
|
|
|
|
}
|
|
|
|
|
2016-04-06 08:37:09 +00:00
|
|
|
Handle<JSFunction> CreateFunction(Isolate* isolate, Handle<String> name,
|
|
|
|
InstanceType type, int instance_size,
|
|
|
|
MaybeHandle<JSObject> maybe_prototype,
|
|
|
|
Builtins::Name call,
|
|
|
|
bool strict_function_map = false) {
|
2015-12-14 15:11:55 +00:00
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
Handle<Code> call_code(isolate->builtins()->builtin(call));
|
|
|
|
Handle<JSObject> prototype;
|
|
|
|
return maybe_prototype.ToHandle(&prototype)
|
|
|
|
? factory->NewFunction(name, call_code, prototype, type,
|
2016-06-24 13:51:24 +00:00
|
|
|
instance_size, strict_function_map)
|
2015-12-14 15:11:55 +00:00
|
|
|
: factory->NewFunctionWithoutPrototype(name, call_code,
|
|
|
|
strict_function_map);
|
2015-12-08 16:04:08 +00:00
|
|
|
}
|
|
|
|
|
2015-08-31 12:52:59 +00:00
|
|
|
Handle<JSFunction> InstallFunction(Handle<JSObject> target, Handle<Name> name,
|
|
|
|
InstanceType type, int instance_size,
|
|
|
|
MaybeHandle<JSObject> maybe_prototype,
|
|
|
|
Builtins::Name call,
|
|
|
|
PropertyAttributes attributes,
|
|
|
|
bool strict_function_map = false) {
|
|
|
|
Handle<String> name_string = Name::ToFunctionName(name).ToHandleChecked();
|
2015-08-31 10:09:52 +00:00
|
|
|
Handle<JSFunction> function =
|
2015-12-14 15:11:55 +00:00
|
|
|
CreateFunction(target->GetIsolate(), name_string, type, instance_size,
|
|
|
|
maybe_prototype, call, strict_function_map);
|
|
|
|
InstallFunction(target, name, function, name_string, attributes);
|
|
|
|
return function;
|
2015-08-31 12:52:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Handle<JSFunction> InstallFunction(Handle<JSObject> target, const char* name,
|
|
|
|
InstanceType type, int instance_size,
|
|
|
|
MaybeHandle<JSObject> maybe_prototype,
|
|
|
|
Builtins::Name call,
|
|
|
|
bool strict_function_map = false) {
|
|
|
|
Factory* const factory = target->GetIsolate()->factory();
|
2015-11-02 13:04:20 +00:00
|
|
|
PropertyAttributes attributes = DONT_ENUM;
|
2015-08-31 12:52:59 +00:00
|
|
|
return InstallFunction(target, factory->InternalizeUtf8String(name), type,
|
|
|
|
instance_size, maybe_prototype, call, attributes,
|
|
|
|
strict_function_map);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2016-04-06 08:37:09 +00:00
|
|
|
Handle<JSFunction> SimpleCreateFunction(Isolate* isolate, Handle<String> name,
|
|
|
|
Builtins::Name call, int len,
|
|
|
|
bool adapt) {
|
|
|
|
Handle<JSFunction> fun =
|
|
|
|
CreateFunction(isolate, name, JS_OBJECT_TYPE, JSObject::kHeaderSize,
|
|
|
|
MaybeHandle<JSObject>(), call);
|
|
|
|
if (adapt) {
|
|
|
|
fun->shared()->set_internal_formal_parameter_count(len);
|
|
|
|
} else {
|
|
|
|
fun->shared()->DontAdaptArguments();
|
|
|
|
}
|
|
|
|
fun->shared()->set_length(len);
|
|
|
|
return fun;
|
|
|
|
}
|
2015-08-31 12:52:59 +00:00
|
|
|
|
2016-04-06 08:37:09 +00:00
|
|
|
Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base,
|
|
|
|
Handle<String> name,
|
|
|
|
Builtins::Name call, int len,
|
2016-07-22 10:12:24 +00:00
|
|
|
bool adapt,
|
|
|
|
PropertyAttributes attrs = DONT_ENUM) {
|
2016-04-06 08:37:09 +00:00
|
|
|
Handle<JSFunction> fun =
|
|
|
|
SimpleCreateFunction(base->GetIsolate(), name, call, len, adapt);
|
2016-07-22 10:12:24 +00:00
|
|
|
InstallFunction(base, fun, name, attrs);
|
2016-04-06 08:37:09 +00:00
|
|
|
return fun;
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base,
|
|
|
|
const char* name, Builtins::Name call,
|
2016-07-22 10:12:24 +00:00
|
|
|
int len, bool adapt,
|
|
|
|
PropertyAttributes attrs = DONT_ENUM) {
|
2016-04-06 08:37:09 +00:00
|
|
|
Factory* const factory = base->GetIsolate()->factory();
|
|
|
|
return SimpleInstallFunction(base, factory->InternalizeUtf8String(name), call,
|
2016-07-22 10:12:24 +00:00
|
|
|
len, adapt, attrs);
|
2016-04-06 08:37:09 +00:00
|
|
|
}
|
|
|
|
|
2016-08-09 07:13:38 +00:00
|
|
|
Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base,
|
|
|
|
const char* name, Builtins::Name call,
|
|
|
|
int len, bool adapt,
|
|
|
|
BuiltinFunctionId id) {
|
|
|
|
Handle<JSFunction> fun = SimpleInstallFunction(base, name, call, len, adapt);
|
|
|
|
fun->shared()->set_builtin_function_id(id);
|
|
|
|
return fun;
|
|
|
|
}
|
|
|
|
|
2016-10-06 13:00:56 +00:00
|
|
|
void SimpleInstallGetterSetter(Handle<JSObject> base, Handle<String> name,
|
|
|
|
Builtins::Name call_getter,
|
|
|
|
Builtins::Name call_setter,
|
|
|
|
PropertyAttributes attribs) {
|
|
|
|
Isolate* const isolate = base->GetIsolate();
|
|
|
|
|
|
|
|
Handle<String> getter_name =
|
|
|
|
Name::ToFunctionName(name, isolate->factory()->get_string())
|
|
|
|
.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
|
|
|
getter->shared()->set_native(true);
|
|
|
|
|
|
|
|
Handle<String> setter_name =
|
|
|
|
Name::ToFunctionName(name, isolate->factory()->set_string())
|
|
|
|
.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
|
|
|
setter->shared()->set_native(true);
|
|
|
|
|
|
|
|
JSObject::DefineAccessor(base, name, getter, setter, attribs).Check();
|
|
|
|
}
|
|
|
|
|
2016-06-08 07:40:11 +00:00
|
|
|
Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base,
|
2016-10-06 13:00:56 +00:00
|
|
|
Handle<String> name,
|
|
|
|
Handle<Name> property_name,
|
|
|
|
Builtins::Name call, bool adapt) {
|
2016-06-08 07:40:11 +00:00
|
|
|
Isolate* const isolate = base->GetIsolate();
|
2016-10-06 13:00:56 +00:00
|
|
|
|
|
|
|
Handle<String> getter_name =
|
2016-06-08 07:40:11 +00:00
|
|
|
Name::ToFunctionName(name, isolate->factory()->get_string())
|
|
|
|
.ToHandleChecked();
|
2016-10-06 13:00:56 +00:00
|
|
|
Handle<JSFunction> getter =
|
|
|
|
SimpleCreateFunction(isolate, getter_name, call, 0, adapt);
|
|
|
|
getter->shared()->set_native(true);
|
|
|
|
|
|
|
|
Handle<Object> setter = isolate->factory()->undefined_value();
|
|
|
|
|
|
|
|
JSObject::DefineAccessor(base, property_name, getter, setter, DONT_ENUM)
|
|
|
|
.Check();
|
|
|
|
|
|
|
|
return getter;
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base,
|
|
|
|
Handle<String> name, Builtins::Name call,
|
|
|
|
bool adapt) {
|
|
|
|
return SimpleInstallGetter(base, name, name, call, adapt);
|
2016-06-08 07:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base,
|
|
|
|
Handle<String> name, Builtins::Name call,
|
|
|
|
bool adapt, BuiltinFunctionId id) {
|
|
|
|
Handle<JSFunction> fun = SimpleInstallGetter(base, name, call, adapt);
|
|
|
|
fun->shared()->set_builtin_function_id(id);
|
|
|
|
return fun;
|
|
|
|
}
|
|
|
|
|
2016-04-06 08:37:09 +00:00
|
|
|
} // namespace
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-04-14 08:01:19 +00:00
|
|
|
Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) {
|
2011-03-17 20:28:17 +00:00
|
|
|
// Allocate the map for function instances. Maps are allocated first and their
|
|
|
|
// prototypes patched later, once empty function is created.
|
|
|
|
|
2010-04-28 12:05:40 +00:00
|
|
|
// Functions with this map will not have a 'prototype' property, and
|
|
|
|
// can not be used as constructors.
|
2011-03-30 10:46:55 +00:00
|
|
|
Handle<Map> function_without_prototype_map =
|
2016-07-18 15:35:37 +00:00
|
|
|
factory()->CreateSloppyFunctionMap(FUNCTION_WITHOUT_PROTOTYPE);
|
2014-03-11 14:41:22 +00:00
|
|
|
native_context()->set_sloppy_function_without_prototype_map(
|
2011-03-30 10:46:55 +00:00
|
|
|
*function_without_prototype_map);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-17 20:28:17 +00:00
|
|
|
// Allocate the function map. This map is temporary, used only for processing
|
|
|
|
// of builtins.
|
|
|
|
// Later the map is replaced with writable prototype map, allocated below.
|
2014-06-13 12:19:04 +00:00
|
|
|
Handle<Map> function_map =
|
2016-07-18 15:35:37 +00:00
|
|
|
factory()->CreateSloppyFunctionMap(FUNCTION_WITH_READONLY_PROTOTYPE);
|
2014-03-11 14:41:22 +00:00
|
|
|
native_context()->set_sloppy_function_map(*function_map);
|
2014-05-09 17:59:15 +00:00
|
|
|
native_context()->set_sloppy_function_with_readonly_prototype_map(
|
|
|
|
*function_map);
|
2011-03-17 20:28:17 +00:00
|
|
|
|
|
|
|
// The final map for functions. Writeable prototype.
|
|
|
|
// This map is installed in MakeFunctionInstancePrototypeWritable.
|
2014-03-11 14:41:22 +00:00
|
|
|
sloppy_function_map_writable_prototype_ =
|
2016-07-18 15:35:37 +00:00
|
|
|
factory()->CreateSloppyFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE);
|
2011-03-28 13:09:37 +00:00
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
|
2013-05-13 10:59:00 +00:00
|
|
|
Handle<String> object_name = factory->Object_string();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-12-15 19:57:37 +00:00
|
|
|
Handle<JSObject> object_function_prototype;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
{ // --- O b j e c t ---
|
2014-05-09 16:39:33 +00:00
|
|
|
Handle<JSFunction> object_fun = factory->NewFunction(object_name);
|
2014-09-19 13:40:38 +00:00
|
|
|
int unused = JSObject::kInitialGlobalObjectUnusedPropertiesCount;
|
|
|
|
int instance_size = JSObject::kHeaderSize + kPointerSize * unused;
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<Map> object_function_map =
|
2014-09-19 13:40:38 +00:00
|
|
|
factory->NewMap(JS_OBJECT_TYPE, instance_size);
|
2015-08-11 19:36:04 +00:00
|
|
|
object_function_map->SetInObjectProperties(unused);
|
2014-08-11 14:00:58 +00:00
|
|
|
JSFunction::SetInitialMap(object_fun, object_function_map,
|
|
|
|
isolate->factory()->null_value());
|
2014-09-19 13:40:38 +00:00
|
|
|
object_function_map->set_unused_property_fields(unused);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_object_function(*object_fun);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Allocate a new prototype for the object function.
|
2014-12-15 19:57:37 +00:00
|
|
|
object_function_prototype =
|
|
|
|
factory->NewJSObject(isolate->object_function(), TENURED);
|
|
|
|
Handle<Map> map = Map::Copy(handle(object_function_prototype->map()),
|
|
|
|
"EmptyObjectPrototype");
|
2014-08-11 14:00:58 +00:00
|
|
|
map->set_is_prototype_map(true);
|
2016-07-01 19:16:53 +00:00
|
|
|
// Ban re-setting Object.prototype.__proto__ to prevent Proxy security bug
|
|
|
|
map->set_immutable_proto(true);
|
2014-12-15 19:57:37 +00:00
|
|
|
object_function_prototype->set_map(*map);
|
2013-04-04 12:10:23 +00:00
|
|
|
|
2014-12-15 19:57:37 +00:00
|
|
|
native_context()->set_initial_object_prototype(*object_function_prototype);
|
2013-05-13 07:35:26 +00:00
|
|
|
// For bootstrapping set the array prototype to be the same as the object
|
|
|
|
// prototype, otherwise the missing initial_array_prototype will cause
|
|
|
|
// assertions during startup.
|
2014-12-15 19:57:37 +00:00
|
|
|
native_context()->set_initial_array_prototype(*object_function_prototype);
|
|
|
|
Accessors::FunctionSetPrototype(object_fun, object_function_prototype)
|
|
|
|
.Assert();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2015-04-23 00:29:40 +00:00
|
|
|
// Allocate the empty function as the prototype for function - ES6 19.2.3
|
2015-11-24 17:16:40 +00:00
|
|
|
Handle<Code> code(isolate->builtins()->EmptyFunction());
|
2015-04-23 00:29:40 +00:00
|
|
|
Handle<JSFunction> empty_function =
|
|
|
|
factory->NewFunctionWithoutPrototype(factory->empty_string(), code);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-08-11 14:00:58 +00:00
|
|
|
// Allocate the function map first and then patch the prototype later
|
|
|
|
Handle<Map> empty_function_map =
|
2016-07-18 15:35:37 +00:00
|
|
|
factory->CreateSloppyFunctionMap(FUNCTION_WITHOUT_PROTOTYPE);
|
2014-08-11 14:00:58 +00:00
|
|
|
DCHECK(!empty_function_map->is_dictionary_map());
|
2015-04-10 12:13:18 +00:00
|
|
|
Map::SetPrototype(empty_function_map, object_function_prototype);
|
2014-08-11 14:00:58 +00:00
|
|
|
empty_function_map->set_is_prototype_map(true);
|
2015-04-09 22:40:16 +00:00
|
|
|
|
2014-08-11 14:00:58 +00:00
|
|
|
empty_function->set_map(*empty_function_map);
|
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
// --- E m p t y ---
|
2014-09-10 12:38:12 +00:00
|
|
|
Handle<String> source = factory->NewStringFromStaticChars("() {}");
|
2011-03-28 13:09:37 +00:00
|
|
|
Handle<Script> script = factory->NewScript(source);
|
2015-09-28 13:10:13 +00:00
|
|
|
script->set_type(Script::TYPE_NATIVE);
|
2010-03-23 11:40:38 +00:00
|
|
|
empty_function->shared()->set_start_position(0);
|
|
|
|
empty_function->shared()->set_end_position(source->length());
|
|
|
|
empty_function->shared()->DontAdaptArguments();
|
2015-06-25 12:19:55 +00:00
|
|
|
SharedFunctionInfo::SetScript(handle(empty_function->shared()), script);
|
2011-03-17 20:28:17 +00:00
|
|
|
|
|
|
|
// Set prototypes for the function maps.
|
2015-04-10 12:13:18 +00:00
|
|
|
Handle<Map> sloppy_function_map(native_context()->sloppy_function_map(),
|
|
|
|
isolate);
|
|
|
|
Handle<Map> sloppy_function_without_prototype_map(
|
|
|
|
native_context()->sloppy_function_without_prototype_map(), isolate);
|
|
|
|
Map::SetPrototype(sloppy_function_map, empty_function);
|
|
|
|
Map::SetPrototype(sloppy_function_without_prototype_map, empty_function);
|
|
|
|
Map::SetPrototype(sloppy_function_map_writable_prototype_, empty_function);
|
2015-04-09 22:40:16 +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
|
|
|
|
|
|
|
|
2015-04-15 17:15:32 +00:00
|
|
|
// Creates the %ThrowTypeError% function.
|
|
|
|
Handle<JSFunction> Genesis::GetThrowTypeErrorIntrinsic(
|
|
|
|
Builtins::Name builtin_name) {
|
|
|
|
Handle<String> name =
|
|
|
|
factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("ThrowTypeError"));
|
|
|
|
Handle<Code> code(isolate()->builtins()->builtin(builtin_name));
|
|
|
|
Handle<JSFunction> function =
|
2016-05-25 17:00:28 +00:00
|
|
|
factory()->NewFunctionWithoutPrototype(name, code, true);
|
2015-04-15 17:15:32 +00:00
|
|
|
function->shared()->DontAdaptArguments();
|
|
|
|
|
|
|
|
// %ThrowTypeError% must not have a name property.
|
2015-11-26 09:34:11 +00:00
|
|
|
if (JSReceiver::DeleteProperty(function, factory()->name_string())
|
2015-12-09 18:06:49 +00:00
|
|
|
.IsNothing()) {
|
2015-11-26 09:34:11 +00:00
|
|
|
DCHECK(false);
|
2015-12-09 18:06:49 +00:00
|
|
|
}
|
2015-04-15 17:15:32 +00:00
|
|
|
|
|
|
|
// length needs to be non configurable.
|
|
|
|
Handle<Object> value(Smi::FromInt(function->shared()->length()), isolate());
|
|
|
|
JSObject::SetOwnPropertyIgnoreAttributes(
|
|
|
|
function, factory()->length_string(), value,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY))
|
|
|
|
.Assert();
|
|
|
|
|
2015-12-09 18:06:49 +00:00
|
|
|
if (JSObject::PreventExtensions(function, Object::THROW_ON_ERROR)
|
|
|
|
.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
|
|
|
|
|
|
|
return function;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-17 20:28:17 +00:00
|
|
|
// ECMAScript 5th Edition, 13.2.3
|
2015-04-09 22:40:16 +00:00
|
|
|
Handle<JSFunction> Genesis::GetRestrictedFunctionPropertiesThrower() {
|
2015-04-15 17:15:32 +00:00
|
|
|
if (restricted_function_properties_thrower_.is_null()) {
|
|
|
|
restricted_function_properties_thrower_ = GetThrowTypeErrorIntrinsic(
|
|
|
|
Builtins::kRestrictedFunctionPropertiesThrower);
|
2014-05-19 10:47:00 +00:00
|
|
|
}
|
2015-04-15 17:15:32 +00:00
|
|
|
return restricted_function_properties_thrower_;
|
2014-05-19 10:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-09 22:40:16 +00:00
|
|
|
Handle<JSFunction> Genesis::GetStrictArgumentsPoisonFunction() {
|
2015-04-15 17:15:32 +00:00
|
|
|
if (strict_poison_function_.is_null()) {
|
|
|
|
strict_poison_function_ = GetThrowTypeErrorIntrinsic(
|
|
|
|
Builtins::kRestrictedStrictArgumentsPropertiesThrower);
|
2011-05-24 11:07:06 +00:00
|
|
|
}
|
2015-04-15 17:15:32 +00:00
|
|
|
return strict_poison_function_;
|
2011-03-17 20:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) {
|
|
|
|
// Allocate map for the prototype-less strict mode instances.
|
2014-03-11 14:41:22 +00:00
|
|
|
Handle<Map> strict_function_without_prototype_map =
|
2016-07-18 15:35:37 +00:00
|
|
|
factory()->CreateStrictFunctionMap(FUNCTION_WITHOUT_PROTOTYPE, empty);
|
2014-03-11 14:41:22 +00:00
|
|
|
native_context()->set_strict_function_without_prototype_map(
|
|
|
|
*strict_function_without_prototype_map);
|
2011-03-17 20:28:17 +00:00
|
|
|
|
|
|
|
// Allocate map for the strict mode functions. This map is temporary, used
|
|
|
|
// only for processing of builtins.
|
|
|
|
// Later the map is replaced with writable prototype map, allocated below.
|
2016-07-18 15:35:37 +00:00
|
|
|
Handle<Map> strict_function_map = factory()->CreateStrictFunctionMap(
|
|
|
|
FUNCTION_WITH_READONLY_PROTOTYPE, empty);
|
2014-03-11 14:41:22 +00:00
|
|
|
native_context()->set_strict_function_map(*strict_function_map);
|
2011-03-17 20:28:17 +00:00
|
|
|
|
|
|
|
// The final map for the strict mode functions. Writeable prototype.
|
|
|
|
// This map is installed in MakeFunctionInstancePrototypeWritable.
|
2016-07-18 15:35:37 +00:00
|
|
|
strict_function_map_writable_prototype_ = factory()->CreateStrictFunctionMap(
|
|
|
|
FUNCTION_WITH_WRITEABLE_PROTOTYPE, empty);
|
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
|
|
|
}
|
|
|
|
|
2016-04-06 08:37:09 +00:00
|
|
|
void Genesis::CreateIteratorMaps(Handle<JSFunction> empty) {
|
2015-10-16 11:27:14 +00:00
|
|
|
// Create iterator-related meta-objects.
|
|
|
|
Handle<JSObject> iterator_prototype =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
2016-09-21 14:17:42 +00:00
|
|
|
|
|
|
|
Handle<JSFunction> iterator_prototype_iterator = SimpleCreateFunction(
|
|
|
|
isolate(), factory()->NewStringFromAsciiChecked("[Symbol.iterator]"),
|
2016-09-27 11:05:26 +00:00
|
|
|
Builtins::kIteratorPrototypeIterator, 0, true);
|
2016-09-21 14:17:42 +00:00
|
|
|
iterator_prototype_iterator->shared()->set_native(true);
|
|
|
|
|
|
|
|
JSObject::AddProperty(iterator_prototype, factory()->iterator_symbol(),
|
|
|
|
iterator_prototype_iterator, DONT_ENUM);
|
|
|
|
native_context()->set_initial_iterator_prototype(*iterator_prototype);
|
|
|
|
|
2015-10-16 11:27:14 +00:00
|
|
|
Handle<JSObject> generator_object_prototype =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
2016-05-18 09:15:40 +00:00
|
|
|
native_context()->set_initial_generator_prototype(
|
|
|
|
*generator_object_prototype);
|
2016-07-19 11:28:43 +00:00
|
|
|
JSObject::ForceSetPrototype(generator_object_prototype, iterator_prototype);
|
2015-10-16 11:27:14 +00:00
|
|
|
Handle<JSObject> generator_function_prototype =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
2016-07-19 11:28:43 +00:00
|
|
|
JSObject::ForceSetPrototype(generator_function_prototype, empty);
|
2015-10-16 11:27:14 +00:00
|
|
|
|
2016-04-06 08:37:09 +00:00
|
|
|
JSObject::AddProperty(
|
|
|
|
generator_function_prototype, factory()->to_string_tag_symbol(),
|
|
|
|
factory()->NewStringFromAsciiChecked("GeneratorFunction"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
2015-10-16 11:27:14 +00:00
|
|
|
JSObject::AddProperty(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));
|
|
|
|
|
2016-04-06 08:37:09 +00:00
|
|
|
JSObject::AddProperty(generator_object_prototype,
|
|
|
|
factory()->constructor_string(),
|
|
|
|
generator_function_prototype,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
JSObject::AddProperty(generator_object_prototype,
|
|
|
|
factory()->to_string_tag_symbol(),
|
|
|
|
factory()->NewStringFromAsciiChecked("Generator"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
SimpleInstallFunction(generator_object_prototype, "next",
|
|
|
|
Builtins::kGeneratorPrototypeNext, 1, true);
|
|
|
|
SimpleInstallFunction(generator_object_prototype, "return",
|
|
|
|
Builtins::kGeneratorPrototypeReturn, 1, true);
|
|
|
|
SimpleInstallFunction(generator_object_prototype, "throw",
|
|
|
|
Builtins::kGeneratorPrototypeThrow, 1, true);
|
|
|
|
|
2016-09-30 07:53:43 +00:00
|
|
|
// Internal version of generator_prototype_next, flagged as non-native.
|
|
|
|
Handle<JSFunction> generator_next_internal =
|
|
|
|
SimpleCreateFunction(isolate(), factory()->next_string(),
|
|
|
|
Builtins::kGeneratorPrototypeNext, 1, true);
|
|
|
|
native_context()->set_generator_next_internal(*generator_next_internal);
|
|
|
|
|
2015-10-16 11:27:14 +00:00
|
|
|
// Create maps for generator functions and their prototypes. Store those
|
|
|
|
// maps in the native context. The "prototype" property descriptor is
|
|
|
|
// writable, non-enumerable, and non-configurable (as per ES6 draft
|
|
|
|
// 04-14-15, section 25.2.4.3).
|
|
|
|
Handle<Map> strict_function_map(strict_function_map_writable_prototype_);
|
|
|
|
// Generator functions do not have "caller" or "arguments" accessors.
|
|
|
|
Handle<Map> sloppy_generator_function_map =
|
|
|
|
Map::Copy(strict_function_map, "SloppyGeneratorFunction");
|
2016-01-18 13:10:38 +00:00
|
|
|
sloppy_generator_function_map->set_is_constructor(false);
|
2015-10-16 11:27:14 +00:00
|
|
|
Map::SetPrototype(sloppy_generator_function_map,
|
|
|
|
generator_function_prototype);
|
|
|
|
native_context()->set_sloppy_generator_function_map(
|
|
|
|
*sloppy_generator_function_map);
|
|
|
|
|
|
|
|
Handle<Map> strict_generator_function_map =
|
|
|
|
Map::Copy(strict_function_map, "StrictGeneratorFunction");
|
2016-01-18 13:10:38 +00:00
|
|
|
strict_generator_function_map->set_is_constructor(false);
|
2015-10-16 11:27:14 +00:00
|
|
|
Map::SetPrototype(strict_generator_function_map,
|
|
|
|
generator_function_prototype);
|
|
|
|
native_context()->set_strict_generator_function_map(
|
|
|
|
*strict_generator_function_map);
|
|
|
|
|
|
|
|
Handle<JSFunction> object_function(native_context()->object_function());
|
|
|
|
Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0);
|
|
|
|
Map::SetPrototype(generator_object_prototype_map, generator_object_prototype);
|
|
|
|
native_context()->set_generator_object_prototype_map(
|
|
|
|
*generator_object_prototype_map);
|
|
|
|
}
|
|
|
|
|
2016-05-17 00:26:53 +00:00
|
|
|
void Genesis::CreateAsyncFunctionMaps(Handle<JSFunction> empty) {
|
|
|
|
// %AsyncFunctionPrototype% intrinsic
|
|
|
|
Handle<JSObject> async_function_prototype =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
2016-07-19 11:28:43 +00:00
|
|
|
JSObject::ForceSetPrototype(async_function_prototype, empty);
|
2016-05-17 00:26:53 +00:00
|
|
|
|
|
|
|
JSObject::AddProperty(async_function_prototype,
|
|
|
|
factory()->to_string_tag_symbol(),
|
|
|
|
factory()->NewStringFromAsciiChecked("AsyncFunction"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
|
|
|
Handle<Map> strict_function_map(
|
|
|
|
native_context()->strict_function_without_prototype_map());
|
|
|
|
Handle<Map> sloppy_async_function_map =
|
|
|
|
Map::Copy(strict_function_map, "SloppyAsyncFunction");
|
|
|
|
sloppy_async_function_map->set_is_constructor(false);
|
|
|
|
Map::SetPrototype(sloppy_async_function_map, async_function_prototype);
|
|
|
|
native_context()->set_sloppy_async_function_map(*sloppy_async_function_map);
|
|
|
|
|
|
|
|
Handle<Map> strict_async_function_map =
|
|
|
|
Map::Copy(strict_function_map, "StrictAsyncFunction");
|
|
|
|
strict_async_function_map->set_is_constructor(false);
|
|
|
|
Map::SetPrototype(strict_async_function_map, async_function_prototype);
|
|
|
|
native_context()->set_strict_async_function_map(*strict_async_function_map);
|
|
|
|
}
|
|
|
|
|
2016-03-21 19:39:16 +00:00
|
|
|
void Genesis::CreateJSProxyMaps() {
|
|
|
|
// Allocate the different maps for all Proxy types.
|
|
|
|
// Next to the default proxy, we need maps indicating callable and
|
|
|
|
// constructable proxies.
|
|
|
|
Handle<Map> proxy_function_map =
|
|
|
|
Map::Copy(isolate()->sloppy_function_without_prototype_map(), "Proxy");
|
|
|
|
proxy_function_map->set_is_constructor(true);
|
|
|
|
native_context()->set_proxy_function_map(*proxy_function_map);
|
|
|
|
|
|
|
|
Handle<Map> proxy_map =
|
|
|
|
factory()->NewMap(JS_PROXY_TYPE, JSProxy::kSize, FAST_ELEMENTS);
|
|
|
|
proxy_map->set_dictionary_map(true);
|
|
|
|
native_context()->set_proxy_map(*proxy_map);
|
|
|
|
|
|
|
|
Handle<Map> proxy_callable_map = Map::Copy(proxy_map, "callable Proxy");
|
|
|
|
proxy_callable_map->set_is_callable();
|
|
|
|
native_context()->set_proxy_callable_map(*proxy_callable_map);
|
|
|
|
proxy_callable_map->SetConstructor(native_context()->function_function());
|
|
|
|
|
|
|
|
Handle<Map> proxy_constructor_map =
|
|
|
|
Map::Copy(proxy_callable_map, "constructor Proxy");
|
|
|
|
proxy_constructor_map->set_is_constructor(true);
|
|
|
|
native_context()->set_proxy_constructor_map(*proxy_constructor_map);
|
|
|
|
}
|
2015-10-16 11:27:14 +00:00
|
|
|
|
2014-05-19 10:47:00 +00:00
|
|
|
static void ReplaceAccessors(Handle<Map> map,
|
|
|
|
Handle<String> name,
|
|
|
|
PropertyAttributes attributes,
|
|
|
|
Handle<AccessorPair> accessor_pair) {
|
|
|
|
DescriptorArray* descriptors = map->instance_descriptors();
|
2016-02-17 16:23:38 +00:00
|
|
|
int idx = descriptors->SearchWithCache(map->GetIsolate(), *name, *map);
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor descriptor(name, accessor_pair, attributes);
|
2014-05-19 10:47:00 +00:00
|
|
|
descriptors->Replace(idx, &descriptor);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
Handle<JSFunction> thrower = GetRestrictedFunctionPropertiesThrower();
|
|
|
|
Handle<AccessorPair> accessors = factory()->NewAccessorPair();
|
|
|
|
accessors->set_getter(*thrower);
|
|
|
|
accessors->set_setter(*thrower);
|
|
|
|
|
2016-05-25 17:00:28 +00:00
|
|
|
Handle<Map> map(empty->map());
|
2015-04-09 22:40:16 +00:00
|
|
|
ReplaceAccessors(map, factory()->arguments_string(), rw_attribs, accessors);
|
|
|
|
ReplaceAccessors(map, factory()->caller_string(), rw_attribs, accessors);
|
2011-03-17 20:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
static void AddToWeakNativeContextList(Context* context) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(context->IsNativeContext());
|
2016-06-06 12:58:10 +00:00
|
|
|
Isolate* isolate = context->GetIsolate();
|
|
|
|
Heap* heap = isolate->heap();
|
2010-12-07 11:31:57 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
{ // NOLINT
|
2016-06-06 12:58:10 +00:00
|
|
|
DCHECK(context->next_context_link()->IsUndefined(isolate));
|
2010-12-07 11:31:57 +00:00
|
|
|
// Check that context is not in the list yet.
|
2012-08-17 09:03:08 +00:00
|
|
|
for (Object* current = heap->native_contexts_list();
|
2016-06-06 12:58:10 +00:00
|
|
|
!current->IsUndefined(isolate);
|
2016-05-12 08:50:18 +00:00
|
|
|
current = Context::cast(current)->next_context_link()) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(current != context);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2015-05-27 14:13:04 +00:00
|
|
|
context->set(Context::NEXT_CONTEXT_LINK, heap->native_contexts_list(),
|
|
|
|
UPDATE_WEAK_WRITE_BARRIER);
|
2012-08-17 09:03:08 +00:00
|
|
|
heap->set_native_contexts_list(context);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
void Genesis::CreateRoots() {
|
2012-08-17 09:03:08 +00:00
|
|
|
// Allocate the native context FixedArray first and then patch the
|
2010-03-23 11:40:38 +00:00
|
|
|
// closure and extension object later (we need the empty function
|
|
|
|
// and the global object, but in order to create those, we need the
|
2012-08-17 09:03:08 +00:00
|
|
|
// native context).
|
2013-03-18 17:36:47 +00:00
|
|
|
native_context_ = factory()->NewNativeContext();
|
|
|
|
AddToWeakNativeContextList(*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(
|
|
|
|
native_context()->script_context_table());
|
|
|
|
Handle<ScopeInfo> scope_info = ScopeInfo::CreateGlobalThisBinding(isolate());
|
|
|
|
Handle<JSFunction> closure(native_context()->closure());
|
|
|
|
Handle<Context> context = factory()->NewScriptContext(closure, scope_info);
|
|
|
|
|
|
|
|
// Go ahead and hook it up while we're at it.
|
|
|
|
int slot = scope_info->ReceiverContextSlotIndex();
|
|
|
|
DCHECK_EQ(slot, Context::MIN_CONTEXT_SLOTS);
|
|
|
|
context->set(slot, native_context()->global_proxy());
|
|
|
|
|
|
|
|
Handle<ScriptContextTable> new_script_contexts =
|
|
|
|
ScriptContextTable::Extend(script_contexts, context);
|
|
|
|
native_context()->set_script_context_table(*new_script_contexts);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-02 14:57:59 +00:00
|
|
|
Handle<JSGlobalObject> Genesis::CreateNewGlobals(
|
2015-07-06 07:09:07 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> global_proxy_template,
|
2015-01-14 16:42:15 +00:00
|
|
|
Handle<JSGlobalProxy> global_proxy) {
|
2014-07-01 12:12:34 +00:00
|
|
|
// The argument global_proxy_template aka data is an ObjectTemplateInfo.
|
2010-03-23 11:40:38 +00:00
|
|
|
// It has a constructor pointer that points at global_constructor which is a
|
|
|
|
// FunctionTemplateInfo.
|
2015-01-14 16:42:15 +00:00
|
|
|
// The global_proxy_constructor is used to (re)initialize the
|
2014-07-01 12:12:34 +00:00
|
|
|
// global_proxy. The global_proxy_constructor also has a prototype_template
|
|
|
|
// pointer that points at js_global_object_template which is an
|
|
|
|
// ObjectTemplateInfo.
|
2010-03-23 11:40:38 +00:00
|
|
|
// That in turn has a constructor pointer that points at
|
2014-07-01 12:12:34 +00:00
|
|
|
// js_global_object_constructor which is a FunctionTemplateInfo.
|
|
|
|
// js_global_object_constructor is used to make js_global_object_function
|
|
|
|
// js_global_object_function is used to make the new global_object.
|
2010-03-23 11:40:38 +00:00
|
|
|
//
|
|
|
|
// --- G l o b a l ---
|
2014-07-01 12:12:34 +00:00
|
|
|
// Step 1: Create a fresh JSGlobalObject.
|
|
|
|
Handle<JSFunction> js_global_object_function;
|
|
|
|
Handle<ObjectTemplateInfo> js_global_object_template;
|
|
|
|
if (!global_proxy_template.IsEmpty()) {
|
|
|
|
// Get prototype template of the global_proxy_template.
|
2010-03-23 11:40:38 +00:00
|
|
|
Handle<ObjectTemplateInfo> data =
|
2014-07-01 12:12:34 +00:00
|
|
|
v8::Utils::OpenHandle(*global_proxy_template);
|
2010-03-23 11:40:38 +00:00
|
|
|
Handle<FunctionTemplateInfo> global_constructor =
|
|
|
|
Handle<FunctionTemplateInfo>(
|
|
|
|
FunctionTemplateInfo::cast(data->constructor()));
|
2013-02-25 14:46:09 +00:00
|
|
|
Handle<Object> proto_template(global_constructor->prototype_template(),
|
|
|
|
isolate());
|
2016-06-06 12:58:10 +00:00
|
|
|
if (!proto_template->IsUndefined(isolate())) {
|
2014-07-01 12:12:34 +00:00
|
|
|
js_global_object_template =
|
2010-03-23 11:40:38 +00:00
|
|
|
Handle<ObjectTemplateInfo>::cast(proto_template);
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
}
|
2010-03-23 11:40:38 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-07-01 12:12:34 +00:00
|
|
|
if (js_global_object_template.is_null()) {
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> name = Handle<String>(heap()->empty_string());
|
2015-11-24 17:16:40 +00:00
|
|
|
Handle<Code> code = isolate()->builtins()->Illegal();
|
2016-06-27 18:03:59 +00:00
|
|
|
Handle<JSObject> prototype =
|
|
|
|
factory()->NewFunctionPrototype(isolate()->object_function());
|
2014-07-07 13:27:37 +00:00
|
|
|
js_global_object_function = factory()->NewFunction(
|
2016-06-27 18:03:59 +00:00
|
|
|
name, code, prototype, JS_GLOBAL_OBJECT_TYPE, JSGlobalObject::kSize);
|
|
|
|
#ifdef DEBUG
|
|
|
|
LookupIterator it(prototype, factory()->constructor_string(),
|
|
|
|
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(
|
|
|
|
FunctionTemplateInfo::cast(js_global_object_template->constructor()));
|
2015-02-04 13:01:34 +00:00
|
|
|
js_global_object_function = ApiNatives::CreateApiFunction(
|
2016-06-27 18:03:59 +00:00
|
|
|
isolate(), js_global_object_constructor, factory()->the_hole_value(),
|
|
|
|
ApiNatives::GlobalObjectType);
|
2010-03-23 11:40:38 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2015-04-07 10:42:45 +00:00
|
|
|
js_global_object_function->initial_map()->set_is_prototype_map(true);
|
2014-07-01 12:12:34 +00:00
|
|
|
js_global_object_function->initial_map()->set_dictionary_map(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()) {
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> name = Handle<String>(heap()->empty_string());
|
2015-11-24 17:16:40 +00:00
|
|
|
Handle<Code> code = isolate()->builtins()->Illegal();
|
2016-11-02 14:39:58 +00:00
|
|
|
global_proxy_function =
|
|
|
|
factory()->NewFunction(name, code, JS_GLOBAL_PROXY_TYPE,
|
2016-11-04 10:02:02 +00:00
|
|
|
JSGlobalProxy::SizeWithInternalFields(0));
|
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(
|
|
|
|
FunctionTemplateInfo::cast(data->constructor()));
|
2015-02-04 13:01:34 +00:00
|
|
|
global_proxy_function = ApiNatives::CreateApiFunction(
|
2016-06-27 18:03:59 +00:00
|
|
|
isolate(), global_constructor, factory()->the_hole_value(),
|
|
|
|
ApiNatives::GlobalProxyType);
|
2010-03-23 11:40:38 +00:00
|
|
|
}
|
2014-08-18 07:54:19 +00:00
|
|
|
Handle<String> global_name = factory()->global_string();
|
2010-03-23 11:40:38 +00:00
|
|
|
global_proxy_function->shared()->set_instance_class_name(*global_name);
|
|
|
|
global_proxy_function->initial_map()->set_is_access_check_needed(true);
|
2016-02-08 13:49:47 +00:00
|
|
|
global_proxy_function->initial_map()->set_has_hidden_prototype(true);
|
2010-03-23 11:40:38 +00:00
|
|
|
|
|
|
|
// Set global_proxy.__proto__ to js_global after ConfigureGlobalObjects
|
|
|
|
// Return the global proxy.
|
|
|
|
|
2015-01-14 16:42:15 +00:00
|
|
|
factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function);
|
|
|
|
return global_object;
|
2010-03-23 11:40:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-02 14:57:59 +00:00
|
|
|
void Genesis::HookUpGlobalProxy(Handle<JSGlobalObject> global_object,
|
2010-03-23 11:40:38 +00:00
|
|
|
Handle<JSGlobalProxy> global_proxy) {
|
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);
|
2012-08-20 11:35:50 +00:00
|
|
|
global_proxy->set_native_context(*native_context());
|
2015-01-14 16:42:15 +00:00
|
|
|
// If we deserialized the context, the global proxy is already
|
|
|
|
// correctly set up. Otherwise it's undefined.
|
2016-06-06 12:58:10 +00:00
|
|
|
DCHECK(native_context()
|
|
|
|
->get(Context::GLOBAL_PROXY_INDEX)
|
|
|
|
->IsUndefined(isolate()) ||
|
2015-01-14 16:42:15 +00:00
|
|
|
native_context()->global_proxy() == *global_proxy);
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_global_proxy(*global_proxy);
|
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(
|
|
|
|
JSGlobalObject::cast(native_context()->extension()));
|
2014-07-01 12:12:34 +00:00
|
|
|
native_context()->set_extension(*global_object);
|
|
|
|
native_context()->set_security_token(*global_object);
|
2015-01-13 08:48:00 +00:00
|
|
|
|
2014-07-01 12:12:34 +00:00
|
|
|
TransferNamedProperties(global_object_from_snapshot, global_object);
|
|
|
|
TransferIndexedProperties(global_object_from_snapshot, global_object);
|
2010-03-23 11:40:38 +00:00
|
|
|
}
|
|
|
|
|
2015-12-07 16:35:03 +00:00
|
|
|
static void InstallWithIntrinsicDefaultProto(Isolate* isolate,
|
|
|
|
Handle<JSFunction> function,
|
|
|
|
int context_index) {
|
|
|
|
Handle<Smi> index(Smi::FromInt(context_index), isolate);
|
|
|
|
JSObject::AddProperty(
|
|
|
|
function, isolate->factory()->native_context_index_symbol(), index, NONE);
|
|
|
|
isolate->native_context()->set(context_index, *function);
|
|
|
|
}
|
|
|
|
|
2016-07-20 13:02:36 +00:00
|
|
|
static void InstallError(Isolate* isolate, Handle<JSObject> global,
|
|
|
|
Handle<String> name, int context_index) {
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
|
|
|
|
Handle<JSFunction> error_fun =
|
|
|
|
InstallFunction(global, name, JS_ERROR_TYPE, JSObject::kHeaderSize,
|
|
|
|
isolate->initial_object_prototype(),
|
|
|
|
Builtins::kErrorConstructor, DONT_ENUM);
|
|
|
|
error_fun->shared()->set_instance_class_name(*factory->Error_string());
|
|
|
|
error_fun->shared()->DontAdaptArguments();
|
|
|
|
error_fun->shared()->set_construct_stub(
|
|
|
|
*isolate->builtins()->ErrorConstructor());
|
|
|
|
error_fun->shared()->set_length(1);
|
|
|
|
|
|
|
|
if (context_index == Context::ERROR_FUNCTION_INDEX) {
|
2016-09-27 22:29:37 +00:00
|
|
|
SimpleInstallFunction(error_fun, "captureStackTrace",
|
|
|
|
Builtins::kErrorCaptureStackTrace, 2, false);
|
2016-07-20 13:02:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InstallWithIntrinsicDefaultProto(isolate, error_fun, context_index);
|
|
|
|
|
|
|
|
{
|
|
|
|
Handle<JSObject> prototype =
|
|
|
|
factory->NewJSObject(isolate->object_function(), TENURED);
|
|
|
|
|
|
|
|
JSObject::AddProperty(prototype, factory->name_string(), name, DONT_ENUM);
|
|
|
|
JSObject::AddProperty(prototype, factory->message_string(),
|
|
|
|
factory->empty_string(), DONT_ENUM);
|
|
|
|
JSObject::AddProperty(prototype, factory->constructor_string(), error_fun,
|
|
|
|
DONT_ENUM);
|
|
|
|
|
2016-08-03 12:20:39 +00:00
|
|
|
if (context_index == Context::ERROR_FUNCTION_INDEX) {
|
|
|
|
Handle<JSFunction> to_string_fun =
|
|
|
|
SimpleInstallFunction(prototype, factory->toString_string(),
|
|
|
|
Builtins::kErrorPrototypeToString, 0, true);
|
|
|
|
isolate->native_context()->set_error_to_string(*to_string_fun);
|
|
|
|
} else {
|
|
|
|
DCHECK(isolate->native_context()->error_to_string()->IsJSFunction());
|
|
|
|
|
|
|
|
InstallFunction(prototype, isolate->error_to_string(),
|
|
|
|
factory->toString_string(), DONT_ENUM);
|
2016-07-20 13:02:36 +00:00
|
|
|
|
|
|
|
Handle<JSFunction> global_error = isolate->error_function();
|
|
|
|
CHECK(JSReceiver::SetPrototype(error_fun, global_error, false,
|
|
|
|
Object::THROW_ON_ERROR)
|
|
|
|
.FromMaybe(false));
|
|
|
|
CHECK(JSReceiver::SetPrototype(prototype,
|
|
|
|
handle(global_error->prototype(), isolate),
|
|
|
|
false, Object::THROW_ON_ERROR)
|
|
|
|
.FromMaybe(false));
|
|
|
|
}
|
|
|
|
|
|
|
|
Accessors::FunctionSetPrototype(error_fun, prototype).Assert();
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<Map> initial_map(error_fun->initial_map());
|
|
|
|
Map::EnsureDescriptorSlack(initial_map, 1);
|
|
|
|
|
|
|
|
PropertyAttributes attribs = DONT_ENUM;
|
|
|
|
Handle<AccessorInfo> error_stack =
|
|
|
|
Accessors::ErrorStackInfo(isolate, attribs);
|
|
|
|
{
|
|
|
|
AccessorConstantDescriptor d(Handle<Name>(Name::cast(error_stack->name())),
|
|
|
|
error_stack, attribs);
|
|
|
|
initial_map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
}
|
2015-12-07 16:35:03 +00:00
|
|
|
|
2016-08-09 07:36:19 +00:00
|
|
|
static void InstallMakeError(Isolate* isolate, Handle<Code> code,
|
|
|
|
int context_index) {
|
|
|
|
Handle<JSFunction> function =
|
|
|
|
isolate->factory()->NewFunction(isolate->factory()->empty_string(), code,
|
|
|
|
JS_OBJECT_TYPE, JSObject::kHeaderSize);
|
|
|
|
function->shared()->DontAdaptArguments();
|
|
|
|
isolate->native_context()->set(context_index, *function);
|
|
|
|
}
|
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
// This is only called if we are not using snapshots. The equivalent
|
2014-07-01 12:12:34 +00:00
|
|
|
// work in the snapshot case is done in HookUpGlobalObject.
|
2015-11-02 14:57:59 +00:00
|
|
|
void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
|
2015-07-13 09:45:43 +00:00
|
|
|
Handle<JSFunction> empty_function,
|
2016-02-02 07:25:30 +00:00
|
|
|
GlobalContextType context_type) {
|
2013-10-14 13:25:36 +00:00
|
|
|
// --- N a t i v e C o n t e x t ---
|
2010-03-23 11:40:38 +00:00
|
|
|
// Use the empty function as closure (no scope info).
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_closure(*empty_function);
|
|
|
|
native_context()->set_previous(NULL);
|
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);
|
|
|
|
|
|
|
|
Isolate* isolate = global_object->GetIsolate();
|
2011-03-28 13:09:37 +00:00
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
|
2014-11-12 11:34:09 +00:00
|
|
|
Handle<ScriptContextTable> script_context_table =
|
|
|
|
factory->NewScriptContextTable();
|
|
|
|
native_context()->set_script_context_table(*script_context_table);
|
2015-06-12 12:34:10 +00:00
|
|
|
InstallGlobalThisBinding();
|
2014-11-07 16:29:13 +00:00
|
|
|
|
2016-01-04 08:10:13 +00:00
|
|
|
{ // --- O b j e c t ---
|
|
|
|
Handle<String> object_name = factory->Object_string();
|
|
|
|
Handle<JSFunction> object_function = isolate->object_function();
|
|
|
|
JSObject::AddProperty(global_object, object_name, object_function,
|
|
|
|
DONT_ENUM);
|
2016-04-25 11:44:13 +00:00
|
|
|
|
2016-01-04 08:10:13 +00:00
|
|
|
SimpleInstallFunction(object_function, factory->assign_string(),
|
|
|
|
Builtins::kObjectAssign, 2, false);
|
|
|
|
SimpleInstallFunction(object_function, factory->create_string(),
|
2016-10-19 11:33:30 +00:00
|
|
|
Builtins::kObjectCreate, 2, true);
|
2016-02-05 13:12:00 +00:00
|
|
|
SimpleInstallFunction(object_function, "getOwnPropertyDescriptor",
|
|
|
|
Builtins::kObjectGetOwnPropertyDescriptor, 2, false);
|
2016-10-31 22:52:55 +00:00
|
|
|
SimpleInstallFunction(object_function,
|
|
|
|
factory->getOwnPropertyDescriptors_string(),
|
|
|
|
Builtins::kObjectGetOwnPropertyDescriptors, 1, false);
|
2016-01-20 19:30:12 +00:00
|
|
|
SimpleInstallFunction(object_function, "getOwnPropertyNames",
|
|
|
|
Builtins::kObjectGetOwnPropertyNames, 1, false);
|
2016-01-15 09:51:41 +00:00
|
|
|
SimpleInstallFunction(object_function, "getOwnPropertySymbols",
|
|
|
|
Builtins::kObjectGetOwnPropertySymbols, 1, false);
|
2016-04-25 11:44:13 +00:00
|
|
|
SimpleInstallFunction(object_function, "is",
|
|
|
|
Builtins::kObjectIs, 2, true);
|
|
|
|
SimpleInstallFunction(object_function, "preventExtensions",
|
|
|
|
Builtins::kObjectPreventExtensions, 1, false);
|
|
|
|
SimpleInstallFunction(object_function, "seal",
|
|
|
|
Builtins::kObjectSeal, 1, false);
|
|
|
|
|
2016-04-25 12:24:02 +00:00
|
|
|
Handle<JSFunction> object_define_properties = SimpleInstallFunction(
|
|
|
|
object_function, "defineProperties",
|
|
|
|
Builtins::kObjectDefineProperties, 2, true);
|
|
|
|
native_context()->set_object_define_properties(*object_define_properties);
|
|
|
|
|
|
|
|
Handle<JSFunction> object_define_property = SimpleInstallFunction(
|
|
|
|
object_function, factory->defineProperty_string(),
|
|
|
|
Builtins::kObjectDefineProperty, 3, true);
|
|
|
|
native_context()->set_object_define_property(*object_define_property);
|
|
|
|
|
2016-04-25 11:44:13 +00:00
|
|
|
Handle<JSFunction> object_freeze = SimpleInstallFunction(
|
|
|
|
object_function, "freeze", Builtins::kObjectFreeze, 1, false);
|
|
|
|
native_context()->set_object_freeze(*object_freeze);
|
|
|
|
|
|
|
|
Handle<JSFunction> object_get_prototype_of = SimpleInstallFunction(
|
|
|
|
object_function, "getPrototypeOf", Builtins::kObjectGetPrototypeOf,
|
|
|
|
1, false);
|
|
|
|
native_context()->set_object_get_prototype_of(*object_get_prototype_of);
|
2016-10-14 08:09:53 +00:00
|
|
|
SimpleInstallFunction(object_function, "setPrototypeOf",
|
|
|
|
Builtins::kObjectSetPrototypeOf, 2, false);
|
2016-04-25 11:44:13 +00:00
|
|
|
|
|
|
|
Handle<JSFunction> object_is_extensible = SimpleInstallFunction(
|
|
|
|
object_function, "isExtensible", Builtins::kObjectIsExtensible,
|
|
|
|
1, false);
|
2016-01-04 08:10:13 +00:00
|
|
|
native_context()->set_object_is_extensible(*object_is_extensible);
|
2016-04-25 11:44:13 +00:00
|
|
|
|
2016-01-04 08:10:13 +00:00
|
|
|
Handle<JSFunction> object_is_frozen = SimpleInstallFunction(
|
|
|
|
object_function, "isFrozen", Builtins::kObjectIsFrozen, 1, false);
|
|
|
|
native_context()->set_object_is_frozen(*object_is_frozen);
|
2016-04-25 11:44:13 +00:00
|
|
|
|
2016-01-04 08:10:13 +00:00
|
|
|
Handle<JSFunction> object_is_sealed = SimpleInstallFunction(
|
|
|
|
object_function, "isSealed", Builtins::kObjectIsSealed, 1, false);
|
|
|
|
native_context()->set_object_is_sealed(*object_is_sealed);
|
2016-04-25 11:44:13 +00:00
|
|
|
|
2016-01-08 06:40:18 +00:00
|
|
|
Handle<JSFunction> object_keys = SimpleInstallFunction(
|
|
|
|
object_function, "keys", Builtins::kObjectKeys, 1, false);
|
|
|
|
native_context()->set_object_keys(*object_keys);
|
2016-10-31 22:52:55 +00:00
|
|
|
SimpleInstallFunction(object_function, factory->entries_string(),
|
|
|
|
Builtins::kObjectEntries, 1, false);
|
|
|
|
SimpleInstallFunction(object_function, factory->values_string(),
|
|
|
|
Builtins::kObjectValues, 1, false);
|
2016-02-29 10:54:23 +00:00
|
|
|
|
2016-04-29 10:14:42 +00:00
|
|
|
SimpleInstallFunction(isolate->initial_object_prototype(),
|
|
|
|
"__defineGetter__", Builtins::kObjectDefineGetter, 2,
|
|
|
|
true);
|
|
|
|
SimpleInstallFunction(isolate->initial_object_prototype(),
|
|
|
|
"__defineSetter__", Builtins::kObjectDefineSetter, 2,
|
|
|
|
true);
|
2016-02-29 10:54:23 +00:00
|
|
|
SimpleInstallFunction(isolate->initial_object_prototype(), "hasOwnProperty",
|
2016-03-31 07:53:10 +00:00
|
|
|
Builtins::kObjectHasOwnProperty, 1, true);
|
2016-04-29 10:14:42 +00:00
|
|
|
SimpleInstallFunction(isolate->initial_object_prototype(),
|
|
|
|
"__lookupGetter__", Builtins::kObjectLookupGetter, 1,
|
|
|
|
true);
|
|
|
|
SimpleInstallFunction(isolate->initial_object_prototype(),
|
|
|
|
"__lookupSetter__", Builtins::kObjectLookupSetter, 1,
|
|
|
|
true);
|
2016-07-12 06:38:40 +00:00
|
|
|
SimpleInstallFunction(
|
|
|
|
isolate->initial_object_prototype(), "propertyIsEnumerable",
|
|
|
|
Builtins::kObjectPrototypePropertyIsEnumerable, 1, false);
|
2016-10-14 11:24:44 +00:00
|
|
|
|
|
|
|
SimpleInstallGetterSetter(isolate->initial_object_prototype(),
|
|
|
|
factory->proto_string(),
|
|
|
|
Builtins::kObjectPrototypeGetProto,
|
|
|
|
Builtins::kObjectPrototypeSetProto, DONT_ENUM);
|
2016-01-04 08:10:13 +00:00
|
|
|
}
|
2010-03-23 11:40:38 +00:00
|
|
|
|
2014-05-09 17:21:51 +00:00
|
|
|
Handle<JSObject> global(native_context()->global_object());
|
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;
|
|
|
|
Handle<JSFunction> function_fun =
|
2015-12-07 16:35:03 +00:00
|
|
|
InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize,
|
2016-01-12 16:43:28 +00:00
|
|
|
prototype, Builtins::kFunctionConstructor);
|
|
|
|
function_fun->set_prototype_or_initial_map(
|
2015-12-10 17:27:44 +00:00
|
|
|
*sloppy_function_map_writable_prototype_);
|
2016-01-12 16:43:28 +00:00
|
|
|
function_fun->shared()->DontAdaptArguments();
|
2016-07-11 10:03:02 +00:00
|
|
|
function_fun->shared()->SetConstructStub(
|
2015-12-22 14:15:19 +00:00
|
|
|
*isolate->builtins()->FunctionConstructor());
|
2016-01-12 16:43:28 +00:00
|
|
|
function_fun->shared()->set_length(1);
|
|
|
|
InstallWithIntrinsicDefaultProto(isolate, function_fun,
|
2015-12-07 16:35:03 +00:00
|
|
|
Context::FUNCTION_FUNCTION_INDEX);
|
2015-12-10 17:27:44 +00:00
|
|
|
|
2016-01-12 16:43:28 +00:00
|
|
|
// Setup the methods on the %FunctionPrototype%.
|
|
|
|
SimpleInstallFunction(prototype, factory->apply_string(),
|
|
|
|
Builtins::kFunctionPrototypeApply, 2, false);
|
2016-06-08 09:44:27 +00:00
|
|
|
|
2016-07-28 22:15:00 +00:00
|
|
|
if (FLAG_minimal) {
|
|
|
|
SimpleInstallFunction(prototype, factory->bind_string(),
|
|
|
|
Builtins::kFunctionPrototypeBind, 1, false);
|
|
|
|
} else {
|
|
|
|
FastFunctionBindStub bind_stub(isolate);
|
|
|
|
Handle<JSFunction> bind_function = factory->NewFunctionWithoutPrototype(
|
|
|
|
factory->bind_string(), bind_stub.GetCode(), false);
|
|
|
|
bind_function->shared()->DontAdaptArguments();
|
|
|
|
bind_function->shared()->set_length(1);
|
|
|
|
InstallFunction(prototype, bind_function, factory->bind_string(),
|
|
|
|
DONT_ENUM);
|
|
|
|
}
|
2016-06-08 09:44:27 +00:00
|
|
|
|
2016-01-12 16:43:28 +00:00
|
|
|
SimpleInstallFunction(prototype, factory->call_string(),
|
|
|
|
Builtins::kFunctionPrototypeCall, 1, false);
|
|
|
|
SimpleInstallFunction(prototype, factory->toString_string(),
|
|
|
|
Builtins::kFunctionPrototypeToString, 0, false);
|
|
|
|
|
2016-02-11 11:58:47 +00:00
|
|
|
// Install the @@hasInstance function.
|
|
|
|
Handle<JSFunction> has_instance = InstallFunction(
|
|
|
|
prototype, factory->has_instance_symbol(), JS_OBJECT_TYPE,
|
|
|
|
JSObject::kHeaderSize, MaybeHandle<JSObject>(),
|
2016-05-17 11:23:59 +00:00
|
|
|
Builtins::kFunctionPrototypeHasInstance,
|
2016-02-11 11:58:47 +00:00
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY));
|
2016-11-18 06:30:57 +00:00
|
|
|
has_instance->shared()->set_builtin_function_id(kFunctionHasInstance);
|
2016-11-17 06:39:28 +00:00
|
|
|
native_context()->set_function_has_instance(*has_instance);
|
2016-02-11 11:58:47 +00:00
|
|
|
|
|
|
|
// Set the expected parameters for @@hasInstance to 1; required by builtin.
|
|
|
|
has_instance->shared()->set_internal_formal_parameter_count(1);
|
|
|
|
|
|
|
|
// Set the length for the function to satisfy ECMA-262.
|
|
|
|
has_instance->shared()->set_length(1);
|
|
|
|
|
2016-01-12 16:43:28 +00:00
|
|
|
// Install the "constructor" property on the %FunctionPrototype%.
|
|
|
|
JSObject::AddProperty(prototype, factory->constructor_string(),
|
|
|
|
function_fun, DONT_ENUM);
|
|
|
|
|
|
|
|
sloppy_function_map_writable_prototype_->SetConstructor(*function_fun);
|
|
|
|
strict_function_map_writable_prototype_->SetConstructor(*function_fun);
|
2015-12-07 16:35:03 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
{ // --- A r r a y ---
|
2015-08-31 10:09:52 +00:00
|
|
|
Handle<JSFunction> array_function =
|
|
|
|
InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize,
|
|
|
|
isolate->initial_object_prototype(),
|
|
|
|
Builtins::kArrayCode);
|
2008-09-16 10:12:32 +00:00
|
|
|
array_function->shared()->DontAdaptArguments();
|
2016-02-25 16:06:01 +00:00
|
|
|
array_function->shared()->set_builtin_function_id(kArrayCode);
|
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
|
|
|
|
2012-08-13 08:43:16 +00:00
|
|
|
Handle<Map> initial_map(array_function->initial_map());
|
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());
|
2014-04-11 12:13:53 +00:00
|
|
|
Map::EnsureDescriptorSlack(initial_map, 1);
|
2012-07-23 16:18:25 +00:00
|
|
|
|
2012-07-18 14:00:58 +00:00
|
|
|
PropertyAttributes attribs = static_cast<PropertyAttributes>(
|
|
|
|
DONT_ENUM | DONT_DELETE);
|
|
|
|
|
2014-04-28 14:59:29 +00:00
|
|
|
Handle<AccessorInfo> array_length =
|
|
|
|
Accessors::ArrayLengthInfo(isolate, attribs);
|
2012-07-18 14:00:58 +00:00
|
|
|
{ // Add length.
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(
|
|
|
|
Handle<Name>(Name::cast(array_length->name())), array_length,
|
|
|
|
attribs);
|
2014-11-11 10:24:52 +00:00
|
|
|
initial_map->AppendDescriptor(&d);
|
2012-07-18 14:00:58 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2015-12-07 16:35:03 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate, array_function,
|
|
|
|
Context::ARRAY_FUNCTION_INDEX);
|
2013-04-25 16:00:32 +00:00
|
|
|
|
2013-06-25 16:31:07 +00:00
|
|
|
// Cache the array maps, needed by ArrayConstructorStub
|
|
|
|
CacheInitialJSArrayMaps(native_context(), initial_map);
|
|
|
|
ArrayConstructorStub array_constructor_stub(isolate);
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> code = array_constructor_stub.GetCode();
|
2016-07-11 10:03:02 +00:00
|
|
|
array_function->shared()->SetConstructStub(*code);
|
2015-05-20 07:07:54 +00:00
|
|
|
|
2015-12-14 15:11:55 +00:00
|
|
|
Handle<JSFunction> is_arraylike = SimpleInstallFunction(
|
|
|
|
array_function, isolate->factory()->InternalizeUtf8String("isArray"),
|
|
|
|
Builtins::kArrayIsArray, 1, true);
|
|
|
|
native_context()->set_is_arraylike(*is_arraylike);
|
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(
|
|
|
|
native_context()->initial_iterator_prototype());
|
|
|
|
|
|
|
|
Handle<JSObject> array_iterator_prototype =
|
|
|
|
factory->NewJSObject(isolate->object_function(), TENURED);
|
|
|
|
JSObject::ForceSetPrototype(array_iterator_prototype, iterator_prototype);
|
|
|
|
|
|
|
|
JSObject::AddProperty(
|
|
|
|
array_iterator_prototype, factory->to_string_tag_symbol(),
|
|
|
|
factory->ArrayIterator_string(),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
|
|
|
Handle<JSFunction> next = InstallFunction(
|
|
|
|
array_iterator_prototype, "next", JS_OBJECT_TYPE, JSObject::kHeaderSize,
|
|
|
|
MaybeHandle<JSObject>(), Builtins::kArrayIteratorPrototypeNext);
|
2016-11-14 15:58:48 +00:00
|
|
|
next->shared()->set_builtin_function_id(kArrayIteratorNext);
|
2016-10-18 02:42:42 +00:00
|
|
|
|
|
|
|
// Set the expected parameters for %ArrayIteratorPrototype%.next to 0 (not
|
|
|
|
// including the receiver), as required by the builtin.
|
|
|
|
next->shared()->set_internal_formal_parameter_count(0);
|
|
|
|
|
|
|
|
// Set the length for the function to satisfy ECMA-262.
|
|
|
|
next->shared()->set_length(0);
|
|
|
|
|
|
|
|
Handle<JSFunction> array_iterator_function = CreateFunction(
|
|
|
|
isolate, factory->ArrayIterator_string(),
|
|
|
|
JS_FAST_ARRAY_VALUE_ITERATOR_TYPE, JSArrayIterator::kSize,
|
|
|
|
array_iterator_prototype, Builtins::kIllegal);
|
|
|
|
array_iterator_function->shared()->set_instance_class_name(
|
|
|
|
isolate->heap()->ArrayIterator_string());
|
|
|
|
|
2016-11-15 14:41:27 +00:00
|
|
|
native_context()->set_initial_array_iterator_prototype(
|
|
|
|
*array_iterator_prototype);
|
|
|
|
native_context()->set_initial_array_iterator_prototype_map(
|
|
|
|
array_iterator_prototype->map());
|
|
|
|
|
2016-10-18 02:42:42 +00:00
|
|
|
Handle<Map> initial_map(array_iterator_function->initial_map(), isolate);
|
|
|
|
|
|
|
|
#define ARRAY_ITERATOR_LIST(V) \
|
|
|
|
V(TYPED_ARRAY, KEY, typed_array, key) \
|
|
|
|
V(FAST_ARRAY, KEY, fast_array, key) \
|
|
|
|
V(GENERIC_ARRAY, KEY, array, key) \
|
|
|
|
V(UINT8_ARRAY, KEY_VALUE, uint8_array, key_value) \
|
|
|
|
V(INT8_ARRAY, KEY_VALUE, int8_array, key_value) \
|
|
|
|
V(UINT16_ARRAY, KEY_VALUE, uint16_array, key_value) \
|
|
|
|
V(INT16_ARRAY, KEY_VALUE, int16_array, key_value) \
|
|
|
|
V(UINT32_ARRAY, KEY_VALUE, uint32_array, key_value) \
|
|
|
|
V(INT32_ARRAY, KEY_VALUE, int32_array, key_value) \
|
|
|
|
V(FLOAT32_ARRAY, KEY_VALUE, float32_array, key_value) \
|
|
|
|
V(FLOAT64_ARRAY, KEY_VALUE, float64_array, key_value) \
|
|
|
|
V(UINT8_CLAMPED_ARRAY, KEY_VALUE, uint8_clamped_array, key_value) \
|
|
|
|
V(FAST_SMI_ARRAY, KEY_VALUE, fast_smi_array, key_value) \
|
|
|
|
V(FAST_HOLEY_SMI_ARRAY, KEY_VALUE, fast_holey_smi_array, key_value) \
|
|
|
|
V(FAST_ARRAY, KEY_VALUE, fast_array, key_value) \
|
|
|
|
V(FAST_HOLEY_ARRAY, KEY_VALUE, fast_holey_array, key_value) \
|
|
|
|
V(FAST_DOUBLE_ARRAY, KEY_VALUE, fast_double_array, key_value) \
|
|
|
|
V(FAST_HOLEY_DOUBLE_ARRAY, KEY_VALUE, fast_holey_double_array, key_value) \
|
|
|
|
V(GENERIC_ARRAY, KEY_VALUE, array, key_value) \
|
|
|
|
V(UINT8_ARRAY, VALUE, uint8_array, value) \
|
|
|
|
V(INT8_ARRAY, VALUE, int8_array, value) \
|
|
|
|
V(UINT16_ARRAY, VALUE, uint16_array, value) \
|
|
|
|
V(INT16_ARRAY, VALUE, int16_array, value) \
|
|
|
|
V(UINT32_ARRAY, VALUE, uint32_array, value) \
|
|
|
|
V(INT32_ARRAY, VALUE, int32_array, value) \
|
|
|
|
V(FLOAT32_ARRAY, VALUE, float32_array, value) \
|
|
|
|
V(FLOAT64_ARRAY, VALUE, float64_array, value) \
|
|
|
|
V(UINT8_CLAMPED_ARRAY, VALUE, uint8_clamped_array, value) \
|
|
|
|
V(FAST_SMI_ARRAY, VALUE, fast_smi_array, value) \
|
|
|
|
V(FAST_HOLEY_SMI_ARRAY, VALUE, fast_holey_smi_array, value) \
|
|
|
|
V(FAST_ARRAY, VALUE, fast_array, value) \
|
|
|
|
V(FAST_HOLEY_ARRAY, VALUE, fast_holey_array, value) \
|
|
|
|
V(FAST_DOUBLE_ARRAY, VALUE, fast_double_array, value) \
|
|
|
|
V(FAST_HOLEY_DOUBLE_ARRAY, VALUE, fast_holey_double_array, value) \
|
|
|
|
V(GENERIC_ARRAY, VALUE, array, value)
|
|
|
|
|
|
|
|
#define CREATE_ARRAY_ITERATOR_MAP(PREFIX, SUFFIX, prefix, suffix) \
|
|
|
|
do { \
|
|
|
|
const InstanceType type = JS_##PREFIX##_##SUFFIX##_ITERATOR_TYPE; \
|
|
|
|
Handle<Map> map = \
|
|
|
|
Map::Copy(initial_map, "JS_" #PREFIX "_" #SUFFIX "_ITERATOR_TYPE"); \
|
|
|
|
map->set_instance_type(type); \
|
|
|
|
native_context()->set_##prefix##_##suffix##_iterator_map(*map); \
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
ARRAY_ITERATOR_LIST(CREATE_ARRAY_ITERATOR_MAP)
|
|
|
|
|
|
|
|
#undef CREATE_ARRAY_ITERATOR_MAP
|
|
|
|
#undef ARRAY_ITERATOR_LIST
|
|
|
|
}
|
|
|
|
|
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(
|
|
|
|
global, "Number", JS_VALUE_TYPE, JSValue::kSize,
|
|
|
|
isolate->initial_object_prototype(), Builtins::kNumberConstructor);
|
|
|
|
number_fun->shared()->DontAdaptArguments();
|
2016-07-11 10:03:02 +00:00
|
|
|
number_fun->shared()->SetConstructStub(
|
2016-01-13 15:14:16 +00:00
|
|
|
*isolate->builtins()->NumberConstructor_ConstructStub());
|
|
|
|
number_fun->shared()->set_length(1);
|
2015-12-07 16:35:03 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate, number_fun,
|
|
|
|
Context::NUMBER_FUNCTION_INDEX);
|
2016-07-05 10:03:38 +00:00
|
|
|
|
|
|
|
// Create the %NumberPrototype%
|
|
|
|
Handle<JSValue> prototype =
|
|
|
|
Handle<JSValue>::cast(factory->NewJSObject(number_fun, TENURED));
|
2016-10-07 13:05:07 +00:00
|
|
|
prototype->set_value(Smi::kZero);
|
2016-07-05 10:03:38 +00:00
|
|
|
Accessors::FunctionSetPrototype(number_fun, prototype).Assert();
|
|
|
|
|
|
|
|
// Install the "constructor" property on the {prototype}.
|
|
|
|
JSObject::AddProperty(prototype, factory->constructor_string(), number_fun,
|
|
|
|
DONT_ENUM);
|
|
|
|
|
|
|
|
// Install the Number.prototype methods.
|
|
|
|
SimpleInstallFunction(prototype, "toExponential",
|
|
|
|
Builtins::kNumberPrototypeToExponential, 1, false);
|
|
|
|
SimpleInstallFunction(prototype, "toFixed",
|
|
|
|
Builtins::kNumberPrototypeToFixed, 1, false);
|
|
|
|
SimpleInstallFunction(prototype, "toPrecision",
|
|
|
|
Builtins::kNumberPrototypeToPrecision, 1, false);
|
|
|
|
SimpleInstallFunction(prototype, "toString",
|
|
|
|
Builtins::kNumberPrototypeToString, 1, false);
|
|
|
|
SimpleInstallFunction(prototype, "valueOf",
|
|
|
|
Builtins::kNumberPrototypeValueOf, 0, true);
|
|
|
|
|
|
|
|
// Install i18n fallback functions.
|
|
|
|
SimpleInstallFunction(prototype, "toLocaleString",
|
|
|
|
Builtins::kNumberPrototypeToLocaleString, 0, false);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
|
|
|
// Install the Number functions.
|
|
|
|
SimpleInstallFunction(number_fun, "isFinite", Builtins::kNumberIsFinite, 1,
|
|
|
|
true);
|
|
|
|
SimpleInstallFunction(number_fun, "isInteger", Builtins::kNumberIsInteger,
|
|
|
|
1, true);
|
|
|
|
SimpleInstallFunction(number_fun, "isNaN", Builtins::kNumberIsNaN, 1, true);
|
|
|
|
SimpleInstallFunction(number_fun, "isSafeInteger",
|
|
|
|
Builtins::kNumberIsSafeInteger, 1, true);
|
2016-10-07 08:58:43 +00:00
|
|
|
|
|
|
|
// Install Number.parseFloat and Global.parseFloat.
|
|
|
|
Handle<JSFunction> parse_float_fun = SimpleInstallFunction(
|
|
|
|
number_fun, "parseFloat", Builtins::kNumberParseFloat, 1, true);
|
|
|
|
JSObject::AddProperty(global_object,
|
|
|
|
factory->NewStringFromAsciiChecked("parseFloat"),
|
|
|
|
parse_float_fun, DONT_ENUM);
|
2016-10-18 12:44:48 +00:00
|
|
|
|
|
|
|
// Install Number.parseInt and Global.parseInt.
|
|
|
|
Handle<JSFunction> parse_int_fun = SimpleInstallFunction(
|
|
|
|
number_fun, "parseInt", Builtins::kNumberParseInt, 2, true);
|
|
|
|
JSObject::AddProperty(global_object,
|
|
|
|
factory->NewStringFromAsciiChecked("parseInt"),
|
|
|
|
parse_int_fun, DONT_ENUM);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // --- B o o l e a n ---
|
2015-08-31 10:09:52 +00:00
|
|
|
Handle<JSFunction> boolean_fun =
|
|
|
|
InstallFunction(global, "Boolean", JS_VALUE_TYPE, JSValue::kSize,
|
|
|
|
isolate->initial_object_prototype(),
|
2016-02-16 14:02:59 +00:00
|
|
|
Builtins::kBooleanConstructor);
|
|
|
|
boolean_fun->shared()->DontAdaptArguments();
|
2016-07-11 10:03:02 +00:00
|
|
|
boolean_fun->shared()->SetConstructStub(
|
2016-02-16 14:02:59 +00:00
|
|
|
*isolate->builtins()->BooleanConstructor_ConstructStub());
|
|
|
|
boolean_fun->shared()->set_length(1);
|
2015-12-07 16:35:03 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate, boolean_fun,
|
|
|
|
Context::BOOLEAN_FUNCTION_INDEX);
|
2016-02-17 10:35:53 +00:00
|
|
|
|
|
|
|
// Create the %BooleanPrototype%
|
|
|
|
Handle<JSValue> prototype =
|
|
|
|
Handle<JSValue>::cast(factory->NewJSObject(boolean_fun, TENURED));
|
|
|
|
prototype->set_value(isolate->heap()->false_value());
|
|
|
|
Accessors::FunctionSetPrototype(boolean_fun, prototype).Assert();
|
|
|
|
|
|
|
|
// Install the "constructor" property on the {prototype}.
|
|
|
|
JSObject::AddProperty(prototype, factory->constructor_string(), boolean_fun,
|
|
|
|
DONT_ENUM);
|
|
|
|
|
|
|
|
// Install the Boolean.prototype methods.
|
|
|
|
SimpleInstallFunction(prototype, "toString",
|
2016-07-05 10:03:38 +00:00
|
|
|
Builtins::kBooleanPrototypeToString, 0, true);
|
2016-02-17 10:35:53 +00:00
|
|
|
SimpleInstallFunction(prototype, "valueOf",
|
2016-07-05 10:03:38 +00:00
|
|
|
Builtins::kBooleanPrototypeValueOf, 0, true);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // --- S t r i n g ---
|
2015-09-16 10:44:36 +00:00
|
|
|
Handle<JSFunction> string_fun = InstallFunction(
|
|
|
|
global, "String", JS_VALUE_TYPE, JSValue::kSize,
|
|
|
|
isolate->initial_object_prototype(), Builtins::kStringConstructor);
|
2016-07-11 10:03:02 +00:00
|
|
|
string_fun->shared()->SetConstructStub(
|
2015-11-24 17:16:40 +00:00
|
|
|
*isolate->builtins()->StringConstructor_ConstructStub());
|
2015-09-16 10:44:36 +00:00
|
|
|
string_fun->shared()->DontAdaptArguments();
|
|
|
|
string_fun->shared()->set_length(1);
|
2015-12-07 16:35:03 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate, string_fun,
|
|
|
|
Context::STRING_FUNCTION_INDEX);
|
2012-07-18 14:00:58 +00:00
|
|
|
|
2012-07-19 10:01:52 +00:00
|
|
|
Handle<Map> string_map =
|
2012-08-17 09:03:08 +00:00
|
|
|
Handle<Map>(native_context()->string_function()->initial_map());
|
2016-01-29 18:57:26 +00:00
|
|
|
string_map->set_elements_kind(FAST_STRING_WRAPPER_ELEMENTS);
|
2014-04-11 12:13:53 +00:00
|
|
|
Map::EnsureDescriptorSlack(string_map, 1);
|
2012-07-23 16:18:25 +00:00
|
|
|
|
2012-07-18 14:00:58 +00:00
|
|
|
PropertyAttributes attribs = static_cast<PropertyAttributes>(
|
|
|
|
DONT_ENUM | DONT_DELETE | READ_ONLY);
|
2014-04-15 13:25:17 +00:00
|
|
|
Handle<AccessorInfo> string_length(
|
|
|
|
Accessors::StringLengthInfo(isolate, attribs));
|
2012-07-18 14:00:58 +00:00
|
|
|
|
|
|
|
{ // Add length.
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(factory->length_string(), string_length,
|
|
|
|
attribs);
|
2014-04-11 12:13:53 +00:00
|
|
|
string_map->AppendDescriptor(&d);
|
2012-07-18 14:00:58 +00:00
|
|
|
}
|
2016-04-12 10:29:49 +00:00
|
|
|
|
2016-05-21 16:58:17 +00:00
|
|
|
// Install the String.fromCharCode function.
|
|
|
|
SimpleInstallFunction(string_fun, "fromCharCode",
|
2016-11-07 21:26:18 +00:00
|
|
|
Builtins::kStringFromCharCode, 1, false);
|
2016-05-21 16:58:17 +00:00
|
|
|
|
2016-06-27 13:47:35 +00:00
|
|
|
// Install the String.fromCodePoint function.
|
|
|
|
SimpleInstallFunction(string_fun, "fromCodePoint",
|
|
|
|
Builtins::kStringFromCodePoint, 1, false);
|
|
|
|
|
2016-04-12 10:29:49 +00:00
|
|
|
// Create the %StringPrototype%
|
|
|
|
Handle<JSValue> prototype =
|
|
|
|
Handle<JSValue>::cast(factory->NewJSObject(string_fun, TENURED));
|
|
|
|
prototype->set_value(isolate->heap()->empty_string());
|
|
|
|
Accessors::FunctionSetPrototype(string_fun, prototype).Assert();
|
|
|
|
|
|
|
|
// Install the "constructor" property on the {prototype}.
|
|
|
|
JSObject::AddProperty(prototype, factory->constructor_string(), string_fun,
|
|
|
|
DONT_ENUM);
|
|
|
|
|
|
|
|
// Install the String.prototype methods.
|
|
|
|
SimpleInstallFunction(prototype, "charAt", Builtins::kStringPrototypeCharAt,
|
|
|
|
1, true);
|
|
|
|
SimpleInstallFunction(prototype, "charCodeAt",
|
|
|
|
Builtins::kStringPrototypeCharCodeAt, 1, true);
|
2016-10-11 11:27:55 +00:00
|
|
|
SimpleInstallFunction(prototype, "endsWith",
|
|
|
|
Builtins::kStringPrototypeEndsWith, 1, false);
|
2016-10-10 15:01:21 +00:00
|
|
|
SimpleInstallFunction(prototype, "includes",
|
|
|
|
Builtins::kStringPrototypeIncludes, 1, false);
|
2016-10-07 17:03:55 +00:00
|
|
|
SimpleInstallFunction(prototype, "indexOf",
|
|
|
|
Builtins::kStringPrototypeIndexOf, 1, false);
|
2016-09-19 10:22:30 +00:00
|
|
|
SimpleInstallFunction(prototype, "lastIndexOf",
|
|
|
|
Builtins::kStringPrototypeLastIndexOf, 1, false);
|
2016-09-12 11:39:57 +00:00
|
|
|
SimpleInstallFunction(prototype, "localeCompare",
|
|
|
|
Builtins::kStringPrototypeLocaleCompare, 1, true);
|
2016-09-12 10:53:36 +00:00
|
|
|
SimpleInstallFunction(prototype, "normalize",
|
|
|
|
Builtins::kStringPrototypeNormalize, 0, false);
|
2016-10-04 12:00:15 +00:00
|
|
|
SimpleInstallFunction(prototype, "substr", Builtins::kStringPrototypeSubstr,
|
|
|
|
2, true);
|
2016-09-29 08:16:05 +00:00
|
|
|
SimpleInstallFunction(prototype, "substring",
|
|
|
|
Builtins::kStringPrototypeSubstring, 2, true);
|
2016-10-11 11:35:59 +00:00
|
|
|
SimpleInstallFunction(prototype, "startsWith",
|
|
|
|
Builtins::kStringPrototypeStartsWith, 1, false);
|
2016-07-05 10:03:38 +00:00
|
|
|
SimpleInstallFunction(prototype, "toString",
|
|
|
|
Builtins::kStringPrototypeToString, 0, true);
|
2016-05-27 17:48:34 +00:00
|
|
|
SimpleInstallFunction(prototype, "trim", Builtins::kStringPrototypeTrim, 0,
|
|
|
|
false);
|
|
|
|
SimpleInstallFunction(prototype, "trimLeft",
|
|
|
|
Builtins::kStringPrototypeTrimLeft, 0, false);
|
|
|
|
SimpleInstallFunction(prototype, "trimRight",
|
|
|
|
Builtins::kStringPrototypeTrimRight, 0, false);
|
2016-07-05 10:03:38 +00:00
|
|
|
SimpleInstallFunction(prototype, "valueOf",
|
|
|
|
Builtins::kStringPrototypeValueOf, 0, true);
|
2016-09-21 14:17:42 +00:00
|
|
|
|
|
|
|
Handle<JSFunction> iterator = SimpleCreateFunction(
|
|
|
|
isolate, factory->NewStringFromAsciiChecked("[Symbol.iterator]"),
|
|
|
|
Builtins::kStringPrototypeIterator, 0, true);
|
|
|
|
iterator->shared()->set_native(true);
|
2016-10-18 16:32:31 +00:00
|
|
|
iterator->shared()->set_builtin_function_id(kStringIterator);
|
2016-09-21 14:17:42 +00:00
|
|
|
JSObject::AddProperty(prototype, factory->iterator_symbol(), iterator,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM));
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // --- S t r i n g I t e r a t o r ---
|
|
|
|
Handle<JSObject> iterator_prototype(
|
|
|
|
native_context()->initial_iterator_prototype());
|
|
|
|
|
|
|
|
Handle<JSObject> string_iterator_prototype =
|
|
|
|
factory->NewJSObject(isolate->object_function(), TENURED);
|
|
|
|
JSObject::ForceSetPrototype(string_iterator_prototype, iterator_prototype);
|
|
|
|
|
|
|
|
JSObject::AddProperty(
|
|
|
|
string_iterator_prototype, factory->to_string_tag_symbol(),
|
|
|
|
factory->NewStringFromAsciiChecked("String Iterator"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
2016-09-29 15:49:08 +00:00
|
|
|
Handle<JSFunction> next =
|
|
|
|
InstallFunction(string_iterator_prototype, "next", JS_OBJECT_TYPE,
|
|
|
|
JSObject::kHeaderSize, MaybeHandle<JSObject>(),
|
|
|
|
Builtins::kStringIteratorPrototypeNext);
|
2016-10-05 18:45:54 +00:00
|
|
|
next->shared()->set_builtin_function_id(kStringIteratorNext);
|
2016-09-29 15:49:08 +00:00
|
|
|
|
|
|
|
// Set the expected parameters for %StringIteratorPrototype%.next to 0 (not
|
|
|
|
// including the receiver), as required by the builtin.
|
|
|
|
next->shared()->set_internal_formal_parameter_count(0);
|
|
|
|
|
|
|
|
// Set the length for the function to satisfy ECMA-262.
|
|
|
|
next->shared()->set_length(0);
|
2016-09-21 14:17:42 +00:00
|
|
|
|
|
|
|
Handle<JSFunction> string_iterator_function = CreateFunction(
|
|
|
|
isolate, factory->NewStringFromAsciiChecked("StringIterator"),
|
|
|
|
JS_STRING_ITERATOR_TYPE, JSStringIterator::kSize,
|
|
|
|
string_iterator_prototype, Builtins::kIllegal);
|
|
|
|
native_context()->set_string_iterator_map(
|
|
|
|
string_iterator_function->initial_map());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2014-08-06 09:31:21 +00:00
|
|
|
{
|
|
|
|
// --- S y m b o l ---
|
2016-01-15 09:51:41 +00:00
|
|
|
Handle<JSObject> prototype =
|
|
|
|
factory->NewJSObject(isolate->object_function(), TENURED);
|
|
|
|
Handle<JSFunction> symbol_fun =
|
|
|
|
InstallFunction(global, "Symbol", JS_VALUE_TYPE, JSValue::kSize,
|
|
|
|
prototype, Builtins::kSymbolConstructor);
|
2016-07-11 10:03:02 +00:00
|
|
|
symbol_fun->shared()->SetConstructStub(
|
2015-11-24 17:16:40 +00:00
|
|
|
*isolate->builtins()->SymbolConstructor_ConstructStub());
|
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-07-05 10:03:38 +00:00
|
|
|
// Install the @@toStringTag property on the {prototype}.
|
|
|
|
JSObject::AddProperty(
|
|
|
|
prototype, factory->to_string_tag_symbol(),
|
|
|
|
factory->NewStringFromAsciiChecked("Symbol"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
2016-01-15 09:51:41 +00:00
|
|
|
// Install the "constructor" property on the {prototype}.
|
|
|
|
JSObject::AddProperty(prototype, factory->constructor_string(), symbol_fun,
|
|
|
|
DONT_ENUM);
|
2016-07-05 10:03:38 +00:00
|
|
|
|
|
|
|
// Install the Symbol.prototype methods.
|
|
|
|
SimpleInstallFunction(prototype, "toString",
|
|
|
|
Builtins::kSymbolPrototypeToString, 0, true);
|
|
|
|
SimpleInstallFunction(prototype, "valueOf",
|
|
|
|
Builtins::kSymbolPrototypeValueOf, 0, true);
|
|
|
|
|
|
|
|
// Install the @@toPrimitive function.
|
|
|
|
Handle<JSFunction> to_primitive = InstallFunction(
|
|
|
|
prototype, factory->to_primitive_symbol(), JS_OBJECT_TYPE,
|
|
|
|
JSObject::kHeaderSize, MaybeHandle<JSObject>(),
|
|
|
|
Builtins::kSymbolPrototypeToPrimitive,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
|
|
|
// Set the expected parameters for @@toPrimitive to 1; required by builtin.
|
|
|
|
to_primitive->shared()->set_internal_formal_parameter_count(1);
|
|
|
|
|
|
|
|
// Set the length for the function to satisfy ECMA-262.
|
|
|
|
to_primitive->shared()->set_length(1);
|
2014-08-06 09:31:21 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
{ // --- D a t e ---
|
|
|
|
// Builtin functions for Date.prototype.
|
2016-01-12 10:47:27 +00:00
|
|
|
Handle<JSObject> prototype =
|
|
|
|
factory->NewJSObject(isolate->object_function(), TENURED);
|
|
|
|
Handle<JSFunction> date_fun =
|
|
|
|
InstallFunction(global, "Date", JS_DATE_TYPE, JSDate::kSize, prototype,
|
|
|
|
Builtins::kDateConstructor);
|
2015-12-07 16:35:03 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate, date_fun,
|
|
|
|
Context::DATE_FUNCTION_INDEX);
|
2016-07-11 10:03:02 +00:00
|
|
|
date_fun->shared()->SetConstructStub(
|
2016-01-05 11:05:41 +00:00
|
|
|
*isolate->builtins()->DateConstructor_ConstructStub());
|
|
|
|
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.
|
|
|
|
SimpleInstallFunction(date_fun, "now", Builtins::kDateNow, 0, false);
|
|
|
|
SimpleInstallFunction(date_fun, "parse", Builtins::kDateParse, 1, false);
|
|
|
|
SimpleInstallFunction(date_fun, "UTC", Builtins::kDateUTC, 7, false);
|
|
|
|
|
|
|
|
// Install the "constructor" property on the {prototype}.
|
|
|
|
JSObject::AddProperty(prototype, factory->constructor_string(), date_fun,
|
|
|
|
DONT_ENUM);
|
|
|
|
|
|
|
|
// Install the Date.prototype methods.
|
|
|
|
SimpleInstallFunction(prototype, "toString",
|
|
|
|
Builtins::kDatePrototypeToString, 0, false);
|
|
|
|
SimpleInstallFunction(prototype, "toDateString",
|
|
|
|
Builtins::kDatePrototypeToDateString, 0, false);
|
|
|
|
SimpleInstallFunction(prototype, "toTimeString",
|
|
|
|
Builtins::kDatePrototypeToTimeString, 0, false);
|
|
|
|
SimpleInstallFunction(prototype, "toISOString",
|
|
|
|
Builtins::kDatePrototypeToISOString, 0, false);
|
2016-02-19 02:18:44 +00:00
|
|
|
Handle<JSFunction> to_utc_string =
|
|
|
|
SimpleInstallFunction(prototype, "toUTCString",
|
|
|
|
Builtins::kDatePrototypeToUTCString, 0, false);
|
|
|
|
InstallFunction(prototype, to_utc_string,
|
|
|
|
factory->InternalizeUtf8String("toGMTString"), DONT_ENUM);
|
2016-01-12 10:47:27 +00:00
|
|
|
SimpleInstallFunction(prototype, "getDate", Builtins::kDatePrototypeGetDate,
|
|
|
|
0, true);
|
|
|
|
SimpleInstallFunction(prototype, "setDate", Builtins::kDatePrototypeSetDate,
|
|
|
|
1, false);
|
|
|
|
SimpleInstallFunction(prototype, "getDay", Builtins::kDatePrototypeGetDay,
|
|
|
|
0, true);
|
|
|
|
SimpleInstallFunction(prototype, "getFullYear",
|
|
|
|
Builtins::kDatePrototypeGetFullYear, 0, true);
|
|
|
|
SimpleInstallFunction(prototype, "setFullYear",
|
|
|
|
Builtins::kDatePrototypeSetFullYear, 3, false);
|
|
|
|
SimpleInstallFunction(prototype, "getHours",
|
|
|
|
Builtins::kDatePrototypeGetHours, 0, true);
|
|
|
|
SimpleInstallFunction(prototype, "setHours",
|
|
|
|
Builtins::kDatePrototypeSetHours, 4, false);
|
|
|
|
SimpleInstallFunction(prototype, "getMilliseconds",
|
|
|
|
Builtins::kDatePrototypeGetMilliseconds, 0, true);
|
|
|
|
SimpleInstallFunction(prototype, "setMilliseconds",
|
|
|
|
Builtins::kDatePrototypeSetMilliseconds, 1, false);
|
|
|
|
SimpleInstallFunction(prototype, "getMinutes",
|
|
|
|
Builtins::kDatePrototypeGetMinutes, 0, true);
|
|
|
|
SimpleInstallFunction(prototype, "setMinutes",
|
|
|
|
Builtins::kDatePrototypeSetMinutes, 3, false);
|
|
|
|
SimpleInstallFunction(prototype, "getMonth",
|
|
|
|
Builtins::kDatePrototypeGetMonth, 0, true);
|
|
|
|
SimpleInstallFunction(prototype, "setMonth",
|
|
|
|
Builtins::kDatePrototypeSetMonth, 2, false);
|
|
|
|
SimpleInstallFunction(prototype, "getSeconds",
|
|
|
|
Builtins::kDatePrototypeGetSeconds, 0, true);
|
|
|
|
SimpleInstallFunction(prototype, "setSeconds",
|
|
|
|
Builtins::kDatePrototypeSetSeconds, 2, false);
|
|
|
|
SimpleInstallFunction(prototype, "getTime", Builtins::kDatePrototypeGetTime,
|
|
|
|
0, true);
|
|
|
|
SimpleInstallFunction(prototype, "setTime", Builtins::kDatePrototypeSetTime,
|
|
|
|
1, false);
|
|
|
|
SimpleInstallFunction(prototype, "getTimezoneOffset",
|
|
|
|
Builtins::kDatePrototypeGetTimezoneOffset, 0, true);
|
|
|
|
SimpleInstallFunction(prototype, "getUTCDate",
|
|
|
|
Builtins::kDatePrototypeGetUTCDate, 0, true);
|
|
|
|
SimpleInstallFunction(prototype, "setUTCDate",
|
|
|
|
Builtins::kDatePrototypeSetUTCDate, 1, false);
|
|
|
|
SimpleInstallFunction(prototype, "getUTCDay",
|
|
|
|
Builtins::kDatePrototypeGetUTCDay, 0, true);
|
|
|
|
SimpleInstallFunction(prototype, "getUTCFullYear",
|
|
|
|
Builtins::kDatePrototypeGetUTCFullYear, 0, true);
|
|
|
|
SimpleInstallFunction(prototype, "setUTCFullYear",
|
|
|
|
Builtins::kDatePrototypeSetUTCFullYear, 3, false);
|
|
|
|
SimpleInstallFunction(prototype, "getUTCHours",
|
|
|
|
Builtins::kDatePrototypeGetUTCHours, 0, true);
|
|
|
|
SimpleInstallFunction(prototype, "setUTCHours",
|
|
|
|
Builtins::kDatePrototypeSetUTCHours, 4, false);
|
|
|
|
SimpleInstallFunction(prototype, "getUTCMilliseconds",
|
|
|
|
Builtins::kDatePrototypeGetUTCMilliseconds, 0, true);
|
|
|
|
SimpleInstallFunction(prototype, "setUTCMilliseconds",
|
|
|
|
Builtins::kDatePrototypeSetUTCMilliseconds, 1, false);
|
|
|
|
SimpleInstallFunction(prototype, "getUTCMinutes",
|
|
|
|
Builtins::kDatePrototypeGetUTCMinutes, 0, true);
|
|
|
|
SimpleInstallFunction(prototype, "setUTCMinutes",
|
|
|
|
Builtins::kDatePrototypeSetUTCMinutes, 3, false);
|
|
|
|
SimpleInstallFunction(prototype, "getUTCMonth",
|
|
|
|
Builtins::kDatePrototypeGetUTCMonth, 0, true);
|
|
|
|
SimpleInstallFunction(prototype, "setUTCMonth",
|
|
|
|
Builtins::kDatePrototypeSetUTCMonth, 2, false);
|
|
|
|
SimpleInstallFunction(prototype, "getUTCSeconds",
|
|
|
|
Builtins::kDatePrototypeGetUTCSeconds, 0, true);
|
|
|
|
SimpleInstallFunction(prototype, "setUTCSeconds",
|
|
|
|
Builtins::kDatePrototypeSetUTCSeconds, 2, false);
|
|
|
|
SimpleInstallFunction(prototype, "valueOf", Builtins::kDatePrototypeValueOf,
|
|
|
|
0, false);
|
|
|
|
SimpleInstallFunction(prototype, "getYear", Builtins::kDatePrototypeGetYear,
|
|
|
|
0, true);
|
|
|
|
SimpleInstallFunction(prototype, "setYear", Builtins::kDatePrototypeSetYear,
|
|
|
|
1, false);
|
2016-05-31 09:32:25 +00:00
|
|
|
SimpleInstallFunction(prototype, "toJSON", Builtins::kDatePrototypeToJson,
|
|
|
|
1, false);
|
2016-01-12 10:47:27 +00:00
|
|
|
|
|
|
|
// Install i18n fallback functions.
|
|
|
|
SimpleInstallFunction(prototype, "toLocaleString",
|
|
|
|
Builtins::kDatePrototypeToString, 0, false);
|
|
|
|
SimpleInstallFunction(prototype, "toLocaleDateString",
|
|
|
|
Builtins::kDatePrototypeToDateString, 0, false);
|
|
|
|
SimpleInstallFunction(prototype, "toLocaleTimeString",
|
|
|
|
Builtins::kDatePrototypeToTimeString, 0, false);
|
|
|
|
|
|
|
|
// Install the @@toPrimitive function.
|
|
|
|
Handle<JSFunction> to_primitive = InstallFunction(
|
|
|
|
prototype, factory->to_primitive_symbol(), JS_OBJECT_TYPE,
|
|
|
|
JSObject::kHeaderSize, MaybeHandle<JSObject>(),
|
|
|
|
Builtins::kDatePrototypeToPrimitive,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
|
|
|
// Set the expected parameters for @@toPrimitive to 1; required by builtin.
|
|
|
|
to_primitive->shared()->set_internal_formal_parameter_count(1);
|
|
|
|
|
|
|
|
// Set the length for the function to satisfy ECMA-262.
|
|
|
|
to_primitive->shared()->set_length(1);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- R e g E x p
|
|
|
|
// Builtin functions for RegExp.prototype.
|
2016-09-30 07:24:20 +00:00
|
|
|
Handle<JSObject> prototype =
|
|
|
|
factory->NewJSObject(isolate->object_function(), TENURED);
|
|
|
|
Handle<JSFunction> regexp_fun =
|
|
|
|
InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize,
|
2016-10-05 09:13:04 +00:00
|
|
|
prototype, Builtins::kRegExpConstructor);
|
2015-12-07 16:35:03 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate, regexp_fun,
|
|
|
|
Context::REGEXP_FUNCTION_INDEX);
|
2016-10-05 09:13:04 +00:00
|
|
|
|
|
|
|
Handle<SharedFunctionInfo> shared(regexp_fun->shared(), isolate);
|
|
|
|
shared->SetConstructStub(*isolate->builtins()->RegExpConstructor());
|
|
|
|
shared->set_instance_class_name(isolate->heap()->RegExp_string());
|
|
|
|
shared->DontAdaptArguments();
|
|
|
|
shared->set_length(2);
|
2016-10-14 11:46:43 +00:00
|
|
|
|
2016-10-06 13:00:56 +00:00
|
|
|
{
|
|
|
|
// RegExp.prototype setup.
|
|
|
|
|
|
|
|
// Install the "constructor" property on the {prototype}.
|
|
|
|
JSObject::AddProperty(prototype, factory->constructor_string(),
|
|
|
|
regexp_fun, DONT_ENUM);
|
|
|
|
|
2016-10-10 13:56:46 +00:00
|
|
|
{
|
|
|
|
Handle<JSFunction> fun = SimpleInstallFunction(
|
2016-10-24 12:40:45 +00:00
|
|
|
prototype, factory->exec_string(), Builtins::kRegExpPrototypeExec,
|
|
|
|
1, true, DONT_ENUM);
|
2016-10-10 13:56:46 +00:00
|
|
|
native_context()->set_regexp_exec_function(*fun);
|
|
|
|
}
|
2016-10-06 13:00:56 +00:00
|
|
|
|
|
|
|
SimpleInstallGetter(prototype, factory->flags_string(),
|
|
|
|
Builtins::kRegExpPrototypeFlagsGetter, true);
|
|
|
|
SimpleInstallGetter(prototype, factory->global_string(),
|
|
|
|
Builtins::kRegExpPrototypeGlobalGetter, true);
|
|
|
|
SimpleInstallGetter(prototype, factory->ignoreCase_string(),
|
|
|
|
Builtins::kRegExpPrototypeIgnoreCaseGetter, true);
|
|
|
|
SimpleInstallGetter(prototype, factory->multiline_string(),
|
|
|
|
Builtins::kRegExpPrototypeMultilineGetter, true);
|
|
|
|
SimpleInstallGetter(prototype, factory->source_string(),
|
|
|
|
Builtins::kRegExpPrototypeSourceGetter, false);
|
|
|
|
SimpleInstallGetter(prototype, factory->sticky_string(),
|
|
|
|
Builtins::kRegExpPrototypeStickyGetter, true);
|
|
|
|
SimpleInstallGetter(prototype, factory->unicode_string(),
|
|
|
|
Builtins::kRegExpPrototypeUnicodeGetter, true);
|
2016-10-10 13:06:24 +00:00
|
|
|
|
|
|
|
SimpleInstallFunction(prototype, "compile",
|
|
|
|
Builtins::kRegExpPrototypeCompile, 2, false,
|
|
|
|
DONT_ENUM);
|
|
|
|
SimpleInstallFunction(prototype, factory->toString_string(),
|
|
|
|
Builtins::kRegExpPrototypeToString, 0, false,
|
|
|
|
DONT_ENUM);
|
2016-10-10 13:56:46 +00:00
|
|
|
SimpleInstallFunction(prototype, "test", Builtins::kRegExpPrototypeTest,
|
2016-10-24 12:40:45 +00:00
|
|
|
1, true, DONT_ENUM);
|
2016-10-10 13:56:46 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
Handle<JSFunction> fun = SimpleCreateFunction(
|
|
|
|
isolate, factory->InternalizeUtf8String("[Symbol.match]"),
|
2016-11-29 09:02:48 +00:00
|
|
|
Builtins::kRegExpPrototypeMatch, 1, true);
|
2016-10-10 13:56:46 +00:00
|
|
|
InstallFunction(prototype, fun, factory->match_symbol(), DONT_ENUM);
|
|
|
|
}
|
|
|
|
|
2016-10-13 11:27:25 +00:00
|
|
|
{
|
|
|
|
Handle<JSFunction> fun = SimpleCreateFunction(
|
|
|
|
isolate, factory->InternalizeUtf8String("[Symbol.replace]"),
|
|
|
|
Builtins::kRegExpPrototypeReplace, 2, true);
|
|
|
|
InstallFunction(prototype, fun, factory->replace_symbol(), DONT_ENUM);
|
|
|
|
}
|
|
|
|
|
2016-10-10 13:56:46 +00:00
|
|
|
{
|
|
|
|
Handle<JSFunction> fun = SimpleCreateFunction(
|
|
|
|
isolate, factory->InternalizeUtf8String("[Symbol.search]"),
|
2016-11-15 16:05:47 +00:00
|
|
|
Builtins::kRegExpPrototypeSearch, 1, true);
|
2016-10-10 13:56:46 +00:00
|
|
|
InstallFunction(prototype, fun, factory->search_symbol(), DONT_ENUM);
|
|
|
|
}
|
2016-10-11 10:38:02 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
Handle<JSFunction> fun = SimpleCreateFunction(
|
|
|
|
isolate, factory->InternalizeUtf8String("[Symbol.split]"),
|
2016-12-01 08:24:57 +00:00
|
|
|
Builtins::kRegExpPrototypeSplit, 2, true);
|
2016-10-11 10:38:02 +00:00
|
|
|
InstallFunction(prototype, fun, factory->split_symbol(), DONT_ENUM);
|
|
|
|
}
|
2016-10-13 11:27:25 +00:00
|
|
|
|
2016-11-29 07:41:08 +00:00
|
|
|
Handle<Map> prototype_map(prototype->map());
|
|
|
|
Map::SetShouldBeFastPrototypeMap(prototype_map, true, isolate);
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
SimpleInstallGetter(regexp_fun,
|
|
|
|
factory->InternalizeUtf8String("[Symbol.species]"),
|
|
|
|
factory->species_symbol(),
|
|
|
|
Builtins::kRegExpPrototypeSpeciesGetter, false);
|
|
|
|
|
|
|
|
// Static properties set by a successful match.
|
|
|
|
|
2016-10-27 08:25:24 +00:00
|
|
|
const PropertyAttributes no_enum = DONT_ENUM;
|
2016-10-06 13:00:56 +00:00
|
|
|
SimpleInstallGetterSetter(regexp_fun, factory->input_string(),
|
|
|
|
Builtins::kRegExpInputGetter,
|
2016-10-27 08:25:24 +00:00
|
|
|
Builtins::kRegExpInputSetter, no_enum);
|
2016-10-06 13:00:56 +00:00
|
|
|
SimpleInstallGetterSetter(
|
|
|
|
regexp_fun, factory->InternalizeUtf8String("$_"),
|
|
|
|
Builtins::kRegExpInputGetter, Builtins::kRegExpInputSetter, no_enum);
|
|
|
|
|
|
|
|
SimpleInstallGetterSetter(
|
|
|
|
regexp_fun, factory->InternalizeUtf8String("lastMatch"),
|
|
|
|
Builtins::kRegExpLastMatchGetter, Builtins::kEmptyFunction, no_enum);
|
|
|
|
SimpleInstallGetterSetter(
|
|
|
|
regexp_fun, factory->InternalizeUtf8String("$&"),
|
|
|
|
Builtins::kRegExpLastMatchGetter, Builtins::kEmptyFunction, no_enum);
|
|
|
|
|
|
|
|
SimpleInstallGetterSetter(
|
|
|
|
regexp_fun, factory->InternalizeUtf8String("lastParen"),
|
|
|
|
Builtins::kRegExpLastParenGetter, Builtins::kEmptyFunction, no_enum);
|
|
|
|
SimpleInstallGetterSetter(
|
|
|
|
regexp_fun, factory->InternalizeUtf8String("$+"),
|
|
|
|
Builtins::kRegExpLastParenGetter, Builtins::kEmptyFunction, no_enum);
|
|
|
|
|
|
|
|
SimpleInstallGetterSetter(regexp_fun,
|
|
|
|
factory->InternalizeUtf8String("leftContext"),
|
|
|
|
Builtins::kRegExpLeftContextGetter,
|
|
|
|
Builtins::kEmptyFunction, no_enum);
|
|
|
|
SimpleInstallGetterSetter(regexp_fun,
|
|
|
|
factory->InternalizeUtf8String("$`"),
|
|
|
|
Builtins::kRegExpLeftContextGetter,
|
|
|
|
Builtins::kEmptyFunction, no_enum);
|
|
|
|
|
|
|
|
SimpleInstallGetterSetter(regexp_fun,
|
|
|
|
factory->InternalizeUtf8String("rightContext"),
|
|
|
|
Builtins::kRegExpRightContextGetter,
|
|
|
|
Builtins::kEmptyFunction, no_enum);
|
|
|
|
SimpleInstallGetterSetter(regexp_fun,
|
|
|
|
factory->InternalizeUtf8String("$'"),
|
|
|
|
Builtins::kRegExpRightContextGetter,
|
|
|
|
Builtins::kEmptyFunction, no_enum);
|
|
|
|
|
2016-10-27 08:25:24 +00:00
|
|
|
#define INSTALL_CAPTURE_GETTER(i) \
|
|
|
|
SimpleInstallGetterSetter( \
|
|
|
|
regexp_fun, factory->InternalizeUtf8String("$" #i), \
|
|
|
|
Builtins::kRegExpCapture##i##Getter, Builtins::kEmptyFunction, no_enum)
|
2016-10-06 13:00:56 +00:00
|
|
|
INSTALL_CAPTURE_GETTER(1);
|
|
|
|
INSTALL_CAPTURE_GETTER(2);
|
|
|
|
INSTALL_CAPTURE_GETTER(3);
|
|
|
|
INSTALL_CAPTURE_GETTER(4);
|
|
|
|
INSTALL_CAPTURE_GETTER(5);
|
|
|
|
INSTALL_CAPTURE_GETTER(6);
|
|
|
|
INSTALL_CAPTURE_GETTER(7);
|
|
|
|
INSTALL_CAPTURE_GETTER(8);
|
|
|
|
INSTALL_CAPTURE_GETTER(9);
|
|
|
|
#undef INSTALL_CAPTURE_GETTER
|
|
|
|
}
|
2016-09-05 11:52:53 +00:00
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(regexp_fun->has_initial_map());
|
2010-03-26 14:19:47 +00:00
|
|
|
Handle<Map> initial_map(regexp_fun->initial_map());
|
|
|
|
|
2015-08-11 19:36:04 +00:00
|
|
|
DCHECK_EQ(0, initial_map->GetInObjectProperties());
|
2010-03-26 14:19:47 +00:00
|
|
|
|
2015-11-05 19:10:07 +00:00
|
|
|
Map::EnsureDescriptorSlack(initial_map, 1);
|
|
|
|
|
|
|
|
// ECMA-262, section 15.10.7.5.
|
|
|
|
PropertyAttributes writable =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE);
|
2016-10-10 13:56:46 +00:00
|
|
|
DataDescriptor field(factory->lastIndex_string(),
|
2015-11-05 19:10:07 +00:00
|
|
|
JSRegExp::kLastIndexFieldIndex, writable,
|
|
|
|
Representation::Tagged());
|
|
|
|
initial_map->AppendDescriptor(&field);
|
2010-03-26 14:19:47 +00:00
|
|
|
|
2014-11-21 10:50:12 +00:00
|
|
|
static const int num_fields = JSRegExp::kInObjectFieldCount;
|
2015-08-11 19:36:04 +00:00
|
|
|
initial_map->SetInObjectProperties(num_fields);
|
2010-03-26 14:19:47 +00:00
|
|
|
initial_map->set_unused_property_fields(0);
|
2014-11-21 10:50:12 +00:00
|
|
|
initial_map->set_instance_size(initial_map->instance_size() +
|
|
|
|
num_fields * kPointerSize);
|
2016-10-13 15:02:47 +00:00
|
|
|
|
|
|
|
{ // Internal: RegExpInternalMatch
|
|
|
|
Handle<JSFunction> function =
|
|
|
|
factory->NewFunction(isolate->factory()->empty_string(),
|
|
|
|
isolate->builtins()->RegExpInternalMatch(),
|
|
|
|
JS_OBJECT_TYPE, JSObject::kHeaderSize);
|
|
|
|
function->shared()->set_internal_formal_parameter_count(2);
|
|
|
|
function->shared()->set_length(2);
|
|
|
|
function->shared()->set_native(true);
|
2016-10-14 11:46:43 +00:00
|
|
|
native_context()->set(Context::REGEXP_INTERNAL_MATCH, *function);
|
2016-10-13 15:02:47 +00:00
|
|
|
}
|
2016-10-14 11:46:43 +00:00
|
|
|
|
|
|
|
// Create the last match info. One for external use, and one for internal
|
|
|
|
// use when we don't want to modify the externally visible match info.
|
|
|
|
Handle<RegExpMatchInfo> last_match_info = factory->NewRegExpMatchInfo();
|
|
|
|
native_context()->set_regexp_last_match_info(*last_match_info);
|
|
|
|
Handle<RegExpMatchInfo> internal_match_info = factory->NewRegExpMatchInfo();
|
|
|
|
native_context()->set_regexp_internal_match_info(*internal_match_info);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2015-12-09 07:53:19 +00:00
|
|
|
{ // -- E r r o r
|
2016-07-20 13:02:36 +00:00
|
|
|
InstallError(isolate, global, factory->Error_string(),
|
|
|
|
Context::ERROR_FUNCTION_INDEX);
|
2016-08-09 07:36:19 +00:00
|
|
|
InstallMakeError(isolate, isolate->builtins()->MakeError(),
|
|
|
|
Context::MAKE_ERROR_INDEX);
|
2015-12-09 07:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- E v a l E r r o r
|
2016-07-20 13:02:36 +00:00
|
|
|
InstallError(isolate, global, factory->EvalError_string(),
|
|
|
|
Context::EVAL_ERROR_FUNCTION_INDEX);
|
2015-12-09 07:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- R a n g e E r r o r
|
2016-07-20 13:02:36 +00:00
|
|
|
InstallError(isolate, global, factory->RangeError_string(),
|
|
|
|
Context::RANGE_ERROR_FUNCTION_INDEX);
|
2016-08-09 07:36:19 +00:00
|
|
|
InstallMakeError(isolate, isolate->builtins()->MakeRangeError(),
|
|
|
|
Context::MAKE_RANGE_ERROR_INDEX);
|
2015-12-09 07:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- R e f e r e n c e E r r o r
|
2016-07-20 13:02:36 +00:00
|
|
|
InstallError(isolate, global, factory->ReferenceError_string(),
|
|
|
|
Context::REFERENCE_ERROR_FUNCTION_INDEX);
|
2015-12-09 07:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- S y n t a x E r r o r
|
2016-07-20 13:02:36 +00:00
|
|
|
InstallError(isolate, global, factory->SyntaxError_string(),
|
|
|
|
Context::SYNTAX_ERROR_FUNCTION_INDEX);
|
2016-08-09 07:36:19 +00:00
|
|
|
InstallMakeError(isolate, isolate->builtins()->MakeSyntaxError(),
|
|
|
|
Context::MAKE_SYNTAX_ERROR_INDEX);
|
2015-12-09 07:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- T y p e E r r o r
|
2016-07-20 13:02:36 +00:00
|
|
|
InstallError(isolate, global, factory->TypeError_string(),
|
|
|
|
Context::TYPE_ERROR_FUNCTION_INDEX);
|
2016-08-09 07:36:19 +00:00
|
|
|
InstallMakeError(isolate, isolate->builtins()->MakeTypeError(),
|
|
|
|
Context::MAKE_TYPE_ERROR_INDEX);
|
2015-12-09 07:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- U R I E r r o r
|
2016-07-20 13:02:36 +00:00
|
|
|
InstallError(isolate, global, factory->URIError_string(),
|
|
|
|
Context::URI_ERROR_FUNCTION_INDEX);
|
2016-08-09 07:36:19 +00:00
|
|
|
InstallMakeError(isolate, isolate->builtins()->MakeURIError(),
|
|
|
|
Context::MAKE_URI_ERROR_INDEX);
|
2015-12-09 07:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-10-13 16:17:44 +00:00
|
|
|
{ // -- C o m p i l e E r r o r
|
|
|
|
Handle<JSObject> dummy = factory->NewJSObject(isolate->object_function());
|
|
|
|
InstallError(isolate, dummy, factory->CompileError_string(),
|
|
|
|
Context::WASM_COMPILE_ERROR_FUNCTION_INDEX);
|
|
|
|
|
|
|
|
// -- R u n t i m e E r r o r
|
|
|
|
InstallError(isolate, dummy, factory->RuntimeError_string(),
|
|
|
|
Context::WASM_RUNTIME_ERROR_FUNCTION_INDEX);
|
|
|
|
}
|
|
|
|
|
2015-07-13 09:45:43 +00:00
|
|
|
// Initialize the embedder data slot.
|
|
|
|
Handle<FixedArray> embedder_data = factory->NewFixedArray(3);
|
|
|
|
native_context()->set_embedder_data(*embedder_data);
|
|
|
|
|
2009-04-24 08:13:09 +00:00
|
|
|
{ // -- J S O N
|
2013-09-25 15:11:48 +00:00
|
|
|
Handle<String> name = factory->InternalizeUtf8String("JSON");
|
2014-05-09 16:39:33 +00:00
|
|
|
Handle<JSFunction> cons = factory->NewFunction(name);
|
2013-07-18 07:59:48 +00:00
|
|
|
JSFunction::SetInstancePrototype(cons,
|
|
|
|
Handle<Object>(native_context()->initial_object_prototype(), isolate));
|
2011-03-28 13:09:37 +00:00
|
|
|
Handle<JSObject> json_object = factory->NewJSObject(cons, TENURED);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(json_object->IsJSObject());
|
2014-06-30 13:48:57 +00:00
|
|
|
JSObject::AddProperty(global, name, json_object, DONT_ENUM);
|
2016-06-03 18:40:54 +00:00
|
|
|
SimpleInstallFunction(json_object, "parse", Builtins::kJsonParse, 2, false);
|
2016-05-25 12:32:07 +00:00
|
|
|
SimpleInstallFunction(json_object, "stringify", Builtins::kJsonStringify, 3,
|
|
|
|
true);
|
2016-05-31 09:32:25 +00:00
|
|
|
JSObject::AddProperty(
|
|
|
|
json_object, factory->to_string_tag_symbol(),
|
|
|
|
factory->NewStringFromAsciiChecked("JSON"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
2015-08-14 15:12:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- M a t h
|
|
|
|
Handle<String> name = factory->InternalizeUtf8String("Math");
|
|
|
|
Handle<JSFunction> cons = factory->NewFunction(name);
|
|
|
|
JSFunction::SetInstancePrototype(
|
|
|
|
cons,
|
|
|
|
Handle<Object>(native_context()->initial_object_prototype(), isolate));
|
2016-01-28 13:06:43 +00:00
|
|
|
Handle<JSObject> math = factory->NewJSObject(cons, TENURED);
|
|
|
|
DCHECK(math->IsJSObject());
|
|
|
|
JSObject::AddProperty(global, name, math, DONT_ENUM);
|
[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
|
|
|
SimpleInstallFunction(math, "abs", Builtins::kMathAbs, 1, true);
|
2016-02-25 08:06:15 +00:00
|
|
|
SimpleInstallFunction(math, "acos", Builtins::kMathAcos, 1, true);
|
[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
|
|
|
SimpleInstallFunction(math, "acosh", Builtins::kMathAcosh, 1, true);
|
2016-02-25 08:06:15 +00:00
|
|
|
SimpleInstallFunction(math, "asin", Builtins::kMathAsin, 1, true);
|
[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
|
|
|
SimpleInstallFunction(math, "asinh", Builtins::kMathAsinh, 1, true);
|
2016-02-25 08:06:15 +00:00
|
|
|
SimpleInstallFunction(math, "atan", Builtins::kMathAtan, 1, true);
|
2016-06-17 09:13:22 +00:00
|
|
|
SimpleInstallFunction(math, "atanh", Builtins::kMathAtanh, 1, true);
|
[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
|
|
|
SimpleInstallFunction(math, "atan2", Builtins::kMathAtan2, 2, true);
|
2016-03-30 11:56:31 +00:00
|
|
|
SimpleInstallFunction(math, "ceil", Builtins::kMathCeil, 1, true);
|
2016-06-17 09:13:22 +00:00
|
|
|
SimpleInstallFunction(math, "cbrt", Builtins::kMathCbrt, 1, true);
|
|
|
|
SimpleInstallFunction(math, "expm1", Builtins::kMathExpm1, 1, true);
|
2016-04-01 14:35:29 +00:00
|
|
|
SimpleInstallFunction(math, "clz32", Builtins::kMathClz32, 1, true);
|
2016-06-17 15:21:48 +00:00
|
|
|
SimpleInstallFunction(math, "cos", Builtins::kMathCos, 1, true);
|
2016-06-30 08:41:05 +00:00
|
|
|
SimpleInstallFunction(math, "cosh", Builtins::kMathCosh, 1, true);
|
[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
|
|
|
SimpleInstallFunction(math, "exp", Builtins::kMathExp, 1, true);
|
2016-03-28 17:30:05 +00:00
|
|
|
Handle<JSFunction> math_floor =
|
|
|
|
SimpleInstallFunction(math, "floor", Builtins::kMathFloor, 1, true);
|
|
|
|
native_context()->set_math_floor(*math_floor);
|
2016-02-25 08:06:15 +00:00
|
|
|
SimpleInstallFunction(math, "fround", Builtins::kMathFround, 1, true);
|
2016-07-01 08:13:29 +00:00
|
|
|
SimpleInstallFunction(math, "hypot", Builtins::kMathHypot, 2, false);
|
2016-02-25 08:06:15 +00:00
|
|
|
SimpleInstallFunction(math, "imul", Builtins::kMathImul, 2, true);
|
[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
|
|
|
SimpleInstallFunction(math, "log", Builtins::kMathLog, 1, true);
|
2016-06-13 05:46:38 +00:00
|
|
|
SimpleInstallFunction(math, "log1p", Builtins::kMathLog1p, 1, true);
|
2016-06-16 11:22:32 +00:00
|
|
|
SimpleInstallFunction(math, "log2", Builtins::kMathLog2, 1, true);
|
|
|
|
SimpleInstallFunction(math, "log10", Builtins::kMathLog10, 1, true);
|
2016-01-28 13:06:43 +00:00
|
|
|
SimpleInstallFunction(math, "max", Builtins::kMathMax, 2, false);
|
|
|
|
SimpleInstallFunction(math, "min", Builtins::kMathMin, 2, false);
|
2016-06-28 10:23:58 +00:00
|
|
|
Handle<JSFunction> math_pow =
|
|
|
|
SimpleInstallFunction(math, "pow", Builtins::kMathPow, 2, true);
|
|
|
|
native_context()->set_math_pow(*math_pow);
|
2016-10-11 06:46:56 +00:00
|
|
|
SimpleInstallFunction(math, "random", Builtins::kMathRandom, 0, true);
|
2016-03-30 11:56:31 +00:00
|
|
|
SimpleInstallFunction(math, "round", Builtins::kMathRound, 1, true);
|
[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
|
|
|
SimpleInstallFunction(math, "sign", Builtins::kMathSign, 1, true);
|
2016-06-17 15:21:48 +00:00
|
|
|
SimpleInstallFunction(math, "sin", Builtins::kMathSin, 1, true);
|
2016-06-30 08:41:05 +00:00
|
|
|
SimpleInstallFunction(math, "sinh", Builtins::kMathSinh, 1, true);
|
[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
|
|
|
SimpleInstallFunction(math, "sqrt", Builtins::kMathSqrt, 1, true);
|
2016-06-20 05:51:37 +00:00
|
|
|
SimpleInstallFunction(math, "tan", Builtins::kMathTan, 1, true);
|
2016-06-30 08:41:05 +00:00
|
|
|
SimpleInstallFunction(math, "tanh", Builtins::kMathTanh, 1, true);
|
2016-03-30 11:56:31 +00:00
|
|
|
SimpleInstallFunction(math, "trunc", Builtins::kMathTrunc, 1, true);
|
2016-06-21 07:01:59 +00:00
|
|
|
|
|
|
|
// Install math constants.
|
|
|
|
double const kE = base::ieee754::exp(1.0);
|
[builtins] Unify most of the remaining Math builtins.
Import fdlibm versions of acos, acosh, asin and asinh, which are more
precise and produce the same result across platforms (we were using
libm versions for asin and acos so far, where both speed and precision
depended on the operating system so far). Introduce appropriate TurboFan
operators for these functions and use them both for inlining and for the
generic builtin.
Also migrate the Math.imul and Math.fround builtins to TurboFan builtins
to ensure that their behavior is always exactly the same as the inlined
TurboFan version (i.e. C++ truncation semantics for double to float
don't necessarily meet the JavaScript semantics).
For completeness, also migrate Math.sign, which can even get some nice
love in TurboFan.
Drive-by-fix: Some alpha-sorting on the Math related functions, and
cleanup the list of Math intrinsics that we have to export via the
native context currently.
BUG=v8:3266,v8:3496,v8:3509,v8:3952,v8:5169,v8:5170,v8:5171,v8:5172
TBR=rossberg@chromium.org
R=franzih@chromium.org
Review-Url: https://codereview.chromium.org/2116753002
Cr-Commit-Position: refs/heads/master@{#37476}
2016-07-01 11:11:33 +00:00
|
|
|
double const kPI = 3.1415926535897932;
|
2016-06-21 07:01:59 +00:00
|
|
|
JSObject::AddProperty(
|
|
|
|
math, factory->NewStringFromAsciiChecked("E"), factory->NewNumber(kE),
|
|
|
|
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY));
|
|
|
|
JSObject::AddProperty(
|
|
|
|
math, factory->NewStringFromAsciiChecked("LN10"),
|
|
|
|
factory->NewNumber(base::ieee754::log(10.0)),
|
|
|
|
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY));
|
|
|
|
JSObject::AddProperty(
|
|
|
|
math, factory->NewStringFromAsciiChecked("LN2"),
|
|
|
|
factory->NewNumber(base::ieee754::log(2.0)),
|
|
|
|
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY));
|
|
|
|
JSObject::AddProperty(
|
|
|
|
math, factory->NewStringFromAsciiChecked("LOG10E"),
|
|
|
|
factory->NewNumber(base::ieee754::log10(kE)),
|
|
|
|
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY));
|
|
|
|
JSObject::AddProperty(
|
|
|
|
math, factory->NewStringFromAsciiChecked("LOG2E"),
|
|
|
|
factory->NewNumber(base::ieee754::log2(kE)),
|
|
|
|
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY));
|
[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
|
|
|
JSObject::AddProperty(
|
|
|
|
math, factory->NewStringFromAsciiChecked("PI"), factory->NewNumber(kPI),
|
|
|
|
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY));
|
|
|
|
JSObject::AddProperty(
|
|
|
|
math, factory->NewStringFromAsciiChecked("SQRT1_2"),
|
|
|
|
factory->NewNumber(std::sqrt(0.5)),
|
|
|
|
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY));
|
|
|
|
JSObject::AddProperty(
|
|
|
|
math, factory->NewStringFromAsciiChecked("SQRT2"),
|
|
|
|
factory->NewNumber(std::sqrt(2.0)),
|
|
|
|
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY));
|
2016-10-11 06:46:56 +00:00
|
|
|
JSObject::AddProperty(
|
|
|
|
math, factory->to_string_tag_symbol(),
|
|
|
|
factory->NewStringFromAsciiChecked("Math"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
2009-04-24 08:13:09 +00:00
|
|
|
}
|
|
|
|
|
2014-06-06 08:15:05 +00:00
|
|
|
{ // -- A r r a y B u f f e r
|
2016-07-07 19:42:15 +00:00
|
|
|
Handle<JSFunction> array_buffer_fun = InstallArrayBuffer(
|
|
|
|
global, "ArrayBuffer", Builtins::kArrayBufferPrototypeGetByteLength,
|
|
|
|
BuiltinFunctionId::kArrayBufferByteLength);
|
2015-12-07 16:35:03 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate, array_buffer_fun,
|
|
|
|
Context::ARRAY_BUFFER_FUN_INDEX);
|
2013-08-20 13:55:52 +00:00
|
|
|
}
|
|
|
|
|
2016-06-08 07:40:11 +00:00
|
|
|
{ // -- T y p e d A r r a y
|
|
|
|
Handle<JSObject> prototype =
|
|
|
|
factory->NewJSObject(isolate->object_function(), TENURED);
|
|
|
|
native_context()->set_typed_array_prototype(*prototype);
|
|
|
|
|
|
|
|
Handle<JSFunction> typed_array_fun =
|
|
|
|
CreateFunction(isolate, factory->InternalizeUtf8String("TypedArray"),
|
|
|
|
JS_TYPED_ARRAY_TYPE, JSTypedArray::kSize, prototype,
|
|
|
|
Builtins::kIllegal);
|
|
|
|
|
|
|
|
// Install the "constructor" property on the {prototype}.
|
|
|
|
JSObject::AddProperty(prototype, factory->constructor_string(),
|
|
|
|
typed_array_fun, DONT_ENUM);
|
|
|
|
native_context()->set_typed_array_function(*typed_array_fun);
|
|
|
|
|
|
|
|
// Install the "buffer", "byteOffset", "byteLength" and "length"
|
|
|
|
// getters on the {prototype}.
|
|
|
|
SimpleInstallGetter(prototype, factory->buffer_string(),
|
|
|
|
Builtins::kTypedArrayPrototypeBuffer, false);
|
|
|
|
SimpleInstallGetter(prototype, factory->byte_length_string(),
|
|
|
|
Builtins::kTypedArrayPrototypeByteLength, true,
|
|
|
|
kTypedArrayByteLength);
|
|
|
|
SimpleInstallGetter(prototype, factory->byte_offset_string(),
|
|
|
|
Builtins::kTypedArrayPrototypeByteOffset, true,
|
|
|
|
kTypedArrayByteOffset);
|
|
|
|
SimpleInstallGetter(prototype, factory->length_string(),
|
|
|
|
Builtins::kTypedArrayPrototypeLength, true,
|
|
|
|
kTypedArrayLength);
|
2016-10-18 02:42:42 +00:00
|
|
|
|
|
|
|
// Install "keys", "values" and "entries" methods on the {prototype}.
|
2016-11-14 15:58:48 +00:00
|
|
|
Handle<JSFunction> entries =
|
|
|
|
SimpleInstallFunction(prototype, factory->entries_string(),
|
|
|
|
Builtins::kTypedArrayPrototypeEntries, 0, true);
|
|
|
|
entries->shared()->set_builtin_function_id(kTypedArrayEntries);
|
|
|
|
|
|
|
|
Handle<JSFunction> keys =
|
|
|
|
SimpleInstallFunction(prototype, factory->keys_string(),
|
|
|
|
Builtins::kTypedArrayPrototypeKeys, 0, true);
|
|
|
|
keys->shared()->set_builtin_function_id(kTypedArrayKeys);
|
|
|
|
|
|
|
|
Handle<JSFunction> values =
|
2016-10-18 02:42:42 +00:00
|
|
|
SimpleInstallFunction(prototype, factory->values_string(),
|
|
|
|
Builtins::kTypedArrayPrototypeValues, 0, true);
|
2016-11-14 15:58:48 +00:00
|
|
|
values->shared()->set_builtin_function_id(kTypedArrayValues);
|
|
|
|
JSObject::AddProperty(prototype, factory->iterator_symbol(), values,
|
2016-10-18 02:42:42 +00:00
|
|
|
DONT_ENUM);
|
2016-06-08 07:40:11 +00:00
|
|
|
}
|
|
|
|
|
2014-06-06 08:15:05 +00:00
|
|
|
{ // -- T y p e d A r r a y s
|
2015-12-07 16:35:03 +00:00
|
|
|
#define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype, size) \
|
|
|
|
{ \
|
|
|
|
Handle<JSFunction> fun; \
|
|
|
|
InstallTypedArray(#Type "Array", TYPE##_ELEMENTS, &fun); \
|
|
|
|
InstallWithIntrinsicDefaultProto(isolate, fun, \
|
|
|
|
Context::TYPE##_ARRAY_FUN_INDEX); \
|
2015-07-28 09:29:34 +00:00
|
|
|
}
|
2014-01-24 16:01:15 +00:00
|
|
|
TYPED_ARRAYS(INSTALL_TYPED_ARRAY)
|
|
|
|
#undef INSTALL_TYPED_ARRAY
|
2016-06-08 07:40:11 +00:00
|
|
|
}
|
2013-08-20 13:55:52 +00:00
|
|
|
|
2016-06-08 07:40:11 +00:00
|
|
|
{ // -- D a t a V i e w
|
|
|
|
Handle<JSObject> prototype =
|
|
|
|
factory->NewJSObject(isolate->object_function(), TENURED);
|
|
|
|
Handle<JSFunction> data_view_fun =
|
|
|
|
InstallFunction(global, "DataView", JS_DATA_VIEW_TYPE,
|
|
|
|
JSDataView::kSizeWithInternalFields, prototype,
|
|
|
|
Builtins::kDataViewConstructor);
|
2015-12-07 16:35:03 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate, data_view_fun,
|
|
|
|
Context::DATA_VIEW_FUN_INDEX);
|
2016-07-11 10:03:02 +00:00
|
|
|
data_view_fun->shared()->SetConstructStub(
|
2016-02-19 08:58:33 +00:00
|
|
|
*isolate->builtins()->DataViewConstructor_ConstructStub());
|
|
|
|
data_view_fun->shared()->set_length(3);
|
|
|
|
data_view_fun->shared()->DontAdaptArguments();
|
2016-06-08 07:40:11 +00:00
|
|
|
|
|
|
|
// Install the @@toStringTag property on the {prototype}.
|
|
|
|
JSObject::AddProperty(
|
|
|
|
prototype, factory->to_string_tag_symbol(),
|
|
|
|
factory->NewStringFromAsciiChecked("DataView"),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
|
|
|
// Install the "constructor" property on the {prototype}.
|
|
|
|
JSObject::AddProperty(prototype, factory->constructor_string(),
|
|
|
|
data_view_fun, DONT_ENUM);
|
|
|
|
|
|
|
|
// Install the "buffer", "byteOffset" and "byteLength" getters
|
|
|
|
// on the {prototype}.
|
|
|
|
SimpleInstallGetter(prototype, factory->buffer_string(),
|
|
|
|
Builtins::kDataViewPrototypeGetBuffer, false,
|
|
|
|
kDataViewBuffer);
|
|
|
|
SimpleInstallGetter(prototype, factory->byte_length_string(),
|
|
|
|
Builtins::kDataViewPrototypeGetByteLength, false,
|
|
|
|
kDataViewByteLength);
|
|
|
|
SimpleInstallGetter(prototype, factory->byte_offset_string(),
|
|
|
|
Builtins::kDataViewPrototypeGetByteOffset, false,
|
|
|
|
kDataViewByteOffset);
|
2016-09-02 18:31:41 +00:00
|
|
|
|
|
|
|
SimpleInstallFunction(prototype, "getInt8",
|
|
|
|
Builtins::kDataViewPrototypeGetInt8, 1, false);
|
|
|
|
SimpleInstallFunction(prototype, "setInt8",
|
|
|
|
Builtins::kDataViewPrototypeSetInt8, 2, false);
|
|
|
|
SimpleInstallFunction(prototype, "getUint8",
|
|
|
|
Builtins::kDataViewPrototypeGetUint8, 1, false);
|
|
|
|
SimpleInstallFunction(prototype, "setUint8",
|
|
|
|
Builtins::kDataViewPrototypeSetUint8, 2, false);
|
|
|
|
SimpleInstallFunction(prototype, "getInt16",
|
|
|
|
Builtins::kDataViewPrototypeGetInt16, 1, false);
|
|
|
|
SimpleInstallFunction(prototype, "setInt16",
|
|
|
|
Builtins::kDataViewPrototypeSetInt16, 2, false);
|
|
|
|
SimpleInstallFunction(prototype, "getUint16",
|
|
|
|
Builtins::kDataViewPrototypeGetUint16, 1, false);
|
|
|
|
SimpleInstallFunction(prototype, "setUint16",
|
|
|
|
Builtins::kDataViewPrototypeSetUint16, 2, false);
|
|
|
|
SimpleInstallFunction(prototype, "getInt32",
|
|
|
|
Builtins::kDataViewPrototypeGetInt32, 1, false);
|
|
|
|
SimpleInstallFunction(prototype, "setInt32",
|
|
|
|
Builtins::kDataViewPrototypeSetInt32, 2, false);
|
|
|
|
SimpleInstallFunction(prototype, "getUint32",
|
|
|
|
Builtins::kDataViewPrototypeGetUint32, 1, false);
|
|
|
|
SimpleInstallFunction(prototype, "setUint32",
|
|
|
|
Builtins::kDataViewPrototypeSetUint32, 2, false);
|
|
|
|
SimpleInstallFunction(prototype, "getFloat32",
|
|
|
|
Builtins::kDataViewPrototypeGetFloat32, 1, false);
|
|
|
|
SimpleInstallFunction(prototype, "setFloat32",
|
|
|
|
Builtins::kDataViewPrototypeSetFloat32, 2, false);
|
|
|
|
SimpleInstallFunction(prototype, "getFloat64",
|
|
|
|
Builtins::kDataViewPrototypeGetFloat64, 1, false);
|
|
|
|
SimpleInstallFunction(prototype, "setFloat64",
|
|
|
|
Builtins::kDataViewPrototypeSetFloat64, 2, false);
|
2013-08-20 13:55:52 +00:00
|
|
|
}
|
|
|
|
|
2015-05-26 17:36:48 +00:00
|
|
|
{ // -- M a p
|
2015-08-31 10:09:52 +00:00
|
|
|
Handle<JSFunction> js_map_fun = InstallFunction(
|
2015-05-26 17:36:48 +00:00
|
|
|
global, "Map", JS_MAP_TYPE, JSMap::kSize,
|
|
|
|
isolate->initial_object_prototype(), Builtins::kIllegal);
|
2015-12-07 16:35:03 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate, js_map_fun,
|
|
|
|
Context::JS_MAP_FUN_INDEX);
|
2015-05-26 17:36:48 +00:00
|
|
|
}
|
2014-08-05 19:37:32 +00:00
|
|
|
|
2015-05-26 17:36:48 +00:00
|
|
|
{ // -- S e t
|
2015-08-31 10:09:52 +00:00
|
|
|
Handle<JSFunction> js_set_fun = InstallFunction(
|
2015-05-26 17:36:48 +00:00
|
|
|
global, "Set", JS_SET_TYPE, JSSet::kSize,
|
|
|
|
isolate->initial_object_prototype(), Builtins::kIllegal);
|
2015-12-07 16:35:03 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate, js_set_fun,
|
|
|
|
Context::JS_SET_FUN_INDEX);
|
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
|
|
|
|
Handle<Map> map =
|
|
|
|
factory->NewMap(JS_MODULE_NAMESPACE_TYPE, JSModuleNamespace::kSize);
|
|
|
|
Map::SetPrototype(map, isolate->factory()->null_value());
|
2016-10-13 13:34:50 +00:00
|
|
|
Map::EnsureDescriptorSlack(map, 2);
|
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 =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
|
|
|
|
DataConstantDescriptor d(factory->to_string_tag_symbol(),
|
|
|
|
factory->NewStringFromAsciiChecked("Module"),
|
|
|
|
attribs);
|
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
2016-10-07 19:37:04 +00:00
|
|
|
|
2016-10-13 13:34:50 +00:00
|
|
|
{ // Install @@iterator.
|
|
|
|
Handle<JSFunction> iterator = SimpleCreateFunction(
|
|
|
|
isolate, factory->NewStringFromAsciiChecked("[Symbol.iterator]"),
|
|
|
|
Builtins::kModuleNamespaceIterator, 0, true);
|
|
|
|
iterator->shared()->set_native(true);
|
|
|
|
// TODO(neis): Is this really supposed to be writable?
|
|
|
|
DataConstantDescriptor d(factory->iterator_symbol(), iterator, DONT_ENUM);
|
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
2016-10-07 19:37:04 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 12:16:15 +00:00
|
|
|
{ // -- I t e r a t o r R e s u l t
|
|
|
|
Handle<Map> map =
|
2016-02-08 06:55:16 +00:00
|
|
|
factory->NewMap(JS_OBJECT_TYPE, JSIteratorResult::kSize);
|
2015-09-03 12:16:15 +00:00
|
|
|
Map::SetPrototype(map, isolate->initial_object_prototype());
|
|
|
|
Map::EnsureDescriptorSlack(map, 2);
|
|
|
|
|
|
|
|
{ // value
|
|
|
|
DataDescriptor d(factory->value_string(), JSIteratorResult::kValueIndex,
|
|
|
|
NONE, Representation::Tagged());
|
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // done
|
|
|
|
DataDescriptor d(factory->done_string(), JSIteratorResult::kDoneIndex,
|
|
|
|
NONE, Representation::Tagged());
|
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
2016-02-08 07:00:02 +00:00
|
|
|
map->SetConstructor(native_context()->object_function());
|
2015-09-03 12:16:15 +00:00
|
|
|
map->SetInObjectProperties(2);
|
|
|
|
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
|
|
|
|
Handle<JSFunction> js_weak_map_fun = InstallFunction(
|
|
|
|
global, "WeakMap", JS_WEAK_MAP_TYPE, JSWeakMap::kSize,
|
|
|
|
isolate->initial_object_prototype(), Builtins::kIllegal);
|
|
|
|
InstallWithIntrinsicDefaultProto(isolate, js_weak_map_fun,
|
|
|
|
Context::JS_WEAK_MAP_FUN_INDEX);
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- W e a k S e t
|
|
|
|
Handle<JSFunction> js_weak_set_fun = InstallFunction(
|
|
|
|
global, "WeakSet", JS_WEAK_SET_TYPE, JSWeakSet::kSize,
|
|
|
|
isolate->initial_object_prototype(), Builtins::kIllegal);
|
|
|
|
InstallWithIntrinsicDefaultProto(isolate, js_weak_set_fun,
|
|
|
|
Context::JS_WEAK_SET_FUN_INDEX);
|
|
|
|
}
|
2014-05-06 14:48:34 +00:00
|
|
|
|
2016-03-21 19:39:16 +00:00
|
|
|
{ // -- P r o x y
|
|
|
|
CreateJSProxyMaps();
|
|
|
|
|
|
|
|
Handle<String> name = factory->Proxy_string();
|
|
|
|
Handle<Code> code(isolate->builtins()->ProxyConstructor());
|
|
|
|
|
|
|
|
Handle<JSFunction> proxy_function =
|
|
|
|
factory->NewFunction(isolate->proxy_function_map(),
|
|
|
|
factory->Proxy_string(), MaybeHandle<Code>(code));
|
|
|
|
|
|
|
|
JSFunction::SetInitialMap(
|
|
|
|
proxy_function, Handle<Map>(native_context()->proxy_map(), isolate),
|
|
|
|
factory->null_value());
|
|
|
|
|
2016-07-11 10:03:02 +00:00
|
|
|
proxy_function->shared()->SetConstructStub(
|
2016-03-21 19:39:16 +00:00
|
|
|
*isolate->builtins()->ProxyConstructor_ConstructStub());
|
|
|
|
proxy_function->shared()->set_internal_formal_parameter_count(2);
|
|
|
|
proxy_function->shared()->set_length(2);
|
|
|
|
|
|
|
|
native_context()->set_proxy_function(*proxy_function);
|
|
|
|
InstallFunction(global, name, proxy_function, factory->Object_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- R e f l e c t
|
|
|
|
Handle<String> reflect_string = factory->InternalizeUtf8String("Reflect");
|
|
|
|
Handle<JSObject> reflect =
|
|
|
|
factory->NewJSObject(isolate->object_function(), TENURED);
|
|
|
|
JSObject::AddProperty(global, reflect_string, reflect, DONT_ENUM);
|
|
|
|
|
|
|
|
Handle<JSFunction> define_property =
|
|
|
|
SimpleInstallFunction(reflect, factory->defineProperty_string(),
|
|
|
|
Builtins::kReflectDefineProperty, 3, true);
|
|
|
|
native_context()->set_reflect_define_property(*define_property);
|
|
|
|
|
|
|
|
Handle<JSFunction> delete_property =
|
|
|
|
SimpleInstallFunction(reflect, factory->deleteProperty_string(),
|
|
|
|
Builtins::kReflectDeleteProperty, 2, true);
|
|
|
|
native_context()->set_reflect_delete_property(*delete_property);
|
|
|
|
|
|
|
|
Handle<JSFunction> apply = SimpleInstallFunction(
|
|
|
|
reflect, factory->apply_string(), Builtins::kReflectApply, 3, false);
|
|
|
|
native_context()->set_reflect_apply(*apply);
|
|
|
|
|
|
|
|
Handle<JSFunction> construct =
|
|
|
|
SimpleInstallFunction(reflect, factory->construct_string(),
|
|
|
|
Builtins::kReflectConstruct, 2, false);
|
|
|
|
native_context()->set_reflect_construct(*construct);
|
|
|
|
|
|
|
|
SimpleInstallFunction(reflect, factory->get_string(), Builtins::kReflectGet,
|
|
|
|
2, false);
|
|
|
|
SimpleInstallFunction(reflect, factory->getOwnPropertyDescriptor_string(),
|
|
|
|
Builtins::kReflectGetOwnPropertyDescriptor, 2, true);
|
|
|
|
SimpleInstallFunction(reflect, factory->getPrototypeOf_string(),
|
|
|
|
Builtins::kReflectGetPrototypeOf, 1, true);
|
|
|
|
SimpleInstallFunction(reflect, factory->has_string(), Builtins::kReflectHas,
|
|
|
|
2, true);
|
|
|
|
SimpleInstallFunction(reflect, factory->isExtensible_string(),
|
|
|
|
Builtins::kReflectIsExtensible, 1, true);
|
|
|
|
SimpleInstallFunction(reflect, factory->ownKeys_string(),
|
|
|
|
Builtins::kReflectOwnKeys, 1, true);
|
|
|
|
SimpleInstallFunction(reflect, factory->preventExtensions_string(),
|
|
|
|
Builtins::kReflectPreventExtensions, 1, true);
|
|
|
|
SimpleInstallFunction(reflect, factory->set_string(), Builtins::kReflectSet,
|
|
|
|
3, false);
|
|
|
|
SimpleInstallFunction(reflect, factory->setPrototypeOf_string(),
|
|
|
|
Builtins::kReflectSetPrototypeOf, 2, true);
|
|
|
|
}
|
|
|
|
|
2015-12-27 06:30:53 +00:00
|
|
|
{ // --- B o u n d F u n c t i o n
|
|
|
|
Handle<Map> map =
|
|
|
|
factory->NewMap(JS_BOUND_FUNCTION_TYPE, JSBoundFunction::kSize);
|
|
|
|
map->set_is_callable();
|
|
|
|
Map::SetPrototype(map, empty_function);
|
|
|
|
|
|
|
|
PropertyAttributes roc_attribs =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
|
|
|
|
Map::EnsureDescriptorSlack(map, 2);
|
|
|
|
|
2016-04-07 13:36:40 +00:00
|
|
|
Handle<AccessorInfo> bound_length =
|
|
|
|
Accessors::BoundFunctionLengthInfo(isolate, roc_attribs);
|
2015-12-27 06:30:53 +00:00
|
|
|
{ // length
|
2016-04-07 13:36:40 +00:00
|
|
|
AccessorConstantDescriptor d(factory->length_string(), bound_length,
|
|
|
|
roc_attribs);
|
2015-12-27 06:30:53 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
2016-04-07 13:36:40 +00:00
|
|
|
Handle<AccessorInfo> bound_name =
|
|
|
|
Accessors::BoundFunctionNameInfo(isolate, roc_attribs);
|
|
|
|
{ // length
|
|
|
|
AccessorConstantDescriptor d(factory->name_string(), bound_name,
|
|
|
|
roc_attribs);
|
2015-12-27 06:30:53 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
2016-04-07 13:36:40 +00:00
|
|
|
map->SetInObjectProperties(0);
|
2015-12-27 06:30:53 +00:00
|
|
|
native_context()->set_bound_function_without_constructor_map(*map);
|
|
|
|
|
|
|
|
map = Map::Copy(map, "IsConstructor");
|
2016-01-18 13:10:38 +00:00
|
|
|
map->set_is_constructor(true);
|
2015-12-27 06:30:53 +00:00
|
|
|
native_context()->set_bound_function_with_constructor_map(*map);
|
|
|
|
}
|
|
|
|
|
2014-07-07 13:27:37 +00:00
|
|
|
{ // --- sloppy arguments map
|
2008-07-03 15:10:15 +00:00
|
|
|
// Make sure we can recognize argument objects at runtime.
|
|
|
|
// This is done by introducing an anonymous function with
|
|
|
|
// class_name equals 'Arguments'.
|
2014-08-18 07:54:19 +00:00
|
|
|
Handle<String> arguments_string = factory->Arguments_string();
|
2015-11-24 17:16:40 +00:00
|
|
|
Handle<Code> code = isolate->builtins()->Illegal();
|
2014-05-09 17:39:54 +00:00
|
|
|
Handle<JSFunction> function = factory->NewFunctionWithoutPrototype(
|
|
|
|
arguments_string, code);
|
2014-07-07 13:12:29 +00:00
|
|
|
function->shared()->set_instance_class_name(*arguments_string);
|
2011-03-17 20:28:41 +00:00
|
|
|
|
2015-11-11 12:08:26 +00:00
|
|
|
Handle<Map> map = factory->NewMap(
|
2016-06-23 14:39:30 +00:00
|
|
|
JS_ARGUMENTS_TYPE, JSSloppyArgumentsObject::kSize, FAST_ELEMENTS);
|
2014-07-07 13:27:37 +00:00
|
|
|
// Create the descriptor array for the arguments object.
|
|
|
|
Map::EnsureDescriptorSlack(map, 2);
|
|
|
|
|
|
|
|
{ // length
|
2016-02-12 05:10:38 +00:00
|
|
|
DataDescriptor d(factory->length_string(),
|
|
|
|
JSSloppyArgumentsObject::kLengthIndex, DONT_ENUM,
|
|
|
|
Representation::Tagged());
|
2014-07-07 13:27:37 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
{ // callee
|
2016-02-12 05:10:38 +00:00
|
|
|
DataDescriptor d(factory->callee_string(),
|
|
|
|
JSSloppyArgumentsObject::kCalleeIndex, DONT_ENUM,
|
|
|
|
Representation::Tagged());
|
2014-07-07 13:27:37 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
2014-08-25 09:12:22 +00:00
|
|
|
// @@iterator method is added later.
|
2014-07-07 13:27:37 +00:00
|
|
|
|
2015-08-11 19:36:04 +00:00
|
|
|
map->SetInObjectProperties(2);
|
2014-07-07 13:27:37 +00:00
|
|
|
native_context()->set_sloppy_arguments_map(*map);
|
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!function->has_initial_map());
|
2014-08-11 14:00:58 +00:00
|
|
|
JSFunction::SetInitialMap(function, map,
|
|
|
|
isolate->initial_object_prototype());
|
2014-07-07 13:27:37 +00:00
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!map->is_dictionary_map());
|
|
|
|
DCHECK(IsFastObjectElementsKind(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
|
|
|
|
Handle<Map> map = isolate->sloppy_arguments_map();
|
|
|
|
map = Map::Copy(map, "FastAliasedArguments");
|
|
|
|
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);
|
|
|
|
|
|
|
|
map = Map::Copy(map, "SlowAliasedArguments");
|
|
|
|
map->set_elements_kind(SLOW_SLOPPY_ARGUMENTS_ELEMENTS);
|
2015-08-11 19:36:04 +00:00
|
|
|
DCHECK_EQ(2, map->GetInObjectProperties());
|
2015-07-02 14:38:37 +00:00
|
|
|
native_context()->set_slow_aliased_arguments_map(*map);
|
2014-07-07 13:27:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // --- strict mode arguments map
|
2011-03-17 20:28:41 +00:00
|
|
|
const PropertyAttributes attributes =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
|
|
|
|
|
2016-11-04 14:29:46 +00:00
|
|
|
// Create the ThrowTypeError function.
|
2012-01-10 16:11:33 +00:00
|
|
|
Handle<AccessorPair> callee = factory->NewAccessorPair();
|
2011-03-17 20:28:41 +00:00
|
|
|
|
2015-04-09 22:40:16 +00:00
|
|
|
Handle<JSFunction> poison = GetStrictArgumentsPoisonFunction();
|
2011-03-17 20:28:41 +00:00
|
|
|
|
2016-11-04 14:29:46 +00:00
|
|
|
// Install the ThrowTypeError function.
|
2014-05-19 10:47:00 +00:00
|
|
|
callee->set_getter(*poison);
|
|
|
|
callee->set_setter(*poison);
|
2011-03-17 20:28:41 +00:00
|
|
|
|
2012-07-18 15:38:58 +00:00
|
|
|
// Create the map. Allocate one in-object field for length.
|
2015-11-11 12:08:26 +00:00
|
|
|
Handle<Map> map = factory->NewMap(
|
2016-06-23 14:39:30 +00:00
|
|
|
JS_ARGUMENTS_TYPE, JSStrictArgumentsObject::kSize, FAST_ELEMENTS);
|
2011-03-17 20:28:41 +00:00
|
|
|
// Create the descriptor array for the arguments object.
|
2016-11-04 14:29:46 +00:00
|
|
|
Map::EnsureDescriptorSlack(map, 2);
|
2012-07-19 10:01:52 +00:00
|
|
|
|
2011-03-17 20:28:41 +00:00
|
|
|
{ // length
|
2016-02-12 05:10:38 +00:00
|
|
|
DataDescriptor d(factory->length_string(),
|
|
|
|
JSStrictArgumentsObject::kLengthIndex, DONT_ENUM,
|
|
|
|
Representation::Tagged());
|
2014-04-11 12:13:53 +00:00
|
|
|
map->AppendDescriptor(&d);
|
2011-03-17 20:28:41 +00:00
|
|
|
}
|
|
|
|
{ // callee
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(factory->callee_string(), callee,
|
|
|
|
attributes);
|
2014-04-11 12:13:53 +00:00
|
|
|
map->AppendDescriptor(&d);
|
2011-03-17 20:28:41 +00:00
|
|
|
}
|
2014-08-25 09:12:22 +00:00
|
|
|
// @@iterator method is added later.
|
2012-07-18 15:38:58 +00:00
|
|
|
|
2014-12-15 19:57:37 +00:00
|
|
|
DCHECK_EQ(native_context()->object_function()->prototype(),
|
|
|
|
*isolate->initial_object_prototype());
|
2015-04-10 12:13:18 +00:00
|
|
|
Map::SetPrototype(map, isolate->initial_object_prototype());
|
2015-08-11 19:36:04 +00:00
|
|
|
map->SetInObjectProperties(1);
|
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());
|
|
|
|
DCHECK(IsFastObjectElementsKind(map->elements_kind()));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // --- context extension
|
|
|
|
// Create a function for the context extension objects.
|
2015-11-24 17:16:40 +00:00
|
|
|
Handle<Code> code = isolate->builtins()->Illegal();
|
2014-05-09 16:42:57 +00:00
|
|
|
Handle<JSFunction> context_extension_fun = factory->NewFunction(
|
2014-05-09 17:39:54 +00:00
|
|
|
factory->empty_string(), code, JS_CONTEXT_EXTENSION_OBJECT_TYPE,
|
|
|
|
JSObject::kHeaderSize);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> name = factory->InternalizeOneByteString(
|
2014-09-10 12:38:12 +00:00
|
|
|
STATIC_CHAR_VECTOR("context_extension"));
|
2008-07-03 15:10:15 +00:00
|
|
|
context_extension_fun->shared()->set_instance_class_name(*name);
|
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.
|
2015-11-24 17:16:40 +00:00
|
|
|
Handle<Code> code = isolate->builtins()->HandleApiCallAsFunction();
|
2014-05-09 16:42:57 +00:00
|
|
|
Handle<JSFunction> delegate = factory->NewFunction(
|
2014-05-09 17:39:54 +00:00
|
|
|
factory->empty_string(), code, JS_OBJECT_TYPE, JSObject::kHeaderSize);
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_call_as_function_delegate(*delegate);
|
2009-05-20 19:33:44 +00:00
|
|
|
delegate->shared()->DontAdaptArguments();
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2011-08-30 09:35:20 +00:00
|
|
|
// Set up the call-as-constructor delegate.
|
2015-11-24 17:16:40 +00:00
|
|
|
Handle<Code> code = isolate->builtins()->HandleApiCallAsConstructor();
|
2014-05-09 16:42:57 +00:00
|
|
|
Handle<JSFunction> delegate = factory->NewFunction(
|
2014-05-09 17:39:54 +00:00
|
|
|
factory->empty_string(), code, JS_OBJECT_TYPE, JSObject::kHeaderSize);
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_call_as_constructor_delegate(*delegate);
|
2009-05-20 19:33:44 +00:00
|
|
|
delegate->shared()->DontAdaptArguments();
|
|
|
|
}
|
2016-01-12 10:47:27 +00:00
|
|
|
} // NOLINT(readability/fn_size)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2015-07-28 09:29:34 +00:00
|
|
|
void Genesis::InstallTypedArray(const char* name, ElementsKind elements_kind,
|
|
|
|
Handle<JSFunction>* fun) {
|
2013-04-16 14:16:30 +00:00
|
|
|
Handle<JSObject> global = Handle<JSObject>(native_context()->global_object());
|
2016-06-08 07:40:11 +00:00
|
|
|
|
|
|
|
Handle<JSObject> typed_array_prototype =
|
|
|
|
Handle<JSObject>(isolate()->typed_array_prototype());
|
|
|
|
Handle<JSFunction> typed_array_function =
|
|
|
|
Handle<JSFunction>(isolate()->typed_array_function());
|
|
|
|
|
|
|
|
Handle<JSObject> prototype =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
2016-11-10 01:49:23 +00:00
|
|
|
Handle<JSFunction> result = InstallFunction(
|
|
|
|
global, name, JS_TYPED_ARRAY_TYPE, JSTypedArray::kSizeWithInternalFields,
|
|
|
|
prototype, Builtins::kIllegal);
|
|
|
|
result->initial_map()->set_elements_kind(elements_kind);
|
2016-06-08 07:40:11 +00:00
|
|
|
|
|
|
|
CHECK(JSObject::SetPrototype(result, typed_array_function, false,
|
|
|
|
Object::DONT_THROW)
|
|
|
|
.FromJust());
|
|
|
|
|
|
|
|
CHECK(JSObject::SetPrototype(prototype, typed_array_prototype, false,
|
|
|
|
Object::DONT_THROW)
|
|
|
|
.FromJust());
|
2014-04-22 12:24:28 +00:00
|
|
|
*fun = result;
|
2013-04-16 14:16:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-19 07:36:05 +00:00
|
|
|
void Genesis::InitializeExperimentalGlobal() {
|
2014-10-20 13:33:34 +00:00
|
|
|
#define FEATURE_INITIALIZE_GLOBAL(id, descr) InitializeGlobal_##id();
|
2014-09-19 07:36:05 +00:00
|
|
|
|
2014-11-04 16:05:27 +00:00
|
|
|
HARMONY_INPROGRESS(FEATURE_INITIALIZE_GLOBAL)
|
|
|
|
HARMONY_STAGED(FEATURE_INITIALIZE_GLOBAL)
|
2014-11-28 20:07:11 +00:00
|
|
|
HARMONY_SHIPPING(FEATURE_INITIALIZE_GLOBAL)
|
2014-10-20 13:33:34 +00:00
|
|
|
#undef FEATURE_INITIALIZE_GLOBAL
|
2014-09-19 07:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-13 09:45:43 +00:00
|
|
|
bool Bootstrapper::CompileBuiltin(Isolate* isolate, int index) {
|
2008-07-03 15:10:15 +00:00
|
|
|
Vector<const char> name = Natives::GetScriptName(index);
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<String> source_code =
|
2015-04-30 15:10:43 +00:00
|
|
|
isolate->bootstrapper()->SourceLookup<Natives>(index);
|
2015-09-16 21:00:45 +00:00
|
|
|
|
|
|
|
// We pass in extras_utils so that builtin code can set it up for later use
|
|
|
|
// by actual extras code, compiled with CompileExtraBuiltin.
|
2015-05-12 14:00:47 +00:00
|
|
|
Handle<Object> global = isolate->global_object();
|
2015-05-21 06:15:33 +00:00
|
|
|
Handle<Object> utils = isolate->natives_utils_object();
|
2015-09-16 21:00:45 +00:00
|
|
|
Handle<Object> extras_utils = isolate->extras_utils_object();
|
|
|
|
Handle<Object> args[] = {global, utils, extras_utils};
|
2015-07-13 09:45:43 +00:00
|
|
|
|
2015-11-02 13:04:20 +00:00
|
|
|
return Bootstrapper::CompileNative(isolate, name, source_code,
|
2016-02-05 12:33:20 +00:00
|
|
|
arraysize(args), args, NATIVES_CODE);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-13 09:45:43 +00:00
|
|
|
bool Bootstrapper::CompileExperimentalBuiltin(Isolate* isolate, int index) {
|
2015-05-12 14:00:47 +00:00
|
|
|
HandleScope scope(isolate);
|
2011-04-15 12:31:03 +00:00
|
|
|
Vector<const char> name = ExperimentalNatives::GetScriptName(index);
|
2015-04-30 15:10:43 +00:00
|
|
|
Handle<String> source_code =
|
|
|
|
isolate->bootstrapper()->SourceLookup<ExperimentalNatives>(index);
|
2015-05-12 14:00:47 +00:00
|
|
|
Handle<Object> global = isolate->global_object();
|
2015-05-21 06:15:33 +00:00
|
|
|
Handle<Object> utils = isolate->natives_utils_object();
|
|
|
|
Handle<Object> args[] = {global, utils};
|
2015-11-02 13:04:20 +00:00
|
|
|
return Bootstrapper::CompileNative(isolate, name, source_code,
|
2016-02-05 12:33:20 +00:00
|
|
|
arraysize(args), args, NATIVES_CODE);
|
2011-04-15 12:31:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-13 09:45:43 +00:00
|
|
|
bool Bootstrapper::CompileExtraBuiltin(Isolate* isolate, int index) {
|
2015-05-12 14:00:47 +00:00
|
|
|
HandleScope scope(isolate);
|
2015-05-08 08:44:47 +00:00
|
|
|
Vector<const char> name = ExtraNatives::GetScriptName(index);
|
|
|
|
Handle<String> source_code =
|
|
|
|
isolate->bootstrapper()->SourceLookup<ExtraNatives>(index);
|
2015-05-12 14:00:47 +00:00
|
|
|
Handle<Object> global = isolate->global_object();
|
2015-08-06 23:52:47 +00:00
|
|
|
Handle<Object> binding = isolate->extras_binding_object();
|
2015-09-16 21:00:45 +00:00
|
|
|
Handle<Object> extras_utils = isolate->extras_utils_object();
|
|
|
|
Handle<Object> args[] = {global, binding, extras_utils};
|
2015-11-02 13:04:20 +00:00
|
|
|
return Bootstrapper::CompileNative(isolate, name, source_code,
|
2016-02-05 12:33:20 +00:00
|
|
|
arraysize(args), args, EXTENSION_CODE);
|
2015-05-08 08:44:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-20 00:01:07 +00:00
|
|
|
bool Bootstrapper::CompileExperimentalExtraBuiltin(Isolate* isolate,
|
|
|
|
int index) {
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
Vector<const char> name = ExperimentalExtraNatives::GetScriptName(index);
|
|
|
|
Handle<String> source_code =
|
|
|
|
isolate->bootstrapper()->SourceLookup<ExperimentalExtraNatives>(index);
|
|
|
|
Handle<Object> global = isolate->global_object();
|
|
|
|
Handle<Object> binding = isolate->extras_binding_object();
|
2015-09-16 21:00:45 +00:00
|
|
|
Handle<Object> extras_utils = isolate->extras_utils_object();
|
|
|
|
Handle<Object> args[] = {global, binding, extras_utils};
|
2015-11-02 13:04:20 +00:00
|
|
|
return Bootstrapper::CompileNative(isolate, name, source_code,
|
2016-02-05 12:33:20 +00:00
|
|
|
arraysize(args), args, EXTENSION_CODE);
|
2015-08-20 00:01:07 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 09:45:43 +00:00
|
|
|
bool Bootstrapper::CompileNative(Isolate* isolate, Vector<const char> name,
|
|
|
|
Handle<String> source, int argc,
|
2016-02-05 12:33:20 +00:00
|
|
|
Handle<Object> argv[],
|
|
|
|
NativesFlag natives_flag) {
|
2014-06-02 11:41:50 +00:00
|
|
|
SuppressDebug compiling_natives(isolate->debug());
|
2014-03-28 14:16:11 +00:00
|
|
|
// During genesis, the boilerplate for stack overflow won't work until the
|
|
|
|
// environment has been at least partially initialized. Add a stack check
|
|
|
|
// before entering JS code to catch overflow early.
|
|
|
|
StackLimitCheck check(isolate);
|
2015-06-24 14:57:39 +00:00
|
|
|
if (check.JsHasOverflowed(1 * KB)) {
|
2015-05-29 11:37:10 +00:00
|
|
|
isolate->StackOverflow();
|
|
|
|
return false;
|
|
|
|
}
|
2012-04-03 15:54:07 +00:00
|
|
|
|
2015-05-12 14:00:47 +00:00
|
|
|
Handle<Context> context(isolate->context());
|
|
|
|
|
|
|
|
Handle<String> script_name =
|
|
|
|
isolate->factory()->NewStringFromUtf8(name).ToHandleChecked();
|
2016-03-08 12:07:27 +00:00
|
|
|
Handle<SharedFunctionInfo> function_info =
|
|
|
|
Compiler::GetSharedFunctionInfoForScript(
|
|
|
|
source, script_name, 0, 0, ScriptOriginOptions(), Handle<Object>(),
|
|
|
|
context, NULL, NULL, ScriptCompiler::kNoCompileOptions, natives_flag,
|
|
|
|
false);
|
2015-05-18 15:50:38 +00:00
|
|
|
if (function_info.is_null()) return false;
|
2015-05-12 14:00:47 +00:00
|
|
|
|
|
|
|
DCHECK(context->IsNativeContext());
|
|
|
|
|
|
|
|
Handle<JSFunction> fun =
|
|
|
|
isolate->factory()->NewFunctionFromSharedFunctionInfo(function_info,
|
2015-11-27 16:59:28 +00:00
|
|
|
context);
|
2015-11-02 13:04:20 +00:00
|
|
|
Handle<Object> receiver = isolate->factory()->undefined_value();
|
2015-05-12 14:00:47 +00:00
|
|
|
|
|
|
|
// For non-extension scripts, run script to get the function wrapper.
|
|
|
|
Handle<Object> wrapper;
|
|
|
|
if (!Execution::Call(isolate, fun, receiver, 0, NULL).ToHandle(&wrapper)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Then run the function wrapper.
|
|
|
|
return !Execution::Call(isolate, Handle<JSFunction>::cast(wrapper), receiver,
|
|
|
|
argc, argv).is_null();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-21 06:15:33 +00:00
|
|
|
bool Genesis::CallUtilsFunction(Isolate* isolate, const char* name) {
|
|
|
|
Handle<JSObject> utils =
|
|
|
|
Handle<JSObject>::cast(isolate->natives_utils_object());
|
2015-08-31 10:09:52 +00:00
|
|
|
Handle<String> name_string =
|
|
|
|
isolate->factory()->NewStringFromAsciiChecked(name);
|
2015-05-21 06:15:33 +00:00
|
|
|
Handle<Object> fun = JSObject::GetDataProperty(utils, name_string);
|
|
|
|
Handle<Object> receiver = isolate->factory()->undefined_value();
|
2015-05-26 07:24:13 +00:00
|
|
|
Handle<Object> args[] = {utils};
|
|
|
|
return !Execution::Call(isolate, fun, receiver, 1, args).is_null();
|
2015-05-21 06:15:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-12 14:00:47 +00:00
|
|
|
bool Genesis::CompileExtension(Isolate* isolate, v8::Extension* extension) {
|
2013-02-15 09:27:10 +00:00
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
HandleScope scope(isolate);
|
2010-03-23 06:04:44 +00:00
|
|
|
Handle<SharedFunctionInfo> function_info;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2015-05-12 14:00:47 +00:00
|
|
|
Handle<String> source =
|
|
|
|
isolate->factory()
|
|
|
|
->NewExternalStringFromOneByte(extension->source())
|
|
|
|
.ToHandleChecked();
|
|
|
|
DCHECK(source->IsOneByteRepresentation());
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// If we can't find the function in the cache, we compile a new
|
|
|
|
// function and insert it into the cache.
|
2015-05-12 14:00:47 +00:00
|
|
|
Vector<const char> name = CStrVector(extension->name());
|
|
|
|
SourceCodeCache* cache = isolate->bootstrapper()->extensions_cache();
|
|
|
|
Handle<Context> context(isolate->context());
|
|
|
|
DCHECK(context->IsNativeContext());
|
|
|
|
|
|
|
|
if (!cache->Lookup(name, &function_info)) {
|
2014-04-17 13:27:02 +00:00
|
|
|
Handle<String> script_name =
|
|
|
|
factory->NewStringFromUtf8(name).ToHandleChecked();
|
2016-03-08 12:07:27 +00:00
|
|
|
function_info = Compiler::GetSharedFunctionInfoForScript(
|
2015-05-19 03:11:33 +00:00
|
|
|
source, script_name, 0, 0, ScriptOriginOptions(), Handle<Object>(),
|
|
|
|
context, extension, NULL, ScriptCompiler::kNoCompileOptions,
|
2016-02-05 12:33:20 +00:00
|
|
|
EXTENSION_CODE, false);
|
2010-03-23 06:04:44 +00:00
|
|
|
if (function_info.is_null()) return false;
|
2015-05-12 14:00:47 +00:00
|
|
|
cache->Add(name, function_info);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up the function context. Conceptually, we should clone the
|
2008-07-03 15:10:15 +00:00
|
|
|
// function before overwriting the context but since we're in a
|
|
|
|
// single-threaded environment it is not strictly necessary.
|
|
|
|
Handle<JSFunction> fun =
|
2011-03-28 13:09:37 +00:00
|
|
|
factory->NewFunctionFromSharedFunctionInfo(function_info, context);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-01-28 10:46:58 +00:00
|
|
|
// Call function using either the runtime object or the global
|
2008-07-03 15:10:15 +00:00
|
|
|
// object as the receiver. Provide no parameters.
|
2015-05-12 14:00:47 +00:00
|
|
|
Handle<Object> receiver = isolate->global_object();
|
|
|
|
return !Execution::Call(isolate, fun, receiver, 0, NULL).is_null();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
static Handle<JSObject> ResolveBuiltinIdHolder(Handle<Context> native_context,
|
|
|
|
const char* holder_expr) {
|
|
|
|
Isolate* isolate = native_context->GetIsolate();
|
|
|
|
Factory* factory = isolate->factory();
|
2015-11-02 14:57:59 +00:00
|
|
|
Handle<JSGlobalObject> global(native_context->global_object());
|
2014-07-30 13:54:45 +00:00
|
|
|
const char* period_pos = strchr(holder_expr, '.');
|
|
|
|
if (period_pos == NULL) {
|
|
|
|
return Handle<JSObject>::cast(
|
|
|
|
Object::GetPropertyOrElement(
|
|
|
|
global, factory->InternalizeUtf8String(holder_expr))
|
|
|
|
.ToHandleChecked());
|
|
|
|
}
|
|
|
|
const char* inner = period_pos + 1;
|
2015-01-30 09:29:25 +00:00
|
|
|
DCHECK(!strchr(inner, '.'));
|
2014-07-30 13:54:45 +00:00
|
|
|
Vector<const char> property(holder_expr,
|
|
|
|
static_cast<int>(period_pos - holder_expr));
|
|
|
|
Handle<String> property_string = factory->InternalizeUtf8String(property);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!property_string.is_null());
|
2014-07-30 13:54:45 +00:00
|
|
|
Handle<JSObject> object = Handle<JSObject>::cast(
|
2016-03-08 17:29:05 +00:00
|
|
|
JSReceiver::GetProperty(global, property_string).ToHandleChecked());
|
2014-07-30 13:54:45 +00:00
|
|
|
if (strcmp("prototype", inner) == 0) {
|
|
|
|
Handle<JSFunction> function = Handle<JSFunction>::cast(object);
|
|
|
|
return Handle<JSObject>(JSObject::cast(function->prototype()));
|
|
|
|
}
|
|
|
|
Handle<String> inner_string = factory->InternalizeUtf8String(inner);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!inner_string.is_null());
|
2014-07-30 13:54:45 +00:00
|
|
|
Handle<Object> value =
|
2016-03-08 17:29:05 +00:00
|
|
|
JSReceiver::GetProperty(object, inner_string).ToHandleChecked();
|
2014-07-30 13:54:45 +00:00
|
|
|
return Handle<JSObject>::cast(value);
|
|
|
|
}
|
|
|
|
|
2016-02-02 07:25:30 +00:00
|
|
|
void Genesis::ConfigureUtilsObject(GlobalContextType context_type) {
|
2015-10-16 11:27:14 +00:00
|
|
|
switch (context_type) {
|
|
|
|
// We still need the utils object to find debug functions.
|
|
|
|
case DEBUG_CONTEXT:
|
|
|
|
return;
|
|
|
|
// Expose the natives in global if a valid name for it is specified.
|
|
|
|
case FULL_CONTEXT: {
|
|
|
|
// We still need the utils object after deserialization.
|
|
|
|
if (isolate()->serializer_enabled()) return;
|
|
|
|
if (FLAG_expose_natives_as == NULL) break;
|
|
|
|
if (strlen(FLAG_expose_natives_as) == 0) break;
|
|
|
|
HandleScope scope(isolate());
|
|
|
|
Handle<String> natives_key =
|
|
|
|
factory()->InternalizeUtf8String(FLAG_expose_natives_as);
|
|
|
|
uint32_t dummy_index;
|
|
|
|
if (natives_key->AsArrayIndex(&dummy_index)) break;
|
|
|
|
Handle<Object> utils = isolate()->natives_utils_object();
|
|
|
|
Handle<JSObject> global = isolate()->global_object();
|
|
|
|
JSObject::AddProperty(global, natives_key, utils, DONT_ENUM);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The utils object can be removed for cases that reach this point.
|
|
|
|
native_context()->set_natives_utils_object(heap()->undefined_value());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-28 10:22:31 +00:00
|
|
|
void Bootstrapper::ExportFromRuntime(Isolate* isolate,
|
|
|
|
Handle<JSObject> container) {
|
2015-10-19 11:36:00 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2015-08-21 06:44:17 +00:00
|
|
|
HandleScope scope(isolate);
|
2015-10-19 11:36:00 +00:00
|
|
|
Handle<Context> native_context = isolate->native_context();
|
|
|
|
#define EXPORT_PRIVATE_SYMBOL(NAME) \
|
|
|
|
Handle<String> NAME##_name = factory->NewStringFromAsciiChecked(#NAME); \
|
|
|
|
JSObject::AddProperty(container, NAME##_name, factory->NAME(), NONE);
|
2015-08-21 06:44:17 +00:00
|
|
|
PRIVATE_SYMBOL_LIST(EXPORT_PRIVATE_SYMBOL)
|
|
|
|
#undef EXPORT_PRIVATE_SYMBOL
|
2015-08-28 10:22:31 +00:00
|
|
|
|
2015-10-19 11:36:00 +00:00
|
|
|
#define EXPORT_PUBLIC_SYMBOL(NAME, DESCRIPTION) \
|
|
|
|
Handle<String> NAME##_name = factory->NewStringFromAsciiChecked(#NAME); \
|
|
|
|
JSObject::AddProperty(container, NAME##_name, factory->NAME(), NONE);
|
2015-08-28 10:22:31 +00:00
|
|
|
PUBLIC_SYMBOL_LIST(EXPORT_PUBLIC_SYMBOL)
|
2015-10-06 18:10:20 +00:00
|
|
|
WELL_KNOWN_SYMBOL_LIST(EXPORT_PUBLIC_SYMBOL)
|
2015-08-28 10:22:31 +00:00
|
|
|
#undef EXPORT_PUBLIC_SYMBOL
|
|
|
|
|
2015-12-11 04:26:34 +00:00
|
|
|
{
|
|
|
|
Handle<JSFunction> to_string = InstallFunction(
|
|
|
|
container, "object_to_string", JS_OBJECT_TYPE, JSObject::kHeaderSize,
|
|
|
|
MaybeHandle<JSObject>(), Builtins::kObjectProtoToString);
|
2016-07-18 10:02:31 +00:00
|
|
|
to_string->shared()->set_internal_formal_parameter_count(0);
|
2015-12-11 04:26:34 +00:00
|
|
|
to_string->shared()->set_length(0);
|
|
|
|
native_context->set_object_to_string(*to_string);
|
|
|
|
}
|
|
|
|
|
2016-09-21 14:17:42 +00:00
|
|
|
Handle<JSObject> iterator_prototype(
|
|
|
|
native_context->initial_iterator_prototype());
|
2015-10-16 11:27:14 +00:00
|
|
|
|
2016-09-21 14:17:42 +00:00
|
|
|
JSObject::AddProperty(container,
|
|
|
|
factory->InternalizeUtf8String("IteratorPrototype"),
|
|
|
|
iterator_prototype, NONE);
|
2015-10-16 11:27:14 +00:00
|
|
|
|
|
|
|
{
|
2015-10-19 11:36:00 +00:00
|
|
|
PrototypeIterator iter(native_context->sloppy_generator_function_map());
|
2015-10-16 11:27:14 +00:00
|
|
|
Handle<JSObject> generator_function_prototype(iter.GetCurrent<JSObject>());
|
|
|
|
|
2015-10-19 11:36:00 +00:00
|
|
|
JSObject::AddProperty(
|
|
|
|
container, factory->InternalizeUtf8String("GeneratorFunctionPrototype"),
|
|
|
|
generator_function_prototype, NONE);
|
2015-10-16 11:27:14 +00:00
|
|
|
|
|
|
|
static const bool kUseStrictFunctionMap = true;
|
2015-12-22 14:15:19 +00:00
|
|
|
Handle<JSFunction> generator_function_function = InstallFunction(
|
|
|
|
container, "GeneratorFunction", JS_FUNCTION_TYPE, JSFunction::kSize,
|
|
|
|
generator_function_prototype, Builtins::kGeneratorFunctionConstructor,
|
|
|
|
kUseStrictFunctionMap);
|
2015-12-10 17:27:44 +00:00
|
|
|
generator_function_function->set_prototype_or_initial_map(
|
|
|
|
native_context->sloppy_generator_function_map());
|
2015-12-22 14:15:19 +00:00
|
|
|
generator_function_function->shared()->DontAdaptArguments();
|
2016-07-11 10:03:02 +00:00
|
|
|
generator_function_function->shared()->SetConstructStub(
|
2015-12-22 14:15:19 +00:00
|
|
|
*isolate->builtins()->GeneratorFunctionConstructor());
|
|
|
|
generator_function_function->shared()->set_length(1);
|
2015-12-07 16:35:03 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(
|
|
|
|
isolate, generator_function_function,
|
|
|
|
Context::GENERATOR_FUNCTION_FUNCTION_INDEX);
|
2015-12-10 17:27:44 +00:00
|
|
|
|
2016-07-19 11:28:43 +00:00
|
|
|
JSObject::ForceSetPrototype(generator_function_function,
|
|
|
|
isolate->function_function());
|
2016-04-06 08:37:09 +00:00
|
|
|
JSObject::AddProperty(
|
|
|
|
generator_function_prototype, factory->constructor_string(),
|
|
|
|
generator_function_function,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
2015-12-10 17:27:44 +00:00
|
|
|
native_context->sloppy_generator_function_map()->SetConstructor(
|
|
|
|
*generator_function_function);
|
|
|
|
native_context->strict_generator_function_map()->SetConstructor(
|
|
|
|
*generator_function_function);
|
2015-10-16 11:27:14 +00:00
|
|
|
}
|
|
|
|
|
2016-10-13 13:34:50 +00:00
|
|
|
{ // -- F i x e d A r r a y I t e r a t o r
|
|
|
|
int size = JSFixedArrayIterator::kHeaderSize +
|
|
|
|
JSFixedArrayIterator::kInObjectPropertyCount * kPointerSize;
|
|
|
|
Handle<Map> map = factory->NewMap(JS_FIXED_ARRAY_ITERATOR_TYPE, size);
|
|
|
|
Map::SetPrototype(map, iterator_prototype);
|
|
|
|
Map::EnsureDescriptorSlack(map,
|
|
|
|
JSFixedArrayIterator::kInObjectPropertyCount);
|
|
|
|
map->SetInObjectProperties(JSFixedArrayIterator::kInObjectPropertyCount);
|
|
|
|
map->SetConstructor(native_context->object_function());
|
|
|
|
|
|
|
|
{ // next
|
|
|
|
DataDescriptor d(factory->next_string(), JSFixedArrayIterator::kNextIndex,
|
|
|
|
DONT_ENUM, Representation::Tagged());
|
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
|
|
|
native_context->set_fixed_array_iterator_map(*map);
|
|
|
|
}
|
|
|
|
|
2015-10-16 11:27:14 +00:00
|
|
|
{ // -- S e t I t e r a t o r
|
|
|
|
Handle<JSObject> set_iterator_prototype =
|
|
|
|
isolate->factory()->NewJSObject(isolate->object_function(), TENURED);
|
2016-07-19 11:28:43 +00:00
|
|
|
JSObject::ForceSetPrototype(set_iterator_prototype, iterator_prototype);
|
2015-10-16 11:27:14 +00:00
|
|
|
Handle<JSFunction> set_iterator_function = InstallFunction(
|
|
|
|
container, "SetIterator", JS_SET_ITERATOR_TYPE, JSSetIterator::kSize,
|
|
|
|
set_iterator_prototype, Builtins::kIllegal);
|
2015-10-19 11:36:00 +00:00
|
|
|
native_context->set_set_iterator_map(set_iterator_function->initial_map());
|
2015-10-16 11:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- M a p I t e r a t o r
|
|
|
|
Handle<JSObject> map_iterator_prototype =
|
|
|
|
isolate->factory()->NewJSObject(isolate->object_function(), TENURED);
|
2016-07-19 11:28:43 +00:00
|
|
|
JSObject::ForceSetPrototype(map_iterator_prototype, iterator_prototype);
|
2015-10-16 11:27:14 +00:00
|
|
|
Handle<JSFunction> map_iterator_function = InstallFunction(
|
|
|
|
container, "MapIterator", JS_MAP_ITERATOR_TYPE, JSMapIterator::kSize,
|
|
|
|
map_iterator_prototype, Builtins::kIllegal);
|
2015-10-19 11:36:00 +00:00
|
|
|
native_context->set_map_iterator_map(map_iterator_function->initial_map());
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- S c r i p t
|
|
|
|
// Builtin functions for Script.
|
|
|
|
Handle<JSFunction> script_fun = InstallFunction(
|
|
|
|
container, "Script", JS_VALUE_TYPE, JSValue::kSize,
|
2016-08-09 07:36:19 +00:00
|
|
|
isolate->initial_object_prototype(), Builtins::kUnsupportedThrower);
|
2015-10-19 11:36:00 +00:00
|
|
|
Handle<JSObject> prototype =
|
|
|
|
factory->NewJSObject(isolate->object_function(), TENURED);
|
|
|
|
Accessors::FunctionSetPrototype(script_fun, prototype).Assert();
|
|
|
|
native_context->set_script_function(*script_fun);
|
|
|
|
|
|
|
|
Handle<Map> script_map = Handle<Map>(script_fun->initial_map());
|
|
|
|
Map::EnsureDescriptorSlack(script_map, 15);
|
|
|
|
|
|
|
|
PropertyAttributes attribs =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
|
|
|
|
|
|
|
|
Handle<AccessorInfo> script_column =
|
|
|
|
Accessors::ScriptColumnOffsetInfo(isolate, attribs);
|
|
|
|
{
|
|
|
|
AccessorConstantDescriptor d(
|
|
|
|
Handle<Name>(Name::cast(script_column->name())), script_column,
|
|
|
|
attribs);
|
|
|
|
script_map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<AccessorInfo> script_id = Accessors::ScriptIdInfo(isolate, attribs);
|
|
|
|
{
|
|
|
|
AccessorConstantDescriptor d(Handle<Name>(Name::cast(script_id->name())),
|
|
|
|
script_id, attribs);
|
|
|
|
script_map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<AccessorInfo> script_name =
|
|
|
|
Accessors::ScriptNameInfo(isolate, attribs);
|
|
|
|
{
|
|
|
|
AccessorConstantDescriptor d(
|
|
|
|
Handle<Name>(Name::cast(script_name->name())), script_name, attribs);
|
|
|
|
script_map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<AccessorInfo> script_line =
|
|
|
|
Accessors::ScriptLineOffsetInfo(isolate, attribs);
|
|
|
|
{
|
|
|
|
AccessorConstantDescriptor d(
|
|
|
|
Handle<Name>(Name::cast(script_line->name())), script_line, attribs);
|
|
|
|
script_map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<AccessorInfo> script_source =
|
|
|
|
Accessors::ScriptSourceInfo(isolate, attribs);
|
|
|
|
{
|
|
|
|
AccessorConstantDescriptor d(
|
|
|
|
Handle<Name>(Name::cast(script_source->name())), script_source,
|
|
|
|
attribs);
|
|
|
|
script_map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<AccessorInfo> script_type =
|
|
|
|
Accessors::ScriptTypeInfo(isolate, attribs);
|
|
|
|
{
|
|
|
|
AccessorConstantDescriptor d(
|
|
|
|
Handle<Name>(Name::cast(script_type->name())), script_type, attribs);
|
|
|
|
script_map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<AccessorInfo> script_compilation_type =
|
|
|
|
Accessors::ScriptCompilationTypeInfo(isolate, attribs);
|
|
|
|
{
|
|
|
|
AccessorConstantDescriptor d(
|
|
|
|
Handle<Name>(Name::cast(script_compilation_type->name())),
|
|
|
|
script_compilation_type, attribs);
|
|
|
|
script_map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<AccessorInfo> script_context_data =
|
|
|
|
Accessors::ScriptContextDataInfo(isolate, attribs);
|
|
|
|
{
|
|
|
|
AccessorConstantDescriptor d(
|
|
|
|
Handle<Name>(Name::cast(script_context_data->name())),
|
|
|
|
script_context_data, attribs);
|
|
|
|
script_map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<AccessorInfo> script_eval_from_script =
|
|
|
|
Accessors::ScriptEvalFromScriptInfo(isolate, attribs);
|
|
|
|
{
|
|
|
|
AccessorConstantDescriptor d(
|
|
|
|
Handle<Name>(Name::cast(script_eval_from_script->name())),
|
|
|
|
script_eval_from_script, attribs);
|
|
|
|
script_map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<AccessorInfo> script_eval_from_script_position =
|
|
|
|
Accessors::ScriptEvalFromScriptPositionInfo(isolate, attribs);
|
|
|
|
{
|
|
|
|
AccessorConstantDescriptor d(
|
|
|
|
Handle<Name>(Name::cast(script_eval_from_script_position->name())),
|
|
|
|
script_eval_from_script_position, attribs);
|
|
|
|
script_map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<AccessorInfo> script_eval_from_function_name =
|
|
|
|
Accessors::ScriptEvalFromFunctionNameInfo(isolate, attribs);
|
|
|
|
{
|
|
|
|
AccessorConstantDescriptor d(
|
|
|
|
Handle<Name>(Name::cast(script_eval_from_function_name->name())),
|
|
|
|
script_eval_from_function_name, attribs);
|
|
|
|
script_map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<AccessorInfo> script_source_url =
|
|
|
|
Accessors::ScriptSourceUrlInfo(isolate, attribs);
|
|
|
|
{
|
|
|
|
AccessorConstantDescriptor d(
|
|
|
|
Handle<Name>(Name::cast(script_source_url->name())),
|
|
|
|
script_source_url, attribs);
|
|
|
|
script_map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<AccessorInfo> script_source_mapping_url =
|
|
|
|
Accessors::ScriptSourceMappingUrlInfo(isolate, attribs);
|
|
|
|
{
|
|
|
|
AccessorConstantDescriptor d(
|
|
|
|
Handle<Name>(Name::cast(script_source_mapping_url->name())),
|
|
|
|
script_source_mapping_url, attribs);
|
|
|
|
script_map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
2016-05-17 00:26:53 +00:00
|
|
|
{
|
|
|
|
PrototypeIterator iter(native_context->sloppy_async_function_map());
|
|
|
|
Handle<JSObject> async_function_prototype(iter.GetCurrent<JSObject>());
|
|
|
|
|
|
|
|
static const bool kUseStrictFunctionMap = true;
|
|
|
|
Handle<JSFunction> async_function_constructor = InstallFunction(
|
|
|
|
container, "AsyncFunction", JS_FUNCTION_TYPE, JSFunction::kSize,
|
|
|
|
async_function_prototype, Builtins::kAsyncFunctionConstructor,
|
|
|
|
kUseStrictFunctionMap);
|
|
|
|
async_function_constructor->shared()->DontAdaptArguments();
|
2016-07-11 10:03:02 +00:00
|
|
|
async_function_constructor->shared()->SetConstructStub(
|
2016-05-17 00:26:53 +00:00
|
|
|
*isolate->builtins()->AsyncFunctionConstructor());
|
|
|
|
async_function_constructor->shared()->set_length(1);
|
|
|
|
InstallWithIntrinsicDefaultProto(isolate, async_function_constructor,
|
|
|
|
Context::ASYNC_FUNCTION_FUNCTION_INDEX);
|
2016-07-19 11:28:43 +00:00
|
|
|
JSObject::ForceSetPrototype(async_function_constructor,
|
|
|
|
isolate->function_function());
|
2016-05-17 00:26:53 +00:00
|
|
|
|
|
|
|
JSObject::AddProperty(
|
|
|
|
async_function_prototype, factory->constructor_string(),
|
|
|
|
async_function_constructor,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
|
|
|
JSFunction::SetPrototype(async_function_constructor,
|
|
|
|
async_function_prototype);
|
|
|
|
|
|
|
|
Handle<JSFunction> async_function_next =
|
|
|
|
SimpleInstallFunction(container, "AsyncFunctionNext",
|
2016-05-18 20:52:56 +00:00
|
|
|
Builtins::kGeneratorPrototypeNext, 1, true);
|
2016-05-17 00:26:53 +00:00
|
|
|
Handle<JSFunction> async_function_throw =
|
|
|
|
SimpleInstallFunction(container, "AsyncFunctionThrow",
|
2016-05-18 20:52:56 +00:00
|
|
|
Builtins::kGeneratorPrototypeThrow, 1, true);
|
|
|
|
async_function_next->shared()->set_native(false);
|
|
|
|
async_function_throw->shared()->set_native(false);
|
2016-05-17 00:26:53 +00:00
|
|
|
}
|
2015-10-16 11:27:14 +00:00
|
|
|
}
|
2016-07-22 10:12:24 +00:00
|
|
|
|
|
|
|
{ // -- C a l l S i t e
|
|
|
|
// Builtin functions for CallSite.
|
|
|
|
|
2016-08-02 09:29:14 +00:00
|
|
|
// CallSites are a special case; the constructor is for our private use
|
|
|
|
// only, therefore we set it up as a builtin that throws. Internally, we use
|
|
|
|
// CallSiteUtils::Construct to create CallSite objects.
|
|
|
|
|
2016-07-22 10:12:24 +00:00
|
|
|
Handle<JSFunction> callsite_fun = InstallFunction(
|
|
|
|
container, "CallSite", JS_OBJECT_TYPE, JSObject::kHeaderSize,
|
2016-08-02 09:29:14 +00:00
|
|
|
isolate->initial_object_prototype(), Builtins::kUnsupportedThrower);
|
2016-07-22 10:12:24 +00:00
|
|
|
callsite_fun->shared()->DontAdaptArguments();
|
2016-08-01 14:26:53 +00:00
|
|
|
isolate->native_context()->set_callsite_function(*callsite_fun);
|
|
|
|
|
2016-07-22 10:12:24 +00:00
|
|
|
{
|
|
|
|
Handle<JSObject> proto =
|
|
|
|
factory->NewJSObject(isolate->object_function(), TENURED);
|
|
|
|
JSObject::AddProperty(proto, factory->constructor_string(), callsite_fun,
|
|
|
|
DONT_ENUM);
|
|
|
|
|
|
|
|
struct FunctionInfo {
|
|
|
|
const char* name;
|
|
|
|
Builtins::Name id;
|
|
|
|
};
|
|
|
|
|
|
|
|
FunctionInfo infos[] = {
|
|
|
|
{"getColumnNumber", Builtins::kCallSitePrototypeGetColumnNumber},
|
|
|
|
{"getEvalOrigin", Builtins::kCallSitePrototypeGetEvalOrigin},
|
|
|
|
{"getFileName", Builtins::kCallSitePrototypeGetFileName},
|
|
|
|
{"getFunction", Builtins::kCallSitePrototypeGetFunction},
|
|
|
|
{"getFunctionName", Builtins::kCallSitePrototypeGetFunctionName},
|
|
|
|
{"getLineNumber", Builtins::kCallSitePrototypeGetLineNumber},
|
|
|
|
{"getMethodName", Builtins::kCallSitePrototypeGetMethodName},
|
|
|
|
{"getPosition", Builtins::kCallSitePrototypeGetPosition},
|
|
|
|
{"getScriptNameOrSourceURL",
|
|
|
|
Builtins::kCallSitePrototypeGetScriptNameOrSourceURL},
|
|
|
|
{"getThis", Builtins::kCallSitePrototypeGetThis},
|
|
|
|
{"getTypeName", Builtins::kCallSitePrototypeGetTypeName},
|
|
|
|
{"isConstructor", Builtins::kCallSitePrototypeIsConstructor},
|
|
|
|
{"isEval", Builtins::kCallSitePrototypeIsEval},
|
|
|
|
{"isNative", Builtins::kCallSitePrototypeIsNative},
|
2016-07-28 13:39:18 +00:00
|
|
|
{"isToplevel", Builtins::kCallSitePrototypeIsToplevel},
|
|
|
|
{"toString", Builtins::kCallSitePrototypeToString}};
|
2016-07-22 10:12:24 +00:00
|
|
|
|
|
|
|
PropertyAttributes attrs =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
|
|
|
|
|
|
|
|
Handle<JSFunction> fun;
|
|
|
|
for (const FunctionInfo& info : infos) {
|
2016-09-27 22:29:37 +00:00
|
|
|
SimpleInstallFunction(proto, info.name, info.id, 0, true, attrs);
|
2016-07-22 10:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Accessors::FunctionSetPrototype(callsite_fun, proto).Assert();
|
|
|
|
}
|
|
|
|
}
|
2015-08-28 13:39:34 +00:00
|
|
|
}
|
2015-08-28 10:22:31 +00:00
|
|
|
|
2015-08-31 10:09:52 +00:00
|
|
|
|
2015-08-28 10:22:31 +00:00
|
|
|
void Bootstrapper::ExportExperimentalFromRuntime(Isolate* isolate,
|
|
|
|
Handle<JSObject> container) {
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
|
2016-09-06 22:56:52 +00:00
|
|
|
#ifdef V8_I18N_SUPPORT
|
2015-08-31 10:09:52 +00:00
|
|
|
#define INITIALIZE_FLAG(FLAG) \
|
|
|
|
{ \
|
|
|
|
Handle<String> name = \
|
|
|
|
isolate->factory()->NewStringFromAsciiChecked(#FLAG); \
|
|
|
|
JSObject::AddProperty(container, name, \
|
|
|
|
isolate->factory()->ToBoolean(FLAG), NONE); \
|
2015-08-28 10:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef INITIALIZE_FLAG
|
2016-09-06 22:56:52 +00:00
|
|
|
#endif
|
2015-08-21 06:44:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-20 13:33:34 +00:00
|
|
|
#define EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(id) \
|
|
|
|
void Genesis::InitializeGlobal_##id() {}
|
|
|
|
|
2015-10-21 02:55:47 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_do_expressions)
|
2015-11-17 13:33:03 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_regexp_lookbehind)
|
2016-06-15 06:48:31 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_regexp_named_captures)
|
2016-02-10 16:23:53 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_regexp_property)
|
2016-01-28 08:54:29 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_function_sent)
|
2016-01-26 11:07:15 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_tailcalls)
|
2016-03-24 17:14:53 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_string_padding)
|
Use ICU case conversion/transliterator for case conversion
When I18N is enabled, use ICU's case conversion API and transliteration
API [1] to implement String.prototype.to{Upper,Lower}Case and
String.prototype.toLocale{Upper,Lower}Case.
* ICU-based case conversion was implemented in runtime-i18n.cc/i18n.js
* The above 4 functions are overridden with those in i18n.js when
--icu_case_mapping flag is turned on. To control the override by the flag,
they're overriden in icu-case-mapping.js
Previously, toLocale{U,L}Case just called to{U,L}Case so that they didn't
support locale-sensitive case conversion for Turkic languages (az, tr),
Greek (el) and Lithuanian (lt).
Before ICU APIs for the most general case are called, a fast-path for Latin-1
is tried. It's taken from Blink and adopted as necessary. This fast path
is always tried for to{U,L}Case. For toLocale{U,L}Case, it's only taken
when a locale (explicitly specified or default) is not in {az, el, lt, tr}.
With these changes, a build with --icu_case_mapping=true passes a bunch
of tests in test262/intl402/Strings/* and intl/* that failed before.
Handling of pure ASCII strings (aligned at word boundary) are not as fast
as Unibrow's implementation that uses word-by-word case conversion. OTOH,
Latin-1 input handling is faster than Unibrow. General Unicode input
handling is slower but more accurate.
See https://docs.google.com/spreadsheets/d/1KJCJxKc1FxFXjwmYqABS0_2cNdPetvnd8gY8_HGSbrg/edit?usp=sharing for the benchmark.
This CL started with http://crrev.com/1544023002#ps200001 by littledan@,
but has changed significantly since.
[1] See why transliteration API is needed for uppercasing in Greek.
http://bugs.icu-project.org/trac/ticket/10582
R=yangguo
BUG=v8:4476,v8:4477
LOG=Y
TEST=test262/{built-ins,intl402}/Strings/*, webkit/fast/js/*, mjsunit/string-case,
intl/general/case*
Review-Url: https://codereview.chromium.org/1812673005
Cr-Commit-Position: refs/heads/master@{#36187}
2016-05-11 19:01:41 +00:00
|
|
|
#ifdef V8_I18N_SUPPORT
|
2016-09-06 22:56:52 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(datetime_format_to_parts)
|
Use ICU case conversion/transliterator for case conversion
When I18N is enabled, use ICU's case conversion API and transliteration
API [1] to implement String.prototype.to{Upper,Lower}Case and
String.prototype.toLocale{Upper,Lower}Case.
* ICU-based case conversion was implemented in runtime-i18n.cc/i18n.js
* The above 4 functions are overridden with those in i18n.js when
--icu_case_mapping flag is turned on. To control the override by the flag,
they're overriden in icu-case-mapping.js
Previously, toLocale{U,L}Case just called to{U,L}Case so that they didn't
support locale-sensitive case conversion for Turkic languages (az, tr),
Greek (el) and Lithuanian (lt).
Before ICU APIs for the most general case are called, a fast-path for Latin-1
is tried. It's taken from Blink and adopted as necessary. This fast path
is always tried for to{U,L}Case. For toLocale{U,L}Case, it's only taken
when a locale (explicitly specified or default) is not in {az, el, lt, tr}.
With these changes, a build with --icu_case_mapping=true passes a bunch
of tests in test262/intl402/Strings/* and intl/* that failed before.
Handling of pure ASCII strings (aligned at word boundary) are not as fast
as Unibrow's implementation that uses word-by-word case conversion. OTOH,
Latin-1 input handling is faster than Unibrow. General Unicode input
handling is slower but more accurate.
See https://docs.google.com/spreadsheets/d/1KJCJxKc1FxFXjwmYqABS0_2cNdPetvnd8gY8_HGSbrg/edit?usp=sharing for the benchmark.
This CL started with http://crrev.com/1544023002#ps200001 by littledan@,
but has changed significantly since.
[1] See why transliteration API is needed for uppercasing in Greek.
http://bugs.icu-project.org/trac/ticket/10582
R=yangguo
BUG=v8:4476,v8:4477
LOG=Y
TEST=test262/{built-ins,intl402}/Strings/*, webkit/fast/js/*, mjsunit/string-case,
intl/general/case*
Review-Url: https://codereview.chromium.org/1812673005
Cr-Commit-Position: refs/heads/master@{#36187}
2016-05-11 19:01:41 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(icu_case_mapping)
|
|
|
|
#endif
|
2016-05-16 23:17:13 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_async_await)
|
2016-05-27 18:22:29 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_restrictive_generators)
|
Allow trailing commas in function parameter lists
Add a flag harmony_trailing_commas_in_parameters that allows trailing
commas in function parameter declaration lists and function call
parameter lists. Trailing commas are allowed in parenthetical lists like
`(a, b, c,)` only if the next token is `=>`, thereby making it an arrow
function declaration. Only 1 trailing comma is allowed, not `(a,,)`. A
trailing comma must follow a non-rest parameter, so `(,)` and `(...a,)`
are still SyntaxErrors. However, a trailing comma is allowed after a
spread parameter, e.g. `a(...b,);`.
Add parser tests for all of the above.
BUG=v8:5051
LOG=y
Review-Url: https://codereview.chromium.org/2094463002
Cr-Commit-Position: refs/heads/master@{#37355}
2016-06-29 01:37:57 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_trailing_commas)
|
2016-09-16 00:42:30 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_class_fields)
|
2015-09-16 18:01:38 +00:00
|
|
|
|
2015-11-02 08:42:43 +00:00
|
|
|
void InstallPublicSymbol(Factory* factory, Handle<Context> native_context,
|
|
|
|
const char* name, Handle<Symbol> value) {
|
|
|
|
Handle<JSGlobalObject> global(
|
|
|
|
JSGlobalObject::cast(native_context->global_object()));
|
|
|
|
Handle<String> symbol_string = factory->InternalizeUtf8String("Symbol");
|
|
|
|
Handle<JSObject> symbol = Handle<JSObject>::cast(
|
|
|
|
JSObject::GetProperty(global, symbol_string).ToHandleChecked());
|
|
|
|
Handle<String> name_string = factory->InternalizeUtf8String(name);
|
|
|
|
PropertyAttributes attributes =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
|
|
|
|
JSObject::AddProperty(symbol, name_string, value, attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-22 13:43:38 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_sharedarraybuffer() {
|
|
|
|
if (!FLAG_harmony_sharedarraybuffer) return;
|
|
|
|
|
2016-01-01 07:12:48 +00:00
|
|
|
Handle<JSGlobalObject> global(native_context()->global_object());
|
2016-04-13 18:21:30 +00:00
|
|
|
Isolate* isolate = global->GetIsolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
|
2016-01-01 07:12:48 +00:00
|
|
|
Handle<JSFunction> shared_array_buffer_fun =
|
2016-07-07 19:42:15 +00:00
|
|
|
InstallArrayBuffer(global, "SharedArrayBuffer",
|
|
|
|
Builtins::kSharedArrayBufferPrototypeGetByteLength,
|
|
|
|
BuiltinFunctionId::kSharedArrayBufferByteLength);
|
2015-05-22 13:43:38 +00:00
|
|
|
native_context()->set_shared_array_buffer_fun(*shared_array_buffer_fun);
|
2016-04-13 18:21:30 +00:00
|
|
|
|
|
|
|
Handle<String> name = factory->InternalizeUtf8String("Atomics");
|
|
|
|
Handle<JSFunction> cons = factory->NewFunction(name);
|
|
|
|
JSFunction::SetInstancePrototype(
|
|
|
|
cons,
|
|
|
|
Handle<Object>(native_context()->initial_object_prototype(), isolate));
|
|
|
|
Handle<JSObject> atomics_object = factory->NewJSObject(cons, TENURED);
|
|
|
|
DCHECK(atomics_object->IsJSObject());
|
|
|
|
JSObject::AddProperty(global, name, atomics_object, DONT_ENUM);
|
|
|
|
|
|
|
|
SimpleInstallFunction(atomics_object, factory->InternalizeUtf8String("load"),
|
2016-04-18 19:41:09 +00:00
|
|
|
Builtins::kAtomicsLoad, 2, true);
|
2016-05-03 17:27:07 +00:00
|
|
|
SimpleInstallFunction(atomics_object, factory->InternalizeUtf8String("store"),
|
|
|
|
Builtins::kAtomicsStore, 3, true);
|
2015-05-22 13:43:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-16 19:43:21 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_simd() {
|
2015-07-20 10:37:43 +00:00
|
|
|
if (!FLAG_harmony_simd) return;
|
|
|
|
|
2015-07-16 19:43:21 +00:00
|
|
|
Handle<JSGlobalObject> global(
|
|
|
|
JSGlobalObject::cast(native_context()->global_object()));
|
|
|
|
Isolate* isolate = global->GetIsolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
|
|
|
|
Handle<String> name = factory->InternalizeUtf8String("SIMD");
|
|
|
|
Handle<JSFunction> cons = factory->NewFunction(name);
|
|
|
|
JSFunction::SetInstancePrototype(
|
|
|
|
cons,
|
|
|
|
Handle<Object>(native_context()->initial_object_prototype(), isolate));
|
2015-11-04 14:56:11 +00:00
|
|
|
cons->shared()->set_instance_class_name(*name);
|
2015-07-16 19:43:21 +00:00
|
|
|
Handle<JSObject> simd_object = factory->NewJSObject(cons, TENURED);
|
|
|
|
DCHECK(simd_object->IsJSObject());
|
|
|
|
JSObject::AddProperty(global, name, simd_object, DONT_ENUM);
|
|
|
|
|
2015-08-03 13:02:39 +00:00
|
|
|
// Install SIMD type functions. Set the instance class names since
|
2015-11-02 14:57:59 +00:00
|
|
|
// InstallFunction only does this when we install on the JSGlobalObject.
|
2015-08-11 09:45:25 +00:00
|
|
|
#define SIMD128_INSTALL_FUNCTION(TYPE, Type, type, lane_count, lane_type) \
|
2015-08-31 10:09:52 +00:00
|
|
|
Handle<JSFunction> type##_function = InstallFunction( \
|
2015-08-11 09:45:25 +00:00
|
|
|
simd_object, #Type, JS_VALUE_TYPE, JSValue::kSize, \
|
|
|
|
isolate->initial_object_prototype(), Builtins::kIllegal); \
|
|
|
|
native_context()->set_##type##_function(*type##_function); \
|
2015-11-04 14:56:11 +00:00
|
|
|
type##_function->shared()->set_instance_class_name(*factory->Type##_string());
|
2015-08-03 13:02:39 +00:00
|
|
|
SIMD128_TYPES(SIMD128_INSTALL_FUNCTION)
|
2015-08-11 09:45:25 +00:00
|
|
|
#undef SIMD128_INSTALL_FUNCTION
|
2015-07-16 19:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-09 22:27:29 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_array_prototype_values() {
|
|
|
|
if (!FLAG_harmony_array_prototype_values) return;
|
|
|
|
Handle<JSFunction> array_constructor(native_context()->array_function());
|
|
|
|
Handle<JSObject> array_prototype(
|
|
|
|
JSObject::cast(array_constructor->instance_prototype()));
|
|
|
|
Handle<Object> values_iterator =
|
|
|
|
JSObject::GetProperty(array_prototype, factory()->iterator_symbol())
|
|
|
|
.ToHandleChecked();
|
|
|
|
DCHECK(values_iterator->IsJSFunction());
|
|
|
|
JSObject::AddProperty(array_prototype, factory()->values_string(),
|
|
|
|
values_iterator, DONT_ENUM);
|
|
|
|
|
|
|
|
Handle<Object> unscopables =
|
|
|
|
JSObject::GetProperty(array_prototype, factory()->unscopables_symbol())
|
|
|
|
.ToHandleChecked();
|
|
|
|
DCHECK(unscopables->IsJSObject());
|
|
|
|
JSObject::AddProperty(Handle<JSObject>::cast(unscopables),
|
|
|
|
factory()->values_string(), factory()->true_value(),
|
|
|
|
NONE);
|
|
|
|
}
|
2015-11-13 14:13:50 +00:00
|
|
|
|
2016-01-01 07:12:48 +00:00
|
|
|
Handle<JSFunction> Genesis::InstallArrayBuffer(Handle<JSObject> target,
|
2016-07-07 19:42:15 +00:00
|
|
|
const char* name,
|
|
|
|
Builtins::Name call,
|
|
|
|
BuiltinFunctionId id) {
|
2016-07-06 19:23:44 +00:00
|
|
|
// Create the %ArrayBufferPrototype%
|
2016-01-01 07:12:48 +00:00
|
|
|
// Setup the {prototype} with the given {name} for @@toStringTag.
|
|
|
|
Handle<JSObject> prototype =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
|
|
|
JSObject::AddProperty(prototype, factory()->to_string_tag_symbol(),
|
|
|
|
factory()->NewStringFromAsciiChecked(name),
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
|
|
|
// Allocate the constructor with the given {prototype}.
|
|
|
|
Handle<JSFunction> array_buffer_fun =
|
|
|
|
InstallFunction(target, name, JS_ARRAY_BUFFER_TYPE,
|
|
|
|
JSArrayBuffer::kSizeWithInternalFields, prototype,
|
|
|
|
Builtins::kArrayBufferConstructor);
|
2016-07-11 10:03:02 +00:00
|
|
|
array_buffer_fun->shared()->SetConstructStub(
|
2016-01-01 07:12:48 +00:00
|
|
|
*isolate()->builtins()->ArrayBufferConstructor_ConstructStub());
|
|
|
|
array_buffer_fun->shared()->DontAdaptArguments();
|
|
|
|
array_buffer_fun->shared()->set_length(1);
|
|
|
|
|
|
|
|
// Install the "constructor" property on the {prototype}.
|
|
|
|
JSObject::AddProperty(prototype, factory()->constructor_string(),
|
|
|
|
array_buffer_fun, DONT_ENUM);
|
|
|
|
|
|
|
|
SimpleInstallFunction(array_buffer_fun, factory()->isView_string(),
|
|
|
|
Builtins::kArrayBufferIsView, 1, true);
|
|
|
|
|
2016-07-06 19:23:44 +00:00
|
|
|
// Install the "byteLength" getter on the {prototype}.
|
2016-07-07 19:42:15 +00:00
|
|
|
SimpleInstallGetter(prototype, factory()->byte_length_string(), call, false,
|
|
|
|
id);
|
2016-07-06 19:23:44 +00:00
|
|
|
|
2016-01-01 07:12:48 +00:00
|
|
|
return array_buffer_fun;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-12 14:00:47 +00:00
|
|
|
Handle<JSFunction> Genesis::InstallInternalArray(Handle<JSObject> target,
|
|
|
|
const char* name,
|
|
|
|
ElementsKind elements_kind) {
|
2013-02-15 15:20:05 +00:00
|
|
|
// --- I n t e r n a l A r r a y ---
|
|
|
|
// An array constructor on the builtins object that works like
|
|
|
|
// the public Array constructor, except that its prototype
|
|
|
|
// doesn't inherit from Object.prototype.
|
|
|
|
// To be used only for internal work by builtins. Instances
|
|
|
|
// must not be leaked to user code.
|
|
|
|
Handle<JSObject> prototype =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
2015-05-12 14:00:47 +00:00
|
|
|
Handle<JSFunction> array_function =
|
2015-08-31 10:09:52 +00:00
|
|
|
InstallFunction(target, name, JS_ARRAY_TYPE, JSArray::kSize, prototype,
|
|
|
|
Builtins::kInternalArrayCode);
|
2013-02-15 15:20:05 +00:00
|
|
|
|
2013-06-25 16:31:07 +00:00
|
|
|
InternalArrayConstructorStub internal_array_constructor_stub(isolate());
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> code = internal_array_constructor_stub.GetCode();
|
2016-07-11 10:03:02 +00:00
|
|
|
array_function->shared()->SetConstructStub(*code);
|
2013-02-15 15:20:05 +00:00
|
|
|
array_function->shared()->DontAdaptArguments();
|
|
|
|
|
2013-05-29 15:38:09 +00:00
|
|
|
Handle<Map> original_map(array_function->initial_map());
|
2014-11-07 16:03:11 +00:00
|
|
|
Handle<Map> initial_map = Map::Copy(original_map, "InternalArray");
|
2013-05-29 15:38:09 +00:00
|
|
|
initial_map->set_elements_kind(elements_kind);
|
2014-08-11 14:00:58 +00:00
|
|
|
JSFunction::SetInitialMap(array_function, initial_map, prototype);
|
2013-02-15 15:20:05 +00:00
|
|
|
|
|
|
|
// Make "length" magic on instances.
|
2014-04-11 12:13:53 +00:00
|
|
|
Map::EnsureDescriptorSlack(initial_map, 1);
|
2013-02-15 15:20:05 +00:00
|
|
|
|
|
|
|
PropertyAttributes attribs = static_cast<PropertyAttributes>(
|
|
|
|
DONT_ENUM | DONT_DELETE);
|
|
|
|
|
2014-04-28 14:59:29 +00:00
|
|
|
Handle<AccessorInfo> array_length =
|
|
|
|
Accessors::ArrayLengthInfo(isolate(), attribs);
|
2013-02-15 15:20:05 +00:00
|
|
|
{ // Add length.
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(Handle<Name>(Name::cast(array_length->name())),
|
|
|
|
array_length, attribs);
|
2014-11-11 10:24:52 +00:00
|
|
|
initial_map->AppendDescriptor(&d);
|
2013-02-15 15:20:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return array_function;
|
|
|
|
}
|
|
|
|
|
2016-02-02 07:25:30 +00:00
|
|
|
bool Genesis::InstallNatives(GlobalContextType context_type) {
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(isolate());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2015-05-21 06:15:33 +00:00
|
|
|
// Set up the utils object as shared container between native scripts.
|
|
|
|
Handle<JSObject> utils = factory()->NewJSObject(isolate()->object_function());
|
|
|
|
JSObject::NormalizeProperties(utils, CLEAR_INOBJECT_PROPERTIES, 16,
|
|
|
|
"utils container for native scripts");
|
|
|
|
native_context()->set_natives_utils_object(*utils);
|
2015-05-12 14:00:47 +00:00
|
|
|
|
2015-09-16 21:00:45 +00:00
|
|
|
// Set up the extras utils object as a shared container between native
|
|
|
|
// scripts and extras. (Extras consume things added there by native scripts.)
|
|
|
|
Handle<JSObject> extras_utils =
|
|
|
|
factory()->NewJSObject(isolate()->object_function());
|
|
|
|
native_context()->set_extras_utils_object(*extras_utils);
|
|
|
|
|
|
|
|
InstallInternalArray(extras_utils, "InternalPackedArray", FAST_ELEMENTS);
|
|
|
|
|
2015-08-18 11:15:34 +00:00
|
|
|
int builtin_index = Natives::GetDebuggerCount();
|
|
|
|
// Only run prologue.js and runtime.js at this point.
|
|
|
|
DCHECK_EQ(builtin_index, Natives::GetIndex("prologue"));
|
|
|
|
if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false;
|
|
|
|
DCHECK_EQ(builtin_index, Natives::GetIndex("runtime"));
|
|
|
|
if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false;
|
|
|
|
|
2010-02-24 19:59:09 +00:00
|
|
|
{
|
|
|
|
// Builtin function for OpaqueReference -- a JSValue-based object,
|
|
|
|
// that keeps its field isolated from JavaScript code. It may store
|
|
|
|
// objects, that JavaScript code may not access.
|
2015-10-19 11:36:00 +00:00
|
|
|
Handle<JSFunction> opaque_reference_fun = factory()->NewFunction(
|
|
|
|
factory()->empty_string(), isolate()->builtins()->Illegal(),
|
2016-06-27 18:03:59 +00:00
|
|
|
isolate()->initial_object_prototype(), JS_VALUE_TYPE, JSValue::kSize);
|
2010-02-24 19:59:09 +00:00
|
|
|
Handle<JSObject> prototype =
|
2011-04-14 08:01:19 +00:00
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
2016-06-27 18:03:59 +00:00
|
|
|
Accessors::FunctionSetPrototype(opaque_reference_fun, prototype).Assert();
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_opaque_reference_function(*opaque_reference_fun);
|
2010-02-24 19:59:09 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-02-15 15:20:05 +00:00
|
|
|
// InternalArrays should not use Smi-Only array optimizations. There are too
|
|
|
|
// many places in the C++ runtime code (e.g. RegEx) that assume that
|
|
|
|
// elements in InternalArrays can be set to non-Smi values without going
|
|
|
|
// through a common bottleneck that would make the SMI_ONLY -> FAST_ELEMENT
|
|
|
|
// transition easy to trap. Moreover, they rarely are smi-only.
|
|
|
|
{
|
2015-05-12 14:00:47 +00:00
|
|
|
HandleScope scope(isolate());
|
2015-05-21 06:15:33 +00:00
|
|
|
Handle<JSObject> utils =
|
|
|
|
Handle<JSObject>::cast(isolate()->natives_utils_object());
|
|
|
|
Handle<JSFunction> array_function =
|
|
|
|
InstallInternalArray(utils, "InternalArray", FAST_HOLEY_ELEMENTS);
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_internal_array_function(*array_function);
|
2015-05-21 06:15:33 +00:00
|
|
|
InstallInternalArray(utils, "InternalPackedArray", FAST_ELEMENTS);
|
2013-02-15 15:20:05 +00:00
|
|
|
}
|
|
|
|
|
2015-08-18 11:15:34 +00:00
|
|
|
// Run the rest of the native scripts.
|
|
|
|
while (builtin_index < Natives::GetBuiltinsCount()) {
|
|
|
|
if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2015-05-21 06:15:33 +00:00
|
|
|
if (!CallUtilsFunction(isolate(), "PostNatives")) return false;
|
2016-07-28 17:16:33 +00:00
|
|
|
auto fast_template_instantiations_cache = isolate()->factory()->NewFixedArray(
|
|
|
|
TemplateInfo::kFastTemplateInstantiationsCacheSize);
|
|
|
|
native_context()->set_fast_template_instantiations_cache(
|
|
|
|
*fast_template_instantiations_cache);
|
2015-05-21 06:15:33 +00:00
|
|
|
|
2016-07-28 17:16:33 +00:00
|
|
|
auto slow_template_instantiations_cache = UnseededNumberDictionary::New(
|
2016-06-27 18:03:59 +00:00
|
|
|
isolate(), ApiNatives::kInitialFunctionCacheSize);
|
2016-07-28 17:16:33 +00:00
|
|
|
native_context()->set_slow_template_instantiations_cache(
|
|
|
|
*slow_template_instantiations_cache);
|
2016-06-27 18:03:59 +00:00
|
|
|
|
2015-09-23 13:49:09 +00:00
|
|
|
// Store the map for the %ObjectPrototype% after the natives has been compiled
|
|
|
|
// and the Object function has been set up.
|
|
|
|
Handle<JSFunction> object_function(native_context()->object_function());
|
|
|
|
DCHECK(JSObject::cast(object_function->initial_map()->prototype())
|
|
|
|
->HasFastProperties());
|
|
|
|
native_context()->set_object_function_prototype_map(
|
|
|
|
HeapObject::cast(object_function->initial_map()->prototype())->map());
|
|
|
|
|
2016-06-23 12:16:35 +00:00
|
|
|
// Set up the map for Object.create(null) instances.
|
2016-10-25 08:30:37 +00:00
|
|
|
Handle<Map> slow_object_with_null_prototype_map =
|
2016-06-23 12:16:35 +00:00
|
|
|
Map::CopyInitialMap(handle(object_function->initial_map(), isolate()));
|
2016-10-25 08:30:37 +00:00
|
|
|
slow_object_with_null_prototype_map->set_dictionary_map(true);
|
|
|
|
Map::SetPrototype(slow_object_with_null_prototype_map,
|
2016-06-23 12:16:35 +00:00
|
|
|
isolate()->factory()->null_value());
|
2016-10-25 08:30:37 +00:00
|
|
|
native_context()->set_slow_object_with_null_prototype_map(
|
|
|
|
*slow_object_with_null_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.
|
2012-08-17 09:03:08 +00:00
|
|
|
Handle<JSFunction> string_function(native_context()->string_function());
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(JSObject::cast(
|
2010-08-12 13:43:08 +00:00
|
|
|
string_function->initial_map()->prototype())->HasFastProperties());
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_string_function_prototype_map(
|
2010-08-12 13:43:08 +00:00
|
|
|
HeapObject::cast(string_function->initial_map()->prototype())->map());
|
|
|
|
|
2016-05-17 10:54:14 +00:00
|
|
|
Handle<JSGlobalObject> global_object =
|
|
|
|
handle(native_context()->global_object());
|
|
|
|
|
2016-05-27 09:56:04 +00:00
|
|
|
// Install Global.decodeURI.
|
|
|
|
SimpleInstallFunction(global_object, "decodeURI", Builtins::kGlobalDecodeURI,
|
2016-08-09 07:13:38 +00:00
|
|
|
1, false, kGlobalDecodeURI);
|
2016-05-27 09:56:04 +00:00
|
|
|
|
|
|
|
// Install Global.decodeURIComponent.
|
|
|
|
SimpleInstallFunction(global_object, "decodeURIComponent",
|
2016-08-09 07:13:38 +00:00
|
|
|
Builtins::kGlobalDecodeURIComponent, 1, false,
|
|
|
|
kGlobalDecodeURIComponent);
|
2016-05-27 09:56:04 +00:00
|
|
|
|
2016-05-17 10:54:14 +00:00
|
|
|
// Install Global.encodeURI.
|
|
|
|
SimpleInstallFunction(global_object, "encodeURI", Builtins::kGlobalEncodeURI,
|
2016-08-09 07:13:38 +00:00
|
|
|
1, false, kGlobalEncodeURI);
|
2016-05-17 10:54:14 +00:00
|
|
|
|
|
|
|
// Install Global.encodeURIComponent.
|
|
|
|
SimpleInstallFunction(global_object, "encodeURIComponent",
|
2016-08-09 07:13:38 +00:00
|
|
|
Builtins::kGlobalEncodeURIComponent, 1, false,
|
|
|
|
kGlobalEncodeURIComponent);
|
2016-05-17 10:54:14 +00:00
|
|
|
|
2016-06-01 04:24:32 +00:00
|
|
|
// Install Global.escape.
|
|
|
|
SimpleInstallFunction(global_object, "escape", Builtins::kGlobalEscape, 1,
|
2016-08-09 07:13:38 +00:00
|
|
|
false, kGlobalEscape);
|
2016-06-01 04:24:32 +00:00
|
|
|
|
|
|
|
// Install Global.unescape.
|
|
|
|
SimpleInstallFunction(global_object, "unescape", Builtins::kGlobalUnescape, 1,
|
2016-08-09 07:13:38 +00:00
|
|
|
false, kGlobalUnescape);
|
2016-06-01 04:24:32 +00:00
|
|
|
|
2015-12-22 10:07:33 +00:00
|
|
|
// Install Global.eval.
|
|
|
|
{
|
2016-05-17 10:54:14 +00:00
|
|
|
Handle<JSFunction> eval =
|
|
|
|
SimpleInstallFunction(global_object, factory()->eval_string(),
|
|
|
|
Builtins::kGlobalEval, 1, false);
|
2015-12-22 10:07:33 +00:00
|
|
|
native_context()->set_global_eval_fun(*eval);
|
|
|
|
}
|
|
|
|
|
2016-09-07 10:14:19 +00:00
|
|
|
// Install Global.isFinite
|
|
|
|
SimpleInstallFunction(global_object, "isFinite", Builtins::kGlobalIsFinite, 1,
|
|
|
|
true, kGlobalIsFinite);
|
|
|
|
|
|
|
|
// Install Global.isNaN
|
|
|
|
SimpleInstallFunction(global_object, "isNaN", Builtins::kGlobalIsNaN, 1, true,
|
|
|
|
kGlobalIsNaN);
|
|
|
|
|
2015-09-07 13:44:44 +00:00
|
|
|
// Install Array.prototype.concat
|
|
|
|
{
|
|
|
|
Handle<JSFunction> array_constructor(native_context()->array_function());
|
|
|
|
Handle<JSObject> proto(JSObject::cast(array_constructor->prototype()));
|
|
|
|
Handle<JSFunction> concat =
|
|
|
|
InstallFunction(proto, "concat", JS_OBJECT_TYPE, JSObject::kHeaderSize,
|
|
|
|
MaybeHandle<JSObject>(), Builtins::kArrayConcat);
|
|
|
|
|
|
|
|
// Make sure that Array.prototype.concat appears to be compiled.
|
|
|
|
// The code will never be called, but inline caching for call will
|
|
|
|
// only work if it appears to be compiled.
|
|
|
|
concat->shared()->DontAdaptArguments();
|
|
|
|
DCHECK(concat->is_compiled());
|
|
|
|
// Set the lengths for the functions to satisfy ECMA-262.
|
|
|
|
concat->shared()->set_length(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Install InternalArray.prototype.concat
|
|
|
|
{
|
|
|
|
Handle<JSFunction> array_constructor(
|
|
|
|
native_context()->internal_array_function());
|
|
|
|
Handle<JSObject> proto(JSObject::cast(array_constructor->prototype()));
|
|
|
|
Handle<JSFunction> concat =
|
|
|
|
InstallFunction(proto, "concat", JS_OBJECT_TYPE, JSObject::kHeaderSize,
|
|
|
|
MaybeHandle<JSObject>(), Builtins::kArrayConcat);
|
|
|
|
|
|
|
|
// Make sure that InternalArray.prototype.concat appears to be compiled.
|
|
|
|
// The code will never be called, but inline caching for call will
|
|
|
|
// only work if it appears to be compiled.
|
|
|
|
concat->shared()->DontAdaptArguments();
|
|
|
|
DCHECK(concat->is_compiled());
|
|
|
|
// Set the lengths for the functions to satisfy ECMA-262.
|
|
|
|
concat->shared()->set_length(1);
|
|
|
|
}
|
2015-12-27 06:30:53 +00:00
|
|
|
|
2015-11-19 16:11:00 +00:00
|
|
|
// Set up the Promise constructor.
|
|
|
|
{
|
|
|
|
Handle<String> key = factory()->Promise_string();
|
|
|
|
Handle<JSFunction> function = Handle<JSFunction>::cast(
|
2016-05-17 10:54:14 +00:00
|
|
|
JSReceiver::GetProperty(global_object, key).ToHandleChecked());
|
2015-11-19 16:11:00 +00:00
|
|
|
JSFunction::EnsureHasInitialMap(function);
|
|
|
|
function->initial_map()->set_instance_type(JS_PROMISE_TYPE);
|
2016-07-11 10:03:02 +00:00
|
|
|
function->shared()->SetConstructStub(
|
2015-11-24 17:16:40 +00:00
|
|
|
*isolate()->builtins()->JSBuiltinsConstructStub());
|
2015-12-10 00:33:19 +00:00
|
|
|
InstallWithIntrinsicDefaultProto(isolate(), function,
|
|
|
|
Context::PROMISE_FUNCTION_INDEX);
|
2016-11-10 16:04:15 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
Handle<Code> code = handle(
|
|
|
|
isolate()->builtins()->builtin(Builtins::kPromiseResolveClosure),
|
|
|
|
isolate());
|
|
|
|
Handle<SharedFunctionInfo> info =
|
|
|
|
isolate()->factory()->NewSharedFunctionInfo(factory()->empty_string(),
|
|
|
|
code, false);
|
|
|
|
info->set_internal_formal_parameter_count(1);
|
|
|
|
info->set_length(1);
|
|
|
|
native_context()->set_promise_resolve_shared_fun(*info);
|
|
|
|
|
|
|
|
code = handle(
|
|
|
|
isolate()->builtins()->builtin(Builtins::kPromiseRejectClosure),
|
|
|
|
isolate());
|
|
|
|
info = isolate()->factory()->NewSharedFunctionInfo(
|
|
|
|
factory()->empty_string(), code, false);
|
|
|
|
info->set_internal_formal_parameter_count(2);
|
|
|
|
info->set_length(1);
|
|
|
|
native_context()->set_promise_reject_shared_fun(*info);
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<JSFunction> create_resolving_functions =
|
|
|
|
SimpleCreateFunction(isolate(), factory()->empty_string(),
|
|
|
|
Builtins::kCreateResolvingFunctions, 2, false);
|
|
|
|
native_context()->set_create_resolving_functions(
|
|
|
|
*create_resolving_functions);
|
2015-11-19 16:11:00 +00:00
|
|
|
}
|
|
|
|
|
2011-08-10 16:05:17 +00:00
|
|
|
InstallBuiltinFunctionIds();
|
|
|
|
|
2016-01-20 19:04:06 +00:00
|
|
|
// Create a map for accessor property descriptors (a variant of JSObject
|
|
|
|
// that predefines four properties get, set, configurable and enumerable).
|
|
|
|
{
|
|
|
|
// AccessorPropertyDescriptor initial map.
|
|
|
|
Handle<Map> map =
|
|
|
|
factory()->NewMap(JS_OBJECT_TYPE, JSAccessorPropertyDescriptor::kSize);
|
|
|
|
// Create the descriptor array for the property descriptor object.
|
|
|
|
Map::EnsureDescriptorSlack(map, 4);
|
|
|
|
|
|
|
|
{ // get
|
|
|
|
DataDescriptor d(factory()->get_string(),
|
|
|
|
JSAccessorPropertyDescriptor::kGetIndex, NONE,
|
|
|
|
Representation::Tagged());
|
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
{ // set
|
|
|
|
DataDescriptor d(factory()->set_string(),
|
|
|
|
JSAccessorPropertyDescriptor::kSetIndex, NONE,
|
|
|
|
Representation::Tagged());
|
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
{ // enumerable
|
|
|
|
DataDescriptor d(factory()->enumerable_string(),
|
|
|
|
JSAccessorPropertyDescriptor::kEnumerableIndex, NONE,
|
|
|
|
Representation::Tagged());
|
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
{ // configurable
|
|
|
|
DataDescriptor d(factory()->configurable_string(),
|
|
|
|
JSAccessorPropertyDescriptor::kConfigurableIndex, NONE,
|
|
|
|
Representation::Tagged());
|
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
|
|
|
Map::SetPrototype(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
|
|
|
map->SetInObjectProperties(4);
|
|
|
|
map->set_unused_property_fields(0);
|
|
|
|
|
|
|
|
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 =
|
|
|
|
factory()->NewMap(JS_OBJECT_TYPE, JSDataPropertyDescriptor::kSize);
|
|
|
|
// Create the descriptor array for the property descriptor object.
|
|
|
|
Map::EnsureDescriptorSlack(map, 4);
|
|
|
|
|
|
|
|
{ // value
|
|
|
|
DataDescriptor d(factory()->value_string(),
|
|
|
|
JSDataPropertyDescriptor::kValueIndex, NONE,
|
|
|
|
Representation::Tagged());
|
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
{ // writable
|
|
|
|
DataDescriptor d(factory()->writable_string(),
|
|
|
|
JSDataPropertyDescriptor::kWritableIndex, NONE,
|
|
|
|
Representation::Tagged());
|
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
{ // enumerable
|
|
|
|
DataDescriptor d(factory()->enumerable_string(),
|
|
|
|
JSDataPropertyDescriptor::kEnumerableIndex, NONE,
|
|
|
|
Representation::Tagged());
|
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
{ // configurable
|
|
|
|
DataDescriptor d(factory()->configurable_string(),
|
|
|
|
JSDataPropertyDescriptor::kConfigurableIndex, NONE,
|
|
|
|
Representation::Tagged());
|
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
|
|
|
Map::SetPrototype(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
|
|
|
map->SetInObjectProperties(4);
|
|
|
|
map->set_unused_property_fields(0);
|
|
|
|
|
|
|
|
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
|
|
|
|
// predefines the two properties index and match).
|
|
|
|
{
|
|
|
|
// RegExpResult initial map.
|
|
|
|
|
|
|
|
// Find global.Array.prototype to inherit from.
|
2012-08-17 09:03:08 +00:00
|
|
|
Handle<JSFunction> array_constructor(native_context()->array_function());
|
2010-04-13 09:31:03 +00:00
|
|
|
Handle<JSObject> array_prototype(
|
|
|
|
JSObject::cast(array_constructor->instance_prototype()));
|
|
|
|
|
|
|
|
// Add initial map.
|
|
|
|
Handle<Map> initial_map =
|
2013-02-18 10:25:21 +00:00
|
|
|
factory()->NewMap(JS_ARRAY_TYPE, JSRegExpResult::kSize);
|
2015-02-24 20:50:06 +00:00
|
|
|
initial_map->SetConstructor(*array_constructor);
|
2010-04-13 09:31:03 +00:00
|
|
|
|
|
|
|
// Set prototype on map.
|
|
|
|
initial_map->set_non_instance_prototype(false);
|
2015-04-10 12:13:18 +00:00
|
|
|
Map::SetPrototype(initial_map, array_prototype);
|
2010-04-13 09:31:03 +00:00
|
|
|
|
|
|
|
// Update map with length accessor from Array and add "index" and "input".
|
2014-04-11 12:13:53 +00:00
|
|
|
Map::EnsureDescriptorSlack(initial_map, 3);
|
2011-10-21 10:32:38 +00:00
|
|
|
|
2012-07-19 10:01:52 +00:00
|
|
|
{
|
2012-08-17 09:03:08 +00:00
|
|
|
JSFunction* array_function = native_context()->array_function();
|
2012-07-19 10:01:52 +00:00
|
|
|
Handle<DescriptorArray> array_descriptors(
|
|
|
|
array_function->initial_map()->instance_descriptors());
|
2014-04-09 14:26:32 +00:00
|
|
|
Handle<String> length = factory()->length_string();
|
Sharing of descriptor arrays.
This CL adds multiple things:
Transition arrays do not directly point at their descriptor array anymore, but rather do so via an indirect pointer (a JSGlobalPropertyCell).
An ownership bit is added to maps indicating whether it owns its own descriptor array or not.
Maps owning a descriptor array can pass on ownership if a transition from that map is generated; but only if the descriptor array stays exactly the same; or if a descriptor is added.
Maps that don't have ownership get ownership back if their direct child to which ownership was passed is cleared in ClearNonLiveTransitions.
To detect which descriptors in an array are valid, each map knows its own NumberOfOwnDescriptors. Since the descriptors are sorted in order of addition, if we search and find a descriptor with index bigger than this number, it is not valid for the given map.
We currently still build up an enumeration cache (although this may disappear). The enumeration cache is always built for the entire descriptor array, even if not all descriptors are owned by the map. Once a descriptor array has an enumeration cache for a given map; this invariant will always be true, even if the descriptor array was extended. The extended array will inherit the enumeration cache from the smaller descriptor array. If a map with more descriptors needs an enumeration cache, it's EnumLength will still be set to invalid, so it will have to recompute the enumeration cache. This new cache will also be valid for smaller maps since they have their own enumlength; and use this to loop over the cache. If the EnumLength is still invalid, but there is already a cache present that is big enough; we just initialize the EnumLength field for the map.
When we apply ClearNonLiveTransitions and descriptor ownership is passed back to a parent map, the descriptor array is trimmed in-place and resorted. At the same time, the enumeration cache is trimmed in-place.
Only transition arrays contain descriptor arrays. If we transition to a map and pass ownership of the descriptor array along, the child map will not store the descriptor array it owns. Rather its parent will keep the pointer. So for every leaf-map, we find the descriptor array by following the back pointer, reading out the transition array, and fetching the descriptor array from the JSGlobalPropertyCell. If a map has a transition array, we fetch it from there. If a map has undefined as its back-pointer and has no transition array; it is considered to have an empty descriptor array.
When we modify properties, we cannot share the descriptor array. To accommodate this, the child map will get its own transition array; even if there are not necessarily any transitions leaving from the child map. This is necessary since it's the only way to store its own descriptor array.
Review URL: https://chromiumcodereview.appspot.com/10909007
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12492 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-09-12 16:43:57 +00:00
|
|
|
int old = array_descriptors->SearchWithCache(
|
2016-02-17 16:23:38 +00:00
|
|
|
isolate(), *length, array_function->initial_map());
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(old != DescriptorArray::kNotFound);
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor desc(
|
|
|
|
length, handle(array_descriptors->GetValue(old), isolate()),
|
|
|
|
array_descriptors->GetDetails(old).attributes());
|
2014-04-11 12:13:53 +00:00
|
|
|
initial_map->AppendDescriptor(&desc);
|
2012-07-19 10:01:52 +00:00
|
|
|
}
|
2010-04-13 09:31:03 +00:00
|
|
|
{
|
2015-01-19 17:49:13 +00:00
|
|
|
DataDescriptor index_field(factory()->index_string(),
|
|
|
|
JSRegExpResult::kIndexIndex, NONE,
|
|
|
|
Representation::Tagged());
|
2014-04-11 12:13:53 +00:00
|
|
|
initial_map->AppendDescriptor(&index_field);
|
2010-04-13 09:31:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2015-01-19 17:49:13 +00:00
|
|
|
DataDescriptor input_field(factory()->input_string(),
|
|
|
|
JSRegExpResult::kInputIndex, NONE,
|
|
|
|
Representation::Tagged());
|
2014-04-11 12:13:53 +00:00
|
|
|
initial_map->AppendDescriptor(&input_field);
|
2010-04-13 09:31:03 +00:00
|
|
|
}
|
|
|
|
|
2015-08-11 19:36:04 +00:00
|
|
|
initial_map->SetInObjectProperties(2);
|
2010-04-13 09:31:03 +00:00
|
|
|
initial_map->set_unused_property_fields(0);
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_regexp_result_map(*initial_map);
|
2010-04-13 09:31:03 +00:00
|
|
|
}
|
|
|
|
|
2014-08-25 09:12:22 +00:00
|
|
|
// Add @@iterator method to the arguments object maps.
|
|
|
|
{
|
|
|
|
PropertyAttributes attribs = DONT_ENUM;
|
|
|
|
Handle<AccessorInfo> arguments_iterator =
|
|
|
|
Accessors::ArgumentsIteratorInfo(isolate(), attribs);
|
|
|
|
{
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(factory()->iterator_symbol(),
|
|
|
|
arguments_iterator, attribs);
|
2014-08-25 09:12:22 +00:00
|
|
|
Handle<Map> map(native_context()->sloppy_arguments_map());
|
|
|
|
Map::EnsureDescriptorSlack(map, 1);
|
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
{
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(factory()->iterator_symbol(),
|
|
|
|
arguments_iterator, attribs);
|
2015-07-02 14:38:37 +00:00
|
|
|
Handle<Map> map(native_context()->fast_aliased_arguments_map());
|
|
|
|
Map::EnsureDescriptorSlack(map, 1);
|
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
AccessorConstantDescriptor d(factory()->iterator_symbol(),
|
|
|
|
arguments_iterator, attribs);
|
|
|
|
Handle<Map> map(native_context()->slow_aliased_arguments_map());
|
2014-08-25 09:12:22 +00:00
|
|
|
Map::EnsureDescriptorSlack(map, 1);
|
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
{
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(factory()->iterator_symbol(),
|
|
|
|
arguments_iterator, attribs);
|
2014-08-25 09:12:22 +00:00
|
|
|
Handle<Map> map(native_context()->strict_arguments_map());
|
|
|
|
Map::EnsureDescriptorSlack(map, 1);
|
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-15 12:31:03 +00:00
|
|
|
bool Genesis::InstallExperimentalNatives() {
|
2016-01-26 11:07:15 +00:00
|
|
|
static const char* harmony_tailcalls_natives[] = {nullptr};
|
2015-05-22 13:43:38 +00:00
|
|
|
static const char* harmony_sharedarraybuffer_natives[] = {
|
2016-07-07 19:42:15 +00:00
|
|
|
"native harmony-atomics.js", NULL};
|
2015-07-16 19:43:21 +00:00
|
|
|
static const char* harmony_simd_natives[] = {"native harmony-simd.js",
|
|
|
|
nullptr};
|
2015-10-21 02:55:47 +00:00
|
|
|
static const char* harmony_do_expressions_natives[] = {nullptr};
|
2015-11-17 13:33:03 +00:00
|
|
|
static const char* harmony_regexp_lookbehind_natives[] = {nullptr};
|
2016-06-15 06:48:31 +00:00
|
|
|
static const char* harmony_regexp_named_captures_natives[] = {nullptr};
|
2016-02-10 16:23:53 +00:00
|
|
|
static const char* harmony_regexp_property_natives[] = {nullptr};
|
2016-01-28 08:54:29 +00:00
|
|
|
static const char* harmony_function_sent_natives[] = {nullptr};
|
2016-03-09 22:27:29 +00:00
|
|
|
static const char* harmony_array_prototype_values_natives[] = {nullptr};
|
2016-03-24 17:14:53 +00:00
|
|
|
static const char* harmony_string_padding_natives[] = {
|
|
|
|
"native harmony-string-padding.js", nullptr};
|
Use ICU case conversion/transliterator for case conversion
When I18N is enabled, use ICU's case conversion API and transliteration
API [1] to implement String.prototype.to{Upper,Lower}Case and
String.prototype.toLocale{Upper,Lower}Case.
* ICU-based case conversion was implemented in runtime-i18n.cc/i18n.js
* The above 4 functions are overridden with those in i18n.js when
--icu_case_mapping flag is turned on. To control the override by the flag,
they're overriden in icu-case-mapping.js
Previously, toLocale{U,L}Case just called to{U,L}Case so that they didn't
support locale-sensitive case conversion for Turkic languages (az, tr),
Greek (el) and Lithuanian (lt).
Before ICU APIs for the most general case are called, a fast-path for Latin-1
is tried. It's taken from Blink and adopted as necessary. This fast path
is always tried for to{U,L}Case. For toLocale{U,L}Case, it's only taken
when a locale (explicitly specified or default) is not in {az, el, lt, tr}.
With these changes, a build with --icu_case_mapping=true passes a bunch
of tests in test262/intl402/Strings/* and intl/* that failed before.
Handling of pure ASCII strings (aligned at word boundary) are not as fast
as Unibrow's implementation that uses word-by-word case conversion. OTOH,
Latin-1 input handling is faster than Unibrow. General Unicode input
handling is slower but more accurate.
See https://docs.google.com/spreadsheets/d/1KJCJxKc1FxFXjwmYqABS0_2cNdPetvnd8gY8_HGSbrg/edit?usp=sharing for the benchmark.
This CL started with http://crrev.com/1544023002#ps200001 by littledan@,
but has changed significantly since.
[1] See why transliteration API is needed for uppercasing in Greek.
http://bugs.icu-project.org/trac/ticket/10582
R=yangguo
BUG=v8:4476,v8:4477
LOG=Y
TEST=test262/{built-ins,intl402}/Strings/*, webkit/fast/js/*, mjsunit/string-case,
intl/general/case*
Review-Url: https://codereview.chromium.org/1812673005
Cr-Commit-Position: refs/heads/master@{#36187}
2016-05-11 19:01:41 +00:00
|
|
|
#ifdef V8_I18N_SUPPORT
|
|
|
|
static const char* icu_case_mapping_natives[] = {"native icu-case-mapping.js",
|
|
|
|
nullptr};
|
2016-09-06 22:56:52 +00:00
|
|
|
static const char* datetime_format_to_parts_natives[] = {
|
|
|
|
"native datetime-format-to-parts.js", nullptr};
|
Use ICU case conversion/transliterator for case conversion
When I18N is enabled, use ICU's case conversion API and transliteration
API [1] to implement String.prototype.to{Upper,Lower}Case and
String.prototype.toLocale{Upper,Lower}Case.
* ICU-based case conversion was implemented in runtime-i18n.cc/i18n.js
* The above 4 functions are overridden with those in i18n.js when
--icu_case_mapping flag is turned on. To control the override by the flag,
they're overriden in icu-case-mapping.js
Previously, toLocale{U,L}Case just called to{U,L}Case so that they didn't
support locale-sensitive case conversion for Turkic languages (az, tr),
Greek (el) and Lithuanian (lt).
Before ICU APIs for the most general case are called, a fast-path for Latin-1
is tried. It's taken from Blink and adopted as necessary. This fast path
is always tried for to{U,L}Case. For toLocale{U,L}Case, it's only taken
when a locale (explicitly specified or default) is not in {az, el, lt, tr}.
With these changes, a build with --icu_case_mapping=true passes a bunch
of tests in test262/intl402/Strings/* and intl/* that failed before.
Handling of pure ASCII strings (aligned at word boundary) are not as fast
as Unibrow's implementation that uses word-by-word case conversion. OTOH,
Latin-1 input handling is faster than Unibrow. General Unicode input
handling is slower but more accurate.
See https://docs.google.com/spreadsheets/d/1KJCJxKc1FxFXjwmYqABS0_2cNdPetvnd8gY8_HGSbrg/edit?usp=sharing for the benchmark.
This CL started with http://crrev.com/1544023002#ps200001 by littledan@,
but has changed significantly since.
[1] See why transliteration API is needed for uppercasing in Greek.
http://bugs.icu-project.org/trac/ticket/10582
R=yangguo
BUG=v8:4476,v8:4477
LOG=Y
TEST=test262/{built-ins,intl402}/Strings/*, webkit/fast/js/*, mjsunit/string-case,
intl/general/case*
Review-Url: https://codereview.chromium.org/1812673005
Cr-Commit-Position: refs/heads/master@{#36187}
2016-05-11 19:01:41 +00:00
|
|
|
#endif
|
2016-09-24 15:15:07 +00:00
|
|
|
static const char* harmony_async_await_natives[] = {nullptr};
|
2016-05-27 18:22:29 +00:00
|
|
|
static const char* harmony_restrictive_generators_natives[] = {nullptr};
|
Allow trailing commas in function parameter lists
Add a flag harmony_trailing_commas_in_parameters that allows trailing
commas in function parameter declaration lists and function call
parameter lists. Trailing commas are allowed in parenthetical lists like
`(a, b, c,)` only if the next token is `=>`, thereby making it an arrow
function declaration. Only 1 trailing comma is allowed, not `(a,,)`. A
trailing comma must follow a non-rest parameter, so `(,)` and `(...a,)`
are still SyntaxErrors. However, a trailing comma is allowed after a
spread parameter, e.g. `a(...b,);`.
Add parser tests for all of the above.
BUG=v8:5051
LOG=y
Review-Url: https://codereview.chromium.org/2094463002
Cr-Commit-Position: refs/heads/master@{#37355}
2016-06-29 01:37:57 +00:00
|
|
|
static const char* harmony_trailing_commas_natives[] = {nullptr};
|
2016-09-16 00:42:30 +00:00
|
|
|
static const char* harmony_class_fields_natives[] = {nullptr};
|
2014-10-20 13:33:34 +00:00
|
|
|
|
2011-05-13 10:58:25 +00:00
|
|
|
for (int i = ExperimentalNatives::GetDebuggerCount();
|
2014-10-20 13:33:34 +00:00
|
|
|
i < ExperimentalNatives::GetBuiltinsCount(); i++) {
|
2014-12-02 18:53:27 +00:00
|
|
|
#define INSTALL_EXPERIMENTAL_NATIVES(id, desc) \
|
|
|
|
if (FLAG_##id) { \
|
|
|
|
for (size_t j = 0; id##_natives[j] != NULL; j++) { \
|
|
|
|
Vector<const char> script_name = ExperimentalNatives::GetScriptName(i); \
|
|
|
|
if (strncmp(script_name.start(), id##_natives[j], \
|
|
|
|
script_name.length()) == 0) { \
|
2015-07-13 09:45:43 +00:00
|
|
|
if (!Bootstrapper::CompileExperimentalBuiltin(isolate(), i)) { \
|
|
|
|
return false; \
|
|
|
|
} \
|
2014-12-02 18:53:27 +00:00
|
|
|
} \
|
|
|
|
} \
|
2014-10-20 13:33:34 +00:00
|
|
|
}
|
2014-11-04 16:05:27 +00:00
|
|
|
HARMONY_INPROGRESS(INSTALL_EXPERIMENTAL_NATIVES);
|
|
|
|
HARMONY_STAGED(INSTALL_EXPERIMENTAL_NATIVES);
|
2014-11-28 20:07:11 +00:00
|
|
|
HARMONY_SHIPPING(INSTALL_EXPERIMENTAL_NATIVES);
|
2014-10-20 13:33:34 +00:00
|
|
|
#undef INSTALL_EXPERIMENTAL_NATIVES
|
|
|
|
}
|
|
|
|
|
2015-06-05 15:52:04 +00:00
|
|
|
if (!CallUtilsFunction(isolate(), "PostExperimentals")) return false;
|
2015-05-26 07:24:13 +00:00
|
|
|
|
2015-06-03 17:58:29 +00:00
|
|
|
InstallExperimentalBuiltinFunctionIds();
|
2011-04-15 12:31:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-08 08:44:47 +00:00
|
|
|
bool Genesis::InstallExtraNatives() {
|
2015-08-14 18:47:46 +00:00
|
|
|
HandleScope scope(isolate());
|
|
|
|
|
|
|
|
Handle<JSObject> extras_binding =
|
|
|
|
factory()->NewJSObject(isolate()->object_function());
|
|
|
|
native_context()->set_extras_binding_object(*extras_binding);
|
|
|
|
|
2015-05-08 08:44:47 +00:00
|
|
|
for (int i = ExtraNatives::GetDebuggerCount();
|
|
|
|
i < ExtraNatives::GetBuiltinsCount(); i++) {
|
2015-07-13 09:45:43 +00:00
|
|
|
if (!Bootstrapper::CompileExtraBuiltin(isolate(), i)) return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-20 00:01:07 +00:00
|
|
|
bool Genesis::InstallExperimentalExtraNatives() {
|
|
|
|
for (int i = ExperimentalExtraNatives::GetDebuggerCount();
|
|
|
|
i < ExperimentalExtraNatives::GetBuiltinsCount(); i++) {
|
|
|
|
if (!Bootstrapper::CompileExperimentalExtraBuiltin(isolate(), i))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-12 14:22:07 +00:00
|
|
|
bool Genesis::InstallDebuggerNatives() {
|
|
|
|
for (int i = 0; i < Natives::GetDebuggerCount(); ++i) {
|
|
|
|
if (!Bootstrapper::CompileBuiltin(isolate(), i)) return false;
|
|
|
|
}
|
|
|
|
return CallUtilsFunction(isolate(), "PostDebug");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-14 18:53:48 +00:00
|
|
|
static void InstallBuiltinFunctionId(Handle<JSObject> holder,
|
|
|
|
const char* function_name,
|
|
|
|
BuiltinFunctionId id) {
|
2014-04-16 13:28:11 +00:00
|
|
|
Isolate* isolate = holder->GetIsolate();
|
2014-04-11 12:47:34 +00:00
|
|
|
Handle<Object> function_object =
|
2016-03-08 17:29:05 +00:00
|
|
|
JSReceiver::GetProperty(isolate, holder, function_name).ToHandleChecked();
|
2014-04-09 12:21:47 +00:00
|
|
|
Handle<JSFunction> function = Handle<JSFunction>::cast(function_object);
|
2016-02-25 16:06:01 +00:00
|
|
|
function->shared()->set_builtin_function_id(id);
|
2010-05-06 13:21:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-03 17:58:29 +00:00
|
|
|
#define INSTALL_BUILTIN_ID(holder_expr, fun_name, name) \
|
|
|
|
{ #holder_expr, #fun_name, k##name } \
|
|
|
|
,
|
|
|
|
|
|
|
|
|
2010-12-14 18:53:48 +00:00
|
|
|
void Genesis::InstallBuiltinFunctionIds() {
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(isolate());
|
2015-02-27 15:21:42 +00:00
|
|
|
struct BuiltinFunctionIds {
|
|
|
|
const char* holder_expr;
|
|
|
|
const char* fun_name;
|
|
|
|
BuiltinFunctionId id;
|
|
|
|
};
|
|
|
|
|
|
|
|
const BuiltinFunctionIds builtins[] = {
|
|
|
|
FUNCTIONS_WITH_ID_LIST(INSTALL_BUILTIN_ID)};
|
|
|
|
|
|
|
|
for (const BuiltinFunctionIds& builtin : builtins) {
|
|
|
|
Handle<JSObject> holder =
|
|
|
|
ResolveBuiltinIdHolder(native_context(), builtin.holder_expr);
|
|
|
|
InstallBuiltinFunctionId(holder, builtin.fun_name, builtin.id);
|
|
|
|
}
|
2010-05-06 13:21:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-03 17:58:29 +00:00
|
|
|
void Genesis::InstallExperimentalBuiltinFunctionIds() {
|
2015-09-01 18:33:51 +00:00
|
|
|
if (FLAG_harmony_sharedarraybuffer) {
|
2015-06-03 17:58:29 +00:00
|
|
|
struct BuiltinFunctionIds {
|
|
|
|
const char* holder_expr;
|
|
|
|
const char* fun_name;
|
|
|
|
BuiltinFunctionId id;
|
|
|
|
};
|
|
|
|
|
|
|
|
const BuiltinFunctionIds atomic_builtins[] = {
|
|
|
|
ATOMIC_FUNCTIONS_WITH_ID_LIST(INSTALL_BUILTIN_ID)};
|
|
|
|
|
|
|
|
for (const BuiltinFunctionIds& builtin : atomic_builtins) {
|
|
|
|
Handle<JSObject> holder =
|
|
|
|
ResolveBuiltinIdHolder(native_context(), builtin.holder_expr);
|
|
|
|
InstallBuiltinFunctionId(holder, builtin.fun_name, builtin.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#undef INSTALL_BUILTIN_ID
|
|
|
|
|
|
|
|
|
2010-08-25 13:25:54 +00:00
|
|
|
void Genesis::InitializeNormalizedMapCaches() {
|
2014-05-02 13:03:39 +00:00
|
|
|
Handle<NormalizedMapCache> cache = NormalizedMapCache::New(isolate());
|
|
|
|
native_context()->set_normalized_map_cache(*cache);
|
2010-08-25 13:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
bool Bootstrapper::InstallExtensions(Handle<Context> native_context,
|
2010-03-23 11:40:38 +00:00
|
|
|
v8::ExtensionConfiguration* extensions) {
|
2013-02-15 09:27:10 +00:00
|
|
|
BootstrapperActive active(this);
|
|
|
|
SaveContext saved_context(isolate_);
|
|
|
|
isolate_->set_context(*native_context);
|
2014-01-16 13:18:28 +00:00
|
|
|
return Genesis::InstallExtensions(native_context, extensions) &&
|
|
|
|
Genesis::InstallSpecialObjects(native_context);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-16 13:18:28 +00:00
|
|
|
bool Genesis::InstallSpecialObjects(Handle<Context> native_context) {
|
2012-08-17 09:03:08 +00:00
|
|
|
Isolate* isolate = native_context->GetIsolate();
|
2014-07-07 13:27:37 +00:00
|
|
|
// Don't install extensions into the snapshot.
|
|
|
|
if (isolate->serializer_enabled()) return true;
|
|
|
|
|
2012-01-05 17:16:19 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(isolate);
|
2012-08-17 12:59:00 +00:00
|
|
|
Handle<JSGlobalObject> global(JSGlobalObject::cast(
|
|
|
|
native_context->global_object()));
|
2014-07-07 13:27:37 +00:00
|
|
|
|
2015-12-09 07:53:19 +00:00
|
|
|
Handle<JSObject> Error = isolate->error_function();
|
2014-07-07 13:27:37 +00:00
|
|
|
Handle<String> name =
|
2014-09-10 12:38:12 +00:00
|
|
|
factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("stackTraceLimit"));
|
2014-07-07 13:27:37 +00:00
|
|
|
Handle<Smi> stack_trace_limit(Smi::FromInt(FLAG_stack_trace_limit), isolate);
|
|
|
|
JSObject::AddProperty(Error, name, stack_trace_limit, NONE);
|
|
|
|
|
2008-08-14 13:41:48 +00:00
|
|
|
// Expose the debug global object in global if a name for it is specified.
|
|
|
|
if (FLAG_expose_debug_as != NULL && strlen(FLAG_expose_debug_as) != 0) {
|
|
|
|
// If loading fails we just bail out without installing the
|
|
|
|
// debugger but without tanking the whole context.
|
2014-05-20 08:52:42 +00:00
|
|
|
Debug* debug = isolate->debug();
|
2014-01-16 13:18:28 +00:00
|
|
|
if (!debug->Load()) return true;
|
2014-05-20 08:52:42 +00:00
|
|
|
Handle<Context> debug_context = debug->debug_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
|
|
|
// Set the security token for the debugger context to the same as
|
2012-08-17 09:03:08 +00:00
|
|
|
// the shell native context to allow calling between these (otherwise
|
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
|
|
|
// exposing debug global object doesn't make much sense).
|
2014-05-20 08:52:42 +00:00
|
|
|
debug_context->set_security_token(native_context->security_token());
|
2008-08-14 13:41:48 +00:00
|
|
|
Handle<String> debug_string =
|
2013-02-28 17:03:34 +00:00
|
|
|
factory->InternalizeUtf8String(FLAG_expose_debug_as);
|
2014-08-20 11:52:22 +00:00
|
|
|
uint32_t index;
|
|
|
|
if (debug_string->AsArrayIndex(&index)) return true;
|
2014-05-20 08:52:42 +00:00
|
|
|
Handle<Object> global_proxy(debug_context->global_proxy(), isolate);
|
2014-07-07 13:27:37 +00:00
|
|
|
JSObject::AddProperty(global, debug_string, global_proxy, DONT_ENUM);
|
2008-08-14 13:41:48 +00:00
|
|
|
}
|
2015-08-27 14:42:36 +00:00
|
|
|
|
2016-07-01 05:26:58 +00:00
|
|
|
WasmJs::Install(isolate, global);
|
2015-08-27 14:42:36 +00:00
|
|
|
|
2014-01-16 13:18:28 +00:00
|
|
|
return true;
|
2008-08-14 13:41:48 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2011-11-15 22:48:55 +00:00
|
|
|
static uint32_t Hash(RegisteredExtension* extension) {
|
|
|
|
return v8::internal::ComputePointerHash(extension);
|
|
|
|
}
|
|
|
|
|
2016-09-30 16:16:47 +00:00
|
|
|
Genesis::ExtensionStates::ExtensionStates() : map_(8) {}
|
2011-11-15 22:48:55 +00:00
|
|
|
|
|
|
|
Genesis::ExtensionTraversalState Genesis::ExtensionStates::get_state(
|
|
|
|
RegisteredExtension* extension) {
|
2016-06-09 17:58:10 +00:00
|
|
|
base::HashMap::Entry* entry = map_.Lookup(extension, Hash(extension));
|
2011-11-15 22:48:55 +00:00
|
|
|
if (entry == NULL) {
|
|
|
|
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
|
|
|
|
2014-01-16 13:18:28 +00:00
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
bool Genesis::InstallExtensions(Handle<Context> native_context,
|
2010-03-23 11:40:38 +00:00
|
|
|
v8::ExtensionConfiguration* extensions) {
|
2013-02-15 09:27:10 +00:00
|
|
|
Isolate* isolate = native_context->GetIsolate();
|
2011-11-15 23:26:22 +00:00
|
|
|
ExtensionStates extension_states; // All extensions have state UNVISITED.
|
2014-01-16 13:18:28 +00:00
|
|
|
return InstallAutoExtensions(isolate, &extension_states) &&
|
2016-04-27 11:10:41 +00:00
|
|
|
(!FLAG_expose_free_buffer ||
|
|
|
|
InstallExtension(isolate, "v8/free-buffer", &extension_states)) &&
|
|
|
|
(!FLAG_expose_gc ||
|
|
|
|
InstallExtension(isolate, "v8/gc", &extension_states)) &&
|
|
|
|
(!FLAG_expose_externalize_string ||
|
|
|
|
InstallExtension(isolate, "v8/externalize", &extension_states)) &&
|
2016-11-08 03:13:42 +00:00
|
|
|
(!FLAG_gc_stats ||
|
2016-04-27 11:10:41 +00:00
|
|
|
InstallExtension(isolate, "v8/statistics", &extension_states)) &&
|
|
|
|
(!FLAG_expose_trigger_failure ||
|
|
|
|
InstallExtension(isolate, "v8/trigger-failure", &extension_states)) &&
|
2016-10-27 12:17:13 +00:00
|
|
|
(!FLAG_trace_ignition_dispatches ||
|
2016-04-27 11:10:41 +00:00
|
|
|
InstallExtension(isolate, "v8/ignition-statistics",
|
|
|
|
&extension_states)) &&
|
|
|
|
InstallRequestedExtensions(isolate, extensions, &extension_states);
|
2014-01-16 13:18:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-01-16 13:18:28 +00:00
|
|
|
|
|
|
|
bool Genesis::InstallAutoExtensions(Isolate* isolate,
|
|
|
|
ExtensionStates* extension_states) {
|
|
|
|
for (v8::RegisteredExtension* it = v8::RegisteredExtension::first_extension();
|
|
|
|
it != NULL;
|
|
|
|
it = it->next()) {
|
|
|
|
if (it->extension()->auto_enable() &&
|
|
|
|
!InstallExtension(isolate, it, extension_states)) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-05 17:26:22 +00:00
|
|
|
}
|
2014-01-16 13:18:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-01-16 13:18:28 +00:00
|
|
|
bool Genesis::InstallRequestedExtensions(Isolate* isolate,
|
|
|
|
v8::ExtensionConfiguration* extensions,
|
|
|
|
ExtensionStates* extension_states) {
|
2014-01-16 08:17:40 +00:00
|
|
|
for (const char** it = extensions->begin(); it != extensions->end(); ++it) {
|
2014-01-16 13:18:28 +00:00
|
|
|
if (!InstallExtension(isolate, *it, extension_states)) return false;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Installs a named extension. This methods is unoptimized and does
|
|
|
|
// not scale well if we want to support a large number of extensions.
|
2013-02-15 09:27:10 +00:00
|
|
|
bool Genesis::InstallExtension(Isolate* isolate,
|
|
|
|
const char* name,
|
2011-11-15 22:48:55 +00:00
|
|
|
ExtensionStates* extension_states) {
|
2014-01-16 13:18:28 +00:00
|
|
|
for (v8::RegisteredExtension* it = v8::RegisteredExtension::first_extension();
|
|
|
|
it != NULL;
|
|
|
|
it = it->next()) {
|
|
|
|
if (strcmp(name, it->extension()->name()) == 0) {
|
|
|
|
return InstallExtension(isolate, it, extension_states);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2014-01-16 13:18:28 +00:00
|
|
|
return Utils::ApiCheck(false,
|
|
|
|
"v8::Context::New()",
|
|
|
|
"Cannot find required extension");
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-15 09:27:10 +00:00
|
|
|
bool Genesis::InstallExtension(Isolate* isolate,
|
|
|
|
v8::RegisteredExtension* current,
|
2011-11-15 22:48:55 +00:00
|
|
|
ExtensionStates* extension_states) {
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-11-15 22:48:55 +00:00
|
|
|
if (extension_states->get_state(current) == INSTALLED) return true;
|
2008-07-03 15:10:15 +00:00
|
|
|
// The current node has already been visited so there must be a
|
|
|
|
// cycle in the dependency graph; fail.
|
2014-01-13 09:42:23 +00:00
|
|
|
if (!Utils::ApiCheck(extension_states->get_state(current) != VISITED,
|
|
|
|
"v8::Context::New()",
|
|
|
|
"Circular extension dependency")) {
|
2008-07-03 15:10:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(extension_states->get_state(current) == UNVISITED);
|
2011-11-15 22:48:55 +00:00
|
|
|
extension_states->set_state(current, VISITED);
|
2008-07-03 15:10:15 +00:00
|
|
|
v8::Extension* extension = current->extension();
|
|
|
|
// Install the extension's dependencies
|
|
|
|
for (int i = 0; i < extension->dependency_count(); i++) {
|
2013-02-15 09:27:10 +00:00
|
|
|
if (!InstallExtension(isolate,
|
|
|
|
extension->dependencies()[i],
|
|
|
|
extension_states)) {
|
2011-11-15 22:48:55 +00:00
|
|
|
return false;
|
2013-02-15 09:27:10 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2014-03-25 09:09:24 +00:00
|
|
|
// We do not expect this to throw an exception. Change this if it does.
|
2015-05-12 14:00:47 +00:00
|
|
|
bool result = CompileExtension(isolate, extension);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(isolate->has_pending_exception() != result);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (!result) {
|
2011-10-25 13:43:19 +00:00
|
|
|
// We print out the name of the extension that fail to install.
|
|
|
|
// When an error is thrown during bootstrapping we automatically print
|
|
|
|
// the line number at which this happened to the console in the isolate
|
|
|
|
// error throwing functionality.
|
2014-06-30 13:25:46 +00:00
|
|
|
base::OS::PrintError("Error installing extension '%s'.\n",
|
|
|
|
current->extension()->name());
|
2011-03-28 13:09:37 +00:00
|
|
|
isolate->clear_pending_exception();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-11-15 22:48:55 +00:00
|
|
|
extension_states->set_state(current, INSTALLED);
|
|
|
|
isolate->NotifyExtensionInstalled();
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
bool Genesis::ConfigureGlobalObjects(
|
2015-07-06 07:09:07 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> global_proxy_template) {
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
Handle<JSObject> global_proxy(
|
2012-08-17 09:03:08 +00:00
|
|
|
JSObject::cast(native_context()->global_proxy()));
|
2014-07-01 12:12:34 +00:00
|
|
|
Handle<JSObject> global_object(
|
2012-08-17 12:59:00 +00:00
|
|
|
JSObject::cast(native_context()->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
|
|
|
|
|
|
|
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(
|
2014-07-01 12:12:34 +00:00
|
|
|
FunctionTemplateInfo::cast(global_proxy_data->constructor()));
|
2016-06-06 12:58:10 +00:00
|
|
|
if (!proxy_constructor->prototype_template()->IsUndefined(isolate())) {
|
2014-07-01 12:12:34 +00:00
|
|
|
Handle<ObjectTemplateInfo> global_object_data(
|
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
|
|
|
ObjectTemplateInfo::cast(proxy_constructor->prototype_template()));
|
2014-07-01 12:12:34 +00:00
|
|
|
if (!ConfigureApiObject(global_object, global_object_data)) return false;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
|
2016-07-19 11:28:43 +00:00
|
|
|
JSObject::ForceSetPrototype(global_proxy, global_object);
|
2013-05-13 07:35:26 +00:00
|
|
|
|
|
|
|
native_context()->set_initial_array_prototype(
|
|
|
|
JSArray::cast(native_context()->array_function()->prototype()));
|
2015-06-01 14:22:58 +00:00
|
|
|
native_context()->set_array_buffer_map(
|
|
|
|
native_context()->array_buffer_fun()->initial_map());
|
2015-06-01 23:16:27 +00:00
|
|
|
native_context()->set_js_map_map(
|
|
|
|
native_context()->js_map_fun()->initial_map());
|
|
|
|
native_context()->set_js_set_map(
|
|
|
|
native_context()->js_set_fun()->initial_map());
|
2013-05-13 07:35:26 +00:00
|
|
|
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-10-21 20:08:49 +00:00
|
|
|
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
bool Genesis::ConfigureApiObject(Handle<JSObject> object,
|
2014-07-01 12:12:34 +00:00
|
|
|
Handle<ObjectTemplateInfo> object_template) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!object_template.is_null());
|
|
|
|
DCHECK(FunctionTemplateInfo::cast(object_template->constructor())
|
2013-11-19 13:38:15 +00:00
|
|
|
->IsTemplateFor(object->map()));;
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
|
2014-04-11 10:41:09 +00:00
|
|
|
MaybeHandle<JSObject> maybe_obj =
|
2015-02-04 13:01:34 +00:00
|
|
|
ApiNatives::InstantiateObject(object_template);
|
2014-04-11 10:41:09 +00:00
|
|
|
Handle<JSObject> obj;
|
|
|
|
if (!maybe_obj.ToHandle(&obj)) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(isolate()->has_pending_exception());
|
2011-04-14 08:01:19 +00:00
|
|
|
isolate()->clear_pending_exception();
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
TransferObject(obj, object);
|
2008-07-03 15:10:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Genesis::TransferNamedProperties(Handle<JSObject> from,
|
|
|
|
Handle<JSObject> to) {
|
2015-01-14 11:06:38 +00:00
|
|
|
// If JSObject::AddProperty asserts due to already existing property,
|
|
|
|
// it is likely due to both global objects sharing property name(s).
|
|
|
|
// Merging those two global objects is impossible.
|
|
|
|
// The global template must not create properties that already exist
|
|
|
|
// in the snapshotted global object.
|
2008-07-03 15:10:15 +00:00
|
|
|
if (from->HasFastProperties()) {
|
|
|
|
Handle<DescriptorArray> descs =
|
|
|
|
Handle<DescriptorArray>(from->map()->instance_descriptors());
|
2013-05-07 13:09:23 +00:00
|
|
|
for (int i = 0; i < from->map()->NumberOfOwnDescriptors(); i++) {
|
2012-04-17 07:16:19 +00:00
|
|
|
PropertyDetails details = descs->GetDetails(i);
|
2008-07-03 15:10:15 +00:00
|
|
|
switch (details.type()) {
|
2015-01-19 17:49:13 +00:00
|
|
|
case DATA: {
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope inner(isolate());
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<Name> key = Handle<Name>(descs->GetKey(i));
|
2014-06-10 14:01:08 +00:00
|
|
|
FieldIndex index = FieldIndex::ForDescriptor(from->map(), i);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!descs->GetDetails(i).representation().IsDouble());
|
2013-05-08 15:02:08 +00:00
|
|
|
Handle<Object> value = Handle<Object>(from->RawFastPropertyAt(index),
|
2013-02-25 14:46:09 +00:00
|
|
|
isolate());
|
2014-06-30 13:48:57 +00:00
|
|
|
JSObject::AddProperty(to, key, value, details.attributes());
|
2008-07-03 15:10:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-01-19 17:49:13 +00:00
|
|
|
case DATA_CONSTANT: {
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope inner(isolate());
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<Name> key = Handle<Name>(descs->GetKey(i));
|
2013-07-24 12:34:50 +00:00
|
|
|
Handle<Object> constant(descs->GetConstant(i), isolate());
|
2014-06-30 13:48:57 +00:00
|
|
|
JSObject::AddProperty(to, key, constant, details.attributes());
|
2008-07-03 15:10:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-01-19 17:49:13 +00:00
|
|
|
case ACCESSOR:
|
2014-12-16 13:22:23 +00:00
|
|
|
UNREACHABLE();
|
2015-01-19 17:49:13 +00:00
|
|
|
case ACCESSOR_CONSTANT: {
|
2014-08-20 15:08:20 +00:00
|
|
|
Handle<Name> key(descs->GetKey(i));
|
2014-09-03 14:05:55 +00:00
|
|
|
LookupIterator it(to, key, LookupIterator::OWN_SKIP_INTERCEPTOR);
|
|
|
|
CHECK_NE(LookupIterator::ACCESS_CHECK, it.state());
|
2008-07-03 15:10:15 +00:00
|
|
|
// If the property is already there we skip it
|
2014-09-04 12:28:13 +00:00
|
|
|
if (it.IsFound()) continue;
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope inner(isolate());
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!to->HasFastProperties());
|
2010-03-23 11:40:38 +00:00
|
|
|
// Add to dictionary.
|
2013-02-25 14:46:09 +00:00
|
|
|
Handle<Object> callbacks(descs->GetCallbacksObject(i), isolate());
|
2015-03-17 13:27:25 +00:00
|
|
|
PropertyDetails d(details.attributes(), ACCESSOR_CONSTANT, i + 1,
|
|
|
|
PropertyCellType::kMutable);
|
2012-01-05 17:16:19 +00:00
|
|
|
JSObject::SetNormalizedProperty(to, key, callbacks, d);
|
2008-07-03 15:10:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-02 14:57:59 +00:00
|
|
|
} else if (from->IsJSGlobalObject()) {
|
2015-06-01 16:24:59 +00:00
|
|
|
Handle<GlobalDictionary> properties =
|
|
|
|
Handle<GlobalDictionary>(from->global_dictionary());
|
|
|
|
int capacity = properties->Capacity();
|
|
|
|
for (int i = 0; i < capacity; i++) {
|
|
|
|
Object* raw_key(properties->KeyAt(i));
|
2016-06-07 12:21:50 +00:00
|
|
|
if (properties->IsKey(isolate(), raw_key)) {
|
2015-06-01 16:24:59 +00:00
|
|
|
DCHECK(raw_key->IsName());
|
|
|
|
// If the property is already there we skip it.
|
|
|
|
Handle<Name> key(Name::cast(raw_key));
|
|
|
|
LookupIterator it(to, key, LookupIterator::OWN_SKIP_INTERCEPTOR);
|
|
|
|
CHECK_NE(LookupIterator::ACCESS_CHECK, it.state());
|
|
|
|
if (it.IsFound()) continue;
|
|
|
|
// Set the property.
|
2015-06-02 10:29:12 +00:00
|
|
|
DCHECK(properties->ValueAt(i)->IsPropertyCell());
|
|
|
|
Handle<PropertyCell> cell(PropertyCell::cast(properties->ValueAt(i)));
|
|
|
|
Handle<Object> value(cell->value(), isolate());
|
2016-06-06 12:58:10 +00:00
|
|
|
if (value->IsTheHole(isolate())) continue;
|
2015-06-02 10:29:12 +00:00
|
|
|
PropertyDetails details = cell->property_details();
|
2015-06-01 16:24:59 +00:00
|
|
|
DCHECK_EQ(kData, details.kind());
|
|
|
|
JSObject::AddProperty(to, key, value, details.attributes());
|
|
|
|
}
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<NameDictionary> properties =
|
|
|
|
Handle<NameDictionary>(from->property_dictionary());
|
2008-07-03 15:10:15 +00:00
|
|
|
int capacity = properties->Capacity();
|
|
|
|
for (int i = 0; i < capacity; i++) {
|
|
|
|
Object* raw_key(properties->KeyAt(i));
|
2016-06-07 12:21:50 +00:00
|
|
|
if (properties->IsKey(isolate(), raw_key)) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(raw_key->IsName());
|
2008-07-03 15:10:15 +00:00
|
|
|
// If the property is already there we skip it.
|
2014-04-29 13:43:17 +00:00
|
|
|
Handle<Name> key(Name::cast(raw_key));
|
2014-09-03 14:05:55 +00:00
|
|
|
LookupIterator it(to, key, LookupIterator::OWN_SKIP_INTERCEPTOR);
|
|
|
|
CHECK_NE(LookupIterator::ACCESS_CHECK, it.state());
|
2014-09-04 12:28:13 +00:00
|
|
|
if (it.IsFound()) continue;
|
2008-07-03 15:10:15 +00:00
|
|
|
// Set the property.
|
2013-02-25 14:46:09 +00:00
|
|
|
Handle<Object> value = Handle<Object>(properties->ValueAt(i),
|
|
|
|
isolate());
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!value->IsCell());
|
2016-06-06 12:58:10 +00:00
|
|
|
DCHECK(!value->IsTheHole(isolate()));
|
2008-07-03 15:10:15 +00:00
|
|
|
PropertyDetails details = properties->DetailsAt(i);
|
2015-01-19 17:49:13 +00:00
|
|
|
DCHECK_EQ(kData, details.kind());
|
2014-06-30 13:48:57 +00:00
|
|
|
JSObject::AddProperty(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 =
|
|
|
|
Handle<FixedArray>(FixedArray::cast(from->elements()));
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<FixedArray> to_elements = factory()->CopyFixedArray(from_elements);
|
2008-07-03 15:10:15 +00:00
|
|
|
to->set_elements(*to_elements);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Genesis::TransferObject(Handle<JSObject> from, Handle<JSObject> to) {
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope outer(isolate());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!from->IsJSArray());
|
|
|
|
DCHECK(!to->IsJSArray());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
TransferNamedProperties(from, to);
|
|
|
|
TransferIndexedProperties(from, to);
|
|
|
|
|
|
|
|
// Transfer the prototype (new map is needed).
|
2014-06-24 14:53:48 +00:00
|
|
|
Handle<Object> proto(from->map()->prototype(), isolate());
|
2016-07-19 11:28:43 +00:00
|
|
|
JSObject::ForceSetPrototype(to, proto);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Genesis::MakeFunctionInstancePrototypeWritable() {
|
2011-03-17 20:28:17 +00:00
|
|
|
// The maps with writable prototype are created in CreateEmptyFunction
|
|
|
|
// and CreateStrictModeFunctionMaps respectively. Initially the maps are
|
|
|
|
// created with read-only prototype for JS builtins processing.
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!sloppy_function_map_writable_prototype_.is_null());
|
|
|
|
DCHECK(!strict_function_map_writable_prototype_.is_null());
|
2011-03-17 20:28:17 +00:00
|
|
|
|
|
|
|
// Replace function instance maps to make prototype writable.
|
2014-03-11 14:41:22 +00:00
|
|
|
native_context()->set_sloppy_function_map(
|
|
|
|
*sloppy_function_map_writable_prototype_);
|
|
|
|
native_context()->set_strict_function_map(
|
|
|
|
*strict_function_map_writable_prototype_);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-29 14:18:55 +00:00
|
|
|
class NoTrackDoubleFieldsForSerializerScope {
|
|
|
|
public:
|
2014-04-25 08:40:23 +00:00
|
|
|
explicit NoTrackDoubleFieldsForSerializerScope(Isolate* isolate)
|
2014-10-08 09:01:43 +00:00
|
|
|
: flag_(FLAG_track_double_fields), enabled_(false) {
|
2014-05-22 09:36:20 +00:00
|
|
|
if (isolate->serializer_enabled()) {
|
2014-01-29 14:18:55 +00:00
|
|
|
// Disable tracking double fields because heap numbers treated as
|
|
|
|
// immutable by the serializer.
|
|
|
|
FLAG_track_double_fields = false;
|
2014-10-08 09:01:43 +00:00
|
|
|
enabled_ = true;
|
2014-01-29 14:18:55 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-30 09:50:58 +00:00
|
|
|
|
2014-01-29 14:18:55 +00:00
|
|
|
~NoTrackDoubleFieldsForSerializerScope() {
|
2014-10-08 09:01:43 +00:00
|
|
|
if (enabled_) {
|
|
|
|
FLAG_track_double_fields = flag_;
|
|
|
|
}
|
2014-01-29 14:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool flag_;
|
2014-10-08 09:01:43 +00:00
|
|
|
bool enabled_;
|
2014-01-29 14:18:55 +00:00
|
|
|
};
|
|
|
|
|
2011-04-14 08:01:19 +00:00
|
|
|
Genesis::Genesis(Isolate* isolate,
|
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,
|
2015-07-13 09:45:43 +00:00
|
|
|
v8::ExtensionConfiguration* extensions,
|
2016-06-15 15:38:40 +00:00
|
|
|
size_t context_snapshot_index, GlobalContextType context_type)
|
2015-07-06 07:09:07 +00:00
|
|
|
: isolate_(isolate), active_(isolate->bootstrapper()) {
|
2014-04-25 08:40:23 +00:00
|
|
|
NoTrackDoubleFieldsForSerializerScope disable_scope(isolate);
|
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
|
|
|
|
2012-04-05 14:01:39 +00:00
|
|
|
// During genesis, the boilerplate for stack overflow won't work until the
|
|
|
|
// environment has been at least partially initialized. Add a stack check
|
|
|
|
// before entering JS code to catch overflow early.
|
2013-02-15 09:27:10 +00:00
|
|
|
StackLimitCheck check(isolate);
|
2015-05-29 11:37:10 +00:00
|
|
|
if (check.HasOverflowed()) {
|
|
|
|
isolate->StackOverflow();
|
|
|
|
return;
|
|
|
|
}
|
2012-04-05 14:01:39 +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;
|
|
|
|
if (!maybe_global_proxy.ToHandle(&global_proxy)) {
|
2016-11-04 10:02:02 +00:00
|
|
|
const int internal_field_count =
|
|
|
|
!global_proxy_template.IsEmpty()
|
|
|
|
? global_proxy_template->InternalFieldCount()
|
|
|
|
: 0;
|
|
|
|
global_proxy = isolate->factory()->NewUninitializedJSGlobalProxy(
|
|
|
|
JSGlobalProxy::SizeWithInternalFields(internal_field_count));
|
2015-01-14 16:42:15 +00:00
|
|
|
}
|
|
|
|
|
2013-06-28 13:40:41 +00:00
|
|
|
// We can only de-serialize a context if the isolate was initialized from
|
|
|
|
// a snapshot. Otherwise we have to build the context from scratch.
|
2015-05-12 14:00:47 +00:00
|
|
|
// Also create a context from scratch to expose natives, if required by flag.
|
2015-05-12 07:26:05 +00:00
|
|
|
if (!isolate->initialized_from_snapshot() ||
|
2016-06-15 15:38:40 +00:00
|
|
|
!Snapshot::NewContextFromSnapshot(isolate, global_proxy,
|
|
|
|
context_snapshot_index)
|
2015-01-13 08:48:00 +00:00
|
|
|
.ToHandle(&native_context_)) {
|
2013-06-28 13:40:41 +00:00
|
|
|
native_context_ = Handle<Context>();
|
|
|
|
}
|
|
|
|
|
2013-03-18 17:36:47 +00:00
|
|
|
if (!native_context().is_null()) {
|
|
|
|
AddToWeakNativeContextList(*native_context());
|
|
|
|
isolate->set_context(*native_context());
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->counters()->contexts_created_by_snapshot()->Increment();
|
2014-11-07 16:03:11 +00:00
|
|
|
#if TRACE_MAPS
|
|
|
|
if (FLAG_trace_maps) {
|
|
|
|
Handle<JSFunction> object_fun = isolate->object_function();
|
|
|
|
PrintF("[TraceMap: InitialMap map= %p SFI= %d_Object ]\n",
|
|
|
|
reinterpret_cast<void*>(object_fun->initial_map()),
|
|
|
|
object_fun->shared()->unique_id());
|
|
|
|
Map::TraceAllTransitions(object_fun->initial_map());
|
|
|
|
}
|
|
|
|
#endif
|
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);
|
2014-07-01 12:12:34 +00:00
|
|
|
|
|
|
|
HookUpGlobalProxy(global_object, global_proxy);
|
2015-12-01 23:35:57 +00:00
|
|
|
HookUpGlobalObject(global_object);
|
2010-03-23 11:40:38 +00:00
|
|
|
|
2014-07-01 12:12:34 +00:00
|
|
|
if (!ConfigureGlobalObjects(global_proxy_template)) return;
|
2010-03-23 11:40:38 +00:00
|
|
|
} else {
|
|
|
|
// We get here if there was no context snapshot.
|
|
|
|
CreateRoots();
|
2011-04-14 08:01:19 +00:00
|
|
|
Handle<JSFunction> empty_function = CreateEmptyFunction(isolate);
|
2011-03-17 20:28:17 +00:00
|
|
|
CreateStrictModeFunctionMaps(empty_function);
|
2016-04-06 08:37:09 +00:00
|
|
|
CreateIteratorMaps(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);
|
2014-07-01 12:12:34 +00:00
|
|
|
HookUpGlobalProxy(global_object, global_proxy);
|
2015-07-13 09:45:43 +00:00
|
|
|
InitializeGlobal(global_object, empty_function, context_type);
|
2010-08-25 13:25:54 +00:00
|
|
|
InitializeNormalizedMapCaches();
|
2015-07-13 09:45:43 +00:00
|
|
|
|
|
|
|
if (!InstallNatives(context_type)) return;
|
2010-03-23 11:40:38 +00:00
|
|
|
|
|
|
|
MakeFunctionInstancePrototypeWritable();
|
|
|
|
|
2016-06-27 12:49:51 +00:00
|
|
|
if (!InstallExtraNatives()) return;
|
|
|
|
if (!ConfigureGlobalObjects(global_proxy_template)) return;
|
|
|
|
|
2014-02-12 13:27:13 +00:00
|
|
|
isolate->counters()->contexts_created_from_scratch()->Increment();
|
2015-11-06 08:07:52 +00:00
|
|
|
// Re-initialize the counter because it got incremented during snapshot
|
|
|
|
// creation.
|
2016-10-07 13:05:07 +00:00
|
|
|
isolate->native_context()->set_errors_thrown(Smi::kZero);
|
2010-03-23 11:40:38 +00:00
|
|
|
}
|
2008-08-14 13:41:48 +00:00
|
|
|
|
2015-08-14 18:47:46 +00:00
|
|
|
// Install experimental natives. Do not include them into the
|
2015-05-08 08:44:47 +00:00
|
|
|
// snapshot as we should be able to turn them off at runtime. Re-installing
|
|
|
|
// them after they have already been deserialized would also fail.
|
2015-08-13 12:09:30 +00:00
|
|
|
if (context_type == FULL_CONTEXT) {
|
|
|
|
if (!isolate->serializer_enabled()) {
|
|
|
|
InitializeExperimentalGlobal();
|
2015-07-13 09:45:43 +00:00
|
|
|
if (!InstallExperimentalNatives()) return;
|
2015-08-20 00:01:07 +00:00
|
|
|
|
|
|
|
if (FLAG_experimental_extras) {
|
|
|
|
if (!InstallExperimentalExtraNatives()) return;
|
|
|
|
}
|
2015-07-13 09:45:43 +00:00
|
|
|
}
|
2015-08-13 12:09:30 +00:00
|
|
|
// The serializer cannot serialize typed arrays. Reset those typed arrays
|
|
|
|
// for each new context.
|
|
|
|
} else if (context_type == DEBUG_CONTEXT) {
|
|
|
|
DCHECK(!isolate->serializer_enabled());
|
|
|
|
InitializeExperimentalGlobal();
|
|
|
|
if (!InstallDebuggerNatives()) return;
|
2015-07-13 09:45:43 +00:00
|
|
|
}
|
2015-08-13 12:09:30 +00:00
|
|
|
|
2015-10-16 11:27:14 +00:00
|
|
|
ConfigureUtilsObject(context_type);
|
|
|
|
|
2015-08-17 11:00:43 +00:00
|
|
|
// Check that the script context table is empty except for the 'this' binding.
|
|
|
|
// We do not need script contexts for native scripts.
|
2016-08-29 12:49:18 +00:00
|
|
|
DCHECK_EQ(1, native_context()->script_context_table()->used());
|
2015-08-17 11:00:43 +00:00
|
|
|
|
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()) {
|
|
|
|
NoTrackDoubleFieldsForSerializerScope disable_scope(isolate);
|
|
|
|
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);
|
|
|
|
|
|
|
|
// During genesis, the boilerplate for stack overflow won't work until the
|
|
|
|
// environment has been at least partially initialized. Add a stack check
|
|
|
|
// before entering JS code to catch overflow early.
|
|
|
|
StackLimitCheck check(isolate);
|
|
|
|
if (check.HasOverflowed()) {
|
|
|
|
isolate->StackOverflow();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-04 10:02:02 +00:00
|
|
|
const int proxy_size = JSGlobalProxy::SizeWithInternalFields(
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// CreateNewGlobals.
|
|
|
|
Handle<ObjectTemplateInfo> global_proxy_data =
|
|
|
|
v8::Utils::OpenHandle(*global_proxy_template);
|
|
|
|
Handle<FunctionTemplateInfo> global_constructor(
|
|
|
|
FunctionTemplateInfo::cast(global_proxy_data->constructor()));
|
|
|
|
Handle<SharedFunctionInfo> shared =
|
|
|
|
FunctionTemplateInfo::GetOrCreateSharedFunctionInfo(isolate,
|
|
|
|
global_constructor);
|
|
|
|
Handle<Map> initial_map =
|
2016-07-18 15:35:37 +00:00
|
|
|
factory()->CreateSloppyFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE);
|
2016-07-07 19:37:05 +00:00
|
|
|
Handle<JSFunction> global_proxy_function =
|
|
|
|
isolate->factory()->NewFunctionFromSharedFunctionInfo(
|
|
|
|
initial_map, shared, factory()->undefined_value());
|
2016-11-02 14:39:58 +00:00
|
|
|
DCHECK_EQ(global_proxy_data->internal_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(
|
2016-11-04 10:02:02 +00:00
|
|
|
JS_GLOBAL_PROXY_TYPE, proxy_size, FAST_HOLEY_SMI_ELEMENTS);
|
2016-07-07 19:37:05 +00:00
|
|
|
JSFunction::SetInitialMap(global_proxy_function, global_proxy_map,
|
|
|
|
factory()->null_value());
|
|
|
|
global_proxy_map->set_is_access_check_needed(true);
|
|
|
|
global_proxy_map->set_is_callable();
|
|
|
|
global_proxy_map->set_is_constructor(true);
|
|
|
|
global_proxy_map->set_has_hidden_prototype(true);
|
|
|
|
|
|
|
|
Handle<String> global_name = factory()->global_string();
|
|
|
|
global_proxy_function->shared()->set_instance_class_name(*global_name);
|
|
|
|
factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function);
|
|
|
|
|
|
|
|
// HookUpGlobalProxy.
|
2016-10-26 11:22:14 +00:00
|
|
|
global_proxy->set_native_context(heap()->null_value());
|
2016-07-07 19:37:05 +00:00
|
|
|
|
|
|
|
// DetachGlobal.
|
2016-07-19 11:28:43 +00:00
|
|
|
JSObject::ForceSetPrototype(global_proxy, factory()->null_value());
|
2016-07-07 19:37:05 +00:00
|
|
|
|
|
|
|
global_proxy_ = global_proxy;
|
|
|
|
}
|
2009-01-26 18:09:46 +00:00
|
|
|
|
|
|
|
// Support for thread preemption.
|
|
|
|
|
|
|
|
// Reserve space for statics needing saving and restoring.
|
|
|
|
int Bootstrapper::ArchiveSpacePerThread() {
|
2011-03-18 20:35:07 +00:00
|
|
|
return sizeof(NestingCounterType);
|
2009-01-26 18:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-22 15:27:57 +00:00
|
|
|
// Archive statics that are thread-local.
|
2009-01-26 18:09:46 +00:00
|
|
|
char* Bootstrapper::ArchiveState(char* to) {
|
2011-03-18 20:35:07 +00:00
|
|
|
*reinterpret_cast<NestingCounterType*>(to) = nesting_;
|
|
|
|
nesting_ = 0;
|
|
|
|
return to + sizeof(NestingCounterType);
|
2009-01-26 18:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-22 15:27:57 +00:00
|
|
|
// Restore statics that are thread-local.
|
2009-01-26 18:09:46 +00:00
|
|
|
char* Bootstrapper::RestoreState(char* from) {
|
2011-03-18 20:35:07 +00:00
|
|
|
nesting_ = *reinterpret_cast<NestingCounterType*>(from);
|
|
|
|
return from + sizeof(NestingCounterType);
|
2009-01-26 18:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-28 12:25:21 +00:00
|
|
|
// Called when the top-level V8 mutex is destroyed.
|
|
|
|
void Bootstrapper::FreeThreadResources() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!IsActive());
|
2009-01-26 18:09:46 +00:00
|
|
|
}
|
|
|
|
|
2015-06-01 22:46:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|