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"
|
2015-04-21 10:21:50 +00:00
|
|
|
#include "src/base/utils/random-number-generator.h"
|
2014-06-20 08:40:11 +00:00
|
|
|
#include "src/code-stubs.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"
|
|
|
|
#include "src/extensions/statistics-extension.h"
|
|
|
|
#include "src/extensions/trigger-failure-extension.h"
|
2015-03-27 15:28:55 +00:00
|
|
|
#include "src/snapshot/natives.h"
|
|
|
|
#include "src/snapshot/snapshot.h"
|
2014-08-06 11:39:39 +00:00
|
|
|
#include "third_party/fdlibm/fdlibm.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<String> Bootstrapper::NativesSourceLookup(int index) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(0 <= index && index < Natives::GetBuiltinsCount());
|
2013-02-15 09:27:10 +00:00
|
|
|
Heap* heap = isolate_->heap();
|
2011-03-28 13:09:37 +00:00
|
|
|
if (heap->natives_source_cache()->get(index)->IsUndefined()) {
|
2012-01-30 12:25:29 +00:00
|
|
|
// We can use external strings for the natives.
|
2014-12-04 18:51:15 +00:00
|
|
|
Vector<const char> source = Natives::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());
|
2014-03-25 09:09:24 +00:00
|
|
|
// We do not expect this to throw an exception. Change this if it does.
|
2014-09-10 12:38:12 +00:00
|
|
|
Handle<String> source_code = isolate_->factory()
|
|
|
|
->NewExternalStringFromOneByte(resource)
|
|
|
|
.ToHandleChecked();
|
2014-10-02 09:39:13 +00:00
|
|
|
// Mark this external string with a special map.
|
|
|
|
source_code->set_map(isolate_->heap()->native_source_string_map());
|
2012-01-30 12:25:29 +00:00
|
|
|
heap->natives_source_cache()->set(index, *source_code);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2013-02-25 14:46:09 +00:00
|
|
|
Handle<Object> cached_source(heap->natives_source_cache()->get(index),
|
|
|
|
isolate_);
|
2008-07-03 15:10:15 +00:00
|
|
|
return Handle<String>::cast(cached_source);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
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_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Bootstrapper::TearDown() {
|
2015-02-09 09:04:45 +00:00
|
|
|
Object* natives_source_cache = isolate_->heap()->natives_source_cache();
|
|
|
|
if (natives_source_cache->IsFixedArray()) {
|
|
|
|
FixedArray* natives_source_array = FixedArray::cast(natives_source_cache);
|
|
|
|
for (int i = 0; i < Natives::GetBuiltinsCount(); i++) {
|
|
|
|
Object* natives_source = natives_source_array->get(i);
|
|
|
|
if (!natives_source->IsUndefined()) {
|
|
|
|
const NativesExternalStringResource* resource =
|
|
|
|
reinterpret_cast<const NativesExternalStringResource*>(
|
|
|
|
ExternalOneByteString::cast(natives_source)->resource());
|
|
|
|
delete resource;
|
|
|
|
}
|
2009-12-11 10:40:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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:
|
2011-04-14 08:01:19 +00:00
|
|
|
Genesis(Isolate* isolate,
|
2014-07-01 12:12:34 +00:00
|
|
|
MaybeHandle<JSGlobalProxy> maybe_global_proxy,
|
|
|
|
v8::Handle<v8::ObjectTemplate> global_proxy_template,
|
2008-07-03 15:10:15 +00:00
|
|
|
v8::ExtensionConfiguration* extensions);
|
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
|
|
|
|
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);
|
2015-02-25 14:52:36 +00:00
|
|
|
void CreateStrongModeFunctionMaps(Handle<JSFunction> empty);
|
2012-02-20 08:42:18 +00:00
|
|
|
|
|
|
|
// Make the "arguments" and "caller" properties throw a TypeError on access.
|
2015-04-09 22:40:16 +00:00
|
|
|
void AddRestrictedFunctionProperties(Handle<Map> map);
|
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-01-14 16:42:15 +00:00
|
|
|
Handle<GlobalObject> CreateNewGlobals(
|
2014-07-01 12:12:34 +00:00
|
|
|
v8::Handle<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.
|
2014-07-01 12:12:34 +00:00
|
|
|
void HookUpGlobalProxy(Handle<GlobalObject> 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-01-13 08:48:00 +00:00
|
|
|
void HookUpGlobalObject(Handle<GlobalObject> global_object,
|
|
|
|
Handle<FixedArray> outdated_contexts);
|
2010-03-23 11:40:38 +00:00
|
|
|
// New context initialization. Used for creating a context from scratch.
|
2014-07-01 12:12:34 +00:00
|
|
|
void InitializeGlobal(Handle<GlobalObject> global_object,
|
2010-03-23 11:40:38 +00:00
|
|
|
Handle<JSFunction> empty_function);
|
2014-09-19 07:36:05 +00:00
|
|
|
void InitializeExperimentalGlobal();
|
2010-03-23 11:40:38 +00:00
|
|
|
// Installs the contents of the native .js files on the global objects.
|
|
|
|
// Used for creating a context from scratch.
|
2008-07-03 15:10:15 +00:00
|
|
|
void InstallNativeFunctions();
|
2011-05-18 14:00:34 +00:00
|
|
|
void InstallExperimentalNativeFunctions();
|
2015-02-06 09:54:58 +00:00
|
|
|
// Typed arrays are not serializable and have to initialized afterwards.
|
|
|
|
void InitializeBuiltinTypedArrays();
|
2014-10-20 13:33:34 +00:00
|
|
|
|
|
|
|
#define DECLARE_FEATURE_INITIALIZATION(id, descr) \
|
|
|
|
void InstallNativeFunctions_##id(); \
|
|
|
|
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
|
|
|
|
|
2013-02-15 15:20:05 +00:00
|
|
|
Handle<JSFunction> InstallInternalArray(Handle<JSBuiltinsObject> builtins,
|
|
|
|
const char* name,
|
|
|
|
ElementsKind elements_kind);
|
2008-07-03 15:10:15 +00:00
|
|
|
bool InstallNatives();
|
2013-04-16 14:16:30 +00:00
|
|
|
|
2014-04-22 12:24:28 +00:00
|
|
|
void InstallTypedArray(
|
|
|
|
const char* name,
|
|
|
|
ElementsKind elements_kind,
|
|
|
|
Handle<JSFunction>* fun,
|
|
|
|
Handle<Map>* external_map);
|
2011-04-15 12:31:03 +00:00
|
|
|
bool InstallExperimentalNatives();
|
2010-12-14 18:53:48 +00:00
|
|
|
void InstallBuiltinFunctionIds();
|
2010-04-14 14:46:15 +00:00
|
|
|
void InstallJSFunctionResultCaches();
|
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:
|
2011-11-15 22:48:55 +00:00
|
|
|
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);
|
2010-02-11 08:05:33 +00:00
|
|
|
bool InstallJSBuiltins(Handle<JSBuiltinsObject> builtins);
|
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(
|
|
|
|
v8::Handle<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);
|
|
|
|
|
2014-06-13 12:19:04 +00:00
|
|
|
enum FunctionMode {
|
|
|
|
// With prototype.
|
|
|
|
FUNCTION_WITH_WRITEABLE_PROTOTYPE,
|
|
|
|
FUNCTION_WITH_READONLY_PROTOTYPE,
|
|
|
|
// Without prototype.
|
|
|
|
FUNCTION_WITHOUT_PROTOTYPE,
|
|
|
|
BOUND_FUNCTION
|
2010-04-28 12:05:40 +00:00
|
|
|
};
|
2011-03-17 20:28:17 +00:00
|
|
|
|
2014-06-13 12:19:04 +00:00
|
|
|
static bool IsFunctionModeWithPrototype(FunctionMode function_mode) {
|
|
|
|
return (function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE ||
|
|
|
|
function_mode == FUNCTION_WITH_READONLY_PROTOTYPE);
|
|
|
|
}
|
|
|
|
|
2015-02-25 14:52:36 +00:00
|
|
|
Handle<Map> CreateSloppyFunctionMap(FunctionMode function_mode);
|
2011-03-17 20:28:17 +00:00
|
|
|
|
2012-07-18 15:38:58 +00:00
|
|
|
void SetFunctionInstanceDescriptor(Handle<Map> map,
|
2014-06-13 12:19:04 +00:00
|
|
|
FunctionMode function_mode);
|
2008-07-03 15:10:15 +00:00
|
|
|
void MakeFunctionInstancePrototypeWritable();
|
|
|
|
|
2015-02-25 14:52:36 +00:00
|
|
|
Handle<Map> CreateStrictFunctionMap(FunctionMode function_mode,
|
|
|
|
Handle<JSFunction> empty_function);
|
|
|
|
Handle<Map> CreateStrongFunctionMap(Handle<JSFunction> empty_function,
|
|
|
|
bool is_constructor);
|
|
|
|
|
2011-03-17 20:28:17 +00:00
|
|
|
|
2012-07-18 15:38:58 +00:00
|
|
|
void SetStrictFunctionInstanceDescriptor(Handle<Map> map,
|
2014-06-13 12:19:04 +00:00
|
|
|
FunctionMode function_mode);
|
2015-02-25 14:52:36 +00:00
|
|
|
void SetStrongFunctionInstanceDescriptor(Handle<Map> map);
|
2011-03-17 20:28:17 +00:00
|
|
|
|
2011-04-14 08:01:19 +00:00
|
|
|
static bool CompileBuiltin(Isolate* isolate, int index);
|
2011-04-15 12:31:03 +00:00
|
|
|
static bool CompileExperimentalBuiltin(Isolate* isolate, int index);
|
2013-02-15 09:27:10 +00:00
|
|
|
static bool CompileNative(Isolate* isolate,
|
|
|
|
Vector<const char> name,
|
|
|
|
Handle<String> source);
|
|
|
|
static bool CompileScriptCached(Isolate* isolate,
|
|
|
|
Vector<const char> name,
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<String> source,
|
|
|
|
SourceCodeCache* cache,
|
|
|
|
v8::Extension* extension,
|
2010-03-23 11:40:38 +00:00
|
|
|
Handle<Context> top_context,
|
2008-07-03 15:10:15 +00:00
|
|
|
bool use_runtime_context);
|
|
|
|
|
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_;
|
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,
|
|
|
|
v8::Handle<v8::ObjectTemplate> global_proxy_template,
|
2008-07-03 15:10:15 +00:00
|
|
|
v8::ExtensionConfiguration* extensions) {
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(isolate_);
|
2014-07-01 12:12:34 +00:00
|
|
|
Genesis genesis(
|
|
|
|
isolate_, maybe_global_proxy, global_proxy_template, extensions);
|
2013-04-10 09:34:37 +00:00
|
|
|
Handle<Context> env = genesis.result();
|
|
|
|
if (env.is_null() || !InstallExtensions(env, extensions)) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) {
|
|
|
|
// object.__proto__ = proto;
|
2014-06-24 14:53:48 +00:00
|
|
|
Handle<Map> old_map = Handle<Map>(object->map());
|
2014-11-07 16:03:11 +00:00
|
|
|
Handle<Map> new_map = Map::Copy(old_map, "SetObjectPrototype");
|
2015-04-10 12:13:18 +00:00
|
|
|
Map::SetPrototype(new_map, proto, FAST_PROTOTYPE);
|
2014-06-24 14:53:48 +00:00
|
|
|
JSObject::MigrateToMap(object, new_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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Bootstrapper::DetachGlobal(Handle<Context> env) {
|
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());
|
|
|
|
SetObjectPrototype(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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
static Handle<JSFunction> InstallFunction(Handle<JSObject> target,
|
2015-04-09 22:40:16 +00:00
|
|
|
const char* name, InstanceType type,
|
2008-07-03 15:10:15 +00:00
|
|
|
int instance_size,
|
2014-05-09 16:34:58 +00:00
|
|
|
MaybeHandle<JSObject> maybe_prototype,
|
2015-04-09 22:40:16 +00:00
|
|
|
Builtins::Name call,
|
|
|
|
bool strict_function_map = false) {
|
2011-04-14 08:01:19 +00:00
|
|
|
Isolate* isolate = target->GetIsolate();
|
2011-03-28 13:09:37 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> internalized_name = factory->InternalizeUtf8String(name);
|
2011-03-28 13:09:37 +00:00
|
|
|
Handle<Code> call_code = Handle<Code>(isolate->builtins()->builtin(call));
|
2014-05-09 16:59:03 +00:00
|
|
|
Handle<JSObject> prototype;
|
2015-04-09 22:40:16 +00:00
|
|
|
static const bool kReadOnlyPrototype = false;
|
|
|
|
static const bool kInstallConstructor = false;
|
|
|
|
Handle<JSFunction> function =
|
|
|
|
maybe_prototype.ToHandle(&prototype)
|
|
|
|
? factory->NewFunction(internalized_name, call_code, prototype, type,
|
|
|
|
instance_size, kReadOnlyPrototype,
|
|
|
|
kInstallConstructor, strict_function_map)
|
|
|
|
: factory->NewFunctionWithoutPrototype(internalized_name, call_code,
|
|
|
|
strict_function_map);
|
2011-09-01 11:57:02 +00:00
|
|
|
PropertyAttributes attributes;
|
|
|
|
if (target->IsJSBuiltinsObject()) {
|
|
|
|
attributes =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
|
|
|
|
} else {
|
|
|
|
attributes = DONT_ENUM;
|
|
|
|
}
|
2014-06-30 13:48:57 +00:00
|
|
|
JSObject::AddProperty(target, internalized_name, function, attributes);
|
2014-05-09 17:21:51 +00:00
|
|
|
if (target->IsJSGlobalObject()) {
|
2013-02-28 17:03:34 +00:00
|
|
|
function->shared()->set_instance_class_name(*internalized_name);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-10-20 12:31:33 +00:00
|
|
|
function->shared()->set_native(true);
|
2008-07-03 15:10:15 +00:00
|
|
|
return function;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-09 22:40:16 +00:00
|
|
|
void Genesis::SetFunctionInstanceDescriptor(Handle<Map> map,
|
|
|
|
FunctionMode function_mode) {
|
2014-06-13 12:19:04 +00:00
|
|
|
int size = IsFunctionModeWithPrototype(function_mode) ? 5 : 4;
|
2014-04-11 12:13:53 +00:00
|
|
|
Map::EnsureDescriptorSlack(map, size);
|
2012-07-23 16:18:25 +00:00
|
|
|
|
2015-03-04 16:56:55 +00:00
|
|
|
PropertyAttributes ro_attribs =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
|
|
|
|
PropertyAttributes roc_attribs =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
|
2011-10-21 10:32:38 +00:00
|
|
|
|
2014-04-24 11:24:13 +00:00
|
|
|
Handle<AccessorInfo> length =
|
2015-03-13 17:19:40 +00:00
|
|
|
Accessors::FunctionLengthInfo(isolate(), roc_attribs);
|
2011-03-17 20:28:17 +00:00
|
|
|
{ // Add length.
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(Handle<Name>(Name::cast(length->name())),
|
2015-03-13 17:19:40 +00:00
|
|
|
length, roc_attribs);
|
2014-04-11 12:13:53 +00:00
|
|
|
map->AppendDescriptor(&d);
|
2011-03-17 20:28:17 +00:00
|
|
|
}
|
2014-04-28 08:26:35 +00:00
|
|
|
Handle<AccessorInfo> name =
|
2015-03-04 16:56:55 +00:00
|
|
|
Accessors::FunctionNameInfo(isolate(), ro_attribs);
|
2011-03-17 20:28:17 +00:00
|
|
|
{ // Add name.
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(Handle<Name>(Name::cast(name->name())), name,
|
2015-03-04 16:56:55 +00:00
|
|
|
roc_attribs);
|
2014-04-11 12:13:53 +00:00
|
|
|
map->AppendDescriptor(&d);
|
2011-03-17 20:28:17 +00:00
|
|
|
}
|
2014-04-28 12:02:11 +00:00
|
|
|
Handle<AccessorInfo> args =
|
2015-03-04 16:56:55 +00:00
|
|
|
Accessors::FunctionArgumentsInfo(isolate(), ro_attribs);
|
2011-03-17 20:28:17 +00:00
|
|
|
{ // Add arguments.
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(Handle<Name>(Name::cast(args->name())), args,
|
2015-03-04 16:56:55 +00:00
|
|
|
ro_attribs);
|
2014-04-11 12:13:53 +00:00
|
|
|
map->AppendDescriptor(&d);
|
2011-03-17 20:28:17 +00:00
|
|
|
}
|
2014-04-28 13:41:12 +00:00
|
|
|
Handle<AccessorInfo> caller =
|
2015-03-04 16:56:55 +00:00
|
|
|
Accessors::FunctionCallerInfo(isolate(), ro_attribs);
|
2011-03-17 20:28:17 +00:00
|
|
|
{ // Add caller.
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(Handle<Name>(Name::cast(caller->name())),
|
2015-03-04 16:56:55 +00:00
|
|
|
caller, ro_attribs);
|
2014-04-11 12:13:53 +00:00
|
|
|
map->AppendDescriptor(&d);
|
2011-03-17 20:28:17 +00:00
|
|
|
}
|
2014-06-13 12:19:04 +00:00
|
|
|
if (IsFunctionModeWithPrototype(function_mode)) {
|
|
|
|
if (function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE) {
|
2015-03-04 16:56:55 +00:00
|
|
|
ro_attribs = static_cast<PropertyAttributes>(ro_attribs & ~READ_ONLY);
|
2014-02-07 15:29:18 +00:00
|
|
|
}
|
2014-04-24 08:35:53 +00:00
|
|
|
Handle<AccessorInfo> prototype =
|
2015-03-04 16:56:55 +00:00
|
|
|
Accessors::FunctionPrototypeInfo(isolate(), ro_attribs);
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())),
|
2015-03-04 16:56:55 +00:00
|
|
|
prototype, ro_attribs);
|
2014-04-11 12:13:53 +00:00
|
|
|
map->AppendDescriptor(&d);
|
2010-04-28 12:05:40 +00:00
|
|
|
}
|
2011-03-17 20:28:17 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2015-02-25 14:52:36 +00:00
|
|
|
Handle<Map> Genesis::CreateSloppyFunctionMap(FunctionMode function_mode) {
|
2011-04-14 08:01:19 +00:00
|
|
|
Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
|
2014-06-13 12:19:04 +00:00
|
|
|
SetFunctionInstanceDescriptor(map, function_mode);
|
|
|
|
map->set_function_with_prototype(IsFunctionModeWithPrototype(function_mode));
|
2011-03-17 20:28:17 +00:00
|
|
|
return map;
|
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 =
|
2015-02-25 14:52:36 +00:00
|
|
|
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 =
|
2015-02-25 14:52:36 +00:00
|
|
|
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_ =
|
2015-02-25 14:52:36 +00:00
|
|
|
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);
|
|
|
|
object_function_map->set_inobject_properties(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);
|
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
|
2014-04-17 11:57:32 +00:00
|
|
|
Handle<Code> code(isolate->builtins()->builtin(Builtins::kEmptyFunction));
|
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 =
|
2015-02-25 14:52:36 +00:00
|
|
|
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);
|
2010-03-23 11:40:38 +00:00
|
|
|
script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
|
|
|
|
empty_function->shared()->set_script(*script);
|
|
|
|
empty_function->shared()->set_start_position(0);
|
|
|
|
empty_function->shared()->set_end_position(source->length());
|
|
|
|
empty_function->shared()->DontAdaptArguments();
|
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
|
|
|
|
|
|
|
// ES6 draft 03-17-2015, section 8.2.2 step 12
|
|
|
|
AddRestrictedFunctionProperties(empty_function_map);
|
|
|
|
|
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-09 22:40:16 +00:00
|
|
|
void Genesis::SetStrictFunctionInstanceDescriptor(Handle<Map> map,
|
|
|
|
FunctionMode function_mode) {
|
2014-06-13 12:19:04 +00:00
|
|
|
int size = IsFunctionModeWithPrototype(function_mode) ? 5 : 4;
|
2014-04-11 12:13:53 +00:00
|
|
|
Map::EnsureDescriptorSlack(map, size);
|
2012-07-23 16:18:25 +00:00
|
|
|
|
2013-06-18 07:51:50 +00:00
|
|
|
PropertyAttributes rw_attribs =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE);
|
|
|
|
PropertyAttributes ro_attribs =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
|
2015-03-04 16:56:55 +00:00
|
|
|
PropertyAttributes roc_attribs =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
|
2011-10-21 10:32:38 +00:00
|
|
|
|
2014-06-13 12:19:04 +00:00
|
|
|
// Add length.
|
|
|
|
if (function_mode == BOUND_FUNCTION) {
|
|
|
|
Handle<String> length_string = isolate()->factory()->length_string();
|
2015-01-19 17:49:13 +00:00
|
|
|
DataDescriptor d(length_string, 0, ro_attribs, Representation::Tagged());
|
2014-06-13 12:19:04 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
} else {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE ||
|
2014-06-13 12:19:04 +00:00
|
|
|
function_mode == FUNCTION_WITH_READONLY_PROTOTYPE ||
|
|
|
|
function_mode == FUNCTION_WITHOUT_PROTOTYPE);
|
|
|
|
Handle<AccessorInfo> length =
|
2015-03-13 17:19:40 +00:00
|
|
|
Accessors::FunctionLengthInfo(isolate(), roc_attribs);
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(Handle<Name>(Name::cast(length->name())),
|
2015-03-13 17:19:40 +00:00
|
|
|
length, roc_attribs);
|
2014-04-11 12:13:53 +00:00
|
|
|
map->AppendDescriptor(&d);
|
2011-03-17 20:28:17 +00:00
|
|
|
}
|
2014-04-28 08:26:35 +00:00
|
|
|
Handle<AccessorInfo> name =
|
2015-03-04 16:56:55 +00:00
|
|
|
Accessors::FunctionNameInfo(isolate(), roc_attribs);
|
2012-02-20 08:42:18 +00:00
|
|
|
{ // Add name.
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(Handle<Name>(Name::cast(name->name())), name,
|
2015-03-04 16:56:55 +00:00
|
|
|
roc_attribs);
|
2014-04-11 12:13:53 +00:00
|
|
|
map->AppendDescriptor(&d);
|
2011-03-17 20:28:17 +00:00
|
|
|
}
|
2014-06-13 12:19:04 +00:00
|
|
|
if (IsFunctionModeWithPrototype(function_mode)) {
|
2012-02-20 08:42:18 +00:00
|
|
|
// Add prototype.
|
2013-06-18 07:51:50 +00:00
|
|
|
PropertyAttributes attribs =
|
2014-06-13 12:19:04 +00:00
|
|
|
function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE ? rw_attribs
|
|
|
|
: ro_attribs;
|
2014-04-24 08:35:53 +00:00
|
|
|
Handle<AccessorInfo> prototype =
|
|
|
|
Accessors::FunctionPrototypeInfo(isolate(), attribs);
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())),
|
|
|
|
prototype, attribs);
|
2014-04-11 12:13:53 +00:00
|
|
|
map->AppendDescriptor(&d);
|
2011-03-17 20:28:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-25 14:52:36 +00:00
|
|
|
void Genesis::SetStrongFunctionInstanceDescriptor(Handle<Map> map) {
|
|
|
|
Map::EnsureDescriptorSlack(map, 2);
|
|
|
|
|
|
|
|
PropertyAttributes ro_attribs =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
|
|
|
|
|
|
|
|
Handle<AccessorInfo> length =
|
|
|
|
Accessors::FunctionLengthInfo(isolate(), ro_attribs);
|
|
|
|
{ // Add length.
|
|
|
|
AccessorConstantDescriptor d(Handle<Name>(Name::cast(length->name())),
|
|
|
|
length, ro_attribs);
|
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
Handle<AccessorInfo> name =
|
|
|
|
Accessors::FunctionNameInfo(isolate(), ro_attribs);
|
|
|
|
{ // Add name.
|
|
|
|
AccessorConstantDescriptor d(Handle<Name>(Name::cast(name->name())), name,
|
|
|
|
ro_attribs);
|
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 =
|
|
|
|
factory()->NewFunctionWithoutPrototype(name, code);
|
|
|
|
function->set_map(native_context()->sloppy_function_map());
|
|
|
|
function->shared()->DontAdaptArguments();
|
|
|
|
|
|
|
|
// %ThrowTypeError% must not have a name property.
|
|
|
|
JSReceiver::DeleteProperty(function, factory()->name_string()).Assert();
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
JSObject::PreventExtensions(function).Assert();
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-11 14:41:22 +00:00
|
|
|
Handle<Map> Genesis::CreateStrictFunctionMap(
|
2015-04-09 22:40:16 +00:00
|
|
|
FunctionMode function_mode, Handle<JSFunction> empty_function) {
|
2011-04-14 08:01:19 +00:00
|
|
|
Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
|
2014-06-13 12:19:04 +00:00
|
|
|
SetStrictFunctionInstanceDescriptor(map, function_mode);
|
|
|
|
map->set_function_with_prototype(IsFunctionModeWithPrototype(function_mode));
|
2015-04-10 12:13:18 +00:00
|
|
|
Map::SetPrototype(map, empty_function);
|
2011-03-17 20:28:17 +00:00
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-25 14:52:36 +00:00
|
|
|
Handle<Map> Genesis::CreateStrongFunctionMap(
|
|
|
|
Handle<JSFunction> empty_function, bool is_constructor) {
|
|
|
|
Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
|
|
|
|
SetStrongFunctionInstanceDescriptor(map);
|
|
|
|
map->set_function_with_prototype(is_constructor);
|
2015-04-10 12:13:18 +00:00
|
|
|
Map::SetPrototype(map, empty_function);
|
2015-02-25 14:52:36 +00:00
|
|
|
map->set_is_extensible(is_constructor);
|
|
|
|
// TODO(rossberg): mark strong
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 =
|
2014-06-13 12:19:04 +00:00
|
|
|
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.
|
2014-03-11 14:41:22 +00:00
|
|
|
Handle<Map> strict_function_map =
|
2014-06-13 12:19:04 +00:00
|
|
|
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.
|
2014-03-11 14:41:22 +00:00
|
|
|
strict_function_map_writable_prototype_ =
|
2014-06-13 12:19:04 +00:00
|
|
|
CreateStrictFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE, empty);
|
2015-04-09 22:40:16 +00:00
|
|
|
|
2014-06-13 12:19:04 +00:00
|
|
|
// Special map for bound functions.
|
|
|
|
Handle<Map> bound_function_map =
|
|
|
|
CreateStrictFunctionMap(BOUND_FUNCTION, empty);
|
|
|
|
native_context()->set_bound_function_map(*bound_function_map);
|
2012-02-20 08:42:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-25 14:52:36 +00:00
|
|
|
void Genesis::CreateStrongModeFunctionMaps(Handle<JSFunction> empty) {
|
|
|
|
// Allocate map for strong mode instances, which never have prototypes.
|
|
|
|
Handle<Map> strong_function_map = CreateStrongFunctionMap(empty, false);
|
|
|
|
native_context()->set_strong_function_map(*strong_function_map);
|
|
|
|
// Constructors do, though.
|
|
|
|
Handle<Map> strong_constructor_map = CreateStrongFunctionMap(empty, true);
|
|
|
|
native_context()->set_strong_constructor_map(*strong_constructor_map);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
int idx = descriptors->SearchWithCache(*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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-09 22:40:16 +00:00
|
|
|
void Genesis::AddRestrictedFunctionProperties(Handle<Map> map) {
|
|
|
|
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);
|
|
|
|
|
|
|
|
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());
|
2011-04-14 08:01:19 +00:00
|
|
|
Heap* heap = context->GetIsolate()->heap();
|
2010-12-07 11:31:57 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
{ // NOLINT
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(context->get(Context::NEXT_CONTEXT_LINK)->IsUndefined());
|
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();
|
2010-12-07 11:31:57 +00:00
|
|
|
!current->IsUndefined();
|
|
|
|
current = Context::cast(current)->get(Context::NEXT_CONTEXT_LINK)) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(current != context);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2012-08-17 09:03:08 +00:00
|
|
|
context->set(Context::NEXT_CONTEXT_LINK, heap->native_contexts_list());
|
|
|
|
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.
|
|
|
|
{
|
2014-01-08 14:44:30 +00:00
|
|
|
v8::NeanderArray listeners(isolate());
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_message_listeners(*listeners.value());
|
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-01-14 16:42:15 +00:00
|
|
|
Handle<GlobalObject> Genesis::CreateNewGlobals(
|
2014-07-01 12:12:34 +00:00
|
|
|
v8::Handle<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());
|
2010-03-23 11:40:38 +00:00
|
|
|
if (!proto_template->IsUndefined()) {
|
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());
|
2011-04-14 08:01:19 +00:00
|
|
|
Handle<Code> code = Handle<Code>(isolate()->builtins()->builtin(
|
2011-03-23 13:40:07 +00:00
|
|
|
Builtins::kIllegal));
|
2014-07-07 13:12:29 +00:00
|
|
|
Handle<JSObject> prototype =
|
2014-07-07 13:27:37 +00:00
|
|
|
factory()->NewFunctionPrototype(isolate()->object_function());
|
|
|
|
js_global_object_function = factory()->NewFunction(
|
|
|
|
name, code, prototype, JS_GLOBAL_OBJECT_TYPE, JSGlobalObject::kSize);
|
|
|
|
#ifdef DEBUG
|
|
|
|
LookupIterator it(prototype, factory()->constructor_string(),
|
2014-09-03 14:05:55 +00:00
|
|
|
LookupIterator::OWN_SKIP_INTERCEPTOR);
|
2014-07-07 13:27:37 +00:00
|
|
|
Handle<Object> value = JSReceiver::GetProperty(&it).ToHandleChecked();
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(it.IsFound());
|
|
|
|
DCHECK_EQ(*isolate()->object_function(), *value);
|
2014-07-07 13:27:37 +00:00
|
|
|
#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(
|
|
|
|
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_is_hidden_prototype();
|
|
|
|
js_global_object_function->initial_map()->set_dictionary_map(true);
|
|
|
|
Handle<GlobalObject> global_object =
|
|
|
|
factory()->NewGlobalObject(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());
|
2011-04-14 08:01:19 +00:00
|
|
|
Handle<Code> code = Handle<Code>(isolate()->builtins()->builtin(
|
2011-03-23 13:40:07 +00:00
|
|
|
Builtins::kIllegal));
|
2014-05-09 16:42:57 +00:00
|
|
|
global_proxy_function = factory()->NewFunction(
|
2014-05-09 17:39:54 +00:00
|
|
|
name, code, JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize);
|
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(
|
|
|
|
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);
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-01 12:12:34 +00:00
|
|
|
void Genesis::HookUpGlobalProxy(Handle<GlobalObject> 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.
|
|
|
|
DCHECK(native_context()->get(Context::GLOBAL_PROXY_INDEX)->IsUndefined() ||
|
|
|
|
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-01-13 08:48:00 +00:00
|
|
|
void Genesis::HookUpGlobalObject(Handle<GlobalObject> global_object,
|
|
|
|
Handle<FixedArray> outdated_contexts) {
|
2014-07-01 12:12:34 +00:00
|
|
|
Handle<GlobalObject> global_object_from_snapshot(
|
2013-03-18 17:36:47 +00:00
|
|
|
GlobalObject::cast(native_context()->extension()));
|
|
|
|
Handle<JSBuiltinsObject> builtins_global(native_context()->builtins());
|
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
|
|
|
|
|
|
|
// Replace outdated global objects in deserialized contexts.
|
|
|
|
for (int i = 0; i < outdated_contexts->length(); ++i) {
|
|
|
|
Context* context = Context::cast(outdated_contexts->get(i));
|
2015-04-20 09:57:15 +00:00
|
|
|
// Assert that there is only one native context.
|
|
|
|
DCHECK(!context->IsNativeContext() || context == *native_context());
|
2015-01-13 08:48:00 +00:00
|
|
|
DCHECK_EQ(context->global_object(), *global_object_from_snapshot);
|
|
|
|
context->set_global_object(*global_object);
|
|
|
|
}
|
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
static const PropertyAttributes attributes =
|
|
|
|
static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE);
|
2014-08-18 07:54:19 +00:00
|
|
|
Runtime::DefineObjectProperty(builtins_global, factory()->global_string(),
|
|
|
|
global_object, attributes).Assert();
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up the reference from the global object to the builtins object.
|
2014-07-01 12:12:34 +00:00
|
|
|
JSGlobalObject::cast(*global_object)->set_builtins(*builtins_global);
|
|
|
|
TransferNamedProperties(global_object_from_snapshot, global_object);
|
|
|
|
TransferIndexedProperties(global_object_from_snapshot, global_object);
|
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.
|
|
|
|
void Genesis::InitializeGlobal(Handle<GlobalObject> global_object,
|
2010-03-23 11:40:38 +00:00
|
|
|
Handle<JSFunction> empty_function) {
|
2013-10-14 13:25:36 +00:00
|
|
|
// --- N a t i v e C o n t e x t ---
|
2010-03-23 11:40:38 +00:00
|
|
|
// 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);
|
|
|
|
native_context()->set_global_object(*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();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
|
2014-11-12 11:34:09 +00:00
|
|
|
Handle<ScriptContextTable> script_context_table =
|
|
|
|
factory->NewScriptContextTable();
|
|
|
|
native_context()->set_script_context_table(*script_context_table);
|
2014-11-07 16:29:13 +00:00
|
|
|
|
2013-05-13 10:59:00 +00:00
|
|
|
Handle<String> object_name = factory->Object_string();
|
2014-06-30 13:48:57 +00:00
|
|
|
JSObject::AddProperty(
|
2014-07-01 12:12:34 +00:00
|
|
|
global_object, object_name, isolate->object_function(), DONT_ENUM);
|
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
|
|
|
|
|
|
|
// Install global Function object
|
|
|
|
InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize,
|
2014-05-09 17:21:51 +00:00
|
|
|
empty_function, Builtins::kIllegal);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
{ // --- A r r a y ---
|
|
|
|
Handle<JSFunction> array_function =
|
|
|
|
InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize,
|
2011-03-28 13:09:37 +00:00
|
|
|
isolate->initial_object_prototype(),
|
2014-05-09 17:21:51 +00:00
|
|
|
Builtins::kArrayCode);
|
2008-09-16 10:12:32 +00:00
|
|
|
array_function->shared()->DontAdaptArguments();
|
2013-06-19 09:25:24 +00:00
|
|
|
array_function->shared()->set_function_data(Smi::FromInt(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
|
|
|
|
|
|
|
// array_function is used internally. JS code creating array object should
|
|
|
|
// search for the 'Array' property on the global object and use that one
|
|
|
|
// as the constructor. 'Array' property on a global object can be
|
|
|
|
// overwritten by JS code.
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_array_function(*array_function);
|
2013-04-25 16:00:32 +00:00
|
|
|
|
2013-06-25 16:31:07 +00:00
|
|
|
// Cache the array maps, needed by ArrayConstructorStub
|
|
|
|
CacheInitialJSArrayMaps(native_context(), initial_map);
|
|
|
|
ArrayConstructorStub array_constructor_stub(isolate);
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> code = array_constructor_stub.GetCode();
|
2013-06-25 16:31:07 +00:00
|
|
|
array_function->shared()->set_construct_stub(*code);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // --- N u m b e r ---
|
|
|
|
Handle<JSFunction> number_fun =
|
|
|
|
InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize,
|
2011-03-28 13:09:37 +00:00
|
|
|
isolate->initial_object_prototype(),
|
2014-05-09 17:21:51 +00:00
|
|
|
Builtins::kIllegal);
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_number_function(*number_fun);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // --- B o o l e a n ---
|
|
|
|
Handle<JSFunction> boolean_fun =
|
|
|
|
InstallFunction(global, "Boolean", JS_VALUE_TYPE, JSValue::kSize,
|
2011-03-28 13:09:37 +00:00
|
|
|
isolate->initial_object_prototype(),
|
2014-05-09 17:21:51 +00:00
|
|
|
Builtins::kIllegal);
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_boolean_function(*boolean_fun);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // --- S t r i n g ---
|
|
|
|
Handle<JSFunction> string_fun =
|
|
|
|
InstallFunction(global, "String", JS_VALUE_TYPE, JSValue::kSize,
|
2011-03-28 13:09:37 +00:00
|
|
|
isolate->initial_object_prototype(),
|
2014-05-09 17:21:51 +00:00
|
|
|
Builtins::kIllegal);
|
2010-08-26 13:59:37 +00:00
|
|
|
string_fun->shared()->set_construct_stub(
|
2011-03-28 13:09:37 +00:00
|
|
|
isolate->builtins()->builtin(Builtins::kStringConstructCode));
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_string_function(*string_fun);
|
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());
|
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
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2014-08-06 09:31:21 +00:00
|
|
|
{
|
|
|
|
// --- S y m b o l ---
|
|
|
|
Handle<JSFunction> symbol_fun = InstallFunction(
|
|
|
|
global, "Symbol", JS_VALUE_TYPE, JSValue::kSize,
|
|
|
|
isolate->initial_object_prototype(), Builtins::kIllegal);
|
|
|
|
native_context()->set_symbol_function(*symbol_fun);
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
{ // --- D a t e ---
|
|
|
|
// Builtin functions for Date.prototype.
|
|
|
|
Handle<JSFunction> date_fun =
|
2012-03-09 11:11:55 +00:00
|
|
|
InstallFunction(global, "Date", JS_DATE_TYPE, JSDate::kSize,
|
2011-03-28 13:09:37 +00:00
|
|
|
isolate->initial_object_prototype(),
|
2014-05-09 17:21:51 +00:00
|
|
|
Builtins::kIllegal);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_date_function(*date_fun);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{ // -- R e g E x p
|
|
|
|
// Builtin functions for RegExp.prototype.
|
|
|
|
Handle<JSFunction> regexp_fun =
|
2008-09-23 11:45:43 +00:00
|
|
|
InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize,
|
2011-03-28 13:09:37 +00:00
|
|
|
isolate->initial_object_prototype(),
|
2014-05-09 17:21:51 +00:00
|
|
|
Builtins::kIllegal);
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_regexp_function(*regexp_fun);
|
2010-03-26 14:19:47 +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());
|
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK_EQ(0, initial_map->inobject_properties());
|
2010-03-26 14:19:47 +00:00
|
|
|
|
|
|
|
PropertyAttributes final =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
|
2014-04-11 12:13:53 +00:00
|
|
|
Map::EnsureDescriptorSlack(initial_map, 5);
|
2012-07-19 10:01:52 +00:00
|
|
|
|
2010-03-26 14:19:47 +00:00
|
|
|
{
|
|
|
|
// ECMA-262, section 15.10.7.1.
|
2015-04-09 13:22:17 +00:00
|
|
|
DataDescriptor field(factory->source_string(),
|
|
|
|
JSRegExp::kSourceFieldIndex, final,
|
|
|
|
Representation::Tagged());
|
|
|
|
initial_map->AppendDescriptor(&field);
|
2010-03-26 14:19:47 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
// ECMA-262, section 15.10.7.2.
|
2015-01-19 17:49:13 +00:00
|
|
|
DataDescriptor field(factory->global_string(),
|
|
|
|
JSRegExp::kGlobalFieldIndex, final,
|
|
|
|
Representation::Tagged());
|
2014-04-11 12:13:53 +00:00
|
|
|
initial_map->AppendDescriptor(&field);
|
2010-03-26 14:19:47 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
// ECMA-262, section 15.10.7.3.
|
2015-01-19 17:49:13 +00:00
|
|
|
DataDescriptor field(factory->ignore_case_string(),
|
|
|
|
JSRegExp::kIgnoreCaseFieldIndex, final,
|
|
|
|
Representation::Tagged());
|
2014-04-11 12:13:53 +00:00
|
|
|
initial_map->AppendDescriptor(&field);
|
2010-03-26 14:19:47 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
// ECMA-262, section 15.10.7.4.
|
2015-01-19 17:49:13 +00:00
|
|
|
DataDescriptor field(factory->multiline_string(),
|
|
|
|
JSRegExp::kMultilineFieldIndex, final,
|
|
|
|
Representation::Tagged());
|
2014-04-11 12:13:53 +00:00
|
|
|
initial_map->AppendDescriptor(&field);
|
2010-03-26 14:19:47 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
// ECMA-262, section 15.10.7.5.
|
|
|
|
PropertyAttributes writable =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE);
|
2015-01-19 17:49:13 +00:00
|
|
|
DataDescriptor field(factory->last_index_string(),
|
|
|
|
JSRegExp::kLastIndexFieldIndex, writable,
|
|
|
|
Representation::Tagged());
|
2014-04-11 12:13:53 +00:00
|
|
|
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;
|
|
|
|
initial_map->set_inobject_properties(num_fields);
|
|
|
|
initial_map->set_pre_allocated_property_fields(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);
|
2011-09-26 08:42:01 +00:00
|
|
|
|
|
|
|
// RegExp prototype object is itself a RegExp.
|
2014-11-07 16:03:11 +00:00
|
|
|
Handle<Map> proto_map = Map::Copy(initial_map, "RegExpPrototype");
|
2014-12-15 19:57:37 +00:00
|
|
|
DCHECK(proto_map->prototype() == *isolate->initial_object_prototype());
|
2011-09-26 08:42:01 +00:00
|
|
|
Handle<JSObject> proto = factory->NewJSObjectFromMap(proto_map);
|
2015-04-09 13:22:17 +00:00
|
|
|
proto->InObjectPropertyAtPut(JSRegExp::kSourceFieldIndex,
|
|
|
|
heap->query_colon_string());
|
2011-09-26 08:42:01 +00:00
|
|
|
proto->InObjectPropertyAtPut(JSRegExp::kGlobalFieldIndex,
|
|
|
|
heap->false_value());
|
|
|
|
proto->InObjectPropertyAtPut(JSRegExp::kIgnoreCaseFieldIndex,
|
|
|
|
heap->false_value());
|
|
|
|
proto->InObjectPropertyAtPut(JSRegExp::kMultilineFieldIndex,
|
|
|
|
heap->false_value());
|
|
|
|
proto->InObjectPropertyAtPut(JSRegExp::kLastIndexFieldIndex,
|
|
|
|
Smi::FromInt(0),
|
|
|
|
SKIP_WRITE_BARRIER); // It's a Smi.
|
2014-08-11 14:00:58 +00:00
|
|
|
proto_map->set_is_prototype_map(true);
|
2015-04-10 12:13:18 +00:00
|
|
|
Map::SetPrototype(initial_map, proto);
|
2011-09-26 08:42:01 +00:00
|
|
|
factory->SetRegExpIrregexpData(Handle<JSRegExp>::cast(proto),
|
|
|
|
JSRegExp::IRREGEXP, factory->empty_string(),
|
|
|
|
JSRegExp::Flags(0), 0);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2009-04-24 08:13:09 +00:00
|
|
|
{ // -- J S O N
|
2013-09-25 15:11:48 +00:00
|
|
|
Handle<String> name = factory->InternalizeUtf8String("JSON");
|
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));
|
2009-04-24 08:13:09 +00:00
|
|
|
cons->SetInstanceClassName(*name);
|
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);
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_json_object(*json_object);
|
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
|
2013-08-20 13:55:52 +00:00
|
|
|
Handle<JSFunction> array_buffer_fun =
|
|
|
|
InstallFunction(
|
|
|
|
global, "ArrayBuffer", JS_ARRAY_BUFFER_TYPE,
|
|
|
|
JSArrayBuffer::kSizeWithInternalFields,
|
|
|
|
isolate->initial_object_prototype(),
|
2014-05-09 17:21:51 +00:00
|
|
|
Builtins::kIllegal);
|
2013-08-20 13:55:52 +00:00
|
|
|
native_context()->set_array_buffer_fun(*array_buffer_fun);
|
2015-04-30 13:46:27 +00:00
|
|
|
native_context()->set_array_buffer_map(array_buffer_fun->initial_map());
|
2013-08-20 13:55:52 +00:00
|
|
|
}
|
|
|
|
|
2014-06-06 08:15:05 +00:00
|
|
|
{ // -- T y p e d A r r a y s
|
2014-01-24 16:01:15 +00:00
|
|
|
#define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype, size) \
|
|
|
|
{ \
|
2014-04-22 12:24:28 +00:00
|
|
|
Handle<JSFunction> fun; \
|
|
|
|
Handle<Map> external_map; \
|
|
|
|
InstallTypedArray(#Type "Array", \
|
|
|
|
TYPE##_ELEMENTS, \
|
|
|
|
&fun, \
|
|
|
|
&external_map); \
|
2014-01-24 16:01:15 +00:00
|
|
|
native_context()->set_##type##_array_fun(*fun); \
|
2014-04-22 12:24:28 +00:00
|
|
|
native_context()->set_##type##_array_external_map(*external_map); \
|
2014-01-24 16:01:15 +00:00
|
|
|
}
|
|
|
|
TYPED_ARRAYS(INSTALL_TYPED_ARRAY)
|
|
|
|
#undef INSTALL_TYPED_ARRAY
|
2013-08-20 13:55:52 +00:00
|
|
|
|
|
|
|
Handle<JSFunction> data_view_fun =
|
|
|
|
InstallFunction(
|
|
|
|
global, "DataView", JS_DATA_VIEW_TYPE,
|
|
|
|
JSDataView::kSizeWithInternalFields,
|
|
|
|
isolate->initial_object_prototype(),
|
2014-05-09 17:21:51 +00:00
|
|
|
Builtins::kIllegal);
|
2013-08-20 13:55:52 +00:00
|
|
|
native_context()->set_data_view_fun(*data_view_fun);
|
|
|
|
}
|
|
|
|
|
2014-08-05 19:37:32 +00:00
|
|
|
// -- M a p
|
|
|
|
InstallFunction(global, "Map", JS_MAP_TYPE, JSMap::kSize,
|
|
|
|
isolate->initial_object_prototype(), Builtins::kIllegal);
|
|
|
|
|
|
|
|
// -- S e t
|
|
|
|
InstallFunction(global, "Set", JS_SET_TYPE, JSSet::kSize,
|
|
|
|
isolate->initial_object_prototype(), Builtins::kIllegal);
|
|
|
|
|
|
|
|
{ // Set up the iterator result object
|
|
|
|
STATIC_ASSERT(JSGeneratorObject::kResultPropertyCount == 2);
|
|
|
|
Handle<JSFunction> object_function(native_context()->object_function());
|
|
|
|
Handle<Map> iterator_result_map =
|
2014-09-19 14:59:14 +00:00
|
|
|
Map::Create(isolate, JSGeneratorObject::kResultPropertyCount);
|
|
|
|
DCHECK_EQ(JSGeneratorObject::kResultSize,
|
|
|
|
iterator_result_map->instance_size());
|
|
|
|
DCHECK_EQ(JSGeneratorObject::kResultPropertyCount,
|
|
|
|
iterator_result_map->inobject_properties());
|
2014-08-05 19:37:32 +00:00
|
|
|
Map::EnsureDescriptorSlack(iterator_result_map,
|
|
|
|
JSGeneratorObject::kResultPropertyCount);
|
|
|
|
|
2015-01-19 17:49:13 +00:00
|
|
|
DataDescriptor value_descr(factory->value_string(),
|
|
|
|
JSGeneratorObject::kResultValuePropertyIndex,
|
|
|
|
NONE, Representation::Tagged());
|
2014-08-05 19:37:32 +00:00
|
|
|
iterator_result_map->AppendDescriptor(&value_descr);
|
|
|
|
|
2015-01-19 17:49:13 +00:00
|
|
|
DataDescriptor done_descr(factory->done_string(),
|
|
|
|
JSGeneratorObject::kResultDonePropertyIndex, NONE,
|
|
|
|
Representation::Tagged());
|
2014-08-05 19:37:32 +00:00
|
|
|
iterator_result_map->AppendDescriptor(&done_descr);
|
|
|
|
|
|
|
|
iterator_result_map->set_unused_property_fields(0);
|
2014-09-19 13:40:38 +00:00
|
|
|
iterator_result_map->set_pre_allocated_property_fields(
|
|
|
|
JSGeneratorObject::kResultPropertyCount);
|
2014-08-05 19:37:32 +00:00
|
|
|
DCHECK_EQ(JSGeneratorObject::kResultSize,
|
|
|
|
iterator_result_map->instance_size());
|
|
|
|
native_context()->set_iterator_result_map(*iterator_result_map);
|
|
|
|
}
|
|
|
|
|
2014-05-09 16:34:58 +00:00
|
|
|
// -- W e a k M a p
|
|
|
|
InstallFunction(global, "WeakMap", JS_WEAK_MAP_TYPE, JSWeakMap::kSize,
|
2014-05-09 17:21:51 +00:00
|
|
|
isolate->initial_object_prototype(), Builtins::kIllegal);
|
2014-05-09 16:34:58 +00:00
|
|
|
// -- W e a k S e t
|
|
|
|
InstallFunction(global, "WeakSet", JS_WEAK_SET_TYPE, JSWeakSet::kSize,
|
2014-05-09 17:21:51 +00:00
|
|
|
isolate->initial_object_prototype(), Builtins::kIllegal);
|
2014-05-06 14:48:34 +00:00
|
|
|
|
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();
|
2014-04-22 08:30:09 +00:00
|
|
|
Handle<Code> code(isolate->builtins()->builtin(Builtins::kIllegal));
|
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
|
|
|
|
2014-07-07 13:27:37 +00:00
|
|
|
Handle<Map> map =
|
|
|
|
factory->NewMap(JS_OBJECT_TYPE, Heap::kSloppyArgumentsObjectSize);
|
|
|
|
// Create the descriptor array for the arguments object.
|
|
|
|
Map::EnsureDescriptorSlack(map, 2);
|
|
|
|
|
|
|
|
{ // length
|
2015-01-19 17:49:13 +00:00
|
|
|
DataDescriptor d(factory->length_string(), Heap::kArgumentsLengthIndex,
|
|
|
|
DONT_ENUM, Representation::Tagged());
|
2014-07-07 13:27:37 +00:00
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
{ // callee
|
2015-01-19 17:49:13 +00:00
|
|
|
DataDescriptor d(factory->callee_string(), Heap::kArgumentsCalleeIndex,
|
|
|
|
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
|
|
|
|
|
|
|
map->set_function_with_prototype(true);
|
|
|
|
map->set_pre_allocated_property_fields(2);
|
|
|
|
map->set_inobject_properties(2);
|
|
|
|
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->inobject_properties() > Heap::kArgumentsCalleeIndex);
|
|
|
|
DCHECK(map->inobject_properties() > Heap::kArgumentsLengthIndex);
|
|
|
|
DCHECK(!map->is_dictionary_map());
|
|
|
|
DCHECK(IsFastObjectElementsKind(map->elements_kind()));
|
2014-07-07 12:21:01 +00:00
|
|
|
}
|
|
|
|
|
2014-07-07 13:27:37 +00:00
|
|
|
{ // --- aliased arguments map
|
2014-11-07 16:03:11 +00:00
|
|
|
Handle<Map> map =
|
|
|
|
Map::Copy(isolate->sloppy_arguments_map(), "AliasedArguments");
|
2014-07-07 13:27:37 +00:00
|
|
|
map->set_elements_kind(SLOPPY_ARGUMENTS_ELEMENTS);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK_EQ(2, map->pre_allocated_property_fields());
|
2014-07-07 13:27:37 +00:00
|
|
|
native_context()->set_aliased_arguments_map(*map);
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // --- strict mode arguments map
|
2011-03-17 20:28:41 +00:00
|
|
|
const PropertyAttributes attributes =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
|
|
|
|
|
|
|
|
// Create the ThrowTypeError functions.
|
2012-01-10 16:11:33 +00:00
|
|
|
Handle<AccessorPair> callee = factory->NewAccessorPair();
|
|
|
|
Handle<AccessorPair> caller = 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
|
|
|
|
|
|
|
// Install the ThrowTypeError functions.
|
2014-05-19 10:47:00 +00:00
|
|
|
callee->set_getter(*poison);
|
|
|
|
callee->set_setter(*poison);
|
|
|
|
caller->set_getter(*poison);
|
|
|
|
caller->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.
|
|
|
|
Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE,
|
2014-03-11 14:41:22 +00:00
|
|
|
Heap::kStrictArgumentsObjectSize);
|
2011-03-17 20:28:41 +00:00
|
|
|
// Create the descriptor array for the arguments object.
|
2014-04-11 12:13:53 +00:00
|
|
|
Map::EnsureDescriptorSlack(map, 3);
|
2012-07-19 10:01:52 +00:00
|
|
|
|
2011-03-17 20:28:41 +00:00
|
|
|
{ // length
|
2015-01-19 17:49:13 +00:00
|
|
|
DataDescriptor d(factory->length_string(), Heap::kArgumentsLengthIndex,
|
|
|
|
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
|
|
|
}
|
|
|
|
{ // caller
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(factory->caller_string(), caller,
|
|
|
|
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
|
|
|
|
2011-03-17 20:28:41 +00:00
|
|
|
map->set_function_with_prototype(true);
|
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());
|
2011-03-17 20:28:41 +00:00
|
|
|
map->set_pre_allocated_property_fields(1);
|
|
|
|
map->set_inobject_properties(1);
|
|
|
|
|
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->inobject_properties() > Heap::kArgumentsLengthIndex);
|
|
|
|
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.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Code> code = Handle<Code>(
|
2011-03-28 13:09:37 +00:00
|
|
|
isolate->builtins()->builtin(Builtins::kIllegal));
|
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.
|
2009-05-20 19:33:44 +00:00
|
|
|
Handle<Code> code =
|
2011-03-28 13:09:37 +00:00
|
|
|
Handle<Code>(isolate->builtins()->builtin(
|
2011-03-23 13:40:07 +00:00
|
|
|
Builtins::kHandleApiCallAsFunction));
|
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.
|
2009-05-20 19:33:44 +00:00
|
|
|
Handle<Code> code =
|
2011-03-28 13:09:37 +00:00
|
|
|
Handle<Code>(isolate->builtins()->builtin(
|
2011-03-23 13:40:07 +00:00
|
|
|
Builtins::kHandleApiCallAsConstructor));
|
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();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-11-13 12:27:03 +00:00
|
|
|
// Initialize the embedder data slot.
|
2013-12-18 08:45:17 +00:00
|
|
|
Handle<FixedArray> embedder_data = factory->NewFixedArray(3);
|
2012-11-13 12:27:03 +00:00
|
|
|
native_context()->set_embedder_data(*embedder_data);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-22 12:24:28 +00:00
|
|
|
void Genesis::InstallTypedArray(
|
|
|
|
const char* name,
|
|
|
|
ElementsKind elements_kind,
|
|
|
|
Handle<JSFunction>* fun,
|
|
|
|
Handle<Map>* external_map) {
|
2013-04-16 14:16:30 +00:00
|
|
|
Handle<JSObject> global = Handle<JSObject>(native_context()->global_object());
|
2014-05-09 17:21:51 +00:00
|
|
|
Handle<JSFunction> result = InstallFunction(
|
|
|
|
global, name, JS_TYPED_ARRAY_TYPE, JSTypedArray::kSize,
|
|
|
|
isolate()->initial_object_prototype(), Builtins::kIllegal);
|
2013-05-15 15:23:53 +00:00
|
|
|
|
|
|
|
Handle<Map> initial_map = isolate()->factory()->NewMap(
|
2014-04-22 12:24:28 +00:00
|
|
|
JS_TYPED_ARRAY_TYPE,
|
|
|
|
JSTypedArray::kSizeWithInternalFields,
|
|
|
|
elements_kind);
|
2014-08-11 14:00:58 +00:00
|
|
|
JSFunction::SetInitialMap(result, initial_map,
|
|
|
|
handle(initial_map->prototype(), isolate()));
|
2014-04-22 12:24:28 +00:00
|
|
|
*fun = result;
|
|
|
|
|
|
|
|
ElementsKind external_kind = GetNextTransitionElementsKind(elements_kind);
|
|
|
|
*external_map = Map::AsElementsKind(initial_map, external_kind);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-14 08:01:19 +00:00
|
|
|
bool Genesis::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 =
|
2011-04-14 08:01:19 +00:00
|
|
|
isolate->bootstrapper()->NativesSourceLookup(index);
|
2013-02-15 09:27:10 +00:00
|
|
|
return CompileNative(isolate, name, source_code);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-15 12:31:03 +00:00
|
|
|
bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) {
|
|
|
|
Vector<const char> name = ExperimentalNatives::GetScriptName(index);
|
|
|
|
Factory* factory = isolate->factory();
|
2014-04-17 13:27:02 +00:00
|
|
|
Handle<String> source_code;
|
|
|
|
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
|
2014-12-04 18:51:15 +00:00
|
|
|
isolate, source_code,
|
|
|
|
factory->NewStringFromAscii(ExperimentalNatives::GetScriptSource(index)),
|
2014-04-17 13:27:02 +00:00
|
|
|
false);
|
2015-02-12 16:29:42 +00:00
|
|
|
return CompileNative(isolate, name, source_code);
|
2011-04-15 12:31:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-15 09:27:10 +00:00
|
|
|
bool Genesis::CompileNative(Isolate* isolate,
|
|
|
|
Vector<const char> name,
|
|
|
|
Handle<String> source) {
|
|
|
|
HandleScope scope(isolate);
|
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);
|
|
|
|
if (check.HasOverflowed()) return false;
|
2012-04-03 15:54:07 +00:00
|
|
|
|
2013-02-15 09:27:10 +00:00
|
|
|
bool result = CompileScriptCached(isolate,
|
|
|
|
name,
|
2010-03-23 11:40:38 +00:00
|
|
|
source,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Context>(isolate->context()),
|
2010-03-23 11:40:38 +00:00
|
|
|
true);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(isolate->has_pending_exception() != result);
|
2011-03-18 20:35:07 +00:00
|
|
|
if (!result) isolate->clear_pending_exception();
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-15 09:27:10 +00:00
|
|
|
bool Genesis::CompileScriptCached(Isolate* isolate,
|
|
|
|
Vector<const char> name,
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<String> source,
|
|
|
|
SourceCodeCache* cache,
|
|
|
|
v8::Extension* extension,
|
2010-03-23 11:40:38 +00:00
|
|
|
Handle<Context> top_context,
|
2008-07-03 15:10:15 +00:00
|
|
|
bool use_runtime_context) {
|
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
|
|
|
|
|
|
|
// If we can't find the function in the cache, we compile a new
|
|
|
|
// function and insert it into the cache.
|
2010-03-23 11:40:38 +00:00
|
|
|
if (cache == NULL || !cache->Lookup(name, &function_info)) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(source->IsOneByteRepresentation());
|
2014-04-17 13:27:02 +00:00
|
|
|
Handle<String> script_name =
|
|
|
|
factory->NewStringFromUtf8(name).ToHandleChecked();
|
2013-12-23 14:30:35 +00:00
|
|
|
function_info = Compiler::CompileScript(
|
2015-03-05 13:03:42 +00:00
|
|
|
source, script_name, 0, 0, false, false, Handle<Object>(), top_context,
|
|
|
|
extension, NULL, ScriptCompiler::kNoCompileOptions,
|
2015-02-06 17:52:20 +00:00
|
|
|
use_runtime_context ? NATIVES_CODE : NOT_NATIVES_CODE, false);
|
2010-03-23 06:04:44 +00:00
|
|
|
if (function_info.is_null()) return false;
|
2010-03-23 11:40:38 +00:00
|
|
|
if (cache != NULL) 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.
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(top_context->IsNativeContext());
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<Context> context =
|
|
|
|
Handle<Context>(use_runtime_context
|
2010-03-23 11:40:38 +00:00
|
|
|
? Handle<Context>(top_context->runtime_context())
|
|
|
|
: top_context);
|
2008-07-03 15:10:15 +00:00
|
|
|
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.
|
|
|
|
Handle<Object> receiver =
|
|
|
|
Handle<Object>(use_runtime_context
|
2010-03-23 11:40:38 +00:00
|
|
|
? top_context->builtins()
|
2013-02-25 14:46:09 +00:00
|
|
|
: top_context->global_object(),
|
|
|
|
isolate);
|
2014-04-11 10:41:09 +00:00
|
|
|
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();
|
|
|
|
Handle<GlobalObject> global(native_context->global_object());
|
|
|
|
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(
|
|
|
|
Object::GetProperty(global, property_string).ToHandleChecked());
|
|
|
|
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 =
|
|
|
|
Object::GetProperty(object, inner_string).ToHandleChecked();
|
|
|
|
return Handle<JSObject>::cast(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-10 12:38:12 +00:00
|
|
|
#define INSTALL_NATIVE(Type, name, var) \
|
|
|
|
Handle<String> var##_name = \
|
|
|
|
factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR(name)); \
|
|
|
|
Handle<Object> var##_native = \
|
|
|
|
Object::GetProperty(handle(native_context()->builtins()), var##_name) \
|
|
|
|
.ToHandleChecked(); \
|
2014-04-09 12:21:47 +00:00
|
|
|
native_context()->set_##var(Type::cast(*var##_native));
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void Genesis::InstallNativeFunctions() {
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(isolate());
|
2015-03-11 15:53:24 +00:00
|
|
|
INSTALL_NATIVE(JSFunction, "$createDate", create_date_fun);
|
2014-05-06 14:48:34 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
INSTALL_NATIVE(JSFunction, "ToNumber", to_number_fun);
|
|
|
|
INSTALL_NATIVE(JSFunction, "ToString", to_string_fun);
|
2015-04-27 12:33:58 +00:00
|
|
|
INSTALL_NATIVE(JSFunction, "$toDetailString", to_detail_string_fun);
|
2008-07-03 15:10:15 +00:00
|
|
|
INSTALL_NATIVE(JSFunction, "ToObject", to_object_fun);
|
|
|
|
INSTALL_NATIVE(JSFunction, "ToInteger", to_integer_fun);
|
|
|
|
INSTALL_NATIVE(JSFunction, "ToUint32", to_uint32_fun);
|
|
|
|
INSTALL_NATIVE(JSFunction, "ToInt32", to_int32_fun);
|
2014-12-15 19:08:32 +00:00
|
|
|
INSTALL_NATIVE(JSFunction, "ToLength", to_length_fun);
|
2014-05-06 14:48:34 +00:00
|
|
|
|
2010-01-05 09:38:02 +00:00
|
|
|
INSTALL_NATIVE(JSFunction, "GlobalEval", global_eval_fun);
|
2015-04-27 12:33:58 +00:00
|
|
|
INSTALL_NATIVE(JSFunction, "$getStackTraceLine", get_stack_trace_line_fun);
|
2011-09-21 12:45:51 +00:00
|
|
|
INSTALL_NATIVE(JSFunction, "ToCompletePropertyDescriptor",
|
|
|
|
to_complete_property_descriptor);
|
2014-05-06 14:48:34 +00:00
|
|
|
|
2015-04-21 14:39:09 +00:00
|
|
|
INSTALL_NATIVE(Symbol, "$promiseStatus", promise_status);
|
|
|
|
INSTALL_NATIVE(JSFunction, "$promiseCreate", promise_create);
|
|
|
|
INSTALL_NATIVE(JSFunction, "$promiseResolve", promise_resolve);
|
|
|
|
INSTALL_NATIVE(JSFunction, "$promiseReject", promise_reject);
|
|
|
|
INSTALL_NATIVE(JSFunction, "$promiseChain", promise_chain);
|
|
|
|
INSTALL_NATIVE(JSFunction, "$promiseCatch", promise_catch);
|
|
|
|
INSTALL_NATIVE(JSFunction, "$promiseThen", promise_then);
|
2014-05-06 14:48:34 +00:00
|
|
|
|
2015-04-17 14:10:05 +00:00
|
|
|
INSTALL_NATIVE(JSFunction, "$observeNotifyChange", observers_notify_change);
|
|
|
|
INSTALL_NATIVE(JSFunction, "$observeEnqueueSpliceRecord",
|
|
|
|
observers_enqueue_splice);
|
|
|
|
INSTALL_NATIVE(JSFunction, "$observeBeginPerformSplice",
|
2014-03-13 00:20:06 +00:00
|
|
|
observers_begin_perform_splice);
|
2015-04-17 14:10:05 +00:00
|
|
|
INSTALL_NATIVE(JSFunction, "$observeEndPerformSplice",
|
2014-03-13 00:20:06 +00:00
|
|
|
observers_end_perform_splice);
|
2015-04-17 14:10:05 +00:00
|
|
|
INSTALL_NATIVE(JSFunction, "$observeNativeObjectObserve",
|
2014-05-02 16:13:10 +00:00
|
|
|
native_object_observe);
|
2015-04-17 14:10:05 +00:00
|
|
|
INSTALL_NATIVE(JSFunction, "$observeNativeObjectGetNotifier",
|
2014-05-02 16:13:10 +00:00
|
|
|
native_object_get_notifier);
|
2015-04-17 14:10:05 +00:00
|
|
|
INSTALL_NATIVE(JSFunction, "$observeNativeObjectNotifierPerformChange",
|
2014-05-02 16:13:10 +00:00
|
|
|
native_object_notifier_perform_change);
|
2015-04-15 10:36:20 +00:00
|
|
|
INSTALL_NATIVE(JSFunction, "$arrayValues", array_values_iterator);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2011-05-18 14:00:34 +00:00
|
|
|
void Genesis::InstallExperimentalNativeFunctions() {
|
|
|
|
if (FLAG_harmony_proxies) {
|
2015-04-10 12:32:20 +00:00
|
|
|
INSTALL_NATIVE(JSFunction, "$proxyDerivedHasTrap", derived_has_trap);
|
|
|
|
INSTALL_NATIVE(JSFunction, "$proxyDerivedGetTrap", derived_get_trap);
|
|
|
|
INSTALL_NATIVE(JSFunction, "$proxyDerivedSetTrap", derived_set_trap);
|
|
|
|
INSTALL_NATIVE(JSFunction, "$proxyEnumerate", proxy_enumerate);
|
2011-05-18 14:00:34 +00:00
|
|
|
}
|
2014-10-20 13:33:34 +00:00
|
|
|
|
|
|
|
#define INSTALL_NATIVE_FUNCTIONS_FOR(id, descr) InstallNativeFunctions_##id();
|
2014-11-04 16:05:27 +00:00
|
|
|
HARMONY_INPROGRESS(INSTALL_NATIVE_FUNCTIONS_FOR)
|
|
|
|
HARMONY_STAGED(INSTALL_NATIVE_FUNCTIONS_FOR)
|
2014-11-28 20:07:11 +00:00
|
|
|
HARMONY_SHIPPING(INSTALL_NATIVE_FUNCTIONS_FOR)
|
2014-10-20 13:33:34 +00:00
|
|
|
#undef INSTALL_NATIVE_FUNCTIONS_FOR
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-06 09:54:58 +00:00
|
|
|
template <typename Data>
|
|
|
|
Data* SetBuiltinTypedArray(Isolate* isolate, Handle<JSBuiltinsObject> builtins,
|
|
|
|
ExternalArrayType type, Data* data,
|
|
|
|
size_t num_elements, const char* name) {
|
|
|
|
size_t byte_length = num_elements * sizeof(*data);
|
|
|
|
Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer();
|
2015-04-28 11:25:25 +00:00
|
|
|
bool is_external = data != nullptr;
|
|
|
|
if (!is_external) {
|
|
|
|
data = reinterpret_cast<Data*>(
|
2015-04-29 09:54:34 +00:00
|
|
|
isolate->array_buffer_allocator()->Allocate(byte_length));
|
2015-02-06 09:54:58 +00:00
|
|
|
}
|
2015-04-28 11:25:25 +00:00
|
|
|
Runtime::SetupArrayBuffer(isolate, buffer, is_external, data, byte_length);
|
2015-02-06 09:54:58 +00:00
|
|
|
|
|
|
|
Handle<JSTypedArray> typed_array =
|
|
|
|
isolate->factory()->NewJSTypedArray(type, buffer, 0, num_elements);
|
|
|
|
Handle<String> name_string = isolate->factory()->InternalizeUtf8String(name);
|
|
|
|
// Reset property cell type before (re)initializing.
|
|
|
|
JSBuiltinsObject::InvalidatePropertyCell(builtins, name_string);
|
|
|
|
JSObject::SetOwnPropertyIgnoreAttributes(builtins, name_string, typed_array,
|
|
|
|
DONT_DELETE).Assert();
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Genesis::InitializeBuiltinTypedArrays() {
|
|
|
|
Handle<JSBuiltinsObject> builtins(native_context()->builtins());
|
|
|
|
{ // Initially seed the per-context random number generator using the
|
|
|
|
// per-isolate random number generator.
|
|
|
|
const size_t num_elements = 2;
|
|
|
|
const size_t num_bytes = num_elements * sizeof(uint32_t);
|
|
|
|
uint32_t* state = SetBuiltinTypedArray<uint32_t>(isolate(), builtins,
|
|
|
|
kExternalUint32Array, NULL,
|
|
|
|
num_elements, "rngstate");
|
|
|
|
do {
|
|
|
|
isolate()->random_number_generator()->NextBytes(state, num_bytes);
|
|
|
|
} while (state[0] == 0 || state[1] == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // Initialize trigonometric lookup tables and constants.
|
|
|
|
const size_t num_elements = arraysize(fdlibm::MathConstants::constants);
|
|
|
|
double* data = const_cast<double*>(fdlibm::MathConstants::constants);
|
|
|
|
SetBuiltinTypedArray<double>(isolate(), builtins, kExternalFloat64Array,
|
|
|
|
data, num_elements, "kMath");
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // Initialize a result array for rempio2 calculation
|
|
|
|
const size_t num_elements = 2;
|
|
|
|
SetBuiltinTypedArray<double>(isolate(), builtins, kExternalFloat64Array,
|
|
|
|
NULL, num_elements, "rempio2result");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-20 13:33:34 +00:00
|
|
|
#define EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(id) \
|
|
|
|
void Genesis::InstallNativeFunctions_##id() {}
|
|
|
|
|
|
|
|
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_modules)
|
|
|
|
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_arrays)
|
2014-12-10 08:58:04 +00:00
|
|
|
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_array_includes)
|
2014-10-20 13:33:34 +00:00
|
|
|
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_classes)
|
|
|
|
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_object_literals)
|
|
|
|
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_regexps)
|
|
|
|
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_arrow_functions)
|
2014-10-21 17:21:32 +00:00
|
|
|
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_tostring)
|
2014-11-20 10:51:49 +00:00
|
|
|
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_sloppy)
|
2014-12-02 10:58:11 +00:00
|
|
|
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_unicode)
|
2015-02-05 14:16:54 +00:00
|
|
|
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_unicode_regexps)
|
2015-01-15 20:02:20 +00:00
|
|
|
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_computed_property_names)
|
2015-01-30 15:21:41 +00:00
|
|
|
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_rest_parameters)
|
2015-03-19 14:47:18 +00:00
|
|
|
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_reflect)
|
2015-04-09 19:37:14 +00:00
|
|
|
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_spreadcalls)
|
2015-04-22 12:35:05 +00:00
|
|
|
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_destructuring)
|
2014-10-20 13:33:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
void Genesis::InstallNativeFunctions_harmony_proxies() {
|
|
|
|
if (FLAG_harmony_proxies) {
|
2015-04-10 12:32:20 +00:00
|
|
|
INSTALL_NATIVE(JSFunction, "$proxyDerivedHasTrap", derived_has_trap);
|
|
|
|
INSTALL_NATIVE(JSFunction, "$proxyDerivedGetTrap", derived_get_trap);
|
|
|
|
INSTALL_NATIVE(JSFunction, "$proxyDerivedSetTrap", derived_set_trap);
|
|
|
|
INSTALL_NATIVE(JSFunction, "$proxyEnumerate", proxy_enumerate);
|
2014-10-20 13:33:34 +00:00
|
|
|
}
|
2011-05-18 14:00:34 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
#undef INSTALL_NATIVE
|
|
|
|
|
2014-10-20 13:33:34 +00:00
|
|
|
#define EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(id) \
|
|
|
|
void Genesis::InitializeGlobal_##id() {}
|
|
|
|
|
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_modules)
|
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_arrays)
|
2014-12-10 08:58:04 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_array_includes)
|
2014-10-20 13:33:34 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_classes)
|
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_object_literals)
|
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_arrow_functions)
|
2014-11-04 16:05:27 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_proxies)
|
2014-11-20 10:51:49 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy)
|
2015-02-05 14:16:54 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_unicode)
|
2015-01-15 20:02:20 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_computed_property_names)
|
2015-01-30 15:21:41 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_rest_parameters)
|
2015-04-09 19:37:14 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_spreadcalls)
|
2015-04-22 12:35:05 +00:00
|
|
|
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_destructuring)
|
2014-10-20 13:33:34 +00:00
|
|
|
|
|
|
|
void Genesis::InitializeGlobal_harmony_regexps() {
|
|
|
|
Handle<JSObject> builtins(native_context()->builtins());
|
|
|
|
|
|
|
|
Handle<HeapObject> flag(FLAG_harmony_regexps ? heap()->true_value()
|
|
|
|
: heap()->false_value());
|
2015-03-12 15:44:32 +00:00
|
|
|
Runtime::SetObjectProperty(isolate(), builtins,
|
|
|
|
factory()->harmony_regexps_string(), flag,
|
|
|
|
STRICT).Assert();
|
2014-10-20 13:33:34 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2015-02-05 14:16:54 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_unicode_regexps() {
|
2015-01-12 09:50:15 +00:00
|
|
|
Handle<JSObject> builtins(native_context()->builtins());
|
|
|
|
|
2015-02-05 14:16:54 +00:00
|
|
|
Handle<HeapObject> flag(FLAG_harmony_unicode_regexps ? heap()->true_value()
|
|
|
|
: heap()->false_value());
|
2015-03-12 15:44:32 +00:00
|
|
|
Runtime::SetObjectProperty(isolate(), builtins,
|
|
|
|
factory()->harmony_unicode_regexps_string(), flag,
|
|
|
|
STRICT).Assert();
|
2015-01-12 09:50:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-19 14:47:18 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_reflect() {
|
|
|
|
Handle<JSObject> builtins(native_context()->builtins());
|
|
|
|
// Install references to functions of the Reflect object
|
2015-04-09 19:37:14 +00:00
|
|
|
if (FLAG_harmony_reflect || FLAG_harmony_spreadcalls) {
|
2015-04-21 09:42:16 +00:00
|
|
|
Handle<JSFunction> apply = InstallFunction(
|
|
|
|
builtins, "$reflectApply", JS_OBJECT_TYPE, JSObject::kHeaderSize,
|
|
|
|
MaybeHandle<JSObject>(), Builtins::kReflectApply);
|
|
|
|
Handle<JSFunction> construct = InstallFunction(
|
|
|
|
builtins, "$reflectConstruct", JS_OBJECT_TYPE, JSObject::kHeaderSize,
|
|
|
|
MaybeHandle<JSObject>(), Builtins::kReflectConstruct);
|
2015-03-19 14:47:18 +00:00
|
|
|
apply->shared()->set_internal_formal_parameter_count(3);
|
|
|
|
apply->shared()->set_length(3);
|
|
|
|
|
|
|
|
construct->shared()->set_internal_formal_parameter_count(3);
|
|
|
|
construct->shared()->set_length(2);
|
|
|
|
}
|
|
|
|
|
2015-04-09 19:37:14 +00:00
|
|
|
if (!FLAG_harmony_reflect) return;
|
2015-03-19 14:47:18 +00:00
|
|
|
Handle<JSGlobalObject> global(JSGlobalObject::cast(
|
|
|
|
native_context()->global_object()));
|
|
|
|
Handle<String> reflect_string =
|
|
|
|
factory()->NewStringFromStaticChars("Reflect");
|
|
|
|
Handle<Object> reflect =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
|
|
|
JSObject::AddProperty(global, reflect_string, reflect, DONT_ENUM);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-09 20:53:46 +00:00
|
|
|
void Genesis::InitializeGlobal_harmony_tostring() {
|
|
|
|
Handle<JSObject> builtins(native_context()->builtins());
|
|
|
|
|
|
|
|
Handle<HeapObject> flag(FLAG_harmony_tostring ? heap()->true_value()
|
|
|
|
: heap()->false_value());
|
|
|
|
Runtime::SetObjectProperty(isolate(), builtins,
|
|
|
|
factory()->harmony_tostring_string(), flag,
|
|
|
|
STRICT).Assert();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-15 15:20:05 +00:00
|
|
|
Handle<JSFunction> Genesis::InstallInternalArray(
|
|
|
|
Handle<JSBuiltinsObject> builtins,
|
|
|
|
const char* name,
|
|
|
|
ElementsKind elements_kind) {
|
|
|
|
// --- 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);
|
2014-05-09 17:21:51 +00:00
|
|
|
Handle<JSFunction> array_function = InstallFunction(
|
|
|
|
builtins, 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();
|
2013-06-25 16:31:07 +00:00
|
|
|
array_function->shared()->set_construct_stub(*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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
bool Genesis::InstallNatives() {
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(isolate());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Create a function for the builtins object. Allocate space for the
|
|
|
|
// JavaScript builtins, a reference to the builtins object
|
2012-08-17 09:03:08 +00:00
|
|
|
// (itself) and a reference to the native_context directly in the object.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Code> code = Handle<Code>(
|
2011-04-14 08:01:19 +00:00
|
|
|
isolate()->builtins()->builtin(Builtins::kIllegal));
|
2014-05-09 16:42:57 +00:00
|
|
|
Handle<JSFunction> builtins_fun = factory()->NewFunction(
|
2014-05-09 17:39:54 +00:00
|
|
|
factory()->empty_string(), code, JS_BUILTINS_OBJECT_TYPE,
|
|
|
|
JSBuiltinsObject::kSize);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-12-17 15:56:16 +00:00
|
|
|
Handle<String> name =
|
2014-09-10 12:38:12 +00:00
|
|
|
factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("builtins"));
|
2008-07-03 15:10:15 +00:00
|
|
|
builtins_fun->shared()->set_instance_class_name(*name);
|
2012-08-06 14:25:19 +00:00
|
|
|
builtins_fun->initial_map()->set_dictionary_map(true);
|
2012-08-13 15:34:49 +00:00
|
|
|
builtins_fun->initial_map()->set_prototype(heap()->null_value());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Allocate the builtins object.
|
|
|
|
Handle<JSBuiltinsObject> builtins =
|
2011-04-14 08:01:19 +00:00
|
|
|
Handle<JSBuiltinsObject>::cast(factory()->NewGlobalObject(builtins_fun));
|
2008-07-03 15:10:15 +00:00
|
|
|
builtins->set_builtins(*builtins);
|
2012-08-17 09:03:08 +00:00
|
|
|
builtins->set_native_context(*native_context());
|
2014-07-01 12:12:34 +00:00
|
|
|
builtins->set_global_proxy(native_context()->global_proxy());
|
2014-01-07 10:46:39 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up the 'global' properties of the builtins object. The
|
2008-07-03 15:10:15 +00:00
|
|
|
// 'global' property that refers to the global object is the only
|
|
|
|
// way to get from code running in the builtins context to the
|
|
|
|
// global object.
|
|
|
|
static const PropertyAttributes attributes =
|
|
|
|
static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE);
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> global_string =
|
2014-09-10 12:38:12 +00:00
|
|
|
factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("global"));
|
2013-02-25 14:46:09 +00:00
|
|
|
Handle<Object> global_obj(native_context()->global_object(), isolate());
|
2014-06-30 13:48:57 +00:00
|
|
|
JSObject::AddProperty(builtins, global_string, global_obj, attributes);
|
2014-01-07 10:46:39 +00:00
|
|
|
Handle<String> builtins_string =
|
2014-09-10 12:38:12 +00:00
|
|
|
factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("builtins"));
|
2014-06-30 13:48:57 +00:00
|
|
|
JSObject::AddProperty(builtins, builtins_string, builtins, attributes);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up the reference from the global object to the builtins object.
|
2012-08-17 12:59:00 +00:00
|
|
|
JSGlobalObject::cast(native_context()->global_object())->
|
|
|
|
set_builtins(*builtins);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
// Create a bridge function that has context in the native context.
|
2014-05-09 16:39:33 +00:00
|
|
|
Handle<JSFunction> bridge = factory()->NewFunction(factory()->empty_string());
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(bridge->context() == *isolate()->native_context());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Allocate the builtins context.
|
|
|
|
Handle<Context> context =
|
2011-04-14 08:01:19 +00:00
|
|
|
factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge);
|
2012-08-17 12:59:00 +00:00
|
|
|
context->set_global_object(*builtins); // override builtins global object
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_runtime_context(*context);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
{ // -- S c r i p t
|
|
|
|
// Builtin functions for Script.
|
2014-05-09 16:34:58 +00:00
|
|
|
Handle<JSFunction> script_fun = InstallFunction(
|
|
|
|
builtins, "Script", JS_VALUE_TYPE, JSValue::kSize,
|
2014-05-09 17:21:51 +00:00
|
|
|
isolate()->initial_object_prototype(), Builtins::kIllegal);
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<JSObject> prototype =
|
2011-04-14 08:01:19 +00:00
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
2014-10-14 14:46:11 +00:00
|
|
|
Accessors::FunctionSetPrototype(script_fun, prototype).Assert();
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_script_function(*script_fun);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-07-18 15:38:58 +00:00
|
|
|
Handle<Map> script_map = Handle<Map>(script_fun->initial_map());
|
2015-01-29 14:01:13 +00:00
|
|
|
Map::EnsureDescriptorSlack(script_map, 15);
|
2012-07-23 16:18:25 +00:00
|
|
|
|
|
|
|
PropertyAttributes attribs =
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
|
2012-07-18 14:00:58 +00:00
|
|
|
|
2014-04-16 11:57:23 +00:00
|
|
|
Handle<AccessorInfo> script_column =
|
|
|
|
Accessors::ScriptColumnOffsetInfo(isolate(), attribs);
|
2012-07-18 14:00:58 +00:00
|
|
|
{
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(
|
|
|
|
Handle<Name>(Name::cast(script_column->name())), script_column,
|
|
|
|
attribs);
|
2014-04-11 12:13:53 +00:00
|
|
|
script_map->AppendDescriptor(&d);
|
2012-07-18 14:00:58 +00:00
|
|
|
}
|
|
|
|
|
2014-04-16 11:57:23 +00:00
|
|
|
Handle<AccessorInfo> script_id =
|
|
|
|
Accessors::ScriptIdInfo(isolate(), attribs);
|
2012-07-18 14:00:58 +00:00
|
|
|
{
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(Handle<Name>(Name::cast(script_id->name())),
|
|
|
|
script_id, attribs);
|
2014-04-11 12:13:53 +00:00
|
|
|
script_map->AppendDescriptor(&d);
|
2012-07-18 14:00:58 +00:00
|
|
|
}
|
|
|
|
|
2014-04-16 11:57:23 +00:00
|
|
|
|
|
|
|
Handle<AccessorInfo> script_name =
|
|
|
|
Accessors::ScriptNameInfo(isolate(), attribs);
|
2012-07-18 14:00:58 +00:00
|
|
|
{
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(
|
|
|
|
Handle<Name>(Name::cast(script_name->name())), script_name, attribs);
|
2014-04-11 12:13:53 +00:00
|
|
|
script_map->AppendDescriptor(&d);
|
2012-07-18 14:00:58 +00:00
|
|
|
}
|
|
|
|
|
2014-04-16 11:57:23 +00:00
|
|
|
Handle<AccessorInfo> script_line =
|
|
|
|
Accessors::ScriptLineOffsetInfo(isolate(), attribs);
|
2012-07-18 14:00:58 +00:00
|
|
|
{
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(
|
|
|
|
Handle<Name>(Name::cast(script_line->name())), script_line, attribs);
|
2014-04-11 12:13:53 +00:00
|
|
|
script_map->AppendDescriptor(&d);
|
2012-07-18 14:00:58 +00:00
|
|
|
}
|
|
|
|
|
2014-04-16 11:57:23 +00:00
|
|
|
Handle<AccessorInfo> script_source =
|
|
|
|
Accessors::ScriptSourceInfo(isolate(), attribs);
|
2012-07-18 14:00:58 +00:00
|
|
|
{
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(
|
|
|
|
Handle<Name>(Name::cast(script_source->name())), script_source,
|
|
|
|
attribs);
|
2014-04-11 12:13:53 +00:00
|
|
|
script_map->AppendDescriptor(&d);
|
2012-07-18 14:00:58 +00:00
|
|
|
}
|
|
|
|
|
2014-04-16 14:30:58 +00:00
|
|
|
Handle<AccessorInfo> script_type =
|
|
|
|
Accessors::ScriptTypeInfo(isolate(), attribs);
|
2012-07-18 14:00:58 +00:00
|
|
|
{
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(
|
|
|
|
Handle<Name>(Name::cast(script_type->name())), script_type, attribs);
|
2014-04-11 12:13:53 +00:00
|
|
|
script_map->AppendDescriptor(&d);
|
2012-07-18 14:00:58 +00:00
|
|
|
}
|
|
|
|
|
2014-04-16 14:30:58 +00:00
|
|
|
Handle<AccessorInfo> script_compilation_type =
|
|
|
|
Accessors::ScriptCompilationTypeInfo(isolate(), attribs);
|
2012-07-18 14:00:58 +00:00
|
|
|
{
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(
|
2014-04-16 14:30:58 +00:00
|
|
|
Handle<Name>(Name::cast(script_compilation_type->name())),
|
|
|
|
script_compilation_type, attribs);
|
2014-04-11 12:13:53 +00:00
|
|
|
script_map->AppendDescriptor(&d);
|
2012-07-18 14:00:58 +00:00
|
|
|
}
|
|
|
|
|
2014-04-16 14:30:58 +00:00
|
|
|
Handle<AccessorInfo> script_line_ends =
|
|
|
|
Accessors::ScriptLineEndsInfo(isolate(), attribs);
|
2012-07-18 14:00:58 +00:00
|
|
|
{
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(
|
|
|
|
Handle<Name>(Name::cast(script_line_ends->name())), script_line_ends,
|
|
|
|
attribs);
|
2014-04-11 12:13:53 +00:00
|
|
|
script_map->AppendDescriptor(&d);
|
2012-07-18 14:00:58 +00:00
|
|
|
}
|
|
|
|
|
2014-04-16 14:30:58 +00:00
|
|
|
Handle<AccessorInfo> script_context_data =
|
|
|
|
Accessors::ScriptContextDataInfo(isolate(), attribs);
|
2012-07-18 14:00:58 +00:00
|
|
|
{
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(
|
2014-04-16 14:30:58 +00:00
|
|
|
Handle<Name>(Name::cast(script_context_data->name())),
|
|
|
|
script_context_data, attribs);
|
2014-04-11 12:13:53 +00:00
|
|
|
script_map->AppendDescriptor(&d);
|
2012-07-18 14:00:58 +00:00
|
|
|
}
|
|
|
|
|
2014-04-16 14:30:58 +00:00
|
|
|
Handle<AccessorInfo> script_eval_from_script =
|
|
|
|
Accessors::ScriptEvalFromScriptInfo(isolate(), attribs);
|
2012-07-18 14:00:58 +00:00
|
|
|
{
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(
|
2014-04-16 14:30:58 +00:00
|
|
|
Handle<Name>(Name::cast(script_eval_from_script->name())),
|
|
|
|
script_eval_from_script, attribs);
|
2014-04-11 12:13:53 +00:00
|
|
|
script_map->AppendDescriptor(&d);
|
2012-07-18 14:00:58 +00:00
|
|
|
}
|
|
|
|
|
2014-04-16 14:30:58 +00:00
|
|
|
Handle<AccessorInfo> script_eval_from_script_position =
|
|
|
|
Accessors::ScriptEvalFromScriptPositionInfo(isolate(), attribs);
|
2012-07-18 14:00:58 +00:00
|
|
|
{
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(
|
2014-04-16 14:30:58 +00:00
|
|
|
Handle<Name>(Name::cast(script_eval_from_script_position->name())),
|
|
|
|
script_eval_from_script_position, attribs);
|
2014-04-11 12:13:53 +00:00
|
|
|
script_map->AppendDescriptor(&d);
|
2012-07-18 14:00:58 +00:00
|
|
|
}
|
|
|
|
|
2014-04-16 14:30:58 +00:00
|
|
|
Handle<AccessorInfo> script_eval_from_function_name =
|
|
|
|
Accessors::ScriptEvalFromFunctionNameInfo(isolate(), attribs);
|
2012-07-18 14:00:58 +00:00
|
|
|
{
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(
|
2014-04-16 14:30:58 +00:00
|
|
|
Handle<Name>(Name::cast(script_eval_from_function_name->name())),
|
|
|
|
script_eval_from_function_name, attribs);
|
2014-04-11 12:13:53 +00:00
|
|
|
script_map->AppendDescriptor(&d);
|
2012-07-18 14:00:58 +00:00
|
|
|
}
|
|
|
|
|
2014-07-02 07:01:31 +00:00
|
|
|
Handle<AccessorInfo> script_source_url =
|
|
|
|
Accessors::ScriptSourceUrlInfo(isolate(), attribs);
|
|
|
|
{
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(
|
|
|
|
Handle<Name>(Name::cast(script_source_url->name())),
|
|
|
|
script_source_url, attribs);
|
2014-07-02 07:01:31 +00:00
|
|
|
script_map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<AccessorInfo> script_source_mapping_url =
|
|
|
|
Accessors::ScriptSourceMappingUrlInfo(isolate(), attribs);
|
|
|
|
{
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor d(
|
2014-07-02 07:01:31 +00:00
|
|
|
Handle<Name>(Name::cast(script_source_mapping_url->name())),
|
|
|
|
script_source_mapping_url, attribs);
|
|
|
|
script_map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
2015-01-29 14:01:13 +00:00
|
|
|
Handle<AccessorInfo> script_is_embedder_debug_script =
|
|
|
|
Accessors::ScriptIsEmbedderDebugScriptInfo(isolate(), attribs);
|
|
|
|
{
|
|
|
|
AccessorConstantDescriptor d(
|
|
|
|
Handle<Name>(Name::cast(script_is_embedder_debug_script->name())),
|
|
|
|
script_is_embedder_debug_script, attribs);
|
|
|
|
script_map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Allocate the empty script.
|
2011-04-14 08:01:19 +00:00
|
|
|
Handle<Script> script = factory()->NewScript(factory()->empty_string());
|
2009-06-08 10:47:49 +00:00
|
|
|
script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
|
2011-04-14 08:01:19 +00:00
|
|
|
heap()->public_set_empty_script(*script);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
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.
|
2014-05-09 16:34:58 +00:00
|
|
|
Handle<JSFunction> opaque_reference_fun = InstallFunction(
|
|
|
|
builtins, "OpaqueReference", JS_VALUE_TYPE, JSValue::kSize,
|
2014-05-09 17:21:51 +00:00
|
|
|
isolate()->initial_object_prototype(), Builtins::kIllegal);
|
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);
|
2014-10-14 14:46:11 +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.
|
|
|
|
{
|
|
|
|
Handle<JSFunction> array_function =
|
|
|
|
InstallInternalArray(builtins, "InternalArray", FAST_HOLEY_ELEMENTS);
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_internal_array_function(*array_function);
|
2011-03-03 11:49:03 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 15:20:05 +00:00
|
|
|
{
|
2013-05-29 15:38:09 +00:00
|
|
|
InstallInternalArray(builtins, "InternalPackedArray", FAST_ELEMENTS);
|
2013-02-15 15:20:05 +00:00
|
|
|
}
|
|
|
|
|
2014-08-05 19:37:32 +00:00
|
|
|
{ // -- S e t I t e r a t o r
|
|
|
|
Handle<JSFunction> set_iterator_function = InstallFunction(
|
|
|
|
builtins, "SetIterator", JS_SET_ITERATOR_TYPE, JSSetIterator::kSize,
|
|
|
|
isolate()->initial_object_prototype(), Builtins::kIllegal);
|
|
|
|
native_context()->set_set_iterator_map(
|
|
|
|
set_iterator_function->initial_map());
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // -- M a p I t e r a t o r
|
|
|
|
Handle<JSFunction> map_iterator_function = InstallFunction(
|
|
|
|
builtins, "MapIterator", JS_MAP_ITERATOR_TYPE, JSMapIterator::kSize,
|
|
|
|
isolate()->initial_object_prototype(), Builtins::kIllegal);
|
|
|
|
native_context()->set_map_iterator_map(
|
|
|
|
map_iterator_function->initial_map());
|
|
|
|
}
|
|
|
|
|
2014-09-16 12:30:39 +00:00
|
|
|
{
|
|
|
|
// Create generator meta-objects and install them on the builtins object.
|
|
|
|
Handle<JSObject> builtins(native_context()->builtins());
|
|
|
|
Handle<JSObject> generator_object_prototype =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
2015-04-06 21:04:43 +00:00
|
|
|
Handle<JSObject> generator_function_prototype =
|
|
|
|
factory()->NewJSObject(isolate()->object_function(), TENURED);
|
|
|
|
JSObject::AddProperty(
|
|
|
|
builtins,
|
|
|
|
factory()->InternalizeUtf8String("GeneratorFunctionPrototype"),
|
|
|
|
generator_function_prototype,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY));
|
|
|
|
|
|
|
|
JSObject::AddProperty(
|
|
|
|
generator_function_prototype,
|
|
|
|
factory()->InternalizeUtf8String("prototype"),
|
|
|
|
generator_object_prototype,
|
|
|
|
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
|
|
|
|
|
2015-04-09 22:40:16 +00:00
|
|
|
static const bool kUseStrictFunctionMap = true;
|
2014-09-16 12:30:39 +00:00
|
|
|
InstallFunction(builtins, "GeneratorFunction", JS_FUNCTION_TYPE,
|
|
|
|
JSFunction::kSize, generator_function_prototype,
|
2015-04-09 22:40:16 +00:00
|
|
|
Builtins::kIllegal, kUseStrictFunctionMap);
|
2014-09-16 12:30:39 +00:00
|
|
|
|
|
|
|
// Create maps for generator functions and their prototypes. Store those
|
2015-04-09 22:40:16 +00:00
|
|
|
// maps in the native context. Generator functions do not have writable
|
|
|
|
// prototypes, nor do they have "caller" or "arguments" accessors.
|
|
|
|
Handle<Map> strict_function_map(native_context()->strict_function_map());
|
|
|
|
Handle<Map> sloppy_generator_function_map =
|
|
|
|
Map::Copy(strict_function_map, "SloppyGeneratorFunction");
|
2015-04-10 12:13:18 +00:00
|
|
|
Map::SetPrototype(sloppy_generator_function_map,
|
|
|
|
generator_function_prototype);
|
2014-09-16 12:30:39 +00:00
|
|
|
native_context()->set_sloppy_generator_function_map(
|
2015-04-09 22:40:16 +00:00
|
|
|
*sloppy_generator_function_map);
|
2014-09-16 12:30:39 +00:00
|
|
|
|
2014-11-07 16:03:11 +00:00
|
|
|
Handle<Map> strict_generator_function_map =
|
|
|
|
Map::Copy(strict_function_map, "StrictGeneratorFunction");
|
2015-04-10 12:13:18 +00:00
|
|
|
Map::SetPrototype(strict_generator_function_map,
|
|
|
|
generator_function_prototype);
|
2014-09-16 12:30:39 +00:00
|
|
|
native_context()->set_strict_generator_function_map(
|
|
|
|
*strict_generator_function_map);
|
|
|
|
|
2015-02-25 14:52:36 +00:00
|
|
|
Handle<Map> strong_function_map(native_context()->strong_function_map());
|
|
|
|
Handle<Map> strong_generator_function_map =
|
|
|
|
Map::Copy(strong_function_map, "StrongGeneratorFunction");
|
2015-04-10 12:13:18 +00:00
|
|
|
Map::SetPrototype(strong_generator_function_map,
|
|
|
|
generator_function_prototype);
|
2015-02-25 14:52:36 +00:00
|
|
|
native_context()->set_strong_generator_function_map(
|
|
|
|
*strong_generator_function_map);
|
|
|
|
|
2014-09-16 12:30:39 +00:00
|
|
|
Handle<JSFunction> object_function(native_context()->object_function());
|
2014-09-19 14:59:14 +00:00
|
|
|
Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0);
|
2015-04-10 12:13:18 +00:00
|
|
|
Map::SetPrototype(generator_object_prototype_map,
|
|
|
|
generator_object_prototype);
|
2014-09-16 12:30:39 +00:00
|
|
|
native_context()->set_generator_object_prototype_map(
|
|
|
|
*generator_object_prototype_map);
|
|
|
|
}
|
|
|
|
|
2010-03-23 15:04:45 +00:00
|
|
|
if (FLAG_disable_native_files) {
|
|
|
|
PrintF("Warning: Running without installed natives!\n");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-13 08:47:52 +00:00
|
|
|
// Install public symbols.
|
|
|
|
{
|
|
|
|
static const PropertyAttributes attributes =
|
|
|
|
static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE);
|
|
|
|
#define INSTALL_PUBLIC_SYMBOL(name, varname, description) \
|
|
|
|
Handle<String> varname = factory()->NewStringFromStaticChars(#varname); \
|
|
|
|
JSObject::AddProperty(builtins, varname, factory()->name(), attributes);
|
|
|
|
PUBLIC_SYMBOL_LIST(INSTALL_PUBLIC_SYMBOL)
|
|
|
|
#undef INSTALL_PUBLIC_SYMBOL
|
|
|
|
}
|
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
// Install natives.
|
2015-03-06 15:06:54 +00:00
|
|
|
int i = Natives::GetDebuggerCount();
|
|
|
|
if (!CompileBuiltin(isolate(), i)) return false;
|
|
|
|
if (!InstallJSBuiltins(builtins)) return false;
|
|
|
|
|
|
|
|
for (++i; i < Natives::GetBuiltinsCount(); ++i) {
|
2011-04-14 08:01:19 +00:00
|
|
|
if (!CompileBuiltin(isolate(), i)) return false;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InstallNativeFunctions();
|
|
|
|
|
2015-03-09 12:26:22 +00:00
|
|
|
auto function_cache =
|
|
|
|
ObjectHashTable::New(isolate(), ApiNatives::kInitialFunctionCacheSize);
|
|
|
|
native_context()->set_function_cache(*function_cache);
|
2015-02-04 13:01:34 +00:00
|
|
|
|
2010-08-12 13:43:08 +00:00
|
|
|
// Store the map for the string prototype 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());
|
|
|
|
|
2008-09-15 15:02:38 +00:00
|
|
|
// Install Function.prototype.call and apply.
|
2014-08-18 07:54:19 +00:00
|
|
|
{
|
|
|
|
Handle<String> key = factory()->Function_string();
|
2008-09-15 15:02:38 +00:00
|
|
|
Handle<JSFunction> function =
|
2014-03-28 09:49:27 +00:00
|
|
|
Handle<JSFunction>::cast(Object::GetProperty(
|
2014-07-01 12:12:34 +00:00
|
|
|
handle(native_context()->global_object()), key).ToHandleChecked());
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<JSObject> proto =
|
|
|
|
Handle<JSObject>(JSObject::cast(function->instance_prototype()));
|
2008-09-15 15:02:38 +00:00
|
|
|
|
|
|
|
// Install the call and the apply functions.
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<JSFunction> call =
|
2008-09-15 15:02:38 +00:00
|
|
|
InstallFunction(proto, "call", JS_OBJECT_TYPE, JSObject::kHeaderSize,
|
2014-05-09 17:21:51 +00:00
|
|
|
MaybeHandle<JSObject>(), Builtins::kFunctionCall);
|
2008-09-15 15:02:38 +00:00
|
|
|
Handle<JSFunction> apply =
|
|
|
|
InstallFunction(proto, "apply", JS_OBJECT_TYPE, JSObject::kHeaderSize,
|
2014-05-09 17:21:51 +00:00
|
|
|
MaybeHandle<JSObject>(), Builtins::kFunctionApply);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Make sure that Function.prototype.call appears to be compiled.
|
|
|
|
// The code will never be called, but inline caching for call will
|
|
|
|
// only work if it appears to be compiled.
|
2008-09-15 15:02:38 +00:00
|
|
|
call->shared()->DontAdaptArguments();
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(call->is_compiled());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-01-15 19:08:34 +00:00
|
|
|
// Set the expected parameters for apply to 2; required by builtin.
|
2015-02-11 09:47:32 +00:00
|
|
|
apply->shared()->set_internal_formal_parameter_count(2);
|
2008-09-15 15:02:38 +00:00
|
|
|
|
|
|
|
// Set the lengths for the functions to satisfy ECMA-262.
|
|
|
|
call->shared()->set_length(1);
|
|
|
|
apply->shared()->set_length(2);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2011-08-10 16:05:17 +00:00
|
|
|
InstallBuiltinFunctionIds();
|
|
|
|
|
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(
|
2014-04-09 14:26:32 +00:00
|
|
|
*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
|
|
|
}
|
|
|
|
|
|
|
|
initial_map->set_inobject_properties(2);
|
|
|
|
initial_map->set_pre_allocated_property_fields(2);
|
|
|
|
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);
|
2014-08-25 09:12:22 +00:00
|
|
|
Handle<Map> map(native_context()->aliased_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);
|
2014-08-25 09:12:22 +00:00
|
|
|
Handle<Map> map(native_context()->strict_arguments_map());
|
|
|
|
Map::EnsureDescriptorSlack(map, 1);
|
|
|
|
map->AppendDescriptor(&d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-15 06:34:22 +00:00
|
|
|
#ifdef VERIFY_HEAP
|
2015-01-19 10:12:28 +00:00
|
|
|
if (FLAG_verify_heap) {
|
|
|
|
builtins->ObjectVerify();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
2010-03-23 11:40:38 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-15 12:31:03 +00:00
|
|
|
bool Genesis::InstallExperimentalNatives() {
|
2014-10-20 13:33:34 +00:00
|
|
|
static const char* harmony_arrays_natives[] = {
|
2015-04-22 12:35:05 +00:00
|
|
|
"native harmony-array.js", "native harmony-typedarray.js", nullptr};
|
2014-12-10 08:58:04 +00:00
|
|
|
static const char* harmony_array_includes_natives[] = {
|
2015-04-22 12:35:05 +00:00
|
|
|
"native harmony-array-includes.js", nullptr};
|
|
|
|
static const char* harmony_proxies_natives[] = {"native proxy.js", nullptr};
|
|
|
|
static const char* harmony_classes_natives[] = {nullptr};
|
|
|
|
static const char* harmony_modules_natives[] = {nullptr};
|
|
|
|
static const char* harmony_object_literals_natives[] = {nullptr};
|
|
|
|
static const char* harmony_regexps_natives[] = {"native harmony-regexp.js",
|
|
|
|
nullptr};
|
|
|
|
static const char* harmony_arrow_functions_natives[] = {nullptr};
|
2014-10-21 17:21:32 +00:00
|
|
|
static const char* harmony_tostring_natives[] = {"native harmony-tostring.js",
|
2015-04-22 12:35:05 +00:00
|
|
|
nullptr};
|
|
|
|
static const char* harmony_sloppy_natives[] = {nullptr};
|
|
|
|
static const char* harmony_unicode_natives[] = {nullptr};
|
|
|
|
static const char* harmony_unicode_regexps_natives[] = {nullptr};
|
|
|
|
static const char* harmony_computed_property_names_natives[] = {nullptr};
|
|
|
|
static const char* harmony_rest_parameters_natives[] = {nullptr};
|
2015-03-19 14:47:18 +00:00
|
|
|
static const char* harmony_reflect_natives[] = {"native harmony-reflect.js",
|
2015-04-22 12:35:05 +00:00
|
|
|
nullptr};
|
2015-04-09 19:37:14 +00:00
|
|
|
static const char* harmony_spreadcalls_natives[] = {
|
2015-04-22 12:35:05 +00:00
|
|
|
"native harmony-spread.js", nullptr};
|
|
|
|
static const char* harmony_destructuring_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) { \
|
|
|
|
if (!CompileExperimentalBuiltin(isolate(), i)) return false; \
|
|
|
|
} \
|
|
|
|
} \
|
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
|
|
|
|
}
|
|
|
|
|
2011-05-18 14:00:34 +00:00
|
|
|
InstallExperimentalNativeFunctions();
|
2011-04-15 12:31:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 =
|
2014-04-16 13:28:11 +00:00
|
|
|
Object::GetProperty(isolate, holder, function_name).ToHandleChecked();
|
2014-04-09 12:21:47 +00:00
|
|
|
Handle<JSFunction> function = Handle<JSFunction>::cast(function_object);
|
2010-05-06 13:21:53 +00:00
|
|
|
function->shared()->set_function_data(Smi::FromInt(id));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2010-12-14 18:53:48 +00:00
|
|
|
#define INSTALL_BUILTIN_ID(holder_expr, fun_name, name) \
|
2015-02-27 15:21:42 +00:00
|
|
|
{ #holder_expr, #fun_name, k##name } \
|
|
|
|
,
|
|
|
|
const BuiltinFunctionIds builtins[] = {
|
|
|
|
FUNCTIONS_WITH_ID_LIST(INSTALL_BUILTIN_ID)};
|
2010-12-14 18:53:48 +00:00
|
|
|
#undef INSTALL_BUILTIN_ID
|
2015-02-27 15:21:42 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-14 14:46:15 +00:00
|
|
|
// Do not forget to update macros.py with named constant
|
|
|
|
// of cache id.
|
|
|
|
#define JSFUNCTION_RESULT_CACHE_LIST(F) \
|
2012-08-17 09:03:08 +00:00
|
|
|
F(16, native_context()->regexp_function())
|
2010-04-14 14:46:15 +00:00
|
|
|
|
|
|
|
|
2011-05-16 09:06:16 +00:00
|
|
|
static FixedArray* CreateCache(int size, Handle<JSFunction> factory_function) {
|
2011-04-14 08:01:19 +00:00
|
|
|
Factory* factory = factory_function->GetIsolate()->factory();
|
2010-04-14 14:46:15 +00:00
|
|
|
// Caches are supposed to live for a long time, allocate in old space.
|
|
|
|
int array_size = JSFunctionResultCache::kEntriesIndex + 2 * size;
|
2010-05-04 16:42:11 +00:00
|
|
|
// Cannot use cast as object is not fully initialized yet.
|
|
|
|
JSFunctionResultCache* cache = reinterpret_cast<JSFunctionResultCache*>(
|
2011-04-14 08:01:19 +00:00
|
|
|
*factory->NewFixedArrayWithHoles(array_size, TENURED));
|
2011-05-16 09:06:16 +00:00
|
|
|
cache->set(JSFunctionResultCache::kFactoryIndex, *factory_function);
|
2010-05-04 16:42:11 +00:00
|
|
|
cache->MakeZeroSize();
|
|
|
|
return cache;
|
2010-04-14 14:46:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Genesis::InstallJSFunctionResultCaches() {
|
|
|
|
const int kNumberOfCaches = 0 +
|
|
|
|
#define F(size, func) + 1
|
|
|
|
JSFUNCTION_RESULT_CACHE_LIST(F)
|
|
|
|
#undef F
|
|
|
|
;
|
|
|
|
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<FixedArray> caches =
|
|
|
|
factory()->NewFixedArray(kNumberOfCaches, TENURED);
|
2010-04-14 14:46:15 +00:00
|
|
|
|
|
|
|
int index = 0;
|
2010-09-23 08:27:51 +00:00
|
|
|
|
2011-05-16 09:06:16 +00:00
|
|
|
#define F(size, func) do { \
|
|
|
|
FixedArray* cache = CreateCache((size), Handle<JSFunction>(func)); \
|
|
|
|
caches->set(index++, cache); \
|
2010-09-23 08:27:51 +00:00
|
|
|
} while (false)
|
|
|
|
|
|
|
|
JSFUNCTION_RESULT_CACHE_LIST(F);
|
|
|
|
|
2010-04-14 14:46:15 +00:00
|
|
|
#undef F
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context()->set_jsfunction_result_caches(*caches);
|
2010-04-14 14:46:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
Handle<JSObject> Error = Handle<JSObject>::cast(
|
|
|
|
Object::GetProperty(isolate, global, "Error").ToHandleChecked());
|
|
|
|
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 natives in global if a name for it is specified.
|
|
|
|
if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) {
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> natives =
|
|
|
|
factory->InternalizeUtf8String(FLAG_expose_natives_as);
|
2014-09-04 15:05:06 +00:00
|
|
|
uint32_t dummy_index;
|
|
|
|
if (natives->AsArrayIndex(&dummy_index)) return true;
|
2014-07-07 13:27:37 +00:00
|
|
|
JSObject::AddProperty(global, natives, handle(global->builtins()),
|
|
|
|
DONT_ENUM);
|
2009-06-30 11:08:37 +00:00
|
|
|
}
|
|
|
|
|
2014-07-02 14:18:10 +00:00
|
|
|
// Expose the stack trace symbol to native JS.
|
2014-09-10 12:38:12 +00:00
|
|
|
RETURN_ON_EXCEPTION_VALUE(isolate,
|
|
|
|
JSObject::SetOwnPropertyIgnoreAttributes(
|
|
|
|
handle(native_context->builtins(), isolate),
|
|
|
|
factory->InternalizeOneByteString(
|
2015-04-27 12:33:58 +00:00
|
|
|
STATIC_CHAR_VECTOR("$stackTraceSymbol")),
|
2014-09-10 12:38:12 +00:00
|
|
|
factory->stack_trace_symbol(), NONE),
|
|
|
|
false);
|
2014-07-02 14:18:10 +00:00
|
|
|
|
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
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2014-04-15 14:48:21 +00:00
|
|
|
Genesis::ExtensionStates::ExtensionStates() : map_(HashMap::PointersMatch, 8) {}
|
2011-11-15 22:48:55 +00:00
|
|
|
|
|
|
|
Genesis::ExtensionTraversalState Genesis::ExtensionStates::get_state(
|
|
|
|
RegisteredExtension* extension) {
|
2015-04-13 19:01:15 +00:00
|
|
|
i::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) &&
|
|
|
|
(!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)) &&
|
|
|
|
(!FLAG_track_gc_object_stats ||
|
|
|
|
InstallExtension(isolate, "v8/statistics", &extension_states)) &&
|
|
|
|
(!FLAG_expose_trigger_failure ||
|
|
|
|
InstallExtension(isolate, "v8/trigger-failure", &extension_states)) &&
|
|
|
|
InstallRequestedExtensions(isolate, extensions, &extension_states);
|
|
|
|
}
|
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.
|
2014-04-03 12:41:37 +00:00
|
|
|
Handle<String> source_code =
|
2014-09-10 12:38:12 +00:00
|
|
|
isolate->factory()
|
|
|
|
->NewExternalStringFromOneByte(extension->source())
|
|
|
|
.ToHandleChecked();
|
2013-02-15 09:27:10 +00:00
|
|
|
bool result = CompileScriptCached(isolate,
|
|
|
|
CStrVector(extension->name()),
|
|
|
|
source_code,
|
|
|
|
isolate->bootstrapper()->extensions_cache(),
|
|
|
|
extension,
|
|
|
|
Handle<Context>(isolate->context()),
|
|
|
|
false);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-11 08:05:33 +00:00
|
|
|
bool Genesis::InstallJSBuiltins(Handle<JSBuiltinsObject> builtins) {
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(isolate());
|
2010-02-11 08:05:33 +00:00
|
|
|
for (int i = 0; i < Builtins::NumberOfJavaScriptBuiltins(); i++) {
|
|
|
|
Builtins::JavaScript id = static_cast<Builtins::JavaScript>(i);
|
2014-04-16 13:28:11 +00:00
|
|
|
Handle<Object> function_object = Object::GetProperty(
|
|
|
|
isolate(), builtins, Builtins::GetName(id)).ToHandleChecked();
|
2014-04-09 12:21:47 +00:00
|
|
|
Handle<JSFunction> function = Handle<JSFunction>::cast(function_object);
|
2010-02-11 08:05:33 +00:00
|
|
|
builtins->set_javascript_builtin(id, *function);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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(
|
|
|
|
v8::Handle<v8::ObjectTemplate> global_proxy_template) {
|
|
|
|
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()));
|
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 (!proxy_constructor->prototype_template()->IsUndefined()) {
|
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
|
|
|
|
2014-07-01 12:12:34 +00:00
|
|
|
SetObjectPrototype(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()));
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} 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));
|
|
|
|
if (properties->IsKey(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());
|
2013-06-14 16:06:12 +00:00
|
|
|
if (value->IsPropertyCell()) {
|
2015-03-19 23:54:04 +00:00
|
|
|
value = handle(PropertyCell::cast(*value)->value(), isolate());
|
2009-06-30 10:05:36 +00:00
|
|
|
}
|
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());
|
|
|
|
SetObjectPrototype(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,
|
|
|
|
v8::Handle<v8::ObjectTemplate> global_proxy_template,
|
2013-02-15 09:27:10 +00:00
|
|
|
v8::ExtensionConfiguration* extensions)
|
|
|
|
: 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();
|
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);
|
2014-03-28 14:16:11 +00:00
|
|
|
if (check.HasOverflowed()) 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)) {
|
|
|
|
global_proxy = isolate->factory()->NewUninitializedJSGlobalProxy();
|
|
|
|
}
|
|
|
|
|
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-01-13 08:48:00 +00:00
|
|
|
Handle<FixedArray> outdated_contexts;
|
|
|
|
if (!isolate->initialized_from_snapshot() ||
|
2015-01-14 16:42:15 +00:00
|
|
|
!Snapshot::NewContextFromSnapshot(isolate, global_proxy,
|
|
|
|
&outdated_contexts)
|
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-01-14 16:42:15 +00:00
|
|
|
Handle<GlobalObject> global_object =
|
|
|
|
CreateNewGlobals(global_proxy_template, global_proxy);
|
2014-07-01 12:12:34 +00:00
|
|
|
|
|
|
|
HookUpGlobalProxy(global_object, global_proxy);
|
2015-01-13 08:48:00 +00:00
|
|
|
HookUpGlobalObject(global_object, outdated_contexts);
|
2014-07-01 12:12:34 +00:00
|
|
|
native_context()->builtins()->set_global_proxy(
|
2014-01-07 10:46:39 +00:00
|
|
|
native_context()->global_proxy());
|
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);
|
2015-02-25 14:52:36 +00:00
|
|
|
CreateStrongModeFunctionMaps(empty_function);
|
2015-01-14 16:42:15 +00:00
|
|
|
Handle<GlobalObject> global_object =
|
|
|
|
CreateNewGlobals(global_proxy_template, global_proxy);
|
2014-07-01 12:12:34 +00:00
|
|
|
HookUpGlobalProxy(global_object, global_proxy);
|
|
|
|
InitializeGlobal(global_object, empty_function);
|
2010-04-14 14:46:15 +00:00
|
|
|
InstallJSFunctionResultCaches();
|
2010-08-25 13:25:54 +00:00
|
|
|
InitializeNormalizedMapCaches();
|
2010-05-12 12:44:00 +00:00
|
|
|
if (!InstallNatives()) return;
|
2010-03-23 11:40:38 +00:00
|
|
|
|
|
|
|
MakeFunctionInstancePrototypeWritable();
|
|
|
|
|
2014-07-01 12:12:34 +00:00
|
|
|
if (!ConfigureGlobalObjects(global_proxy_template)) return;
|
2014-02-12 13:27:13 +00:00
|
|
|
isolate->counters()->contexts_created_from_scratch()->Increment();
|
2010-03-23 11:40:38 +00:00
|
|
|
}
|
2008-08-14 13:41:48 +00:00
|
|
|
|
2015-03-04 13:01:23 +00:00
|
|
|
// Install experimental natives. Do not include them into the 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-03-12 15:44:32 +00:00
|
|
|
if (!isolate->serializer_enabled()) {
|
|
|
|
InitializeExperimentalGlobal();
|
|
|
|
if (!InstallExperimentalNatives()) return;
|
|
|
|
}
|
2011-04-15 12:31:03 +00:00
|
|
|
|
2015-01-15 11:22:04 +00:00
|
|
|
// The serializer cannot serialize typed arrays. Reset those typed arrays
|
|
|
|
// for each new context.
|
2015-02-06 09:54:58 +00:00
|
|
|
InitializeBuiltinTypedArrays();
|
2013-11-22 08:25:50 +00:00
|
|
|
|
2013-03-18 17:36:47 +00:00
|
|
|
result_ = native_context();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|