Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5 | #include "src/bootstrapper.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7 | #include "src/accessors.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8 | #include "src/api-natives.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9 | #include "src/code-stubs.h" |
| 10 | #include "src/extensions/externalize-string-extension.h" |
| 11 | #include "src/extensions/free-buffer-extension.h" |
| 12 | #include "src/extensions/gc-extension.h" |
| 13 | #include "src/extensions/statistics-extension.h" |
| 14 | #include "src/extensions/trigger-failure-extension.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 15 | #include "src/heap/heap.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 16 | #include "src/isolate-inl.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 17 | #include "src/snapshot/natives.h" |
| 18 | #include "src/snapshot/snapshot.h" |
| 19 | #include "src/wasm/wasm-js.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 20 | |
| 21 | namespace v8 { |
| 22 | namespace internal { |
| 23 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 24 | Bootstrapper::Bootstrapper(Isolate* isolate) |
| 25 | : isolate_(isolate), |
| 26 | nesting_(0), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 27 | extensions_cache_(Script::TYPE_EXTENSION) {} |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 28 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 29 | template <class Source> |
| 30 | Handle<String> Bootstrapper::SourceLookup(int index) { |
| 31 | DCHECK(0 <= index && index < Source::GetBuiltinsCount()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 32 | Heap* heap = isolate_->heap(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 33 | if (Source::GetSourceCache(heap)->get(index)->IsUndefined()) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 34 | // We can use external strings for the natives. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 35 | Vector<const char> source = Source::GetScriptSource(index); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 36 | NativesExternalStringResource* resource = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 37 | new NativesExternalStringResource(source.start(), source.length()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 38 | // We do not expect this to throw an exception. Change this if it does. |
| 39 | Handle<String> source_code = isolate_->factory() |
| 40 | ->NewExternalStringFromOneByte(resource) |
| 41 | .ToHandleChecked(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 42 | // Mark this external string with a special map. |
| 43 | source_code->set_map(isolate_->heap()->native_source_string_map()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 44 | Source::GetSourceCache(heap)->set(index, *source_code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 45 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 46 | Handle<Object> cached_source(Source::GetSourceCache(heap)->get(index), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 47 | isolate_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 48 | return Handle<String>::cast(cached_source); |
| 49 | } |
| 50 | |
| 51 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 52 | template Handle<String> Bootstrapper::SourceLookup<Natives>(int index); |
| 53 | template Handle<String> Bootstrapper::SourceLookup<ExperimentalNatives>( |
| 54 | int index); |
| 55 | template Handle<String> Bootstrapper::SourceLookup<ExperimentalExtraNatives>( |
| 56 | int index); |
| 57 | template Handle<String> Bootstrapper::SourceLookup<ExtraNatives>(int index); |
| 58 | |
| 59 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 60 | void Bootstrapper::Initialize(bool create_heap_objects) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 61 | extensions_cache_.Initialize(isolate_, create_heap_objects); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | static const char* GCFunctionName() { |
| 66 | bool flag_given = FLAG_expose_gc_as != NULL && strlen(FLAG_expose_gc_as) != 0; |
| 67 | return flag_given ? FLAG_expose_gc_as : "gc"; |
| 68 | } |
| 69 | |
| 70 | |
| 71 | v8::Extension* Bootstrapper::free_buffer_extension_ = NULL; |
| 72 | v8::Extension* Bootstrapper::gc_extension_ = NULL; |
| 73 | v8::Extension* Bootstrapper::externalize_string_extension_ = NULL; |
| 74 | v8::Extension* Bootstrapper::statistics_extension_ = NULL; |
| 75 | v8::Extension* Bootstrapper::trigger_failure_extension_ = NULL; |
| 76 | |
| 77 | |
| 78 | void Bootstrapper::InitializeOncePerProcess() { |
| 79 | free_buffer_extension_ = new FreeBufferExtension; |
| 80 | v8::RegisterExtension(free_buffer_extension_); |
| 81 | gc_extension_ = new GCExtension(GCFunctionName()); |
| 82 | v8::RegisterExtension(gc_extension_); |
| 83 | externalize_string_extension_ = new ExternalizeStringExtension; |
| 84 | v8::RegisterExtension(externalize_string_extension_); |
| 85 | statistics_extension_ = new StatisticsExtension; |
| 86 | v8::RegisterExtension(statistics_extension_); |
| 87 | trigger_failure_extension_ = new TriggerFailureExtension; |
| 88 | v8::RegisterExtension(trigger_failure_extension_); |
| 89 | } |
| 90 | |
| 91 | |
| 92 | void Bootstrapper::TearDownExtensions() { |
| 93 | delete free_buffer_extension_; |
| 94 | free_buffer_extension_ = NULL; |
| 95 | delete gc_extension_; |
| 96 | gc_extension_ = NULL; |
| 97 | delete externalize_string_extension_; |
| 98 | externalize_string_extension_ = NULL; |
| 99 | delete statistics_extension_; |
| 100 | statistics_extension_ = NULL; |
| 101 | delete trigger_failure_extension_; |
| 102 | trigger_failure_extension_ = NULL; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 106 | void DeleteNativeSources(Object* maybe_array) { |
| 107 | if (maybe_array->IsFixedArray()) { |
| 108 | FixedArray* array = FixedArray::cast(maybe_array); |
| 109 | for (int i = 0; i < array->length(); i++) { |
| 110 | Object* natives_source = array->get(i); |
| 111 | if (!natives_source->IsUndefined()) { |
| 112 | const NativesExternalStringResource* resource = |
| 113 | reinterpret_cast<const NativesExternalStringResource*>( |
| 114 | ExternalOneByteString::cast(natives_source)->resource()); |
| 115 | delete resource; |
| 116 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 117 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 118 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 122 | void Bootstrapper::TearDown() { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 123 | DeleteNativeSources(Natives::GetSourceCache(isolate_->heap())); |
| 124 | DeleteNativeSources(ExperimentalNatives::GetSourceCache(isolate_->heap())); |
| 125 | DeleteNativeSources(ExtraNatives::GetSourceCache(isolate_->heap())); |
| 126 | DeleteNativeSources( |
| 127 | ExperimentalExtraNatives::GetSourceCache(isolate_->heap())); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 128 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 129 | extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 133 | class Genesis BASE_EMBEDDED { |
| 134 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 135 | Genesis(Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
| 136 | v8::Local<v8::ObjectTemplate> global_proxy_template, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 137 | v8::ExtensionConfiguration* extensions, |
| 138 | GlobalContextType context_type); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 139 | ~Genesis() { } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 140 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 141 | Isolate* isolate() const { return isolate_; } |
| 142 | Factory* factory() const { return isolate_->factory(); } |
| 143 | Heap* heap() const { return isolate_->heap(); } |
| 144 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 145 | Handle<Context> result() { return result_; } |
| 146 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 147 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 148 | Handle<Context> native_context() { return native_context_; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 149 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 150 | // Creates some basic objects. Used for creating a context from scratch. |
| 151 | void CreateRoots(); |
| 152 | // Creates the empty function. Used for creating a context from scratch. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 153 | Handle<JSFunction> CreateEmptyFunction(Isolate* isolate); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 154 | // Creates the ThrowTypeError function. ECMA 5th Ed. 13.2.3 |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 155 | Handle<JSFunction> GetRestrictedFunctionPropertiesThrower(); |
| 156 | Handle<JSFunction> GetStrictArgumentsPoisonFunction(); |
| 157 | Handle<JSFunction> GetThrowTypeErrorIntrinsic(Builtins::Name builtin_name); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 158 | |
| 159 | void CreateStrictModeFunctionMaps(Handle<JSFunction> empty); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 160 | void CreateStrongModeFunctionMaps(Handle<JSFunction> empty); |
| 161 | void CreateIteratorMaps(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 162 | |
| 163 | // Make the "arguments" and "caller" properties throw a TypeError on access. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 164 | void AddRestrictedFunctionProperties(Handle<Map> map); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 165 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 166 | // Creates the global objects using the global proxy and the template passed |
| 167 | // in through the API. We call this regardless of whether we are building a |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 168 | // context from scratch or using a deserialized one from the partial snapshot |
| 169 | // but in the latter case we don't use the objects it produces directly, as |
| 170 | // we have to used the deserialized ones that are linked together with the |
| 171 | // rest of the context snapshot. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 172 | Handle<JSGlobalObject> CreateNewGlobals( |
| 173 | v8::Local<v8::ObjectTemplate> global_proxy_template, |
| 174 | Handle<JSGlobalProxy> global_proxy); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 175 | // Hooks the given global proxy into the context. If the context was created |
| 176 | // by deserialization then this will unhook the global proxy that was |
| 177 | // deserialized, leaving the GC to pick it up. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 178 | void HookUpGlobalProxy(Handle<JSGlobalObject> global_object, |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 179 | Handle<JSGlobalProxy> global_proxy); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 180 | // Similarly, we want to use the global that has been created by the templates |
| 181 | // passed through the API. The global from the snapshot is detached from the |
| 182 | // other objects in the snapshot. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 183 | void HookUpGlobalObject(Handle<JSGlobalObject> global_object); |
| 184 | // The native context has a ScriptContextTable that store declarative bindings |
| 185 | // made in script scopes. Add a "this" binding to that table pointing to the |
| 186 | // global proxy. |
| 187 | void InstallGlobalThisBinding(); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 188 | // New context initialization. Used for creating a context from scratch. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 189 | void InitializeGlobal(Handle<JSGlobalObject> global_object, |
| 190 | Handle<JSFunction> empty_function, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 191 | GlobalContextType context_type); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 192 | void InitializeExperimentalGlobal(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 193 | // Depending on the situation, expose and/or get rid of the utils object. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 194 | void ConfigureUtilsObject(GlobalContextType context_type); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 195 | |
| 196 | #define DECLARE_FEATURE_INITIALIZATION(id, descr) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 197 | void InitializeGlobal_##id(); |
| 198 | |
| 199 | HARMONY_INPROGRESS(DECLARE_FEATURE_INITIALIZATION) |
| 200 | HARMONY_STAGED(DECLARE_FEATURE_INITIALIZATION) |
| 201 | HARMONY_SHIPPING(DECLARE_FEATURE_INITIALIZATION) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 202 | DECLARE_FEATURE_INITIALIZATION(promise_extra, "") |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 203 | #undef DECLARE_FEATURE_INITIALIZATION |
| 204 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 205 | Handle<JSFunction> InstallArrayBuffer(Handle<JSObject> target, |
| 206 | const char* name); |
| 207 | Handle<JSFunction> InstallInternalArray(Handle<JSObject> target, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 208 | const char* name, |
| 209 | ElementsKind elements_kind); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 210 | bool InstallNatives(GlobalContextType context_type); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 211 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 212 | void InstallTypedArray(const char* name, ElementsKind elements_kind, |
| 213 | Handle<JSFunction>* fun); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 214 | bool InstallExperimentalNatives(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 215 | bool InstallExtraNatives(); |
| 216 | bool InstallExperimentalExtraNatives(); |
| 217 | bool InstallDebuggerNatives(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 218 | void InstallBuiltinFunctionIds(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 219 | void InstallExperimentalBuiltinFunctionIds(); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 220 | void InitializeNormalizedMapCaches(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 221 | void InstallJSProxyMaps(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 222 | |
| 223 | enum ExtensionTraversalState { |
| 224 | UNVISITED, VISITED, INSTALLED |
| 225 | }; |
| 226 | |
| 227 | class ExtensionStates { |
| 228 | public: |
| 229 | ExtensionStates(); |
| 230 | ExtensionTraversalState get_state(RegisteredExtension* extension); |
| 231 | void set_state(RegisteredExtension* extension, |
| 232 | ExtensionTraversalState state); |
| 233 | private: |
| 234 | HashMap map_; |
| 235 | DISALLOW_COPY_AND_ASSIGN(ExtensionStates); |
| 236 | }; |
| 237 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 238 | // Used both for deserialized and from-scratch contexts to add the extensions |
| 239 | // provided. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 240 | static bool InstallExtensions(Handle<Context> native_context, |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 241 | v8::ExtensionConfiguration* extensions); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 242 | static bool InstallAutoExtensions(Isolate* isolate, |
| 243 | ExtensionStates* extension_states); |
| 244 | static bool InstallRequestedExtensions(Isolate* isolate, |
| 245 | v8::ExtensionConfiguration* extensions, |
| 246 | ExtensionStates* extension_states); |
| 247 | static bool InstallExtension(Isolate* isolate, |
| 248 | const char* name, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 249 | ExtensionStates* extension_states); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 250 | static bool InstallExtension(Isolate* isolate, |
| 251 | v8::RegisteredExtension* current, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 252 | ExtensionStates* extension_states); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 253 | static bool InstallSpecialObjects(Handle<Context> native_context); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 254 | bool ConfigureApiObject(Handle<JSObject> object, |
| 255 | Handle<ObjectTemplateInfo> object_template); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 256 | bool ConfigureGlobalObjects( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 257 | v8::Local<v8::ObjectTemplate> global_proxy_template); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 258 | |
| 259 | // Migrates all properties from the 'from' object to the 'to' |
| 260 | // object and overrides the prototype in 'to' with the one from |
| 261 | // 'from'. |
| 262 | void TransferObject(Handle<JSObject> from, Handle<JSObject> to); |
| 263 | void TransferNamedProperties(Handle<JSObject> from, Handle<JSObject> to); |
| 264 | void TransferIndexedProperties(Handle<JSObject> from, Handle<JSObject> to); |
| 265 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 266 | enum FunctionMode { |
| 267 | // With prototype. |
| 268 | FUNCTION_WITH_WRITEABLE_PROTOTYPE, |
| 269 | FUNCTION_WITH_READONLY_PROTOTYPE, |
| 270 | // Without prototype. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 271 | FUNCTION_WITHOUT_PROTOTYPE |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 272 | }; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 273 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 274 | static bool IsFunctionModeWithPrototype(FunctionMode function_mode) { |
| 275 | return (function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE || |
| 276 | function_mode == FUNCTION_WITH_READONLY_PROTOTYPE); |
| 277 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 278 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 279 | Handle<Map> CreateSloppyFunctionMap(FunctionMode function_mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 280 | |
| 281 | void SetFunctionInstanceDescriptor(Handle<Map> map, |
| 282 | FunctionMode function_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 283 | void MakeFunctionInstancePrototypeWritable(); |
| 284 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 285 | Handle<Map> CreateStrictFunctionMap(FunctionMode function_mode, |
| 286 | Handle<JSFunction> empty_function); |
| 287 | Handle<Map> CreateStrongFunctionMap(Handle<JSFunction> empty_function, |
| 288 | bool is_constructor); |
| 289 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 290 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 291 | void SetStrictFunctionInstanceDescriptor(Handle<Map> map, |
| 292 | FunctionMode function_mode); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 293 | void SetStrongFunctionInstanceDescriptor(Handle<Map> map); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 294 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 295 | static bool CallUtilsFunction(Isolate* isolate, const char* name); |
| 296 | |
| 297 | static bool CompileExtension(Isolate* isolate, v8::Extension* extension); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 298 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 299 | Isolate* isolate_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 300 | Handle<Context> result_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 301 | Handle<Context> native_context_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 302 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 303 | // Function maps. Function maps are created initially with a read only |
| 304 | // prototype for the processing of JS builtins. Later the function maps are |
| 305 | // replaced in order to make prototype writable. These are the final, writable |
| 306 | // prototype, maps. |
| 307 | Handle<Map> sloppy_function_map_writable_prototype_; |
| 308 | Handle<Map> strict_function_map_writable_prototype_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 309 | Handle<JSFunction> strict_poison_function_; |
| 310 | Handle<JSFunction> restricted_function_properties_thrower_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 311 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 312 | BootstrapperActive active_; |
| 313 | friend class Bootstrapper; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 314 | }; |
| 315 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 316 | |
| 317 | void Bootstrapper::Iterate(ObjectVisitor* v) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 318 | extensions_cache_.Iterate(v); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 319 | v->Synchronize(VisitorSynchronization::kExtensions); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 322 | Handle<Context> Bootstrapper::CreateEnvironment( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 323 | MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 324 | v8::Local<v8::ObjectTemplate> global_proxy_template, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 325 | v8::ExtensionConfiguration* extensions, GlobalContextType context_type) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 326 | HandleScope scope(isolate_); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 327 | Genesis genesis(isolate_, maybe_global_proxy, global_proxy_template, |
| 328 | extensions, context_type); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 329 | Handle<Context> env = genesis.result(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 330 | if (env.is_null() || |
| 331 | (context_type != THIN_CONTEXT && !InstallExtensions(env, extensions))) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 332 | return Handle<Context>(); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 333 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 334 | return scope.CloseAndEscape(env); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | |
| 338 | static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) { |
| 339 | // object.__proto__ = proto; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 340 | Handle<Map> old_map = Handle<Map>(object->map()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 341 | Handle<Map> new_map = Map::Copy(old_map, "SetObjectPrototype"); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 342 | Map::SetPrototype(new_map, proto, FAST_PROTOTYPE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 343 | JSObject::MigrateToMap(object, new_map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | |
| 347 | void Bootstrapper::DetachGlobal(Handle<Context> env) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 348 | env->GetIsolate()->counters()->errors_thrown_per_context()->AddSample( |
| 349 | env->GetErrorsThrown()); |
| 350 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 351 | Factory* factory = env->GetIsolate()->factory(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 352 | Handle<JSGlobalProxy> global_proxy(JSGlobalProxy::cast(env->global_proxy())); |
| 353 | global_proxy->set_native_context(*factory->null_value()); |
| 354 | SetObjectPrototype(global_proxy, factory->null_value()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 355 | global_proxy->map()->SetConstructor(*factory->null_value()); |
| 356 | if (FLAG_track_detached_contexts) { |
| 357 | env->GetIsolate()->AddDetachedContext(env); |
| 358 | } |
Andrei Popescu | 74b3c14 | 2010-03-29 12:03:09 +0100 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 362 | namespace { |
| 363 | |
| 364 | void InstallFunction(Handle<JSObject> target, Handle<Name> property_name, |
| 365 | Handle<JSFunction> function, Handle<String> function_name, |
| 366 | PropertyAttributes attributes = DONT_ENUM) { |
| 367 | JSObject::AddProperty(target, property_name, function, attributes); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 368 | if (target->IsJSGlobalObject()) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 369 | function->shared()->set_instance_class_name(*function_name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 370 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 371 | function->shared()->set_native(true); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | |
| 375 | static void InstallFunction(Handle<JSObject> target, |
| 376 | Handle<JSFunction> function, Handle<Name> name, |
| 377 | PropertyAttributes attributes = DONT_ENUM) { |
| 378 | Handle<String> name_string = Name::ToFunctionName(name).ToHandleChecked(); |
| 379 | InstallFunction(target, name, function, name_string, attributes); |
| 380 | } |
| 381 | |
| 382 | |
| 383 | static Handle<JSFunction> CreateFunction(Isolate* isolate, Handle<String> name, |
| 384 | InstanceType type, int instance_size, |
| 385 | MaybeHandle<JSObject> maybe_prototype, |
| 386 | Builtins::Name call, |
| 387 | bool strict_function_map = false) { |
| 388 | Factory* factory = isolate->factory(); |
| 389 | Handle<Code> call_code(isolate->builtins()->builtin(call)); |
| 390 | Handle<JSObject> prototype; |
| 391 | static const bool kReadOnlyPrototype = false; |
| 392 | static const bool kInstallConstructor = false; |
| 393 | return maybe_prototype.ToHandle(&prototype) |
| 394 | ? factory->NewFunction(name, call_code, prototype, type, |
| 395 | instance_size, kReadOnlyPrototype, |
| 396 | kInstallConstructor, strict_function_map) |
| 397 | : factory->NewFunctionWithoutPrototype(name, call_code, |
| 398 | strict_function_map); |
| 399 | } |
| 400 | |
| 401 | |
| 402 | Handle<JSFunction> InstallFunction(Handle<JSObject> target, Handle<Name> name, |
| 403 | InstanceType type, int instance_size, |
| 404 | MaybeHandle<JSObject> maybe_prototype, |
| 405 | Builtins::Name call, |
| 406 | PropertyAttributes attributes, |
| 407 | bool strict_function_map = false) { |
| 408 | Handle<String> name_string = Name::ToFunctionName(name).ToHandleChecked(); |
| 409 | Handle<JSFunction> function = |
| 410 | CreateFunction(target->GetIsolate(), name_string, type, instance_size, |
| 411 | maybe_prototype, call, strict_function_map); |
| 412 | InstallFunction(target, name, function, name_string, attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 413 | return function; |
| 414 | } |
| 415 | |
| 416 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 417 | Handle<JSFunction> InstallFunction(Handle<JSObject> target, const char* name, |
| 418 | InstanceType type, int instance_size, |
| 419 | MaybeHandle<JSObject> maybe_prototype, |
| 420 | Builtins::Name call, |
| 421 | bool strict_function_map = false) { |
| 422 | Factory* const factory = target->GetIsolate()->factory(); |
| 423 | PropertyAttributes attributes = DONT_ENUM; |
| 424 | return InstallFunction(target, factory->InternalizeUtf8String(name), type, |
| 425 | instance_size, maybe_prototype, call, attributes, |
| 426 | strict_function_map); |
| 427 | } |
| 428 | |
| 429 | } // namespace |
| 430 | |
| 431 | |
| 432 | void Genesis::SetFunctionInstanceDescriptor(Handle<Map> map, |
| 433 | FunctionMode function_mode) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 434 | int size = IsFunctionModeWithPrototype(function_mode) ? 5 : 4; |
| 435 | Map::EnsureDescriptorSlack(map, size); |
| 436 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 437 | PropertyAttributes ro_attribs = |
| 438 | static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 439 | PropertyAttributes roc_attribs = |
| 440 | static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 441 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 442 | Handle<AccessorInfo> length = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 443 | Accessors::FunctionLengthInfo(isolate(), roc_attribs); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 444 | { // Add length. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 445 | AccessorConstantDescriptor d(Handle<Name>(Name::cast(length->name())), |
| 446 | length, roc_attribs); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 447 | map->AppendDescriptor(&d); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 448 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 449 | Handle<AccessorInfo> name = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 450 | Accessors::FunctionNameInfo(isolate(), ro_attribs); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 451 | { // Add name. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 452 | AccessorConstantDescriptor d(Handle<Name>(Name::cast(name->name())), name, |
| 453 | roc_attribs); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 454 | map->AppendDescriptor(&d); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 455 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 456 | Handle<AccessorInfo> args = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 457 | Accessors::FunctionArgumentsInfo(isolate(), ro_attribs); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 458 | { // Add arguments. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 459 | AccessorConstantDescriptor d(Handle<Name>(Name::cast(args->name())), args, |
| 460 | ro_attribs); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 461 | map->AppendDescriptor(&d); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 462 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 463 | Handle<AccessorInfo> caller = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 464 | Accessors::FunctionCallerInfo(isolate(), ro_attribs); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 465 | { // Add caller. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 466 | AccessorConstantDescriptor d(Handle<Name>(Name::cast(caller->name())), |
| 467 | caller, ro_attribs); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 468 | map->AppendDescriptor(&d); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 469 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 470 | if (IsFunctionModeWithPrototype(function_mode)) { |
| 471 | if (function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 472 | ro_attribs = static_cast<PropertyAttributes>(ro_attribs & ~READ_ONLY); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 473 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 474 | Handle<AccessorInfo> prototype = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 475 | Accessors::FunctionPrototypeInfo(isolate(), ro_attribs); |
| 476 | AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())), |
| 477 | prototype, ro_attribs); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 478 | map->AppendDescriptor(&d); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 479 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 480 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 481 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 482 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 483 | Handle<Map> Genesis::CreateSloppyFunctionMap(FunctionMode function_mode) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 484 | Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 485 | SetFunctionInstanceDescriptor(map, function_mode); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 486 | map->set_is_constructor(IsFunctionModeWithPrototype(function_mode)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 487 | map->set_is_callable(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 488 | return map; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 492 | Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 493 | // Allocate the map for function instances. Maps are allocated first and their |
| 494 | // prototypes patched later, once empty function is created. |
| 495 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 496 | // Functions with this map will not have a 'prototype' property, and |
| 497 | // can not be used as constructors. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 498 | Handle<Map> function_without_prototype_map = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 499 | CreateSloppyFunctionMap(FUNCTION_WITHOUT_PROTOTYPE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 500 | native_context()->set_sloppy_function_without_prototype_map( |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 501 | *function_without_prototype_map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 502 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 503 | // Allocate the function map. This map is temporary, used only for processing |
| 504 | // of builtins. |
| 505 | // Later the map is replaced with writable prototype map, allocated below. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 506 | Handle<Map> function_map = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 507 | CreateSloppyFunctionMap(FUNCTION_WITH_READONLY_PROTOTYPE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 508 | native_context()->set_sloppy_function_map(*function_map); |
| 509 | native_context()->set_sloppy_function_with_readonly_prototype_map( |
| 510 | *function_map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 511 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 512 | // The final map for functions. Writeable prototype. |
| 513 | // This map is installed in MakeFunctionInstancePrototypeWritable. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 514 | sloppy_function_map_writable_prototype_ = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 515 | CreateSloppyFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 516 | Factory* factory = isolate->factory(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 517 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 518 | Handle<String> object_name = factory->Object_string(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 519 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 520 | Handle<JSObject> object_function_prototype; |
| 521 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 522 | { // --- O b j e c t --- |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 523 | Handle<JSFunction> object_fun = factory->NewFunction(object_name); |
| 524 | int unused = JSObject::kInitialGlobalObjectUnusedPropertiesCount; |
| 525 | int instance_size = JSObject::kHeaderSize + kPointerSize * unused; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 526 | Handle<Map> object_function_map = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 527 | factory->NewMap(JS_OBJECT_TYPE, instance_size); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 528 | object_function_map->SetInObjectProperties(unused); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 529 | JSFunction::SetInitialMap(object_fun, object_function_map, |
| 530 | isolate->factory()->null_value()); |
| 531 | object_function_map->set_unused_property_fields(unused); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 532 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 533 | native_context()->set_object_function(*object_fun); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 534 | |
| 535 | // Allocate a new prototype for the object function. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 536 | object_function_prototype = |
| 537 | factory->NewJSObject(isolate->object_function(), TENURED); |
| 538 | Handle<Map> map = Map::Copy(handle(object_function_prototype->map()), |
| 539 | "EmptyObjectPrototype"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 540 | map->set_is_prototype_map(true); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 541 | object_function_prototype->set_map(*map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 542 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 543 | native_context()->set_initial_object_prototype(*object_function_prototype); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 544 | // For bootstrapping set the array prototype to be the same as the object |
| 545 | // prototype, otherwise the missing initial_array_prototype will cause |
| 546 | // assertions during startup. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 547 | native_context()->set_initial_array_prototype(*object_function_prototype); |
| 548 | Accessors::FunctionSetPrototype(object_fun, object_function_prototype) |
| 549 | .Assert(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 550 | |
| 551 | // Allocate initial strong object map. |
| 552 | Handle<Map> strong_object_map = |
| 553 | Map::Copy(Handle<Map>(object_fun->initial_map()), "EmptyStrongObject"); |
| 554 | strong_object_map->set_is_strong(); |
| 555 | native_context()->set_js_object_strong_map(*strong_object_map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 556 | } |
| 557 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 558 | // Allocate the empty function as the prototype for function - ES6 19.2.3 |
| 559 | Handle<Code> code(isolate->builtins()->EmptyFunction()); |
| 560 | Handle<JSFunction> empty_function = |
| 561 | factory->NewFunctionWithoutPrototype(factory->empty_string(), code); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 562 | |
| 563 | // Allocate the function map first and then patch the prototype later |
| 564 | Handle<Map> empty_function_map = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 565 | CreateSloppyFunctionMap(FUNCTION_WITHOUT_PROTOTYPE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 566 | DCHECK(!empty_function_map->is_dictionary_map()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 567 | Map::SetPrototype(empty_function_map, object_function_prototype); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 568 | empty_function_map->set_is_prototype_map(true); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 569 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 570 | empty_function->set_map(*empty_function_map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 571 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 572 | // --- E m p t y --- |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 573 | Handle<String> source = factory->NewStringFromStaticChars("() {}"); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 574 | Handle<Script> script = factory->NewScript(source); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 575 | script->set_type(Script::TYPE_NATIVE); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 576 | empty_function->shared()->set_start_position(0); |
| 577 | empty_function->shared()->set_end_position(source->length()); |
| 578 | empty_function->shared()->DontAdaptArguments(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 579 | SharedFunctionInfo::SetScript(handle(empty_function->shared()), script); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 580 | |
| 581 | // Set prototypes for the function maps. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 582 | Handle<Map> sloppy_function_map(native_context()->sloppy_function_map(), |
| 583 | isolate); |
| 584 | Handle<Map> sloppy_function_without_prototype_map( |
| 585 | native_context()->sloppy_function_without_prototype_map(), isolate); |
| 586 | Map::SetPrototype(sloppy_function_map, empty_function); |
| 587 | Map::SetPrototype(sloppy_function_without_prototype_map, empty_function); |
| 588 | Map::SetPrototype(sloppy_function_map_writable_prototype_, empty_function); |
| 589 | |
| 590 | // ES6 draft 03-17-2015, section 8.2.2 step 12 |
| 591 | AddRestrictedFunctionProperties(empty_function_map); |
| 592 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 593 | return empty_function; |
| 594 | } |
| 595 | |
| 596 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 597 | void Genesis::SetStrictFunctionInstanceDescriptor(Handle<Map> map, |
| 598 | FunctionMode function_mode) { |
| 599 | int size = IsFunctionModeWithPrototype(function_mode) ? 3 : 2; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 600 | Map::EnsureDescriptorSlack(map, size); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 601 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 602 | PropertyAttributes rw_attribs = |
| 603 | static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); |
| 604 | PropertyAttributes ro_attribs = |
| 605 | static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 606 | PropertyAttributes roc_attribs = |
| 607 | static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 608 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 609 | DCHECK(function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE || |
| 610 | function_mode == FUNCTION_WITH_READONLY_PROTOTYPE || |
| 611 | function_mode == FUNCTION_WITHOUT_PROTOTYPE); |
| 612 | { // Add length. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 613 | Handle<AccessorInfo> length = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 614 | Accessors::FunctionLengthInfo(isolate(), roc_attribs); |
| 615 | AccessorConstantDescriptor d(Handle<Name>(Name::cast(length->name())), |
| 616 | length, roc_attribs); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 617 | map->AppendDescriptor(&d); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 618 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 619 | { // Add name. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 620 | Handle<AccessorInfo> name = |
| 621 | Accessors::FunctionNameInfo(isolate(), roc_attribs); |
| 622 | AccessorConstantDescriptor d(Handle<Name>(Name::cast(name->name())), name, |
| 623 | roc_attribs); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 624 | map->AppendDescriptor(&d); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 625 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 626 | if (IsFunctionModeWithPrototype(function_mode)) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 627 | // Add prototype. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 628 | PropertyAttributes attribs = |
| 629 | function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE ? rw_attribs |
| 630 | : ro_attribs; |
| 631 | Handle<AccessorInfo> prototype = |
| 632 | Accessors::FunctionPrototypeInfo(isolate(), attribs); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 633 | AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())), |
| 634 | prototype, attribs); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 635 | map->AppendDescriptor(&d); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 636 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 640 | void Genesis::SetStrongFunctionInstanceDescriptor(Handle<Map> map) { |
| 641 | Map::EnsureDescriptorSlack(map, 2); |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 642 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 643 | PropertyAttributes ro_attribs = |
| 644 | static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 645 | |
| 646 | Handle<AccessorInfo> length = |
| 647 | Accessors::FunctionLengthInfo(isolate(), ro_attribs); |
| 648 | { // Add length. |
| 649 | AccessorConstantDescriptor d(Handle<Name>(Name::cast(length->name())), |
| 650 | length, ro_attribs); |
| 651 | map->AppendDescriptor(&d); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 652 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 653 | Handle<AccessorInfo> name = |
| 654 | Accessors::FunctionNameInfo(isolate(), ro_attribs); |
| 655 | { // Add name. |
| 656 | AccessorConstantDescriptor d(Handle<Name>(Name::cast(name->name())), name, |
| 657 | ro_attribs); |
| 658 | map->AppendDescriptor(&d); |
| 659 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 663 | // Creates the %ThrowTypeError% function. |
| 664 | Handle<JSFunction> Genesis::GetThrowTypeErrorIntrinsic( |
| 665 | Builtins::Name builtin_name) { |
| 666 | Handle<String> name = |
| 667 | factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("ThrowTypeError")); |
| 668 | Handle<Code> code(isolate()->builtins()->builtin(builtin_name)); |
| 669 | Handle<JSFunction> function = |
| 670 | factory()->NewFunctionWithoutPrototype(name, code); |
| 671 | function->shared()->DontAdaptArguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 672 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 673 | // %ThrowTypeError% must not have a name property. |
| 674 | if (JSReceiver::DeleteProperty(function, factory()->name_string()) |
| 675 | .IsNothing()) { |
| 676 | DCHECK(false); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 677 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 678 | |
| 679 | // length needs to be non configurable. |
| 680 | Handle<Object> value(Smi::FromInt(function->shared()->length()), isolate()); |
| 681 | JSObject::SetOwnPropertyIgnoreAttributes( |
| 682 | function, factory()->length_string(), value, |
| 683 | static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY)) |
| 684 | .Assert(); |
| 685 | |
| 686 | if (JSObject::PreventExtensions(function, Object::THROW_ON_ERROR) |
| 687 | .IsNothing()) { |
| 688 | DCHECK(false); |
| 689 | } |
| 690 | |
| 691 | return function; |
| 692 | } |
| 693 | |
| 694 | |
| 695 | // ECMAScript 5th Edition, 13.2.3 |
| 696 | Handle<JSFunction> Genesis::GetRestrictedFunctionPropertiesThrower() { |
| 697 | if (restricted_function_properties_thrower_.is_null()) { |
| 698 | restricted_function_properties_thrower_ = GetThrowTypeErrorIntrinsic( |
| 699 | Builtins::kRestrictedFunctionPropertiesThrower); |
| 700 | } |
| 701 | return restricted_function_properties_thrower_; |
| 702 | } |
| 703 | |
| 704 | |
| 705 | Handle<JSFunction> Genesis::GetStrictArgumentsPoisonFunction() { |
| 706 | if (strict_poison_function_.is_null()) { |
| 707 | strict_poison_function_ = GetThrowTypeErrorIntrinsic( |
| 708 | Builtins::kRestrictedStrictArgumentsPropertiesThrower); |
| 709 | } |
| 710 | return strict_poison_function_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | |
| 714 | Handle<Map> Genesis::CreateStrictFunctionMap( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 715 | FunctionMode function_mode, Handle<JSFunction> empty_function) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 716 | Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 717 | SetStrictFunctionInstanceDescriptor(map, function_mode); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 718 | map->set_is_constructor(IsFunctionModeWithPrototype(function_mode)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 719 | map->set_is_callable(); |
| 720 | Map::SetPrototype(map, empty_function); |
| 721 | return map; |
| 722 | } |
| 723 | |
| 724 | |
| 725 | Handle<Map> Genesis::CreateStrongFunctionMap( |
| 726 | Handle<JSFunction> empty_function, bool is_constructor) { |
| 727 | Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); |
| 728 | SetStrongFunctionInstanceDescriptor(map); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 729 | map->set_is_constructor(is_constructor); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 730 | Map::SetPrototype(map, empty_function); |
| 731 | map->set_is_callable(); |
| 732 | map->set_is_extensible(is_constructor); |
| 733 | map->set_is_strong(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 734 | return map; |
| 735 | } |
| 736 | |
| 737 | |
| 738 | void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 739 | // Allocate map for the prototype-less strict mode instances. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 740 | Handle<Map> strict_function_without_prototype_map = |
| 741 | CreateStrictFunctionMap(FUNCTION_WITHOUT_PROTOTYPE, empty); |
| 742 | native_context()->set_strict_function_without_prototype_map( |
| 743 | *strict_function_without_prototype_map); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 744 | |
| 745 | // Allocate map for the strict mode functions. This map is temporary, used |
| 746 | // only for processing of builtins. |
| 747 | // Later the map is replaced with writable prototype map, allocated below. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 748 | Handle<Map> strict_function_map = |
| 749 | CreateStrictFunctionMap(FUNCTION_WITH_READONLY_PROTOTYPE, empty); |
| 750 | native_context()->set_strict_function_map(*strict_function_map); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 751 | |
| 752 | // The final map for the strict mode functions. Writeable prototype. |
| 753 | // This map is installed in MakeFunctionInstancePrototypeWritable. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 754 | strict_function_map_writable_prototype_ = |
| 755 | CreateStrictFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE, empty); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 756 | } |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame] | 757 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 758 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 759 | void Genesis::CreateStrongModeFunctionMaps(Handle<JSFunction> empty) { |
| 760 | // Allocate map for strong mode instances, which never have prototypes. |
| 761 | Handle<Map> strong_function_map = CreateStrongFunctionMap(empty, false); |
| 762 | native_context()->set_strong_function_map(*strong_function_map); |
| 763 | // Constructors do, though. |
| 764 | Handle<Map> strong_constructor_map = CreateStrongFunctionMap(empty, true); |
| 765 | native_context()->set_strong_constructor_map(*strong_constructor_map); |
| 766 | } |
| 767 | |
| 768 | |
| 769 | void Genesis::CreateIteratorMaps() { |
| 770 | // Create iterator-related meta-objects. |
| 771 | Handle<JSObject> iterator_prototype = |
| 772 | factory()->NewJSObject(isolate()->object_function(), TENURED); |
| 773 | Handle<JSObject> generator_object_prototype = |
| 774 | factory()->NewJSObject(isolate()->object_function(), TENURED); |
| 775 | Handle<JSObject> generator_function_prototype = |
| 776 | factory()->NewJSObject(isolate()->object_function(), TENURED); |
| 777 | SetObjectPrototype(generator_object_prototype, iterator_prototype); |
| 778 | |
| 779 | JSObject::AddProperty(generator_function_prototype, |
| 780 | factory()->InternalizeUtf8String("prototype"), |
| 781 | generator_object_prototype, |
| 782 | static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); |
| 783 | |
| 784 | // Create maps for generator functions and their prototypes. Store those |
| 785 | // maps in the native context. The "prototype" property descriptor is |
| 786 | // writable, non-enumerable, and non-configurable (as per ES6 draft |
| 787 | // 04-14-15, section 25.2.4.3). |
| 788 | Handle<Map> strict_function_map(strict_function_map_writable_prototype_); |
| 789 | // Generator functions do not have "caller" or "arguments" accessors. |
| 790 | Handle<Map> sloppy_generator_function_map = |
| 791 | Map::Copy(strict_function_map, "SloppyGeneratorFunction"); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 792 | sloppy_generator_function_map->set_is_constructor(false); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 793 | Map::SetPrototype(sloppy_generator_function_map, |
| 794 | generator_function_prototype); |
| 795 | native_context()->set_sloppy_generator_function_map( |
| 796 | *sloppy_generator_function_map); |
| 797 | |
| 798 | Handle<Map> strict_generator_function_map = |
| 799 | Map::Copy(strict_function_map, "StrictGeneratorFunction"); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 800 | strict_generator_function_map->set_is_constructor(false); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 801 | Map::SetPrototype(strict_generator_function_map, |
| 802 | generator_function_prototype); |
| 803 | native_context()->set_strict_generator_function_map( |
| 804 | *strict_generator_function_map); |
| 805 | |
| 806 | Handle<Map> strong_function_map(native_context()->strong_function_map()); |
| 807 | Handle<Map> strong_generator_function_map = |
| 808 | Map::Copy(strong_function_map, "StrongGeneratorFunction"); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 809 | strong_generator_function_map->set_is_constructor(false); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 810 | Map::SetPrototype(strong_generator_function_map, |
| 811 | generator_function_prototype); |
| 812 | native_context()->set_strong_generator_function_map( |
| 813 | *strong_generator_function_map); |
| 814 | |
| 815 | Handle<JSFunction> object_function(native_context()->object_function()); |
| 816 | Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0); |
| 817 | Map::SetPrototype(generator_object_prototype_map, generator_object_prototype); |
| 818 | native_context()->set_generator_object_prototype_map( |
| 819 | *generator_object_prototype_map); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 823 | static void ReplaceAccessors(Handle<Map> map, |
| 824 | Handle<String> name, |
| 825 | PropertyAttributes attributes, |
| 826 | Handle<AccessorPair> accessor_pair) { |
| 827 | DescriptorArray* descriptors = map->instance_descriptors(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 828 | int idx = descriptors->SearchWithCache(map->GetIsolate(), *name, *map); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 829 | AccessorConstantDescriptor descriptor(name, accessor_pair, attributes); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 830 | descriptors->Replace(idx, &descriptor); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 834 | void Genesis::AddRestrictedFunctionProperties(Handle<Map> map) { |
| 835 | PropertyAttributes rw_attribs = static_cast<PropertyAttributes>(DONT_ENUM); |
| 836 | Handle<JSFunction> thrower = GetRestrictedFunctionPropertiesThrower(); |
| 837 | Handle<AccessorPair> accessors = factory()->NewAccessorPair(); |
| 838 | accessors->set_getter(*thrower); |
| 839 | accessors->set_setter(*thrower); |
| 840 | |
| 841 | ReplaceAccessors(map, factory()->arguments_string(), rw_attribs, accessors); |
| 842 | ReplaceAccessors(map, factory()->caller_string(), rw_attribs, accessors); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | |
| 846 | static void AddToWeakNativeContextList(Context* context) { |
| 847 | DCHECK(context->IsNativeContext()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 848 | Heap* heap = context->GetIsolate()->heap(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 849 | #ifdef DEBUG |
| 850 | { // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 851 | DCHECK(context->get(Context::NEXT_CONTEXT_LINK)->IsUndefined()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 852 | // Check that context is not in the list yet. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 853 | for (Object* current = heap->native_contexts_list(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 854 | !current->IsUndefined(); |
| 855 | current = Context::cast(current)->get(Context::NEXT_CONTEXT_LINK)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 856 | DCHECK(current != context); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 857 | } |
| 858 | } |
| 859 | #endif |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 860 | context->set(Context::NEXT_CONTEXT_LINK, heap->native_contexts_list(), |
| 861 | UPDATE_WEAK_WRITE_BARRIER); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 862 | heap->set_native_contexts_list(context); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 866 | void Genesis::CreateRoots() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 867 | // Allocate the native context FixedArray first and then patch the |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 868 | // closure and extension object later (we need the empty function |
| 869 | // and the global object, but in order to create those, we need the |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 870 | // native context). |
| 871 | native_context_ = factory()->NewNativeContext(); |
| 872 | AddToWeakNativeContextList(*native_context()); |
| 873 | isolate()->set_context(*native_context()); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 874 | |
| 875 | // Allocate the message listeners object. |
| 876 | { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 877 | v8::NeanderArray listeners(isolate()); |
| 878 | native_context()->set_message_listeners(*listeners.value()); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 879 | } |
| 880 | } |
| 881 | |
| 882 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 883 | void Genesis::InstallGlobalThisBinding() { |
| 884 | Handle<ScriptContextTable> script_contexts( |
| 885 | native_context()->script_context_table()); |
| 886 | Handle<ScopeInfo> scope_info = ScopeInfo::CreateGlobalThisBinding(isolate()); |
| 887 | Handle<JSFunction> closure(native_context()->closure()); |
| 888 | Handle<Context> context = factory()->NewScriptContext(closure, scope_info); |
| 889 | |
| 890 | // Go ahead and hook it up while we're at it. |
| 891 | int slot = scope_info->ReceiverContextSlotIndex(); |
| 892 | DCHECK_EQ(slot, Context::MIN_CONTEXT_SLOTS); |
| 893 | context->set(slot, native_context()->global_proxy()); |
| 894 | |
| 895 | Handle<ScriptContextTable> new_script_contexts = |
| 896 | ScriptContextTable::Extend(script_contexts, context); |
| 897 | native_context()->set_script_context_table(*new_script_contexts); |
| 898 | } |
| 899 | |
| 900 | |
| 901 | Handle<JSGlobalObject> Genesis::CreateNewGlobals( |
| 902 | v8::Local<v8::ObjectTemplate> global_proxy_template, |
| 903 | Handle<JSGlobalProxy> global_proxy) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 904 | // The argument global_proxy_template aka data is an ObjectTemplateInfo. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 905 | // It has a constructor pointer that points at global_constructor which is a |
| 906 | // FunctionTemplateInfo. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 907 | // The global_proxy_constructor is used to (re)initialize the |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 908 | // global_proxy. The global_proxy_constructor also has a prototype_template |
| 909 | // pointer that points at js_global_object_template which is an |
| 910 | // ObjectTemplateInfo. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 911 | // That in turn has a constructor pointer that points at |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 912 | // js_global_object_constructor which is a FunctionTemplateInfo. |
| 913 | // js_global_object_constructor is used to make js_global_object_function |
| 914 | // js_global_object_function is used to make the new global_object. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 915 | // |
| 916 | // --- G l o b a l --- |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 917 | // Step 1: Create a fresh JSGlobalObject. |
| 918 | Handle<JSFunction> js_global_object_function; |
| 919 | Handle<ObjectTemplateInfo> js_global_object_template; |
| 920 | if (!global_proxy_template.IsEmpty()) { |
| 921 | // Get prototype template of the global_proxy_template. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 922 | Handle<ObjectTemplateInfo> data = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 923 | v8::Utils::OpenHandle(*global_proxy_template); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 924 | Handle<FunctionTemplateInfo> global_constructor = |
| 925 | Handle<FunctionTemplateInfo>( |
| 926 | FunctionTemplateInfo::cast(data->constructor())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 927 | Handle<Object> proto_template(global_constructor->prototype_template(), |
| 928 | isolate()); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 929 | if (!proto_template->IsUndefined()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 930 | js_global_object_template = |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 931 | Handle<ObjectTemplateInfo>::cast(proto_template); |
| 932 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 933 | } |
| 934 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 935 | if (js_global_object_template.is_null()) { |
| 936 | Handle<String> name = Handle<String>(heap()->empty_string()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 937 | Handle<Code> code = isolate()->builtins()->Illegal(); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 938 | Handle<JSObject> prototype = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 939 | factory()->NewFunctionPrototype(isolate()->object_function()); |
| 940 | js_global_object_function = factory()->NewFunction( |
| 941 | name, code, prototype, JS_GLOBAL_OBJECT_TYPE, JSGlobalObject::kSize); |
| 942 | #ifdef DEBUG |
| 943 | LookupIterator it(prototype, factory()->constructor_string(), |
| 944 | LookupIterator::OWN_SKIP_INTERCEPTOR); |
| 945 | Handle<Object> value = JSReceiver::GetProperty(&it).ToHandleChecked(); |
| 946 | DCHECK(it.IsFound()); |
| 947 | DCHECK_EQ(*isolate()->object_function(), *value); |
| 948 | #endif |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 949 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 950 | Handle<FunctionTemplateInfo> js_global_object_constructor( |
| 951 | FunctionTemplateInfo::cast(js_global_object_template->constructor())); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 952 | js_global_object_function = ApiNatives::CreateApiFunction( |
| 953 | isolate(), js_global_object_constructor, factory()->the_hole_value(), |
| 954 | ApiNatives::GlobalObjectType); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 955 | } |
| 956 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 957 | js_global_object_function->initial_map()->set_is_prototype_map(true); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 958 | js_global_object_function->initial_map()->set_dictionary_map(true); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 959 | Handle<JSGlobalObject> global_object = |
| 960 | factory()->NewJSGlobalObject(js_global_object_function); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 961 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 962 | // Step 2: (re)initialize the global proxy object. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 963 | Handle<JSFunction> global_proxy_function; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 964 | if (global_proxy_template.IsEmpty()) { |
| 965 | Handle<String> name = Handle<String>(heap()->empty_string()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 966 | Handle<Code> code = isolate()->builtins()->Illegal(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 967 | global_proxy_function = factory()->NewFunction( |
| 968 | name, code, JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 969 | } else { |
| 970 | Handle<ObjectTemplateInfo> data = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 971 | v8::Utils::OpenHandle(*global_proxy_template); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 972 | Handle<FunctionTemplateInfo> global_constructor( |
| 973 | FunctionTemplateInfo::cast(data->constructor())); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 974 | global_proxy_function = ApiNatives::CreateApiFunction( |
| 975 | isolate(), global_constructor, factory()->the_hole_value(), |
| 976 | ApiNatives::GlobalProxyType); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 977 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 978 | Handle<String> global_name = factory()->global_string(); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 979 | global_proxy_function->shared()->set_instance_class_name(*global_name); |
| 980 | global_proxy_function->initial_map()->set_is_access_check_needed(true); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 981 | global_proxy_function->initial_map()->set_has_hidden_prototype(true); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 982 | |
| 983 | // Set global_proxy.__proto__ to js_global after ConfigureGlobalObjects |
| 984 | // Return the global proxy. |
| 985 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 986 | factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function); |
| 987 | return global_object; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 991 | void Genesis::HookUpGlobalProxy(Handle<JSGlobalObject> global_object, |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 992 | Handle<JSGlobalProxy> global_proxy) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 993 | // Set the native context for the global object. |
| 994 | global_object->set_native_context(*native_context()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 995 | global_object->set_global_proxy(*global_proxy); |
| 996 | global_proxy->set_native_context(*native_context()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 997 | // If we deserialized the context, the global proxy is already |
| 998 | // correctly set up. Otherwise it's undefined. |
| 999 | DCHECK(native_context()->get(Context::GLOBAL_PROXY_INDEX)->IsUndefined() || |
| 1000 | native_context()->global_proxy() == *global_proxy); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1001 | native_context()->set_global_proxy(*global_proxy); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1005 | void Genesis::HookUpGlobalObject(Handle<JSGlobalObject> global_object) { |
| 1006 | Handle<JSGlobalObject> global_object_from_snapshot( |
| 1007 | JSGlobalObject::cast(native_context()->extension())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1008 | native_context()->set_extension(*global_object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1009 | native_context()->set_security_token(*global_object); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1010 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1011 | TransferNamedProperties(global_object_from_snapshot, global_object); |
| 1012 | TransferIndexedProperties(global_object_from_snapshot, global_object); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1016 | static Handle<JSFunction> SimpleCreateFunction(Isolate* isolate, |
| 1017 | Handle<String> name, |
| 1018 | Builtins::Name call, int len, |
| 1019 | bool adapt) { |
| 1020 | Handle<JSFunction> fun = |
| 1021 | CreateFunction(isolate, name, JS_OBJECT_TYPE, JSObject::kHeaderSize, |
| 1022 | MaybeHandle<JSObject>(), call); |
| 1023 | if (adapt) { |
| 1024 | fun->shared()->set_internal_formal_parameter_count(len); |
| 1025 | } else { |
| 1026 | fun->shared()->DontAdaptArguments(); |
| 1027 | } |
| 1028 | fun->shared()->set_length(len); |
| 1029 | return fun; |
| 1030 | } |
| 1031 | |
| 1032 | |
| 1033 | static Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base, |
| 1034 | Handle<String> name, |
| 1035 | Builtins::Name call, int len, |
| 1036 | bool adapt) { |
| 1037 | Handle<JSFunction> fun = |
| 1038 | SimpleCreateFunction(base->GetIsolate(), name, call, len, adapt); |
| 1039 | InstallFunction(base, fun, name, DONT_ENUM); |
| 1040 | return fun; |
| 1041 | } |
| 1042 | |
| 1043 | |
| 1044 | static Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base, |
| 1045 | const char* name, |
| 1046 | Builtins::Name call, int len, |
| 1047 | bool adapt) { |
| 1048 | Factory* const factory = base->GetIsolate()->factory(); |
| 1049 | return SimpleInstallFunction(base, factory->InternalizeUtf8String(name), call, |
| 1050 | len, adapt); |
| 1051 | } |
| 1052 | |
| 1053 | |
| 1054 | static void InstallWithIntrinsicDefaultProto(Isolate* isolate, |
| 1055 | Handle<JSFunction> function, |
| 1056 | int context_index) { |
| 1057 | Handle<Smi> index(Smi::FromInt(context_index), isolate); |
| 1058 | JSObject::AddProperty( |
| 1059 | function, isolate->factory()->native_context_index_symbol(), index, NONE); |
| 1060 | isolate->native_context()->set(context_index, *function); |
| 1061 | } |
| 1062 | |
| 1063 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1064 | // This is only called if we are not using snapshots. The equivalent |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1065 | // work in the snapshot case is done in HookUpGlobalObject. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1066 | void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, |
| 1067 | Handle<JSFunction> empty_function, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1068 | GlobalContextType context_type) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1069 | // --- N a t i v e C o n t e x t --- |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1070 | // Use the empty function as closure (no scope info). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1071 | native_context()->set_closure(*empty_function); |
| 1072 | native_context()->set_previous(NULL); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1073 | // Set extension and global object. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1074 | native_context()->set_extension(*global_object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1075 | // Security setup: Set the security token of the native context to the global |
| 1076 | // object. This makes the security check between two different contexts fail |
| 1077 | // by default even in case of global object reinitialization. |
| 1078 | native_context()->set_security_token(*global_object); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1079 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1080 | Isolate* isolate = global_object->GetIsolate(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1081 | Factory* factory = isolate->factory(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1082 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1083 | Handle<ScriptContextTable> script_context_table = |
| 1084 | factory->NewScriptContextTable(); |
| 1085 | native_context()->set_script_context_table(*script_context_table); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1086 | InstallGlobalThisBinding(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1087 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1088 | { // --- O b j e c t --- |
| 1089 | Handle<String> object_name = factory->Object_string(); |
| 1090 | Handle<JSFunction> object_function = isolate->object_function(); |
| 1091 | JSObject::AddProperty(global_object, object_name, object_function, |
| 1092 | DONT_ENUM); |
| 1093 | SimpleInstallFunction(object_function, factory->assign_string(), |
| 1094 | Builtins::kObjectAssign, 2, false); |
| 1095 | SimpleInstallFunction(object_function, factory->create_string(), |
| 1096 | Builtins::kObjectCreate, 2, false); |
| 1097 | Handle<JSFunction> object_freeze = SimpleInstallFunction( |
| 1098 | object_function, "freeze", Builtins::kObjectFreeze, 1, false); |
| 1099 | native_context()->set_object_freeze(*object_freeze); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1100 | SimpleInstallFunction(object_function, "getOwnPropertyDescriptor", |
| 1101 | Builtins::kObjectGetOwnPropertyDescriptor, 2, false); |
| 1102 | SimpleInstallFunction(object_function, "getOwnPropertyNames", |
| 1103 | Builtins::kObjectGetOwnPropertyNames, 1, false); |
| 1104 | SimpleInstallFunction(object_function, "getOwnPropertySymbols", |
| 1105 | Builtins::kObjectGetOwnPropertySymbols, 1, false); |
| 1106 | SimpleInstallFunction(object_function, "is", Builtins::kObjectIs, 2, true); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1107 | Handle<JSFunction> object_is_extensible = |
| 1108 | SimpleInstallFunction(object_function, "isExtensible", |
| 1109 | Builtins::kObjectIsExtensible, 1, false); |
| 1110 | native_context()->set_object_is_extensible(*object_is_extensible); |
| 1111 | Handle<JSFunction> object_is_frozen = SimpleInstallFunction( |
| 1112 | object_function, "isFrozen", Builtins::kObjectIsFrozen, 1, false); |
| 1113 | native_context()->set_object_is_frozen(*object_is_frozen); |
| 1114 | Handle<JSFunction> object_is_sealed = SimpleInstallFunction( |
| 1115 | object_function, "isSealed", Builtins::kObjectIsSealed, 1, false); |
| 1116 | native_context()->set_object_is_sealed(*object_is_sealed); |
| 1117 | Handle<JSFunction> object_keys = SimpleInstallFunction( |
| 1118 | object_function, "keys", Builtins::kObjectKeys, 1, false); |
| 1119 | native_context()->set_object_keys(*object_keys); |
| 1120 | SimpleInstallFunction(object_function, "preventExtensions", |
| 1121 | Builtins::kObjectPreventExtensions, 1, false); |
| 1122 | SimpleInstallFunction(object_function, "seal", Builtins::kObjectSeal, 1, |
| 1123 | false); |
| 1124 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1125 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1126 | Handle<JSObject> global(native_context()->global_object()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1127 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1128 | { // --- F u n c t i o n --- |
| 1129 | Handle<JSFunction> prototype = empty_function; |
| 1130 | Handle<JSFunction> function_fun = |
| 1131 | InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, |
| 1132 | prototype, Builtins::kFunctionConstructor); |
| 1133 | function_fun->set_prototype_or_initial_map( |
| 1134 | *sloppy_function_map_writable_prototype_); |
| 1135 | function_fun->shared()->DontAdaptArguments(); |
| 1136 | function_fun->shared()->set_construct_stub( |
| 1137 | *isolate->builtins()->FunctionConstructor()); |
| 1138 | function_fun->shared()->set_length(1); |
| 1139 | InstallWithIntrinsicDefaultProto(isolate, function_fun, |
| 1140 | Context::FUNCTION_FUNCTION_INDEX); |
| 1141 | |
| 1142 | // Setup the methods on the %FunctionPrototype%. |
| 1143 | SimpleInstallFunction(prototype, factory->apply_string(), |
| 1144 | Builtins::kFunctionPrototypeApply, 2, false); |
| 1145 | SimpleInstallFunction(prototype, factory->bind_string(), |
| 1146 | Builtins::kFunctionPrototypeBind, 1, false); |
| 1147 | SimpleInstallFunction(prototype, factory->call_string(), |
| 1148 | Builtins::kFunctionPrototypeCall, 1, false); |
| 1149 | SimpleInstallFunction(prototype, factory->toString_string(), |
| 1150 | Builtins::kFunctionPrototypeToString, 0, false); |
| 1151 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1152 | // Install the @@hasInstance function. |
| 1153 | Handle<JSFunction> has_instance = InstallFunction( |
| 1154 | prototype, factory->has_instance_symbol(), JS_OBJECT_TYPE, |
| 1155 | JSObject::kHeaderSize, MaybeHandle<JSObject>(), |
| 1156 | Builtins::kFunctionHasInstance, |
| 1157 | static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY)); |
| 1158 | |
| 1159 | // Set the expected parameters for @@hasInstance to 1; required by builtin. |
| 1160 | has_instance->shared()->set_internal_formal_parameter_count(1); |
| 1161 | |
| 1162 | // Set the length for the function to satisfy ECMA-262. |
| 1163 | has_instance->shared()->set_length(1); |
| 1164 | |
| 1165 | // Install in the native context |
| 1166 | native_context()->set_ordinary_has_instance(*has_instance); |
| 1167 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1168 | // Install the "constructor" property on the %FunctionPrototype%. |
| 1169 | JSObject::AddProperty(prototype, factory->constructor_string(), |
| 1170 | function_fun, DONT_ENUM); |
| 1171 | |
| 1172 | sloppy_function_map_writable_prototype_->SetConstructor(*function_fun); |
| 1173 | strict_function_map_writable_prototype_->SetConstructor(*function_fun); |
| 1174 | native_context()->strong_function_map()->SetConstructor(*function_fun); |
| 1175 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1176 | |
| 1177 | { // --- A r r a y --- |
| 1178 | Handle<JSFunction> array_function = |
| 1179 | InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1180 | isolate->initial_object_prototype(), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1181 | Builtins::kArrayCode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1182 | array_function->shared()->DontAdaptArguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1183 | array_function->shared()->set_function_data(Smi::FromInt(kArrayCode)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1184 | |
| 1185 | // This seems a bit hackish, but we need to make sure Array.length |
| 1186 | // is 1. |
| 1187 | array_function->shared()->set_length(1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1188 | |
| 1189 | Handle<Map> initial_map(array_function->initial_map()); |
| 1190 | |
| 1191 | // This assert protects an optimization in |
| 1192 | // HGraphBuilder::JSArrayBuilder::EmitMapCode() |
| 1193 | DCHECK(initial_map->elements_kind() == GetInitialFastElementsKind()); |
| 1194 | Map::EnsureDescriptorSlack(initial_map, 1); |
| 1195 | |
| 1196 | PropertyAttributes attribs = static_cast<PropertyAttributes>( |
| 1197 | DONT_ENUM | DONT_DELETE); |
| 1198 | |
| 1199 | Handle<AccessorInfo> array_length = |
| 1200 | Accessors::ArrayLengthInfo(isolate, attribs); |
| 1201 | { // Add length. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1202 | AccessorConstantDescriptor d( |
| 1203 | Handle<Name>(Name::cast(array_length->name())), array_length, |
| 1204 | attribs); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1205 | initial_map->AppendDescriptor(&d); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1206 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1207 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1208 | InstallWithIntrinsicDefaultProto(isolate, array_function, |
| 1209 | Context::ARRAY_FUNCTION_INDEX); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1210 | |
| 1211 | // Cache the array maps, needed by ArrayConstructorStub |
| 1212 | CacheInitialJSArrayMaps(native_context(), initial_map); |
| 1213 | ArrayConstructorStub array_constructor_stub(isolate); |
| 1214 | Handle<Code> code = array_constructor_stub.GetCode(); |
| 1215 | array_function->shared()->set_construct_stub(*code); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1216 | |
| 1217 | Handle<Map> initial_strong_map = |
| 1218 | Map::Copy(initial_map, "SetInstancePrototype"); |
| 1219 | initial_strong_map->set_is_strong(); |
| 1220 | CacheInitialJSArrayMaps(native_context(), initial_strong_map); |
| 1221 | |
| 1222 | Handle<JSFunction> is_arraylike = SimpleInstallFunction( |
| 1223 | array_function, isolate->factory()->InternalizeUtf8String("isArray"), |
| 1224 | Builtins::kArrayIsArray, 1, true); |
| 1225 | native_context()->set_is_arraylike(*is_arraylike); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | { // --- N u m b e r --- |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1229 | Handle<JSFunction> number_fun = InstallFunction( |
| 1230 | global, "Number", JS_VALUE_TYPE, JSValue::kSize, |
| 1231 | isolate->initial_object_prototype(), Builtins::kNumberConstructor); |
| 1232 | number_fun->shared()->DontAdaptArguments(); |
| 1233 | number_fun->shared()->set_construct_stub( |
| 1234 | *isolate->builtins()->NumberConstructor_ConstructStub()); |
| 1235 | number_fun->shared()->set_length(1); |
| 1236 | InstallWithIntrinsicDefaultProto(isolate, number_fun, |
| 1237 | Context::NUMBER_FUNCTION_INDEX); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | { // --- B o o l e a n --- |
| 1241 | Handle<JSFunction> boolean_fun = |
| 1242 | InstallFunction(global, "Boolean", JS_VALUE_TYPE, JSValue::kSize, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1243 | isolate->initial_object_prototype(), |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1244 | Builtins::kBooleanConstructor); |
| 1245 | boolean_fun->shared()->DontAdaptArguments(); |
| 1246 | boolean_fun->shared()->set_construct_stub( |
| 1247 | *isolate->builtins()->BooleanConstructor_ConstructStub()); |
| 1248 | boolean_fun->shared()->set_length(1); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1249 | InstallWithIntrinsicDefaultProto(isolate, boolean_fun, |
| 1250 | Context::BOOLEAN_FUNCTION_INDEX); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1251 | |
| 1252 | // Create the %BooleanPrototype% |
| 1253 | Handle<JSValue> prototype = |
| 1254 | Handle<JSValue>::cast(factory->NewJSObject(boolean_fun, TENURED)); |
| 1255 | prototype->set_value(isolate->heap()->false_value()); |
| 1256 | Accessors::FunctionSetPrototype(boolean_fun, prototype).Assert(); |
| 1257 | |
| 1258 | // Install the "constructor" property on the {prototype}. |
| 1259 | JSObject::AddProperty(prototype, factory->constructor_string(), boolean_fun, |
| 1260 | DONT_ENUM); |
| 1261 | |
| 1262 | // Install the Boolean.prototype methods. |
| 1263 | SimpleInstallFunction(prototype, "toString", |
| 1264 | Builtins::kBooleanPrototypeToString, 0, false); |
| 1265 | SimpleInstallFunction(prototype, "valueOf", |
| 1266 | Builtins::kBooleanPrototypeValueOf, 0, false); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | { // --- S t r i n g --- |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1270 | Handle<JSFunction> string_fun = InstallFunction( |
| 1271 | global, "String", JS_VALUE_TYPE, JSValue::kSize, |
| 1272 | isolate->initial_object_prototype(), Builtins::kStringConstructor); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1273 | string_fun->shared()->set_construct_stub( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1274 | *isolate->builtins()->StringConstructor_ConstructStub()); |
| 1275 | string_fun->shared()->DontAdaptArguments(); |
| 1276 | string_fun->shared()->set_length(1); |
| 1277 | InstallWithIntrinsicDefaultProto(isolate, string_fun, |
| 1278 | Context::STRING_FUNCTION_INDEX); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1279 | |
| 1280 | Handle<Map> string_map = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1281 | Handle<Map>(native_context()->string_function()->initial_map()); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1282 | string_map->set_elements_kind(FAST_STRING_WRAPPER_ELEMENTS); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1283 | Map::EnsureDescriptorSlack(string_map, 1); |
| 1284 | |
| 1285 | PropertyAttributes attribs = static_cast<PropertyAttributes>( |
| 1286 | DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 1287 | Handle<AccessorInfo> string_length( |
| 1288 | Accessors::StringLengthInfo(isolate, attribs)); |
| 1289 | |
| 1290 | { // Add length. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1291 | AccessorConstantDescriptor d(factory->length_string(), string_length, |
| 1292 | attribs); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1293 | string_map->AppendDescriptor(&d); |
| 1294 | } |
| 1295 | } |
| 1296 | |
| 1297 | { |
| 1298 | // --- S y m b o l --- |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1299 | Handle<JSObject> prototype = |
| 1300 | factory->NewJSObject(isolate->object_function(), TENURED); |
| 1301 | Handle<JSFunction> symbol_fun = |
| 1302 | InstallFunction(global, "Symbol", JS_VALUE_TYPE, JSValue::kSize, |
| 1303 | prototype, Builtins::kSymbolConstructor); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1304 | symbol_fun->shared()->set_construct_stub( |
| 1305 | *isolate->builtins()->SymbolConstructor_ConstructStub()); |
| 1306 | symbol_fun->shared()->set_length(1); |
| 1307 | symbol_fun->shared()->DontAdaptArguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1308 | native_context()->set_symbol_function(*symbol_fun); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1309 | |
| 1310 | // Install the "constructor" property on the {prototype}. |
| 1311 | JSObject::AddProperty(prototype, factory->constructor_string(), symbol_fun, |
| 1312 | DONT_ENUM); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | { // --- D a t e --- |
| 1316 | // Builtin functions for Date.prototype. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1317 | Handle<JSObject> prototype = |
| 1318 | factory->NewJSObject(isolate->object_function(), TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1319 | Handle<JSFunction> date_fun = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1320 | InstallFunction(global, "Date", JS_DATE_TYPE, JSDate::kSize, prototype, |
| 1321 | Builtins::kDateConstructor); |
| 1322 | InstallWithIntrinsicDefaultProto(isolate, date_fun, |
| 1323 | Context::DATE_FUNCTION_INDEX); |
| 1324 | date_fun->shared()->set_construct_stub( |
| 1325 | *isolate->builtins()->DateConstructor_ConstructStub()); |
| 1326 | date_fun->shared()->set_length(7); |
| 1327 | date_fun->shared()->DontAdaptArguments(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1328 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1329 | // Install the Date.now, Date.parse and Date.UTC functions. |
| 1330 | SimpleInstallFunction(date_fun, "now", Builtins::kDateNow, 0, false); |
| 1331 | SimpleInstallFunction(date_fun, "parse", Builtins::kDateParse, 1, false); |
| 1332 | SimpleInstallFunction(date_fun, "UTC", Builtins::kDateUTC, 7, false); |
| 1333 | |
| 1334 | // Install the "constructor" property on the {prototype}. |
| 1335 | JSObject::AddProperty(prototype, factory->constructor_string(), date_fun, |
| 1336 | DONT_ENUM); |
| 1337 | |
| 1338 | // Install the Date.prototype methods. |
| 1339 | SimpleInstallFunction(prototype, "toString", |
| 1340 | Builtins::kDatePrototypeToString, 0, false); |
| 1341 | SimpleInstallFunction(prototype, "toDateString", |
| 1342 | Builtins::kDatePrototypeToDateString, 0, false); |
| 1343 | SimpleInstallFunction(prototype, "toTimeString", |
| 1344 | Builtins::kDatePrototypeToTimeString, 0, false); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1345 | SimpleInstallFunction(prototype, "toISOString", |
| 1346 | Builtins::kDatePrototypeToISOString, 0, false); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1347 | Handle<JSFunction> to_utc_string = |
| 1348 | SimpleInstallFunction(prototype, "toUTCString", |
| 1349 | Builtins::kDatePrototypeToUTCString, 0, false); |
| 1350 | InstallFunction(prototype, to_utc_string, |
| 1351 | factory->InternalizeUtf8String("toGMTString"), DONT_ENUM); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1352 | SimpleInstallFunction(prototype, "getDate", Builtins::kDatePrototypeGetDate, |
| 1353 | 0, true); |
| 1354 | SimpleInstallFunction(prototype, "setDate", Builtins::kDatePrototypeSetDate, |
| 1355 | 1, false); |
| 1356 | SimpleInstallFunction(prototype, "getDay", Builtins::kDatePrototypeGetDay, |
| 1357 | 0, true); |
| 1358 | SimpleInstallFunction(prototype, "getFullYear", |
| 1359 | Builtins::kDatePrototypeGetFullYear, 0, true); |
| 1360 | SimpleInstallFunction(prototype, "setFullYear", |
| 1361 | Builtins::kDatePrototypeSetFullYear, 3, false); |
| 1362 | SimpleInstallFunction(prototype, "getHours", |
| 1363 | Builtins::kDatePrototypeGetHours, 0, true); |
| 1364 | SimpleInstallFunction(prototype, "setHours", |
| 1365 | Builtins::kDatePrototypeSetHours, 4, false); |
| 1366 | SimpleInstallFunction(prototype, "getMilliseconds", |
| 1367 | Builtins::kDatePrototypeGetMilliseconds, 0, true); |
| 1368 | SimpleInstallFunction(prototype, "setMilliseconds", |
| 1369 | Builtins::kDatePrototypeSetMilliseconds, 1, false); |
| 1370 | SimpleInstallFunction(prototype, "getMinutes", |
| 1371 | Builtins::kDatePrototypeGetMinutes, 0, true); |
| 1372 | SimpleInstallFunction(prototype, "setMinutes", |
| 1373 | Builtins::kDatePrototypeSetMinutes, 3, false); |
| 1374 | SimpleInstallFunction(prototype, "getMonth", |
| 1375 | Builtins::kDatePrototypeGetMonth, 0, true); |
| 1376 | SimpleInstallFunction(prototype, "setMonth", |
| 1377 | Builtins::kDatePrototypeSetMonth, 2, false); |
| 1378 | SimpleInstallFunction(prototype, "getSeconds", |
| 1379 | Builtins::kDatePrototypeGetSeconds, 0, true); |
| 1380 | SimpleInstallFunction(prototype, "setSeconds", |
| 1381 | Builtins::kDatePrototypeSetSeconds, 2, false); |
| 1382 | SimpleInstallFunction(prototype, "getTime", Builtins::kDatePrototypeGetTime, |
| 1383 | 0, true); |
| 1384 | SimpleInstallFunction(prototype, "setTime", Builtins::kDatePrototypeSetTime, |
| 1385 | 1, false); |
| 1386 | SimpleInstallFunction(prototype, "getTimezoneOffset", |
| 1387 | Builtins::kDatePrototypeGetTimezoneOffset, 0, true); |
| 1388 | SimpleInstallFunction(prototype, "getUTCDate", |
| 1389 | Builtins::kDatePrototypeGetUTCDate, 0, true); |
| 1390 | SimpleInstallFunction(prototype, "setUTCDate", |
| 1391 | Builtins::kDatePrototypeSetUTCDate, 1, false); |
| 1392 | SimpleInstallFunction(prototype, "getUTCDay", |
| 1393 | Builtins::kDatePrototypeGetUTCDay, 0, true); |
| 1394 | SimpleInstallFunction(prototype, "getUTCFullYear", |
| 1395 | Builtins::kDatePrototypeGetUTCFullYear, 0, true); |
| 1396 | SimpleInstallFunction(prototype, "setUTCFullYear", |
| 1397 | Builtins::kDatePrototypeSetUTCFullYear, 3, false); |
| 1398 | SimpleInstallFunction(prototype, "getUTCHours", |
| 1399 | Builtins::kDatePrototypeGetUTCHours, 0, true); |
| 1400 | SimpleInstallFunction(prototype, "setUTCHours", |
| 1401 | Builtins::kDatePrototypeSetUTCHours, 4, false); |
| 1402 | SimpleInstallFunction(prototype, "getUTCMilliseconds", |
| 1403 | Builtins::kDatePrototypeGetUTCMilliseconds, 0, true); |
| 1404 | SimpleInstallFunction(prototype, "setUTCMilliseconds", |
| 1405 | Builtins::kDatePrototypeSetUTCMilliseconds, 1, false); |
| 1406 | SimpleInstallFunction(prototype, "getUTCMinutes", |
| 1407 | Builtins::kDatePrototypeGetUTCMinutes, 0, true); |
| 1408 | SimpleInstallFunction(prototype, "setUTCMinutes", |
| 1409 | Builtins::kDatePrototypeSetUTCMinutes, 3, false); |
| 1410 | SimpleInstallFunction(prototype, "getUTCMonth", |
| 1411 | Builtins::kDatePrototypeGetUTCMonth, 0, true); |
| 1412 | SimpleInstallFunction(prototype, "setUTCMonth", |
| 1413 | Builtins::kDatePrototypeSetUTCMonth, 2, false); |
| 1414 | SimpleInstallFunction(prototype, "getUTCSeconds", |
| 1415 | Builtins::kDatePrototypeGetUTCSeconds, 0, true); |
| 1416 | SimpleInstallFunction(prototype, "setUTCSeconds", |
| 1417 | Builtins::kDatePrototypeSetUTCSeconds, 2, false); |
| 1418 | SimpleInstallFunction(prototype, "valueOf", Builtins::kDatePrototypeValueOf, |
| 1419 | 0, false); |
| 1420 | SimpleInstallFunction(prototype, "getYear", Builtins::kDatePrototypeGetYear, |
| 1421 | 0, true); |
| 1422 | SimpleInstallFunction(prototype, "setYear", Builtins::kDatePrototypeSetYear, |
| 1423 | 1, false); |
| 1424 | |
| 1425 | // Install i18n fallback functions. |
| 1426 | SimpleInstallFunction(prototype, "toLocaleString", |
| 1427 | Builtins::kDatePrototypeToString, 0, false); |
| 1428 | SimpleInstallFunction(prototype, "toLocaleDateString", |
| 1429 | Builtins::kDatePrototypeToDateString, 0, false); |
| 1430 | SimpleInstallFunction(prototype, "toLocaleTimeString", |
| 1431 | Builtins::kDatePrototypeToTimeString, 0, false); |
| 1432 | |
| 1433 | // Install the @@toPrimitive function. |
| 1434 | Handle<JSFunction> to_primitive = InstallFunction( |
| 1435 | prototype, factory->to_primitive_symbol(), JS_OBJECT_TYPE, |
| 1436 | JSObject::kHeaderSize, MaybeHandle<JSObject>(), |
| 1437 | Builtins::kDatePrototypeToPrimitive, |
| 1438 | static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); |
| 1439 | |
| 1440 | // Set the expected parameters for @@toPrimitive to 1; required by builtin. |
| 1441 | to_primitive->shared()->set_internal_formal_parameter_count(1); |
| 1442 | |
| 1443 | // Set the length for the function to satisfy ECMA-262. |
| 1444 | to_primitive->shared()->set_length(1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1445 | } |
| 1446 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1447 | { // -- R e g E x p |
| 1448 | // Builtin functions for RegExp.prototype. |
| 1449 | Handle<JSFunction> regexp_fun = |
| 1450 | InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1451 | isolate->initial_object_prototype(), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1452 | Builtins::kIllegal); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1453 | InstallWithIntrinsicDefaultProto(isolate, regexp_fun, |
| 1454 | Context::REGEXP_FUNCTION_INDEX); |
| 1455 | regexp_fun->shared()->set_construct_stub( |
| 1456 | *isolate->builtins()->JSBuiltinsConstructStub()); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1457 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1458 | DCHECK(regexp_fun->has_initial_map()); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1459 | Handle<Map> initial_map(regexp_fun->initial_map()); |
| 1460 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1461 | DCHECK_EQ(0, initial_map->GetInObjectProperties()); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1462 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1463 | Map::EnsureDescriptorSlack(initial_map, 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1464 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1465 | // ECMA-262, section 15.10.7.5. |
| 1466 | PropertyAttributes writable = |
| 1467 | static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); |
| 1468 | DataDescriptor field(factory->last_index_string(), |
| 1469 | JSRegExp::kLastIndexFieldIndex, writable, |
| 1470 | Representation::Tagged()); |
| 1471 | initial_map->AppendDescriptor(&field); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1472 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1473 | static const int num_fields = JSRegExp::kInObjectFieldCount; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1474 | initial_map->SetInObjectProperties(num_fields); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1475 | initial_map->set_unused_property_fields(0); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1476 | initial_map->set_instance_size(initial_map->instance_size() + |
| 1477 | num_fields * kPointerSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1478 | } |
| 1479 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1480 | { // -- E r r o r |
| 1481 | Handle<JSFunction> error_fun = InstallFunction( |
| 1482 | global, "Error", JS_OBJECT_TYPE, JSObject::kHeaderSize, |
| 1483 | isolate->initial_object_prototype(), Builtins::kIllegal); |
| 1484 | InstallWithIntrinsicDefaultProto(isolate, error_fun, |
| 1485 | Context::ERROR_FUNCTION_INDEX); |
| 1486 | } |
| 1487 | |
| 1488 | { // -- E v a l E r r o r |
| 1489 | Handle<JSFunction> eval_error_fun = InstallFunction( |
| 1490 | global, "EvalError", JS_OBJECT_TYPE, JSObject::kHeaderSize, |
| 1491 | isolate->initial_object_prototype(), Builtins::kIllegal); |
| 1492 | InstallWithIntrinsicDefaultProto(isolate, eval_error_fun, |
| 1493 | Context::EVAL_ERROR_FUNCTION_INDEX); |
| 1494 | } |
| 1495 | |
| 1496 | { // -- R a n g e E r r o r |
| 1497 | Handle<JSFunction> range_error_fun = InstallFunction( |
| 1498 | global, "RangeError", JS_OBJECT_TYPE, JSObject::kHeaderSize, |
| 1499 | isolate->initial_object_prototype(), Builtins::kIllegal); |
| 1500 | InstallWithIntrinsicDefaultProto(isolate, range_error_fun, |
| 1501 | Context::RANGE_ERROR_FUNCTION_INDEX); |
| 1502 | } |
| 1503 | |
| 1504 | { // -- R e f e r e n c e E r r o r |
| 1505 | Handle<JSFunction> reference_error_fun = InstallFunction( |
| 1506 | global, "ReferenceError", JS_OBJECT_TYPE, JSObject::kHeaderSize, |
| 1507 | isolate->initial_object_prototype(), Builtins::kIllegal); |
| 1508 | InstallWithIntrinsicDefaultProto(isolate, reference_error_fun, |
| 1509 | Context::REFERENCE_ERROR_FUNCTION_INDEX); |
| 1510 | } |
| 1511 | |
| 1512 | { // -- S y n t a x E r r o r |
| 1513 | Handle<JSFunction> syntax_error_fun = InstallFunction( |
| 1514 | global, "SyntaxError", JS_OBJECT_TYPE, JSObject::kHeaderSize, |
| 1515 | isolate->initial_object_prototype(), Builtins::kIllegal); |
| 1516 | InstallWithIntrinsicDefaultProto(isolate, syntax_error_fun, |
| 1517 | Context::SYNTAX_ERROR_FUNCTION_INDEX); |
| 1518 | } |
| 1519 | |
| 1520 | { // -- T y p e E r r o r |
| 1521 | Handle<JSFunction> type_error_fun = InstallFunction( |
| 1522 | global, "TypeError", JS_OBJECT_TYPE, JSObject::kHeaderSize, |
| 1523 | isolate->initial_object_prototype(), Builtins::kIllegal); |
| 1524 | InstallWithIntrinsicDefaultProto(isolate, type_error_fun, |
| 1525 | Context::TYPE_ERROR_FUNCTION_INDEX); |
| 1526 | } |
| 1527 | |
| 1528 | { // -- U R I E r r o r |
| 1529 | Handle<JSFunction> uri_error_fun = InstallFunction( |
| 1530 | global, "URIError", JS_OBJECT_TYPE, JSObject::kHeaderSize, |
| 1531 | isolate->initial_object_prototype(), Builtins::kIllegal); |
| 1532 | InstallWithIntrinsicDefaultProto(isolate, uri_error_fun, |
| 1533 | Context::URI_ERROR_FUNCTION_INDEX); |
| 1534 | } |
| 1535 | |
| 1536 | // Initialize the embedder data slot. |
| 1537 | Handle<FixedArray> embedder_data = factory->NewFixedArray(3); |
| 1538 | native_context()->set_embedder_data(*embedder_data); |
| 1539 | |
| 1540 | if (context_type == THIN_CONTEXT) return; |
| 1541 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1542 | { // -- J S O N |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1543 | Handle<String> name = factory->InternalizeUtf8String("JSON"); |
| 1544 | Handle<JSFunction> cons = factory->NewFunction(name); |
| 1545 | JSFunction::SetInstancePrototype(cons, |
| 1546 | Handle<Object>(native_context()->initial_object_prototype(), isolate)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1547 | cons->shared()->set_instance_class_name(*name); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1548 | Handle<JSObject> json_object = factory->NewJSObject(cons, TENURED); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1549 | DCHECK(json_object->IsJSObject()); |
| 1550 | JSObject::AddProperty(global, name, json_object, DONT_ENUM); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1551 | } |
| 1552 | |
| 1553 | { // -- M a t h |
| 1554 | Handle<String> name = factory->InternalizeUtf8String("Math"); |
| 1555 | Handle<JSFunction> cons = factory->NewFunction(name); |
| 1556 | JSFunction::SetInstancePrototype( |
| 1557 | cons, |
| 1558 | Handle<Object>(native_context()->initial_object_prototype(), isolate)); |
| 1559 | cons->shared()->set_instance_class_name(*name); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1560 | Handle<JSObject> math = factory->NewJSObject(cons, TENURED); |
| 1561 | DCHECK(math->IsJSObject()); |
| 1562 | JSObject::AddProperty(global, name, math, DONT_ENUM); |
| 1563 | SimpleInstallFunction(math, "max", Builtins::kMathMax, 2, false); |
| 1564 | SimpleInstallFunction(math, "min", Builtins::kMathMin, 2, false); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1565 | } |
| 1566 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1567 | { // -- A r r a y B u f f e r |
| 1568 | Handle<JSFunction> array_buffer_fun = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1569 | InstallArrayBuffer(global, "ArrayBuffer"); |
| 1570 | InstallWithIntrinsicDefaultProto(isolate, array_buffer_fun, |
| 1571 | Context::ARRAY_BUFFER_FUN_INDEX); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | { // -- T y p e d A r r a y s |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1575 | #define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype, size) \ |
| 1576 | { \ |
| 1577 | Handle<JSFunction> fun; \ |
| 1578 | InstallTypedArray(#Type "Array", TYPE##_ELEMENTS, &fun); \ |
| 1579 | InstallWithIntrinsicDefaultProto(isolate, fun, \ |
| 1580 | Context::TYPE##_ARRAY_FUN_INDEX); \ |
| 1581 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1582 | TYPED_ARRAYS(INSTALL_TYPED_ARRAY) |
| 1583 | #undef INSTALL_TYPED_ARRAY |
| 1584 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1585 | Handle<JSFunction> data_view_fun = InstallFunction( |
| 1586 | global, "DataView", JS_DATA_VIEW_TYPE, |
| 1587 | JSDataView::kSizeWithInternalFields, |
| 1588 | isolate->initial_object_prototype(), Builtins::kDataViewConstructor); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1589 | InstallWithIntrinsicDefaultProto(isolate, data_view_fun, |
| 1590 | Context::DATA_VIEW_FUN_INDEX); |
| 1591 | data_view_fun->shared()->set_construct_stub( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1592 | *isolate->builtins()->DataViewConstructor_ConstructStub()); |
| 1593 | data_view_fun->shared()->set_length(3); |
| 1594 | data_view_fun->shared()->DontAdaptArguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1595 | } |
| 1596 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1597 | { // -- M a p |
| 1598 | Handle<JSFunction> js_map_fun = InstallFunction( |
| 1599 | global, "Map", JS_MAP_TYPE, JSMap::kSize, |
| 1600 | isolate->initial_object_prototype(), Builtins::kIllegal); |
| 1601 | InstallWithIntrinsicDefaultProto(isolate, js_map_fun, |
| 1602 | Context::JS_MAP_FUN_INDEX); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1603 | } |
| 1604 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1605 | { // -- S e t |
| 1606 | Handle<JSFunction> js_set_fun = InstallFunction( |
| 1607 | global, "Set", JS_SET_TYPE, JSSet::kSize, |
| 1608 | isolate->initial_object_prototype(), Builtins::kIllegal); |
| 1609 | InstallWithIntrinsicDefaultProto(isolate, js_set_fun, |
| 1610 | Context::JS_SET_FUN_INDEX); |
| 1611 | } |
| 1612 | |
| 1613 | { // -- I t e r a t o r R e s u l t |
| 1614 | Handle<Map> map = |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1615 | factory->NewMap(JS_OBJECT_TYPE, JSIteratorResult::kSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1616 | Map::SetPrototype(map, isolate->initial_object_prototype()); |
| 1617 | Map::EnsureDescriptorSlack(map, 2); |
| 1618 | |
| 1619 | { // value |
| 1620 | DataDescriptor d(factory->value_string(), JSIteratorResult::kValueIndex, |
| 1621 | NONE, Representation::Tagged()); |
| 1622 | map->AppendDescriptor(&d); |
| 1623 | } |
| 1624 | |
| 1625 | { // done |
| 1626 | DataDescriptor d(factory->done_string(), JSIteratorResult::kDoneIndex, |
| 1627 | NONE, Representation::Tagged()); |
| 1628 | map->AppendDescriptor(&d); |
| 1629 | } |
| 1630 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1631 | map->SetConstructor(native_context()->object_function()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1632 | map->SetInObjectProperties(2); |
| 1633 | native_context()->set_iterator_result_map(*map); |
| 1634 | } |
| 1635 | |
| 1636 | { // -- W e a k M a p |
| 1637 | Handle<JSFunction> js_weak_map_fun = InstallFunction( |
| 1638 | global, "WeakMap", JS_WEAK_MAP_TYPE, JSWeakMap::kSize, |
| 1639 | isolate->initial_object_prototype(), Builtins::kIllegal); |
| 1640 | InstallWithIntrinsicDefaultProto(isolate, js_weak_map_fun, |
| 1641 | Context::JS_WEAK_MAP_FUN_INDEX); |
| 1642 | } |
| 1643 | |
| 1644 | { // -- W e a k S e t |
| 1645 | Handle<JSFunction> js_weak_set_fun = InstallFunction( |
| 1646 | global, "WeakSet", JS_WEAK_SET_TYPE, JSWeakSet::kSize, |
| 1647 | isolate->initial_object_prototype(), Builtins::kIllegal); |
| 1648 | InstallWithIntrinsicDefaultProto(isolate, js_weak_set_fun, |
| 1649 | Context::JS_WEAK_SET_FUN_INDEX); |
| 1650 | } |
| 1651 | |
| 1652 | { // --- B o u n d F u n c t i o n |
| 1653 | Handle<Map> map = |
| 1654 | factory->NewMap(JS_BOUND_FUNCTION_TYPE, JSBoundFunction::kSize); |
| 1655 | map->set_is_callable(); |
| 1656 | Map::SetPrototype(map, empty_function); |
| 1657 | |
| 1658 | PropertyAttributes roc_attribs = |
| 1659 | static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); |
| 1660 | Map::EnsureDescriptorSlack(map, 2); |
| 1661 | |
| 1662 | { // length |
| 1663 | DataDescriptor d(factory->length_string(), JSBoundFunction::kLengthIndex, |
| 1664 | roc_attribs, Representation::Tagged()); |
| 1665 | map->AppendDescriptor(&d); |
| 1666 | } |
| 1667 | { // name |
| 1668 | DataDescriptor d(factory->name_string(), JSBoundFunction::kNameIndex, |
| 1669 | roc_attribs, Representation::Tagged()); |
| 1670 | map->AppendDescriptor(&d); |
| 1671 | } |
| 1672 | |
| 1673 | map->SetInObjectProperties(2); |
| 1674 | native_context()->set_bound_function_without_constructor_map(*map); |
| 1675 | |
| 1676 | map = Map::Copy(map, "IsConstructor"); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1677 | map->set_is_constructor(true); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1678 | native_context()->set_bound_function_with_constructor_map(*map); |
| 1679 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1680 | |
| 1681 | { // --- sloppy arguments map |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1682 | // Make sure we can recognize argument objects at runtime. |
| 1683 | // This is done by introducing an anonymous function with |
| 1684 | // class_name equals 'Arguments'. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1685 | Handle<String> arguments_string = factory->Arguments_string(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1686 | Handle<Code> code = isolate->builtins()->Illegal(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1687 | Handle<JSFunction> function = factory->NewFunctionWithoutPrototype( |
| 1688 | arguments_string, code); |
| 1689 | function->shared()->set_instance_class_name(*arguments_string); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1690 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1691 | Handle<Map> map = factory->NewMap( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1692 | JS_OBJECT_TYPE, JSSloppyArgumentsObject::kSize, FAST_ELEMENTS); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1693 | // Create the descriptor array for the arguments object. |
| 1694 | Map::EnsureDescriptorSlack(map, 2); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1695 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1696 | { // length |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1697 | DataDescriptor d(factory->length_string(), |
| 1698 | JSSloppyArgumentsObject::kLengthIndex, DONT_ENUM, |
| 1699 | Representation::Tagged()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1700 | map->AppendDescriptor(&d); |
| 1701 | } |
| 1702 | { // callee |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1703 | DataDescriptor d(factory->callee_string(), |
| 1704 | JSSloppyArgumentsObject::kCalleeIndex, DONT_ENUM, |
| 1705 | Representation::Tagged()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1706 | map->AppendDescriptor(&d); |
| 1707 | } |
| 1708 | // @@iterator method is added later. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1709 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1710 | map->SetInObjectProperties(2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1711 | native_context()->set_sloppy_arguments_map(*map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1712 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1713 | DCHECK(!function->has_initial_map()); |
| 1714 | JSFunction::SetInitialMap(function, map, |
| 1715 | isolate->initial_object_prototype()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1716 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1717 | DCHECK(!map->is_dictionary_map()); |
| 1718 | DCHECK(IsFastObjectElementsKind(map->elements_kind())); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1719 | } |
| 1720 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1721 | { // --- fast and slow aliased arguments map |
| 1722 | Handle<Map> map = isolate->sloppy_arguments_map(); |
| 1723 | map = Map::Copy(map, "FastAliasedArguments"); |
| 1724 | map->set_elements_kind(FAST_SLOPPY_ARGUMENTS_ELEMENTS); |
| 1725 | DCHECK_EQ(2, map->GetInObjectProperties()); |
| 1726 | native_context()->set_fast_aliased_arguments_map(*map); |
| 1727 | |
| 1728 | map = Map::Copy(map, "SlowAliasedArguments"); |
| 1729 | map->set_elements_kind(SLOW_SLOPPY_ARGUMENTS_ELEMENTS); |
| 1730 | DCHECK_EQ(2, map->GetInObjectProperties()); |
| 1731 | native_context()->set_slow_aliased_arguments_map(*map); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1732 | } |
| 1733 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1734 | { // --- strict mode arguments map |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1735 | const PropertyAttributes attributes = |
| 1736 | static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 1737 | |
| 1738 | // Create the ThrowTypeError functions. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1739 | Handle<AccessorPair> callee = factory->NewAccessorPair(); |
| 1740 | Handle<AccessorPair> caller = factory->NewAccessorPair(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1741 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1742 | Handle<JSFunction> poison = GetStrictArgumentsPoisonFunction(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1743 | |
| 1744 | // Install the ThrowTypeError functions. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1745 | callee->set_getter(*poison); |
| 1746 | callee->set_setter(*poison); |
| 1747 | caller->set_getter(*poison); |
| 1748 | caller->set_setter(*poison); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1749 | |
| 1750 | // Create the map. Allocate one in-object field for length. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1751 | Handle<Map> map = factory->NewMap( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1752 | JS_OBJECT_TYPE, JSStrictArgumentsObject::kSize, FAST_ELEMENTS); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1753 | // Create the descriptor array for the arguments object. |
| 1754 | Map::EnsureDescriptorSlack(map, 3); |
| 1755 | |
| 1756 | { // length |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1757 | DataDescriptor d(factory->length_string(), |
| 1758 | JSStrictArgumentsObject::kLengthIndex, DONT_ENUM, |
| 1759 | Representation::Tagged()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1760 | map->AppendDescriptor(&d); |
| 1761 | } |
| 1762 | { // callee |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1763 | AccessorConstantDescriptor d(factory->callee_string(), callee, |
| 1764 | attributes); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1765 | map->AppendDescriptor(&d); |
| 1766 | } |
| 1767 | { // caller |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1768 | AccessorConstantDescriptor d(factory->caller_string(), caller, |
| 1769 | attributes); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1770 | map->AppendDescriptor(&d); |
| 1771 | } |
| 1772 | // @@iterator method is added later. |
| 1773 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1774 | DCHECK_EQ(native_context()->object_function()->prototype(), |
| 1775 | *isolate->initial_object_prototype()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1776 | Map::SetPrototype(map, isolate->initial_object_prototype()); |
| 1777 | map->SetInObjectProperties(1); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1778 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1779 | // Copy constructor from the sloppy arguments boilerplate. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1780 | map->SetConstructor( |
| 1781 | native_context()->sloppy_arguments_map()->GetConstructor()); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1782 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1783 | native_context()->set_strict_arguments_map(*map); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1784 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1785 | DCHECK(!map->is_dictionary_map()); |
| 1786 | DCHECK(IsFastObjectElementsKind(map->elements_kind())); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | { // --- context extension |
| 1790 | // Create a function for the context extension objects. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1791 | Handle<Code> code = isolate->builtins()->Illegal(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1792 | Handle<JSFunction> context_extension_fun = factory->NewFunction( |
| 1793 | factory->empty_string(), code, JS_CONTEXT_EXTENSION_OBJECT_TYPE, |
| 1794 | JSObject::kHeaderSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1795 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1796 | Handle<String> name = factory->InternalizeOneByteString( |
| 1797 | STATIC_CHAR_VECTOR("context_extension")); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1798 | context_extension_fun->shared()->set_instance_class_name(*name); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1799 | native_context()->set_context_extension_function(*context_extension_fun); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | |
| 1803 | { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1804 | // Set up the call-as-function delegate. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1805 | Handle<Code> code = isolate->builtins()->HandleApiCallAsFunction(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1806 | Handle<JSFunction> delegate = factory->NewFunction( |
| 1807 | factory->empty_string(), code, JS_OBJECT_TYPE, JSObject::kHeaderSize); |
| 1808 | native_context()->set_call_as_function_delegate(*delegate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1809 | delegate->shared()->DontAdaptArguments(); |
| 1810 | } |
| 1811 | |
| 1812 | { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1813 | // Set up the call-as-constructor delegate. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1814 | Handle<Code> code = isolate->builtins()->HandleApiCallAsConstructor(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1815 | Handle<JSFunction> delegate = factory->NewFunction( |
| 1816 | factory->empty_string(), code, JS_OBJECT_TYPE, JSObject::kHeaderSize); |
| 1817 | native_context()->set_call_as_constructor_delegate(*delegate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1818 | delegate->shared()->DontAdaptArguments(); |
| 1819 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1820 | } // NOLINT(readability/fn_size) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1821 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1822 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1823 | void Genesis::InstallTypedArray(const char* name, ElementsKind elements_kind, |
| 1824 | Handle<JSFunction>* fun) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1825 | Handle<JSObject> global = Handle<JSObject>(native_context()->global_object()); |
| 1826 | Handle<JSFunction> result = InstallFunction( |
| 1827 | global, name, JS_TYPED_ARRAY_TYPE, JSTypedArray::kSize, |
| 1828 | isolate()->initial_object_prototype(), Builtins::kIllegal); |
| 1829 | |
| 1830 | Handle<Map> initial_map = isolate()->factory()->NewMap( |
| 1831 | JS_TYPED_ARRAY_TYPE, |
| 1832 | JSTypedArray::kSizeWithInternalFields, |
| 1833 | elements_kind); |
| 1834 | JSFunction::SetInitialMap(result, initial_map, |
| 1835 | handle(initial_map->prototype(), isolate())); |
| 1836 | *fun = result; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1840 | void Genesis::InitializeExperimentalGlobal() { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1841 | #define FEATURE_INITIALIZE_GLOBAL(id, descr) InitializeGlobal_##id(); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1842 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1843 | HARMONY_INPROGRESS(FEATURE_INITIALIZE_GLOBAL) |
| 1844 | HARMONY_STAGED(FEATURE_INITIALIZE_GLOBAL) |
| 1845 | HARMONY_SHIPPING(FEATURE_INITIALIZE_GLOBAL) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1846 | FEATURE_INITIALIZE_GLOBAL(promise_extra, "") |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1847 | #undef FEATURE_INITIALIZE_GLOBAL |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1848 | } |
| 1849 | |
| 1850 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1851 | bool Bootstrapper::CompileBuiltin(Isolate* isolate, int index) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1852 | Vector<const char> name = Natives::GetScriptName(index); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1853 | Handle<String> source_code = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1854 | isolate->bootstrapper()->SourceLookup<Natives>(index); |
| 1855 | |
| 1856 | // We pass in extras_utils so that builtin code can set it up for later use |
| 1857 | // by actual extras code, compiled with CompileExtraBuiltin. |
| 1858 | Handle<Object> global = isolate->global_object(); |
| 1859 | Handle<Object> utils = isolate->natives_utils_object(); |
| 1860 | Handle<Object> extras_utils = isolate->extras_utils_object(); |
| 1861 | Handle<Object> args[] = {global, utils, extras_utils}; |
| 1862 | |
| 1863 | return Bootstrapper::CompileNative(isolate, name, source_code, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1864 | arraysize(args), args, NATIVES_CODE); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1865 | } |
| 1866 | |
| 1867 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1868 | bool Bootstrapper::CompileExperimentalBuiltin(Isolate* isolate, int index) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1869 | HandleScope scope(isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1870 | Vector<const char> name = ExperimentalNatives::GetScriptName(index); |
| 1871 | Handle<String> source_code = |
| 1872 | isolate->bootstrapper()->SourceLookup<ExperimentalNatives>(index); |
| 1873 | Handle<Object> global = isolate->global_object(); |
| 1874 | Handle<Object> utils = isolate->natives_utils_object(); |
| 1875 | Handle<Object> args[] = {global, utils}; |
| 1876 | return Bootstrapper::CompileNative(isolate, name, source_code, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1877 | arraysize(args), args, NATIVES_CODE); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1878 | } |
| 1879 | |
| 1880 | |
| 1881 | bool Bootstrapper::CompileExtraBuiltin(Isolate* isolate, int index) { |
| 1882 | HandleScope scope(isolate); |
| 1883 | Vector<const char> name = ExtraNatives::GetScriptName(index); |
| 1884 | Handle<String> source_code = |
| 1885 | isolate->bootstrapper()->SourceLookup<ExtraNatives>(index); |
| 1886 | Handle<Object> global = isolate->global_object(); |
| 1887 | Handle<Object> binding = isolate->extras_binding_object(); |
| 1888 | Handle<Object> extras_utils = isolate->extras_utils_object(); |
| 1889 | Handle<Object> args[] = {global, binding, extras_utils}; |
| 1890 | return Bootstrapper::CompileNative(isolate, name, source_code, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1891 | arraysize(args), args, EXTENSION_CODE); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1892 | } |
| 1893 | |
| 1894 | |
| 1895 | bool Bootstrapper::CompileExperimentalExtraBuiltin(Isolate* isolate, |
| 1896 | int index) { |
| 1897 | HandleScope scope(isolate); |
| 1898 | Vector<const char> name = ExperimentalExtraNatives::GetScriptName(index); |
| 1899 | Handle<String> source_code = |
| 1900 | isolate->bootstrapper()->SourceLookup<ExperimentalExtraNatives>(index); |
| 1901 | Handle<Object> global = isolate->global_object(); |
| 1902 | Handle<Object> binding = isolate->extras_binding_object(); |
| 1903 | Handle<Object> extras_utils = isolate->extras_utils_object(); |
| 1904 | Handle<Object> args[] = {global, binding, extras_utils}; |
| 1905 | return Bootstrapper::CompileNative(isolate, name, source_code, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1906 | arraysize(args), args, EXTENSION_CODE); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1907 | } |
| 1908 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1909 | bool Bootstrapper::CompileNative(Isolate* isolate, Vector<const char> name, |
| 1910 | Handle<String> source, int argc, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1911 | Handle<Object> argv[], |
| 1912 | NativesFlag natives_flag) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1913 | SuppressDebug compiling_natives(isolate->debug()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1914 | // During genesis, the boilerplate for stack overflow won't work until the |
| 1915 | // environment has been at least partially initialized. Add a stack check |
| 1916 | // before entering JS code to catch overflow early. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1917 | StackLimitCheck check(isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1918 | if (check.JsHasOverflowed(1 * KB)) { |
| 1919 | isolate->StackOverflow(); |
| 1920 | return false; |
| 1921 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1922 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1923 | Handle<Context> context(isolate->context()); |
| 1924 | |
| 1925 | Handle<String> script_name = |
| 1926 | isolate->factory()->NewStringFromUtf8(name).ToHandleChecked(); |
| 1927 | Handle<SharedFunctionInfo> function_info = Compiler::CompileScript( |
| 1928 | source, script_name, 0, 0, ScriptOriginOptions(), Handle<Object>(), |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1929 | context, NULL, NULL, ScriptCompiler::kNoCompileOptions, natives_flag, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1930 | false); |
| 1931 | if (function_info.is_null()) return false; |
| 1932 | |
| 1933 | DCHECK(context->IsNativeContext()); |
| 1934 | |
| 1935 | Handle<JSFunction> fun = |
| 1936 | isolate->factory()->NewFunctionFromSharedFunctionInfo(function_info, |
| 1937 | context); |
| 1938 | Handle<Object> receiver = isolate->factory()->undefined_value(); |
| 1939 | |
| 1940 | // For non-extension scripts, run script to get the function wrapper. |
| 1941 | Handle<Object> wrapper; |
| 1942 | if (!Execution::Call(isolate, fun, receiver, 0, NULL).ToHandle(&wrapper)) { |
| 1943 | return false; |
| 1944 | } |
| 1945 | // Then run the function wrapper. |
| 1946 | return !Execution::Call(isolate, Handle<JSFunction>::cast(wrapper), receiver, |
| 1947 | argc, argv).is_null(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1951 | bool Genesis::CallUtilsFunction(Isolate* isolate, const char* name) { |
| 1952 | Handle<JSObject> utils = |
| 1953 | Handle<JSObject>::cast(isolate->natives_utils_object()); |
| 1954 | Handle<String> name_string = |
| 1955 | isolate->factory()->NewStringFromAsciiChecked(name); |
| 1956 | Handle<Object> fun = JSObject::GetDataProperty(utils, name_string); |
| 1957 | Handle<Object> receiver = isolate->factory()->undefined_value(); |
| 1958 | Handle<Object> args[] = {utils}; |
| 1959 | return !Execution::Call(isolate, fun, receiver, 1, args).is_null(); |
| 1960 | } |
| 1961 | |
| 1962 | |
| 1963 | bool Genesis::CompileExtension(Isolate* isolate, v8::Extension* extension) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1964 | Factory* factory = isolate->factory(); |
| 1965 | HandleScope scope(isolate); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1966 | Handle<SharedFunctionInfo> function_info; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1967 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1968 | Handle<String> source = |
| 1969 | isolate->factory() |
| 1970 | ->NewExternalStringFromOneByte(extension->source()) |
| 1971 | .ToHandleChecked(); |
| 1972 | DCHECK(source->IsOneByteRepresentation()); |
| 1973 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1974 | // If we can't find the function in the cache, we compile a new |
| 1975 | // function and insert it into the cache. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1976 | Vector<const char> name = CStrVector(extension->name()); |
| 1977 | SourceCodeCache* cache = isolate->bootstrapper()->extensions_cache(); |
| 1978 | Handle<Context> context(isolate->context()); |
| 1979 | DCHECK(context->IsNativeContext()); |
| 1980 | |
| 1981 | if (!cache->Lookup(name, &function_info)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1982 | Handle<String> script_name = |
| 1983 | factory->NewStringFromUtf8(name).ToHandleChecked(); |
| 1984 | function_info = Compiler::CompileScript( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1985 | source, script_name, 0, 0, ScriptOriginOptions(), Handle<Object>(), |
| 1986 | context, extension, NULL, ScriptCompiler::kNoCompileOptions, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1987 | EXTENSION_CODE, false); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1988 | if (function_info.is_null()) return false; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1989 | cache->Add(name, function_info); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1990 | } |
| 1991 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1992 | // Set up the function context. Conceptually, we should clone the |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1993 | // function before overwriting the context but since we're in a |
| 1994 | // single-threaded environment it is not strictly necessary. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1995 | Handle<JSFunction> fun = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1996 | factory->NewFunctionFromSharedFunctionInfo(function_info, context); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1997 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 1998 | // Call function using either the runtime object or the global |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1999 | // object as the receiver. Provide no parameters. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2000 | Handle<Object> receiver = isolate->global_object(); |
| 2001 | return !Execution::Call(isolate, fun, receiver, 0, NULL).is_null(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2005 | static Handle<JSObject> ResolveBuiltinIdHolder(Handle<Context> native_context, |
| 2006 | const char* holder_expr) { |
| 2007 | Isolate* isolate = native_context->GetIsolate(); |
| 2008 | Factory* factory = isolate->factory(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2009 | Handle<JSGlobalObject> global(native_context->global_object()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2010 | const char* period_pos = strchr(holder_expr, '.'); |
| 2011 | if (period_pos == NULL) { |
| 2012 | return Handle<JSObject>::cast( |
| 2013 | Object::GetPropertyOrElement( |
| 2014 | global, factory->InternalizeUtf8String(holder_expr)) |
| 2015 | .ToHandleChecked()); |
| 2016 | } |
| 2017 | const char* inner = period_pos + 1; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2018 | DCHECK(!strchr(inner, '.')); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2019 | Vector<const char> property(holder_expr, |
| 2020 | static_cast<int>(period_pos - holder_expr)); |
| 2021 | Handle<String> property_string = factory->InternalizeUtf8String(property); |
| 2022 | DCHECK(!property_string.is_null()); |
| 2023 | Handle<JSObject> object = Handle<JSObject>::cast( |
| 2024 | Object::GetProperty(global, property_string).ToHandleChecked()); |
| 2025 | if (strcmp("prototype", inner) == 0) { |
| 2026 | Handle<JSFunction> function = Handle<JSFunction>::cast(object); |
| 2027 | return Handle<JSObject>(JSObject::cast(function->prototype())); |
| 2028 | } |
| 2029 | Handle<String> inner_string = factory->InternalizeUtf8String(inner); |
| 2030 | DCHECK(!inner_string.is_null()); |
| 2031 | Handle<Object> value = |
| 2032 | Object::GetProperty(object, inner_string).ToHandleChecked(); |
| 2033 | return Handle<JSObject>::cast(value); |
| 2034 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2035 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2036 | void Genesis::ConfigureUtilsObject(GlobalContextType context_type) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2037 | switch (context_type) { |
| 2038 | // We still need the utils object to find debug functions. |
| 2039 | case DEBUG_CONTEXT: |
| 2040 | return; |
| 2041 | // Expose the natives in global if a valid name for it is specified. |
| 2042 | case FULL_CONTEXT: { |
| 2043 | // We still need the utils object after deserialization. |
| 2044 | if (isolate()->serializer_enabled()) return; |
| 2045 | if (FLAG_expose_natives_as == NULL) break; |
| 2046 | if (strlen(FLAG_expose_natives_as) == 0) break; |
| 2047 | HandleScope scope(isolate()); |
| 2048 | Handle<String> natives_key = |
| 2049 | factory()->InternalizeUtf8String(FLAG_expose_natives_as); |
| 2050 | uint32_t dummy_index; |
| 2051 | if (natives_key->AsArrayIndex(&dummy_index)) break; |
| 2052 | Handle<Object> utils = isolate()->natives_utils_object(); |
| 2053 | Handle<JSObject> global = isolate()->global_object(); |
| 2054 | JSObject::AddProperty(global, natives_key, utils, DONT_ENUM); |
| 2055 | break; |
| 2056 | } |
| 2057 | case THIN_CONTEXT: |
| 2058 | break; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2059 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2060 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2061 | // The utils object can be removed for cases that reach this point. |
| 2062 | native_context()->set_natives_utils_object(heap()->undefined_value()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2063 | } |
| 2064 | |
| 2065 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2066 | void Bootstrapper::ExportFromRuntime(Isolate* isolate, |
| 2067 | Handle<JSObject> container) { |
| 2068 | Factory* factory = isolate->factory(); |
| 2069 | HandleScope scope(isolate); |
| 2070 | Handle<Context> native_context = isolate->native_context(); |
| 2071 | #define EXPORT_PRIVATE_SYMBOL(NAME) \ |
| 2072 | Handle<String> NAME##_name = factory->NewStringFromAsciiChecked(#NAME); \ |
| 2073 | JSObject::AddProperty(container, NAME##_name, factory->NAME(), NONE); |
| 2074 | PRIVATE_SYMBOL_LIST(EXPORT_PRIVATE_SYMBOL) |
| 2075 | #undef EXPORT_PRIVATE_SYMBOL |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2076 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2077 | #define EXPORT_PUBLIC_SYMBOL(NAME, DESCRIPTION) \ |
| 2078 | Handle<String> NAME##_name = factory->NewStringFromAsciiChecked(#NAME); \ |
| 2079 | JSObject::AddProperty(container, NAME##_name, factory->NAME(), NONE); |
| 2080 | PUBLIC_SYMBOL_LIST(EXPORT_PUBLIC_SYMBOL) |
| 2081 | WELL_KNOWN_SYMBOL_LIST(EXPORT_PUBLIC_SYMBOL) |
| 2082 | #undef EXPORT_PUBLIC_SYMBOL |
| 2083 | |
| 2084 | { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2085 | Handle<JSFunction> to_string = InstallFunction( |
| 2086 | container, "object_to_string", JS_OBJECT_TYPE, JSObject::kHeaderSize, |
| 2087 | MaybeHandle<JSObject>(), Builtins::kObjectProtoToString); |
| 2088 | to_string->shared()->DontAdaptArguments(); |
| 2089 | to_string->shared()->set_length(0); |
| 2090 | native_context->set_object_to_string(*to_string); |
| 2091 | } |
| 2092 | |
| 2093 | Handle<JSObject> iterator_prototype; |
| 2094 | |
| 2095 | { |
| 2096 | PrototypeIterator iter(native_context->generator_object_prototype_map()); |
| 2097 | iter.Advance(); // Advance to the prototype of generator_object_prototype. |
| 2098 | iterator_prototype = Handle<JSObject>(iter.GetCurrent<JSObject>()); |
| 2099 | |
| 2100 | JSObject::AddProperty(container, |
| 2101 | factory->InternalizeUtf8String("IteratorPrototype"), |
| 2102 | iterator_prototype, NONE); |
| 2103 | } |
| 2104 | |
| 2105 | { |
| 2106 | PrototypeIterator iter(native_context->sloppy_generator_function_map()); |
| 2107 | Handle<JSObject> generator_function_prototype(iter.GetCurrent<JSObject>()); |
| 2108 | |
| 2109 | JSObject::AddProperty( |
| 2110 | container, factory->InternalizeUtf8String("GeneratorFunctionPrototype"), |
| 2111 | generator_function_prototype, NONE); |
| 2112 | |
| 2113 | static const bool kUseStrictFunctionMap = true; |
| 2114 | Handle<JSFunction> generator_function_function = InstallFunction( |
| 2115 | container, "GeneratorFunction", JS_FUNCTION_TYPE, JSFunction::kSize, |
| 2116 | generator_function_prototype, Builtins::kGeneratorFunctionConstructor, |
| 2117 | kUseStrictFunctionMap); |
| 2118 | generator_function_function->set_prototype_or_initial_map( |
| 2119 | native_context->sloppy_generator_function_map()); |
| 2120 | generator_function_function->shared()->DontAdaptArguments(); |
| 2121 | generator_function_function->shared()->set_construct_stub( |
| 2122 | *isolate->builtins()->GeneratorFunctionConstructor()); |
| 2123 | generator_function_function->shared()->set_length(1); |
| 2124 | InstallWithIntrinsicDefaultProto( |
| 2125 | isolate, generator_function_function, |
| 2126 | Context::GENERATOR_FUNCTION_FUNCTION_INDEX); |
| 2127 | |
| 2128 | native_context->sloppy_generator_function_map()->SetConstructor( |
| 2129 | *generator_function_function); |
| 2130 | native_context->strict_generator_function_map()->SetConstructor( |
| 2131 | *generator_function_function); |
| 2132 | native_context->strong_generator_function_map()->SetConstructor( |
| 2133 | *generator_function_function); |
| 2134 | } |
| 2135 | |
| 2136 | { // -- S e t I t e r a t o r |
| 2137 | Handle<JSObject> set_iterator_prototype = |
| 2138 | isolate->factory()->NewJSObject(isolate->object_function(), TENURED); |
| 2139 | SetObjectPrototype(set_iterator_prototype, iterator_prototype); |
| 2140 | Handle<JSFunction> set_iterator_function = InstallFunction( |
| 2141 | container, "SetIterator", JS_SET_ITERATOR_TYPE, JSSetIterator::kSize, |
| 2142 | set_iterator_prototype, Builtins::kIllegal); |
| 2143 | native_context->set_set_iterator_map(set_iterator_function->initial_map()); |
| 2144 | } |
| 2145 | |
| 2146 | { // -- M a p I t e r a t o r |
| 2147 | Handle<JSObject> map_iterator_prototype = |
| 2148 | isolate->factory()->NewJSObject(isolate->object_function(), TENURED); |
| 2149 | SetObjectPrototype(map_iterator_prototype, iterator_prototype); |
| 2150 | Handle<JSFunction> map_iterator_function = InstallFunction( |
| 2151 | container, "MapIterator", JS_MAP_ITERATOR_TYPE, JSMapIterator::kSize, |
| 2152 | map_iterator_prototype, Builtins::kIllegal); |
| 2153 | native_context->set_map_iterator_map(map_iterator_function->initial_map()); |
| 2154 | } |
| 2155 | |
| 2156 | { // -- S c r i p t |
| 2157 | // Builtin functions for Script. |
| 2158 | Handle<JSFunction> script_fun = InstallFunction( |
| 2159 | container, "Script", JS_VALUE_TYPE, JSValue::kSize, |
| 2160 | isolate->initial_object_prototype(), Builtins::kIllegal); |
| 2161 | Handle<JSObject> prototype = |
| 2162 | factory->NewJSObject(isolate->object_function(), TENURED); |
| 2163 | Accessors::FunctionSetPrototype(script_fun, prototype).Assert(); |
| 2164 | native_context->set_script_function(*script_fun); |
| 2165 | |
| 2166 | Handle<Map> script_map = Handle<Map>(script_fun->initial_map()); |
| 2167 | Map::EnsureDescriptorSlack(script_map, 15); |
| 2168 | |
| 2169 | PropertyAttributes attribs = |
| 2170 | static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 2171 | |
| 2172 | Handle<AccessorInfo> script_column = |
| 2173 | Accessors::ScriptColumnOffsetInfo(isolate, attribs); |
| 2174 | { |
| 2175 | AccessorConstantDescriptor d( |
| 2176 | Handle<Name>(Name::cast(script_column->name())), script_column, |
| 2177 | attribs); |
| 2178 | script_map->AppendDescriptor(&d); |
| 2179 | } |
| 2180 | |
| 2181 | Handle<AccessorInfo> script_id = Accessors::ScriptIdInfo(isolate, attribs); |
| 2182 | { |
| 2183 | AccessorConstantDescriptor d(Handle<Name>(Name::cast(script_id->name())), |
| 2184 | script_id, attribs); |
| 2185 | script_map->AppendDescriptor(&d); |
| 2186 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2187 | |
| 2188 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2189 | Handle<AccessorInfo> script_name = |
| 2190 | Accessors::ScriptNameInfo(isolate, attribs); |
| 2191 | { |
| 2192 | AccessorConstantDescriptor d( |
| 2193 | Handle<Name>(Name::cast(script_name->name())), script_name, attribs); |
| 2194 | script_map->AppendDescriptor(&d); |
| 2195 | } |
| 2196 | |
| 2197 | Handle<AccessorInfo> script_line = |
| 2198 | Accessors::ScriptLineOffsetInfo(isolate, attribs); |
| 2199 | { |
| 2200 | AccessorConstantDescriptor d( |
| 2201 | Handle<Name>(Name::cast(script_line->name())), script_line, attribs); |
| 2202 | script_map->AppendDescriptor(&d); |
| 2203 | } |
| 2204 | |
| 2205 | Handle<AccessorInfo> script_source = |
| 2206 | Accessors::ScriptSourceInfo(isolate, attribs); |
| 2207 | { |
| 2208 | AccessorConstantDescriptor d( |
| 2209 | Handle<Name>(Name::cast(script_source->name())), script_source, |
| 2210 | attribs); |
| 2211 | script_map->AppendDescriptor(&d); |
| 2212 | } |
| 2213 | |
| 2214 | Handle<AccessorInfo> script_type = |
| 2215 | Accessors::ScriptTypeInfo(isolate, attribs); |
| 2216 | { |
| 2217 | AccessorConstantDescriptor d( |
| 2218 | Handle<Name>(Name::cast(script_type->name())), script_type, attribs); |
| 2219 | script_map->AppendDescriptor(&d); |
| 2220 | } |
| 2221 | |
| 2222 | Handle<AccessorInfo> script_compilation_type = |
| 2223 | Accessors::ScriptCompilationTypeInfo(isolate, attribs); |
| 2224 | { |
| 2225 | AccessorConstantDescriptor d( |
| 2226 | Handle<Name>(Name::cast(script_compilation_type->name())), |
| 2227 | script_compilation_type, attribs); |
| 2228 | script_map->AppendDescriptor(&d); |
| 2229 | } |
| 2230 | |
| 2231 | Handle<AccessorInfo> script_line_ends = |
| 2232 | Accessors::ScriptLineEndsInfo(isolate, attribs); |
| 2233 | { |
| 2234 | AccessorConstantDescriptor d( |
| 2235 | Handle<Name>(Name::cast(script_line_ends->name())), script_line_ends, |
| 2236 | attribs); |
| 2237 | script_map->AppendDescriptor(&d); |
| 2238 | } |
| 2239 | |
| 2240 | Handle<AccessorInfo> script_context_data = |
| 2241 | Accessors::ScriptContextDataInfo(isolate, attribs); |
| 2242 | { |
| 2243 | AccessorConstantDescriptor d( |
| 2244 | Handle<Name>(Name::cast(script_context_data->name())), |
| 2245 | script_context_data, attribs); |
| 2246 | script_map->AppendDescriptor(&d); |
| 2247 | } |
| 2248 | |
| 2249 | Handle<AccessorInfo> script_eval_from_script = |
| 2250 | Accessors::ScriptEvalFromScriptInfo(isolate, attribs); |
| 2251 | { |
| 2252 | AccessorConstantDescriptor d( |
| 2253 | Handle<Name>(Name::cast(script_eval_from_script->name())), |
| 2254 | script_eval_from_script, attribs); |
| 2255 | script_map->AppendDescriptor(&d); |
| 2256 | } |
| 2257 | |
| 2258 | Handle<AccessorInfo> script_eval_from_script_position = |
| 2259 | Accessors::ScriptEvalFromScriptPositionInfo(isolate, attribs); |
| 2260 | { |
| 2261 | AccessorConstantDescriptor d( |
| 2262 | Handle<Name>(Name::cast(script_eval_from_script_position->name())), |
| 2263 | script_eval_from_script_position, attribs); |
| 2264 | script_map->AppendDescriptor(&d); |
| 2265 | } |
| 2266 | |
| 2267 | Handle<AccessorInfo> script_eval_from_function_name = |
| 2268 | Accessors::ScriptEvalFromFunctionNameInfo(isolate, attribs); |
| 2269 | { |
| 2270 | AccessorConstantDescriptor d( |
| 2271 | Handle<Name>(Name::cast(script_eval_from_function_name->name())), |
| 2272 | script_eval_from_function_name, attribs); |
| 2273 | script_map->AppendDescriptor(&d); |
| 2274 | } |
| 2275 | |
| 2276 | Handle<AccessorInfo> script_source_url = |
| 2277 | Accessors::ScriptSourceUrlInfo(isolate, attribs); |
| 2278 | { |
| 2279 | AccessorConstantDescriptor d( |
| 2280 | Handle<Name>(Name::cast(script_source_url->name())), |
| 2281 | script_source_url, attribs); |
| 2282 | script_map->AppendDescriptor(&d); |
| 2283 | } |
| 2284 | |
| 2285 | Handle<AccessorInfo> script_source_mapping_url = |
| 2286 | Accessors::ScriptSourceMappingUrlInfo(isolate, attribs); |
| 2287 | { |
| 2288 | AccessorConstantDescriptor d( |
| 2289 | Handle<Name>(Name::cast(script_source_mapping_url->name())), |
| 2290 | script_source_mapping_url, attribs); |
| 2291 | script_map->AppendDescriptor(&d); |
| 2292 | } |
| 2293 | |
| 2294 | Handle<AccessorInfo> script_is_embedder_debug_script = |
| 2295 | Accessors::ScriptIsEmbedderDebugScriptInfo(isolate, attribs); |
| 2296 | { |
| 2297 | AccessorConstantDescriptor d( |
| 2298 | Handle<Name>(Name::cast(script_is_embedder_debug_script->name())), |
| 2299 | script_is_embedder_debug_script, attribs); |
| 2300 | script_map->AppendDescriptor(&d); |
| 2301 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2302 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2303 | } |
| 2304 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2305 | |
| 2306 | void Bootstrapper::ExportExperimentalFromRuntime(Isolate* isolate, |
| 2307 | Handle<JSObject> container) { |
| 2308 | HandleScope scope(isolate); |
| 2309 | |
| 2310 | #define INITIALIZE_FLAG(FLAG) \ |
| 2311 | { \ |
| 2312 | Handle<String> name = \ |
| 2313 | isolate->factory()->NewStringFromAsciiChecked(#FLAG); \ |
| 2314 | JSObject::AddProperty(container, name, \ |
| 2315 | isolate->factory()->ToBoolean(FLAG), NONE); \ |
| 2316 | } |
| 2317 | |
| 2318 | INITIALIZE_FLAG(FLAG_harmony_tostring) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2319 | INITIALIZE_FLAG(FLAG_harmony_species) |
| 2320 | |
| 2321 | #undef INITIALIZE_FLAG |
| 2322 | } |
| 2323 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2324 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2325 | #define EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(id) \ |
| 2326 | void Genesis::InitializeGlobal_##id() {} |
| 2327 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2328 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_modules) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2329 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2330 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy_function) |
| 2331 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy_let) |
| 2332 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_default_parameters) |
| 2333 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_destructuring_bind) |
| 2334 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_destructuring_assignment) |
| 2335 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_object_observe) |
| 2336 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_regexps) |
| 2337 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_unicode_regexps) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2338 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_do_expressions) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2339 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_iterator_close) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2340 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_regexp_lookbehind) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2341 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_regexp_property) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2342 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_function_name) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2343 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_function_sent) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2344 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(promise_extra) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2345 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_tailcalls) |
| 2346 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_instanceof) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2347 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2348 | void InstallPublicSymbol(Factory* factory, Handle<Context> native_context, |
| 2349 | const char* name, Handle<Symbol> value) { |
| 2350 | Handle<JSGlobalObject> global( |
| 2351 | JSGlobalObject::cast(native_context->global_object())); |
| 2352 | Handle<String> symbol_string = factory->InternalizeUtf8String("Symbol"); |
| 2353 | Handle<JSObject> symbol = Handle<JSObject>::cast( |
| 2354 | JSObject::GetProperty(global, symbol_string).ToHandleChecked()); |
| 2355 | Handle<String> name_string = factory->InternalizeUtf8String(name); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2356 | PropertyAttributes attributes = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2357 | static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 2358 | JSObject::AddProperty(symbol, name_string, value, attributes); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2359 | } |
| 2360 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2361 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2362 | void Genesis::InitializeGlobal_harmony_tostring() { |
| 2363 | if (!FLAG_harmony_tostring) return; |
| 2364 | InstallPublicSymbol(factory(), native_context(), "toStringTag", |
| 2365 | factory()->to_string_tag_symbol()); |
| 2366 | } |
| 2367 | |
| 2368 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2369 | void Genesis::InitializeGlobal_harmony_regexp_subclass() { |
| 2370 | if (!FLAG_harmony_regexp_subclass) return; |
| 2371 | InstallPublicSymbol(factory(), native_context(), "match", |
| 2372 | factory()->match_symbol()); |
| 2373 | InstallPublicSymbol(factory(), native_context(), "replace", |
| 2374 | factory()->replace_symbol()); |
| 2375 | InstallPublicSymbol(factory(), native_context(), "search", |
| 2376 | factory()->search_symbol()); |
| 2377 | InstallPublicSymbol(factory(), native_context(), "split", |
| 2378 | factory()->split_symbol()); |
| 2379 | } |
| 2380 | |
| 2381 | |
| 2382 | void Genesis::InitializeGlobal_harmony_reflect() { |
| 2383 | Factory* factory = isolate()->factory(); |
| 2384 | |
| 2385 | // We currently use some of the Reflect functions internally, even when |
| 2386 | // the --harmony-reflect flag is not given. |
| 2387 | |
| 2388 | Handle<JSFunction> define_property = |
| 2389 | SimpleCreateFunction(isolate(), factory->defineProperty_string(), |
| 2390 | Builtins::kReflectDefineProperty, 3, true); |
| 2391 | native_context()->set_reflect_define_property(*define_property); |
| 2392 | |
| 2393 | Handle<JSFunction> delete_property = |
| 2394 | SimpleCreateFunction(isolate(), factory->deleteProperty_string(), |
| 2395 | Builtins::kReflectDeleteProperty, 2, true); |
| 2396 | native_context()->set_reflect_delete_property(*delete_property); |
| 2397 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2398 | Handle<JSFunction> apply = SimpleCreateFunction( |
| 2399 | isolate(), factory->apply_string(), Builtins::kReflectApply, 3, false); |
| 2400 | native_context()->set_reflect_apply(*apply); |
| 2401 | |
| 2402 | Handle<JSFunction> construct = |
| 2403 | SimpleCreateFunction(isolate(), factory->construct_string(), |
| 2404 | Builtins::kReflectConstruct, 2, false); |
| 2405 | native_context()->set_reflect_construct(*construct); |
| 2406 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2407 | if (!FLAG_harmony_reflect) return; |
| 2408 | |
| 2409 | Handle<JSGlobalObject> global(JSGlobalObject::cast( |
| 2410 | native_context()->global_object())); |
| 2411 | Handle<String> reflect_string = factory->NewStringFromStaticChars("Reflect"); |
| 2412 | Handle<JSObject> reflect = |
| 2413 | factory->NewJSObject(isolate()->object_function(), TENURED); |
| 2414 | JSObject::AddProperty(global, reflect_string, reflect, DONT_ENUM); |
| 2415 | |
| 2416 | InstallFunction(reflect, define_property, factory->defineProperty_string()); |
| 2417 | InstallFunction(reflect, delete_property, factory->deleteProperty_string()); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2418 | InstallFunction(reflect, apply, factory->apply_string()); |
| 2419 | InstallFunction(reflect, construct, factory->construct_string()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2420 | |
| 2421 | SimpleInstallFunction(reflect, factory->get_string(), |
| 2422 | Builtins::kReflectGet, 2, false); |
| 2423 | SimpleInstallFunction(reflect, factory->getOwnPropertyDescriptor_string(), |
| 2424 | Builtins::kReflectGetOwnPropertyDescriptor, 2, true); |
| 2425 | SimpleInstallFunction(reflect, factory->getPrototypeOf_string(), |
| 2426 | Builtins::kReflectGetPrototypeOf, 1, true); |
| 2427 | SimpleInstallFunction(reflect, factory->has_string(), |
| 2428 | Builtins::kReflectHas, 2, true); |
| 2429 | SimpleInstallFunction(reflect, factory->isExtensible_string(), |
| 2430 | Builtins::kReflectIsExtensible, 1, true); |
| 2431 | SimpleInstallFunction(reflect, factory->ownKeys_string(), |
| 2432 | Builtins::kReflectOwnKeys, 1, true); |
| 2433 | SimpleInstallFunction(reflect, factory->preventExtensions_string(), |
| 2434 | Builtins::kReflectPreventExtensions, 1, true); |
| 2435 | SimpleInstallFunction(reflect, factory->set_string(), |
| 2436 | Builtins::kReflectSet, 3, false); |
| 2437 | SimpleInstallFunction(reflect, factory->setPrototypeOf_string(), |
| 2438 | Builtins::kReflectSetPrototypeOf, 2, true); |
| 2439 | } |
| 2440 | |
| 2441 | |
| 2442 | void Genesis::InitializeGlobal_harmony_sharedarraybuffer() { |
| 2443 | if (!FLAG_harmony_sharedarraybuffer) return; |
| 2444 | |
| 2445 | Handle<JSGlobalObject> global(native_context()->global_object()); |
| 2446 | Handle<JSFunction> shared_array_buffer_fun = |
| 2447 | InstallArrayBuffer(global, "SharedArrayBuffer"); |
| 2448 | native_context()->set_shared_array_buffer_fun(*shared_array_buffer_fun); |
| 2449 | } |
| 2450 | |
| 2451 | |
| 2452 | void Genesis::InitializeGlobal_harmony_simd() { |
| 2453 | if (!FLAG_harmony_simd) return; |
| 2454 | |
| 2455 | Handle<JSGlobalObject> global( |
| 2456 | JSGlobalObject::cast(native_context()->global_object())); |
| 2457 | Isolate* isolate = global->GetIsolate(); |
| 2458 | Factory* factory = isolate->factory(); |
| 2459 | |
| 2460 | Handle<String> name = factory->InternalizeUtf8String("SIMD"); |
| 2461 | Handle<JSFunction> cons = factory->NewFunction(name); |
| 2462 | JSFunction::SetInstancePrototype( |
| 2463 | cons, |
| 2464 | Handle<Object>(native_context()->initial_object_prototype(), isolate)); |
| 2465 | cons->shared()->set_instance_class_name(*name); |
| 2466 | Handle<JSObject> simd_object = factory->NewJSObject(cons, TENURED); |
| 2467 | DCHECK(simd_object->IsJSObject()); |
| 2468 | JSObject::AddProperty(global, name, simd_object, DONT_ENUM); |
| 2469 | |
| 2470 | // Install SIMD type functions. Set the instance class names since |
| 2471 | // InstallFunction only does this when we install on the JSGlobalObject. |
| 2472 | #define SIMD128_INSTALL_FUNCTION(TYPE, Type, type, lane_count, lane_type) \ |
| 2473 | Handle<JSFunction> type##_function = InstallFunction( \ |
| 2474 | simd_object, #Type, JS_VALUE_TYPE, JSValue::kSize, \ |
| 2475 | isolate->initial_object_prototype(), Builtins::kIllegal); \ |
| 2476 | native_context()->set_##type##_function(*type##_function); \ |
| 2477 | type##_function->shared()->set_instance_class_name(*factory->Type##_string()); |
| 2478 | SIMD128_TYPES(SIMD128_INSTALL_FUNCTION) |
| 2479 | #undef SIMD128_INSTALL_FUNCTION |
| 2480 | } |
| 2481 | |
| 2482 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2483 | void Genesis::InitializeGlobal_harmony_object_values_entries() { |
| 2484 | if (!FLAG_harmony_object_values_entries) return; |
| 2485 | |
| 2486 | Handle<JSGlobalObject> global( |
| 2487 | JSGlobalObject::cast(native_context()->global_object())); |
| 2488 | Isolate* isolate = global->GetIsolate(); |
| 2489 | Factory* factory = isolate->factory(); |
| 2490 | |
| 2491 | Handle<JSFunction> object_function = isolate->object_function(); |
| 2492 | SimpleInstallFunction(object_function, factory->entries_string(), |
| 2493 | Builtins::kObjectEntries, 1, false); |
| 2494 | SimpleInstallFunction(object_function, factory->values_string(), |
| 2495 | Builtins::kObjectValues, 1, false); |
| 2496 | } |
| 2497 | |
| 2498 | void Genesis::InitializeGlobal_harmony_object_own_property_descriptors() { |
| 2499 | if (!FLAG_harmony_object_own_property_descriptors) return; |
| 2500 | |
| 2501 | Handle<JSGlobalObject> global( |
| 2502 | JSGlobalObject::cast(native_context()->global_object())); |
| 2503 | Isolate* isolate = global->GetIsolate(); |
| 2504 | Factory* factory = isolate->factory(); |
| 2505 | |
| 2506 | Handle<JSFunction> object_function = isolate->object_function(); |
| 2507 | SimpleInstallFunction(object_function, |
| 2508 | factory->getOwnPropertyDescriptors_string(), |
| 2509 | Builtins::kObjectGetOwnPropertyDescriptors, 1, false); |
| 2510 | } |
| 2511 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2512 | void Genesis::InstallJSProxyMaps() { |
| 2513 | // Allocate the different maps for all Proxy types. |
| 2514 | // Next to the default proxy, we need maps indicating callable and |
| 2515 | // constructable proxies. |
| 2516 | |
| 2517 | Handle<Map> proxy_function_map = |
| 2518 | Map::Copy(isolate()->sloppy_function_without_prototype_map(), "Proxy"); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2519 | proxy_function_map->set_is_constructor(true); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2520 | native_context()->set_proxy_function_map(*proxy_function_map); |
| 2521 | |
| 2522 | Handle<Map> proxy_map = |
| 2523 | factory()->NewMap(JS_PROXY_TYPE, JSProxy::kSize, FAST_ELEMENTS); |
| 2524 | proxy_map->set_dictionary_map(true); |
| 2525 | native_context()->set_proxy_map(*proxy_map); |
| 2526 | |
| 2527 | Handle<Map> proxy_callable_map = Map::Copy(proxy_map, "callable Proxy"); |
| 2528 | proxy_callable_map->set_is_callable(); |
| 2529 | native_context()->set_proxy_callable_map(*proxy_callable_map); |
| 2530 | proxy_callable_map->SetConstructor(native_context()->function_function()); |
| 2531 | |
| 2532 | Handle<Map> proxy_constructor_map = |
| 2533 | Map::Copy(proxy_callable_map, "constructor Proxy"); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2534 | proxy_constructor_map->set_is_constructor(true); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2535 | native_context()->set_proxy_constructor_map(*proxy_constructor_map); |
| 2536 | } |
| 2537 | |
| 2538 | |
| 2539 | void Genesis::InitializeGlobal_harmony_proxies() { |
| 2540 | if (!FLAG_harmony_proxies) return; |
| 2541 | Handle<JSGlobalObject> global( |
| 2542 | JSGlobalObject::cast(native_context()->global_object())); |
| 2543 | Isolate* isolate = global->GetIsolate(); |
| 2544 | Factory* factory = isolate->factory(); |
| 2545 | |
| 2546 | InstallJSProxyMaps(); |
| 2547 | |
| 2548 | // Create the Proxy object. |
| 2549 | Handle<String> name = factory->Proxy_string(); |
| 2550 | Handle<Code> code(isolate->builtins()->ProxyConstructor()); |
| 2551 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2552 | Handle<JSFunction> proxy_function = |
| 2553 | factory->NewFunction(isolate->proxy_function_map(), |
| 2554 | factory->Proxy_string(), MaybeHandle<Code>(code)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2555 | |
| 2556 | JSFunction::SetInitialMap(proxy_function, |
| 2557 | Handle<Map>(native_context()->proxy_map(), isolate), |
| 2558 | factory->null_value()); |
| 2559 | |
| 2560 | proxy_function->shared()->set_construct_stub( |
| 2561 | *isolate->builtins()->ProxyConstructor_ConstructStub()); |
| 2562 | proxy_function->shared()->set_internal_formal_parameter_count(2); |
| 2563 | proxy_function->shared()->set_length(2); |
| 2564 | |
| 2565 | native_context()->set_proxy_function(*proxy_function); |
| 2566 | InstallFunction(global, name, proxy_function, factory->Object_string()); |
| 2567 | } |
| 2568 | |
| 2569 | |
| 2570 | Handle<JSFunction> Genesis::InstallArrayBuffer(Handle<JSObject> target, |
| 2571 | const char* name) { |
| 2572 | // Setup the {prototype} with the given {name} for @@toStringTag. |
| 2573 | Handle<JSObject> prototype = |
| 2574 | factory()->NewJSObject(isolate()->object_function(), TENURED); |
| 2575 | JSObject::AddProperty(prototype, factory()->to_string_tag_symbol(), |
| 2576 | factory()->NewStringFromAsciiChecked(name), |
| 2577 | static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); |
| 2578 | |
| 2579 | // Allocate the constructor with the given {prototype}. |
| 2580 | Handle<JSFunction> array_buffer_fun = |
| 2581 | InstallFunction(target, name, JS_ARRAY_BUFFER_TYPE, |
| 2582 | JSArrayBuffer::kSizeWithInternalFields, prototype, |
| 2583 | Builtins::kArrayBufferConstructor); |
| 2584 | array_buffer_fun->shared()->set_construct_stub( |
| 2585 | *isolate()->builtins()->ArrayBufferConstructor_ConstructStub()); |
| 2586 | array_buffer_fun->shared()->DontAdaptArguments(); |
| 2587 | array_buffer_fun->shared()->set_length(1); |
| 2588 | |
| 2589 | // Install the "constructor" property on the {prototype}. |
| 2590 | JSObject::AddProperty(prototype, factory()->constructor_string(), |
| 2591 | array_buffer_fun, DONT_ENUM); |
| 2592 | |
| 2593 | SimpleInstallFunction(array_buffer_fun, factory()->isView_string(), |
| 2594 | Builtins::kArrayBufferIsView, 1, true); |
| 2595 | |
| 2596 | return array_buffer_fun; |
| 2597 | } |
| 2598 | |
| 2599 | |
| 2600 | void Genesis::InitializeGlobal_harmony_species() { |
| 2601 | if (!FLAG_harmony_species) return; |
| 2602 | InstallPublicSymbol(factory(), native_context(), "species", |
| 2603 | factory()->species_symbol()); |
| 2604 | } |
| 2605 | |
| 2606 | |
| 2607 | Handle<JSFunction> Genesis::InstallInternalArray(Handle<JSObject> target, |
| 2608 | const char* name, |
| 2609 | ElementsKind elements_kind) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2610 | // --- I n t e r n a l A r r a y --- |
| 2611 | // An array constructor on the builtins object that works like |
| 2612 | // the public Array constructor, except that its prototype |
| 2613 | // doesn't inherit from Object.prototype. |
| 2614 | // To be used only for internal work by builtins. Instances |
| 2615 | // must not be leaked to user code. |
| 2616 | Handle<JSObject> prototype = |
| 2617 | factory()->NewJSObject(isolate()->object_function(), TENURED); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2618 | Handle<JSFunction> array_function = |
| 2619 | InstallFunction(target, name, JS_ARRAY_TYPE, JSArray::kSize, prototype, |
| 2620 | Builtins::kInternalArrayCode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2621 | |
| 2622 | InternalArrayConstructorStub internal_array_constructor_stub(isolate()); |
| 2623 | Handle<Code> code = internal_array_constructor_stub.GetCode(); |
| 2624 | array_function->shared()->set_construct_stub(*code); |
| 2625 | array_function->shared()->DontAdaptArguments(); |
| 2626 | |
| 2627 | Handle<Map> original_map(array_function->initial_map()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2628 | Handle<Map> initial_map = Map::Copy(original_map, "InternalArray"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2629 | initial_map->set_elements_kind(elements_kind); |
| 2630 | JSFunction::SetInitialMap(array_function, initial_map, prototype); |
| 2631 | |
| 2632 | // Make "length" magic on instances. |
| 2633 | Map::EnsureDescriptorSlack(initial_map, 1); |
| 2634 | |
| 2635 | PropertyAttributes attribs = static_cast<PropertyAttributes>( |
| 2636 | DONT_ENUM | DONT_DELETE); |
| 2637 | |
| 2638 | Handle<AccessorInfo> array_length = |
| 2639 | Accessors::ArrayLengthInfo(isolate(), attribs); |
| 2640 | { // Add length. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2641 | AccessorConstantDescriptor d(Handle<Name>(Name::cast(array_length->name())), |
| 2642 | array_length, attribs); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2643 | initial_map->AppendDescriptor(&d); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2644 | } |
| 2645 | |
| 2646 | return array_function; |
| 2647 | } |
| 2648 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2649 | bool Genesis::InstallNatives(GlobalContextType context_type) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2650 | HandleScope scope(isolate()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2651 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2652 | // Set up the utils object as shared container between native scripts. |
| 2653 | Handle<JSObject> utils = factory()->NewJSObject(isolate()->object_function()); |
| 2654 | JSObject::NormalizeProperties(utils, CLEAR_INOBJECT_PROPERTIES, 16, |
| 2655 | "utils container for native scripts"); |
| 2656 | native_context()->set_natives_utils_object(*utils); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2657 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2658 | // Set up the extras utils object as a shared container between native |
| 2659 | // scripts and extras. (Extras consume things added there by native scripts.) |
| 2660 | Handle<JSObject> extras_utils = |
| 2661 | factory()->NewJSObject(isolate()->object_function()); |
| 2662 | native_context()->set_extras_utils_object(*extras_utils); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2663 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2664 | InstallInternalArray(extras_utils, "InternalPackedArray", FAST_ELEMENTS); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2665 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2666 | int builtin_index = Natives::GetDebuggerCount(); |
| 2667 | // Only run prologue.js and runtime.js at this point. |
| 2668 | DCHECK_EQ(builtin_index, Natives::GetIndex("prologue")); |
| 2669 | if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false; |
| 2670 | DCHECK_EQ(builtin_index, Natives::GetIndex("runtime")); |
| 2671 | if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2672 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2673 | // A thin context is ready at this point. |
| 2674 | if (context_type == THIN_CONTEXT) return true; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2675 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2676 | { |
| 2677 | // Builtin function for OpaqueReference -- a JSValue-based object, |
| 2678 | // that keeps its field isolated from JavaScript code. It may store |
| 2679 | // objects, that JavaScript code may not access. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2680 | Handle<JSFunction> opaque_reference_fun = factory()->NewFunction( |
| 2681 | factory()->empty_string(), isolate()->builtins()->Illegal(), |
| 2682 | isolate()->initial_object_prototype(), JS_VALUE_TYPE, JSValue::kSize); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2683 | Handle<JSObject> prototype = |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2684 | factory()->NewJSObject(isolate()->object_function(), TENURED); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2685 | Accessors::FunctionSetPrototype(opaque_reference_fun, prototype).Assert(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2686 | native_context()->set_opaque_reference_function(*opaque_reference_fun); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2687 | } |
| 2688 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2689 | // InternalArrays should not use Smi-Only array optimizations. There are too |
| 2690 | // many places in the C++ runtime code (e.g. RegEx) that assume that |
| 2691 | // elements in InternalArrays can be set to non-Smi values without going |
| 2692 | // through a common bottleneck that would make the SMI_ONLY -> FAST_ELEMENT |
| 2693 | // transition easy to trap. Moreover, they rarely are smi-only. |
| 2694 | { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2695 | HandleScope scope(isolate()); |
| 2696 | Handle<JSObject> utils = |
| 2697 | Handle<JSObject>::cast(isolate()->natives_utils_object()); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2698 | Handle<JSFunction> array_function = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2699 | InstallInternalArray(utils, "InternalArray", FAST_HOLEY_ELEMENTS); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2700 | native_context()->set_internal_array_function(*array_function); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2701 | InstallInternalArray(utils, "InternalPackedArray", FAST_ELEMENTS); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2702 | } |
| 2703 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2704 | // Run the rest of the native scripts. |
| 2705 | while (builtin_index < Natives::GetBuiltinsCount()) { |
| 2706 | if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2707 | } |
| 2708 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2709 | if (!CallUtilsFunction(isolate(), "PostNatives")) return false; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2710 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2711 | auto template_instantiations_cache = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2712 | ObjectHashTable::New(isolate(), ApiNatives::kInitialFunctionCacheSize, |
| 2713 | USE_CUSTOM_MINIMUM_CAPACITY); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2714 | native_context()->set_template_instantiations_cache( |
| 2715 | *template_instantiations_cache); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2716 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2717 | // Store the map for the %ObjectPrototype% after the natives has been compiled |
| 2718 | // and the Object function has been set up. |
| 2719 | Handle<JSFunction> object_function(native_context()->object_function()); |
| 2720 | DCHECK(JSObject::cast(object_function->initial_map()->prototype()) |
| 2721 | ->HasFastProperties()); |
| 2722 | native_context()->set_object_function_prototype_map( |
| 2723 | HeapObject::cast(object_function->initial_map()->prototype())->map()); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2724 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2725 | // Store the map for the %StringPrototype% after the natives has been compiled |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2726 | // and the String function has been set up. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2727 | Handle<JSFunction> string_function(native_context()->string_function()); |
| 2728 | DCHECK(JSObject::cast( |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2729 | string_function->initial_map()->prototype())->HasFastProperties()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2730 | native_context()->set_string_function_prototype_map( |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2731 | HeapObject::cast(string_function->initial_map()->prototype())->map()); |
| 2732 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2733 | // Install Global.eval. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2734 | { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2735 | Handle<JSFunction> eval = SimpleInstallFunction( |
| 2736 | handle(native_context()->global_object()), factory()->eval_string(), |
| 2737 | Builtins::kGlobalEval, 1, false); |
| 2738 | native_context()->set_global_eval_fun(*eval); |
| 2739 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2740 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2741 | // Install Array.prototype.concat |
| 2742 | { |
| 2743 | Handle<JSFunction> array_constructor(native_context()->array_function()); |
| 2744 | Handle<JSObject> proto(JSObject::cast(array_constructor->prototype())); |
| 2745 | Handle<JSFunction> concat = |
| 2746 | InstallFunction(proto, "concat", JS_OBJECT_TYPE, JSObject::kHeaderSize, |
| 2747 | MaybeHandle<JSObject>(), Builtins::kArrayConcat); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2748 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2749 | // Make sure that Array.prototype.concat appears to be compiled. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2750 | // The code will never be called, but inline caching for call will |
| 2751 | // only work if it appears to be compiled. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2752 | concat->shared()->DontAdaptArguments(); |
| 2753 | DCHECK(concat->is_compiled()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2754 | // Set the lengths for the functions to satisfy ECMA-262. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2755 | concat->shared()->set_length(1); |
| 2756 | } |
| 2757 | |
| 2758 | // Install InternalArray.prototype.concat |
| 2759 | { |
| 2760 | Handle<JSFunction> array_constructor( |
| 2761 | native_context()->internal_array_function()); |
| 2762 | Handle<JSObject> proto(JSObject::cast(array_constructor->prototype())); |
| 2763 | Handle<JSFunction> concat = |
| 2764 | InstallFunction(proto, "concat", JS_OBJECT_TYPE, JSObject::kHeaderSize, |
| 2765 | MaybeHandle<JSObject>(), Builtins::kArrayConcat); |
| 2766 | |
| 2767 | // Make sure that InternalArray.prototype.concat appears to be compiled. |
| 2768 | // The code will never be called, but inline caching for call will |
| 2769 | // only work if it appears to be compiled. |
| 2770 | concat->shared()->DontAdaptArguments(); |
| 2771 | DCHECK(concat->is_compiled()); |
| 2772 | // Set the lengths for the functions to satisfy ECMA-262. |
| 2773 | concat->shared()->set_length(1); |
| 2774 | } |
| 2775 | |
| 2776 | // Set up the Promise constructor. |
| 2777 | { |
| 2778 | Handle<String> key = factory()->Promise_string(); |
| 2779 | Handle<JSFunction> function = Handle<JSFunction>::cast( |
| 2780 | Object::GetProperty(handle(native_context()->global_object()), key) |
| 2781 | .ToHandleChecked()); |
| 2782 | JSFunction::EnsureHasInitialMap(function); |
| 2783 | function->initial_map()->set_instance_type(JS_PROMISE_TYPE); |
| 2784 | function->shared()->set_construct_stub( |
| 2785 | *isolate()->builtins()->JSBuiltinsConstructStub()); |
| 2786 | InstallWithIntrinsicDefaultProto(isolate(), function, |
| 2787 | Context::PROMISE_FUNCTION_INDEX); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2788 | } |
| 2789 | |
Ben Murdoch | 42effa5 | 2011-08-19 16:40:31 +0100 | [diff] [blame] | 2790 | InstallBuiltinFunctionIds(); |
| 2791 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2792 | // Create a map for accessor property descriptors (a variant of JSObject |
| 2793 | // that predefines four properties get, set, configurable and enumerable). |
| 2794 | { |
| 2795 | // AccessorPropertyDescriptor initial map. |
| 2796 | Handle<Map> map = |
| 2797 | factory()->NewMap(JS_OBJECT_TYPE, JSAccessorPropertyDescriptor::kSize); |
| 2798 | // Create the descriptor array for the property descriptor object. |
| 2799 | Map::EnsureDescriptorSlack(map, 4); |
| 2800 | |
| 2801 | { // get |
| 2802 | DataDescriptor d(factory()->get_string(), |
| 2803 | JSAccessorPropertyDescriptor::kGetIndex, NONE, |
| 2804 | Representation::Tagged()); |
| 2805 | map->AppendDescriptor(&d); |
| 2806 | } |
| 2807 | { // set |
| 2808 | DataDescriptor d(factory()->set_string(), |
| 2809 | JSAccessorPropertyDescriptor::kSetIndex, NONE, |
| 2810 | Representation::Tagged()); |
| 2811 | map->AppendDescriptor(&d); |
| 2812 | } |
| 2813 | { // enumerable |
| 2814 | DataDescriptor d(factory()->enumerable_string(), |
| 2815 | JSAccessorPropertyDescriptor::kEnumerableIndex, NONE, |
| 2816 | Representation::Tagged()); |
| 2817 | map->AppendDescriptor(&d); |
| 2818 | } |
| 2819 | { // configurable |
| 2820 | DataDescriptor d(factory()->configurable_string(), |
| 2821 | JSAccessorPropertyDescriptor::kConfigurableIndex, NONE, |
| 2822 | Representation::Tagged()); |
| 2823 | map->AppendDescriptor(&d); |
| 2824 | } |
| 2825 | |
| 2826 | Map::SetPrototype(map, isolate()->initial_object_prototype()); |
| 2827 | map->SetConstructor(native_context()->object_function()); |
| 2828 | map->SetInObjectProperties(4); |
| 2829 | map->set_unused_property_fields(0); |
| 2830 | |
| 2831 | native_context()->set_accessor_property_descriptor_map(*map); |
| 2832 | } |
| 2833 | |
| 2834 | // Create a map for data property descriptors (a variant of JSObject |
| 2835 | // that predefines four properties value, writable, configurable and |
| 2836 | // enumerable). |
| 2837 | { |
| 2838 | // DataPropertyDescriptor initial map. |
| 2839 | Handle<Map> map = |
| 2840 | factory()->NewMap(JS_OBJECT_TYPE, JSDataPropertyDescriptor::kSize); |
| 2841 | // Create the descriptor array for the property descriptor object. |
| 2842 | Map::EnsureDescriptorSlack(map, 4); |
| 2843 | |
| 2844 | { // value |
| 2845 | DataDescriptor d(factory()->value_string(), |
| 2846 | JSDataPropertyDescriptor::kValueIndex, NONE, |
| 2847 | Representation::Tagged()); |
| 2848 | map->AppendDescriptor(&d); |
| 2849 | } |
| 2850 | { // writable |
| 2851 | DataDescriptor d(factory()->writable_string(), |
| 2852 | JSDataPropertyDescriptor::kWritableIndex, NONE, |
| 2853 | Representation::Tagged()); |
| 2854 | map->AppendDescriptor(&d); |
| 2855 | } |
| 2856 | { // enumerable |
| 2857 | DataDescriptor d(factory()->enumerable_string(), |
| 2858 | JSDataPropertyDescriptor::kEnumerableIndex, NONE, |
| 2859 | Representation::Tagged()); |
| 2860 | map->AppendDescriptor(&d); |
| 2861 | } |
| 2862 | { // configurable |
| 2863 | DataDescriptor d(factory()->configurable_string(), |
| 2864 | JSDataPropertyDescriptor::kConfigurableIndex, NONE, |
| 2865 | Representation::Tagged()); |
| 2866 | map->AppendDescriptor(&d); |
| 2867 | } |
| 2868 | |
| 2869 | Map::SetPrototype(map, isolate()->initial_object_prototype()); |
| 2870 | map->SetConstructor(native_context()->object_function()); |
| 2871 | map->SetInObjectProperties(4); |
| 2872 | map->set_unused_property_fields(0); |
| 2873 | |
| 2874 | native_context()->set_data_property_descriptor_map(*map); |
| 2875 | } |
| 2876 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2877 | // Create a constructor for RegExp results (a variant of Array that |
| 2878 | // predefines the two properties index and match). |
| 2879 | { |
| 2880 | // RegExpResult initial map. |
| 2881 | |
| 2882 | // Find global.Array.prototype to inherit from. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2883 | Handle<JSFunction> array_constructor(native_context()->array_function()); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2884 | Handle<JSObject> array_prototype( |
| 2885 | JSObject::cast(array_constructor->instance_prototype())); |
| 2886 | |
| 2887 | // Add initial map. |
| 2888 | Handle<Map> initial_map = |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2889 | factory()->NewMap(JS_ARRAY_TYPE, JSRegExpResult::kSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2890 | initial_map->SetConstructor(*array_constructor); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2891 | |
| 2892 | // Set prototype on map. |
| 2893 | initial_map->set_non_instance_prototype(false); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2894 | Map::SetPrototype(initial_map, array_prototype); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2895 | |
| 2896 | // Update map with length accessor from Array and add "index" and "input". |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2897 | Map::EnsureDescriptorSlack(initial_map, 3); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2898 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2899 | { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2900 | JSFunction* array_function = native_context()->array_function(); |
| 2901 | Handle<DescriptorArray> array_descriptors( |
| 2902 | array_function->initial_map()->instance_descriptors()); |
| 2903 | Handle<String> length = factory()->length_string(); |
| 2904 | int old = array_descriptors->SearchWithCache( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2905 | isolate(), *length, array_function->initial_map()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2906 | DCHECK(old != DescriptorArray::kNotFound); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2907 | AccessorConstantDescriptor desc( |
| 2908 | length, handle(array_descriptors->GetValue(old), isolate()), |
| 2909 | array_descriptors->GetDetails(old).attributes()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2910 | initial_map->AppendDescriptor(&desc); |
| 2911 | } |
| 2912 | { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2913 | DataDescriptor index_field(factory()->index_string(), |
| 2914 | JSRegExpResult::kIndexIndex, NONE, |
| 2915 | Representation::Tagged()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2916 | initial_map->AppendDescriptor(&index_field); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2920 | DataDescriptor input_field(factory()->input_string(), |
| 2921 | JSRegExpResult::kInputIndex, NONE, |
| 2922 | Representation::Tagged()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2923 | initial_map->AppendDescriptor(&input_field); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2924 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2925 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2926 | initial_map->SetInObjectProperties(2); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2927 | initial_map->set_unused_property_fields(0); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2928 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2929 | native_context()->set_regexp_result_map(*initial_map); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2930 | } |
| 2931 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2932 | // Add @@iterator method to the arguments object maps. |
| 2933 | { |
| 2934 | PropertyAttributes attribs = DONT_ENUM; |
| 2935 | Handle<AccessorInfo> arguments_iterator = |
| 2936 | Accessors::ArgumentsIteratorInfo(isolate(), attribs); |
| 2937 | { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2938 | AccessorConstantDescriptor d(factory()->iterator_symbol(), |
| 2939 | arguments_iterator, attribs); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2940 | Handle<Map> map(native_context()->sloppy_arguments_map()); |
| 2941 | Map::EnsureDescriptorSlack(map, 1); |
| 2942 | map->AppendDescriptor(&d); |
| 2943 | } |
| 2944 | { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2945 | AccessorConstantDescriptor d(factory()->iterator_symbol(), |
| 2946 | arguments_iterator, attribs); |
| 2947 | Handle<Map> map(native_context()->fast_aliased_arguments_map()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2948 | Map::EnsureDescriptorSlack(map, 1); |
| 2949 | map->AppendDescriptor(&d); |
| 2950 | } |
| 2951 | { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2952 | AccessorConstantDescriptor d(factory()->iterator_symbol(), |
| 2953 | arguments_iterator, attribs); |
| 2954 | Handle<Map> map(native_context()->slow_aliased_arguments_map()); |
| 2955 | Map::EnsureDescriptorSlack(map, 1); |
| 2956 | map->AppendDescriptor(&d); |
| 2957 | } |
| 2958 | { |
| 2959 | AccessorConstantDescriptor d(factory()->iterator_symbol(), |
| 2960 | arguments_iterator, attribs); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2961 | Handle<Map> map(native_context()->strict_arguments_map()); |
| 2962 | Map::EnsureDescriptorSlack(map, 1); |
| 2963 | map->AppendDescriptor(&d); |
| 2964 | } |
| 2965 | } |
| 2966 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2967 | return true; |
| 2968 | } |
| 2969 | |
| 2970 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2971 | bool Genesis::InstallExperimentalNatives() { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2972 | static const char* harmony_proxies_natives[] = {"native proxy.js", nullptr}; |
| 2973 | static const char* harmony_modules_natives[] = {nullptr}; |
| 2974 | static const char* harmony_regexps_natives[] = {"native harmony-regexp.js", |
| 2975 | nullptr}; |
| 2976 | static const char* harmony_tostring_natives[] = {nullptr}; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2977 | static const char* harmony_iterator_close_natives[] = {nullptr}; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2978 | static const char* harmony_sloppy_natives[] = {nullptr}; |
| 2979 | static const char* harmony_sloppy_function_natives[] = {nullptr}; |
| 2980 | static const char* harmony_sloppy_let_natives[] = {nullptr}; |
| 2981 | static const char* harmony_species_natives[] = {"native harmony-species.js", |
| 2982 | nullptr}; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2983 | static const char* harmony_tailcalls_natives[] = {nullptr}; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2984 | static const char* harmony_unicode_regexps_natives[] = { |
| 2985 | "native harmony-unicode-regexps.js", nullptr}; |
| 2986 | static const char* harmony_default_parameters_natives[] = {nullptr}; |
| 2987 | static const char* harmony_reflect_natives[] = {"native harmony-reflect.js", |
| 2988 | nullptr}; |
| 2989 | static const char* harmony_destructuring_bind_natives[] = {nullptr}; |
| 2990 | static const char* harmony_destructuring_assignment_natives[] = {nullptr}; |
| 2991 | static const char* harmony_object_observe_natives[] = { |
| 2992 | "native harmony-object-observe.js", nullptr}; |
| 2993 | static const char* harmony_sharedarraybuffer_natives[] = { |
| 2994 | "native harmony-sharedarraybuffer.js", "native harmony-atomics.js", NULL}; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2995 | static const char* harmony_simd_natives[] = {"native harmony-simd.js", |
| 2996 | nullptr}; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2997 | static const char* harmony_do_expressions_natives[] = {nullptr}; |
| 2998 | static const char* harmony_regexp_subclass_natives[] = {nullptr}; |
| 2999 | static const char* harmony_regexp_lookbehind_natives[] = {nullptr}; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 3000 | static const char* harmony_instanceof_natives[] = {nullptr}; |
| 3001 | static const char* harmony_regexp_property_natives[] = {nullptr}; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3002 | static const char* harmony_function_name_natives[] = {nullptr}; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 3003 | static const char* harmony_function_sent_natives[] = {nullptr}; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3004 | static const char* promise_extra_natives[] = {"native promise-extra.js", |
| 3005 | nullptr}; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 3006 | static const char* harmony_object_values_entries_natives[] = {nullptr}; |
| 3007 | static const char* harmony_object_own_property_descriptors_natives[] = { |
| 3008 | nullptr}; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3009 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3010 | for (int i = ExperimentalNatives::GetDebuggerCount(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3011 | i < ExperimentalNatives::GetBuiltinsCount(); i++) { |
| 3012 | #define INSTALL_EXPERIMENTAL_NATIVES(id, desc) \ |
| 3013 | if (FLAG_##id) { \ |
| 3014 | for (size_t j = 0; id##_natives[j] != NULL; j++) { \ |
| 3015 | Vector<const char> script_name = ExperimentalNatives::GetScriptName(i); \ |
| 3016 | if (strncmp(script_name.start(), id##_natives[j], \ |
| 3017 | script_name.length()) == 0) { \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3018 | if (!Bootstrapper::CompileExperimentalBuiltin(isolate(), i)) { \ |
| 3019 | return false; \ |
| 3020 | } \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3021 | } \ |
| 3022 | } \ |
| 3023 | } |
| 3024 | HARMONY_INPROGRESS(INSTALL_EXPERIMENTAL_NATIVES); |
| 3025 | HARMONY_STAGED(INSTALL_EXPERIMENTAL_NATIVES); |
| 3026 | HARMONY_SHIPPING(INSTALL_EXPERIMENTAL_NATIVES); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3027 | INSTALL_EXPERIMENTAL_NATIVES(promise_extra, ""); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3028 | #undef INSTALL_EXPERIMENTAL_NATIVES |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3029 | } |
| 3030 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3031 | if (!CallUtilsFunction(isolate(), "PostExperimentals")) return false; |
| 3032 | |
| 3033 | InstallExperimentalBuiltinFunctionIds(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3034 | return true; |
| 3035 | } |
| 3036 | |
| 3037 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3038 | bool Genesis::InstallExtraNatives() { |
| 3039 | HandleScope scope(isolate()); |
| 3040 | |
| 3041 | Handle<JSObject> extras_binding = |
| 3042 | factory()->NewJSObject(isolate()->object_function()); |
| 3043 | native_context()->set_extras_binding_object(*extras_binding); |
| 3044 | |
| 3045 | for (int i = ExtraNatives::GetDebuggerCount(); |
| 3046 | i < ExtraNatives::GetBuiltinsCount(); i++) { |
| 3047 | if (!Bootstrapper::CompileExtraBuiltin(isolate(), i)) return false; |
| 3048 | } |
| 3049 | |
| 3050 | return true; |
| 3051 | } |
| 3052 | |
| 3053 | |
| 3054 | bool Genesis::InstallExperimentalExtraNatives() { |
| 3055 | for (int i = ExperimentalExtraNatives::GetDebuggerCount(); |
| 3056 | i < ExperimentalExtraNatives::GetBuiltinsCount(); i++) { |
| 3057 | if (!Bootstrapper::CompileExperimentalExtraBuiltin(isolate(), i)) |
| 3058 | return false; |
| 3059 | } |
| 3060 | |
| 3061 | return true; |
| 3062 | } |
| 3063 | |
| 3064 | |
| 3065 | bool Genesis::InstallDebuggerNatives() { |
| 3066 | for (int i = 0; i < Natives::GetDebuggerCount(); ++i) { |
| 3067 | if (!Bootstrapper::CompileBuiltin(isolate(), i)) return false; |
| 3068 | } |
| 3069 | return CallUtilsFunction(isolate(), "PostDebug"); |
| 3070 | } |
| 3071 | |
| 3072 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3073 | static void InstallBuiltinFunctionId(Handle<JSObject> holder, |
| 3074 | const char* function_name, |
| 3075 | BuiltinFunctionId id) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3076 | Isolate* isolate = holder->GetIsolate(); |
| 3077 | Handle<Object> function_object = |
| 3078 | Object::GetProperty(isolate, holder, function_name).ToHandleChecked(); |
| 3079 | Handle<JSFunction> function = Handle<JSFunction>::cast(function_object); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 3080 | function->shared()->set_function_data(Smi::FromInt(id)); |
| 3081 | } |
| 3082 | |
| 3083 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3084 | #define INSTALL_BUILTIN_ID(holder_expr, fun_name, name) \ |
| 3085 | { #holder_expr, #fun_name, k##name } \ |
| 3086 | , |
| 3087 | |
| 3088 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3089 | void Genesis::InstallBuiltinFunctionIds() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3090 | HandleScope scope(isolate()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3091 | struct BuiltinFunctionIds { |
| 3092 | const char* holder_expr; |
| 3093 | const char* fun_name; |
| 3094 | BuiltinFunctionId id; |
| 3095 | }; |
| 3096 | |
| 3097 | const BuiltinFunctionIds builtins[] = { |
| 3098 | FUNCTIONS_WITH_ID_LIST(INSTALL_BUILTIN_ID)}; |
| 3099 | |
| 3100 | for (const BuiltinFunctionIds& builtin : builtins) { |
| 3101 | Handle<JSObject> holder = |
| 3102 | ResolveBuiltinIdHolder(native_context(), builtin.holder_expr); |
| 3103 | InstallBuiltinFunctionId(holder, builtin.fun_name, builtin.id); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 3104 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3105 | } |
| 3106 | |
| 3107 | |
| 3108 | void Genesis::InstallExperimentalBuiltinFunctionIds() { |
| 3109 | if (FLAG_harmony_sharedarraybuffer) { |
| 3110 | struct BuiltinFunctionIds { |
| 3111 | const char* holder_expr; |
| 3112 | const char* fun_name; |
| 3113 | BuiltinFunctionId id; |
| 3114 | }; |
| 3115 | |
| 3116 | const BuiltinFunctionIds atomic_builtins[] = { |
| 3117 | ATOMIC_FUNCTIONS_WITH_ID_LIST(INSTALL_BUILTIN_ID)}; |
| 3118 | |
| 3119 | for (const BuiltinFunctionIds& builtin : atomic_builtins) { |
| 3120 | Handle<JSObject> holder = |
| 3121 | ResolveBuiltinIdHolder(native_context(), builtin.holder_expr); |
| 3122 | InstallBuiltinFunctionId(holder, builtin.fun_name, builtin.id); |
| 3123 | } |
| 3124 | } |
| 3125 | } |
| 3126 | |
| 3127 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3128 | #undef INSTALL_BUILTIN_ID |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3129 | |
| 3130 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3131 | void Genesis::InitializeNormalizedMapCaches() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3132 | Handle<NormalizedMapCache> cache = NormalizedMapCache::New(isolate()); |
| 3133 | native_context()->set_normalized_map_cache(*cache); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3134 | } |
| 3135 | |
| 3136 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3137 | bool Bootstrapper::InstallExtensions(Handle<Context> native_context, |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 3138 | v8::ExtensionConfiguration* extensions) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3139 | BootstrapperActive active(this); |
| 3140 | SaveContext saved_context(isolate_); |
| 3141 | isolate_->set_context(*native_context); |
| 3142 | return Genesis::InstallExtensions(native_context, extensions) && |
| 3143 | Genesis::InstallSpecialObjects(native_context); |
| 3144 | } |
| 3145 | |
| 3146 | |
| 3147 | bool Genesis::InstallSpecialObjects(Handle<Context> native_context) { |
| 3148 | Isolate* isolate = native_context->GetIsolate(); |
| 3149 | // Don't install extensions into the snapshot. |
| 3150 | if (isolate->serializer_enabled()) return true; |
| 3151 | |
| 3152 | Factory* factory = isolate->factory(); |
| 3153 | HandleScope scope(isolate); |
| 3154 | Handle<JSGlobalObject> global(JSGlobalObject::cast( |
| 3155 | native_context->global_object())); |
| 3156 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3157 | Handle<JSObject> Error = isolate->error_function(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3158 | Handle<String> name = |
| 3159 | factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("stackTraceLimit")); |
| 3160 | Handle<Smi> stack_trace_limit(Smi::FromInt(FLAG_stack_trace_limit), isolate); |
| 3161 | JSObject::AddProperty(Error, name, stack_trace_limit, NONE); |
| 3162 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3163 | // Expose the debug global object in global if a name for it is specified. |
| 3164 | if (FLAG_expose_debug_as != NULL && strlen(FLAG_expose_debug_as) != 0) { |
| 3165 | // If loading fails we just bail out without installing the |
| 3166 | // debugger but without tanking the whole context. |
| 3167 | Debug* debug = isolate->debug(); |
| 3168 | if (!debug->Load()) return true; |
| 3169 | Handle<Context> debug_context = debug->debug_context(); |
| 3170 | // Set the security token for the debugger context to the same as |
| 3171 | // the shell native context to allow calling between these (otherwise |
| 3172 | // exposing debug global object doesn't make much sense). |
| 3173 | debug_context->set_security_token(native_context->security_token()); |
| 3174 | Handle<String> debug_string = |
| 3175 | factory->InternalizeUtf8String(FLAG_expose_debug_as); |
| 3176 | uint32_t index; |
| 3177 | if (debug_string->AsArrayIndex(&index)) return true; |
| 3178 | Handle<Object> global_proxy(debug_context->global_proxy(), isolate); |
| 3179 | JSObject::AddProperty(global, debug_string, global_proxy, DONT_ENUM); |
| 3180 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3181 | |
| 3182 | if (FLAG_expose_wasm) { |
| 3183 | WasmJs::Install(isolate, global); |
| 3184 | } |
| 3185 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 3186 | return true; |
| 3187 | } |
| 3188 | |
| 3189 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3190 | static uint32_t Hash(RegisteredExtension* extension) { |
| 3191 | return v8::internal::ComputePointerHash(extension); |
| 3192 | } |
| 3193 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3194 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3195 | Genesis::ExtensionStates::ExtensionStates() : map_(HashMap::PointersMatch, 8) {} |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3196 | |
| 3197 | Genesis::ExtensionTraversalState Genesis::ExtensionStates::get_state( |
| 3198 | RegisteredExtension* extension) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3199 | i::HashMap::Entry* entry = map_.Lookup(extension, Hash(extension)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3200 | if (entry == NULL) { |
| 3201 | return UNVISITED; |
| 3202 | } |
| 3203 | return static_cast<ExtensionTraversalState>( |
| 3204 | reinterpret_cast<intptr_t>(entry->value)); |
| 3205 | } |
| 3206 | |
| 3207 | void Genesis::ExtensionStates::set_state(RegisteredExtension* extension, |
| 3208 | ExtensionTraversalState state) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3209 | map_.LookupOrInsert(extension, Hash(extension))->value = |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3210 | reinterpret_cast<void*>(static_cast<intptr_t>(state)); |
| 3211 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3212 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3213 | |
| 3214 | bool Genesis::InstallExtensions(Handle<Context> native_context, |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 3215 | v8::ExtensionConfiguration* extensions) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3216 | Isolate* isolate = native_context->GetIsolate(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3217 | ExtensionStates extension_states; // All extensions have state UNVISITED. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3218 | return InstallAutoExtensions(isolate, &extension_states) && |
| 3219 | (!FLAG_expose_free_buffer || |
| 3220 | InstallExtension(isolate, "v8/free-buffer", &extension_states)) && |
| 3221 | (!FLAG_expose_gc || |
| 3222 | InstallExtension(isolate, "v8/gc", &extension_states)) && |
| 3223 | (!FLAG_expose_externalize_string || |
| 3224 | InstallExtension(isolate, "v8/externalize", &extension_states)) && |
| 3225 | (!FLAG_track_gc_object_stats || |
| 3226 | InstallExtension(isolate, "v8/statistics", &extension_states)) && |
| 3227 | (!FLAG_expose_trigger_failure || |
| 3228 | InstallExtension(isolate, "v8/trigger-failure", &extension_states)) && |
| 3229 | InstallRequestedExtensions(isolate, extensions, &extension_states); |
| 3230 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3231 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3232 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3233 | bool Genesis::InstallAutoExtensions(Isolate* isolate, |
| 3234 | ExtensionStates* extension_states) { |
| 3235 | for (v8::RegisteredExtension* it = v8::RegisteredExtension::first_extension(); |
| 3236 | it != NULL; |
| 3237 | it = it->next()) { |
| 3238 | if (it->extension()->auto_enable() && |
| 3239 | !InstallExtension(isolate, it, extension_states)) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3240 | return false; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3241 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3242 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3243 | return true; |
| 3244 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3245 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3246 | |
| 3247 | bool Genesis::InstallRequestedExtensions(Isolate* isolate, |
| 3248 | v8::ExtensionConfiguration* extensions, |
| 3249 | ExtensionStates* extension_states) { |
| 3250 | for (const char** it = extensions->begin(); it != extensions->end(); ++it) { |
| 3251 | if (!InstallExtension(isolate, *it, extension_states)) return false; |
| 3252 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3253 | return true; |
| 3254 | } |
| 3255 | |
| 3256 | |
| 3257 | // Installs a named extension. This methods is unoptimized and does |
| 3258 | // not scale well if we want to support a large number of extensions. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3259 | bool Genesis::InstallExtension(Isolate* isolate, |
| 3260 | const char* name, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3261 | ExtensionStates* extension_states) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3262 | for (v8::RegisteredExtension* it = v8::RegisteredExtension::first_extension(); |
| 3263 | it != NULL; |
| 3264 | it = it->next()) { |
| 3265 | if (strcmp(name, it->extension()->name()) == 0) { |
| 3266 | return InstallExtension(isolate, it, extension_states); |
| 3267 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3268 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3269 | return Utils::ApiCheck(false, |
| 3270 | "v8::Context::New()", |
| 3271 | "Cannot find required extension"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3272 | } |
| 3273 | |
| 3274 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3275 | bool Genesis::InstallExtension(Isolate* isolate, |
| 3276 | v8::RegisteredExtension* current, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3277 | ExtensionStates* extension_states) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3278 | HandleScope scope(isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3279 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3280 | if (extension_states->get_state(current) == INSTALLED) return true; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3281 | // The current node has already been visited so there must be a |
| 3282 | // cycle in the dependency graph; fail. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3283 | if (!Utils::ApiCheck(extension_states->get_state(current) != VISITED, |
| 3284 | "v8::Context::New()", |
| 3285 | "Circular extension dependency")) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3286 | return false; |
| 3287 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3288 | DCHECK(extension_states->get_state(current) == UNVISITED); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3289 | extension_states->set_state(current, VISITED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3290 | v8::Extension* extension = current->extension(); |
| 3291 | // Install the extension's dependencies |
| 3292 | for (int i = 0; i < extension->dependency_count(); i++) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3293 | if (!InstallExtension(isolate, |
| 3294 | extension->dependencies()[i], |
| 3295 | extension_states)) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3296 | return false; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3297 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3298 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3299 | // We do not expect this to throw an exception. Change this if it does. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3300 | bool result = CompileExtension(isolate, extension); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3301 | DCHECK(isolate->has_pending_exception() != result); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3302 | if (!result) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3303 | // We print out the name of the extension that fail to install. |
| 3304 | // When an error is thrown during bootstrapping we automatically print |
| 3305 | // the line number at which this happened to the console in the isolate |
| 3306 | // error throwing functionality. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3307 | base::OS::PrintError("Error installing extension '%s'.\n", |
| 3308 | current->extension()->name()); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3309 | isolate->clear_pending_exception(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3310 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3311 | extension_states->set_state(current, INSTALLED); |
| 3312 | isolate->NotifyExtensionInstalled(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3313 | return result; |
| 3314 | } |
| 3315 | |
| 3316 | |
| 3317 | bool Genesis::ConfigureGlobalObjects( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3318 | v8::Local<v8::ObjectTemplate> global_proxy_template) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3319 | Handle<JSObject> global_proxy( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3320 | JSObject::cast(native_context()->global_proxy())); |
| 3321 | Handle<JSObject> global_object( |
| 3322 | JSObject::cast(native_context()->global_object())); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3323 | |
| 3324 | if (!global_proxy_template.IsEmpty()) { |
| 3325 | // Configure the global proxy object. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3326 | Handle<ObjectTemplateInfo> global_proxy_data = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3327 | v8::Utils::OpenHandle(*global_proxy_template); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3328 | if (!ConfigureApiObject(global_proxy, global_proxy_data)) return false; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3329 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3330 | // Configure the global object. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3331 | Handle<FunctionTemplateInfo> proxy_constructor( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3332 | FunctionTemplateInfo::cast(global_proxy_data->constructor())); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3333 | if (!proxy_constructor->prototype_template()->IsUndefined()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3334 | Handle<ObjectTemplateInfo> global_object_data( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3335 | ObjectTemplateInfo::cast(proxy_constructor->prototype_template())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3336 | if (!ConfigureApiObject(global_object, global_object_data)) return false; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3337 | } |
| 3338 | } |
| 3339 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3340 | SetObjectPrototype(global_proxy, global_object); |
| 3341 | |
| 3342 | native_context()->set_initial_array_prototype( |
| 3343 | JSArray::cast(native_context()->array_function()->prototype())); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3344 | native_context()->set_array_buffer_map( |
| 3345 | native_context()->array_buffer_fun()->initial_map()); |
| 3346 | native_context()->set_js_map_map( |
| 3347 | native_context()->js_map_fun()->initial_map()); |
| 3348 | native_context()->set_js_set_map( |
| 3349 | native_context()->js_set_fun()->initial_map()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3350 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3351 | return true; |
| 3352 | } |
| 3353 | |
| 3354 | |
| 3355 | bool Genesis::ConfigureApiObject(Handle<JSObject> object, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3356 | Handle<ObjectTemplateInfo> object_template) { |
| 3357 | DCHECK(!object_template.is_null()); |
| 3358 | DCHECK(FunctionTemplateInfo::cast(object_template->constructor()) |
| 3359 | ->IsTemplateFor(object->map()));; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3360 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3361 | MaybeHandle<JSObject> maybe_obj = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3362 | ApiNatives::InstantiateObject(object_template); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3363 | Handle<JSObject> obj; |
| 3364 | if (!maybe_obj.ToHandle(&obj)) { |
| 3365 | DCHECK(isolate()->has_pending_exception()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3366 | isolate()->clear_pending_exception(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3367 | return false; |
| 3368 | } |
| 3369 | TransferObject(obj, object); |
| 3370 | return true; |
| 3371 | } |
| 3372 | |
| 3373 | |
| 3374 | void Genesis::TransferNamedProperties(Handle<JSObject> from, |
| 3375 | Handle<JSObject> to) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3376 | // If JSObject::AddProperty asserts due to already existing property, |
| 3377 | // it is likely due to both global objects sharing property name(s). |
| 3378 | // Merging those two global objects is impossible. |
| 3379 | // The global template must not create properties that already exist |
| 3380 | // in the snapshotted global object. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3381 | if (from->HasFastProperties()) { |
| 3382 | Handle<DescriptorArray> descs = |
| 3383 | Handle<DescriptorArray>(from->map()->instance_descriptors()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3384 | for (int i = 0; i < from->map()->NumberOfOwnDescriptors(); i++) { |
| 3385 | PropertyDetails details = descs->GetDetails(i); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3386 | switch (details.type()) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3387 | case DATA: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3388 | HandleScope inner(isolate()); |
| 3389 | Handle<Name> key = Handle<Name>(descs->GetKey(i)); |
| 3390 | FieldIndex index = FieldIndex::ForDescriptor(from->map(), i); |
| 3391 | DCHECK(!descs->GetDetails(i).representation().IsDouble()); |
| 3392 | Handle<Object> value = Handle<Object>(from->RawFastPropertyAt(index), |
| 3393 | isolate()); |
| 3394 | JSObject::AddProperty(to, key, value, details.attributes()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3395 | break; |
| 3396 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3397 | case DATA_CONSTANT: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3398 | HandleScope inner(isolate()); |
| 3399 | Handle<Name> key = Handle<Name>(descs->GetKey(i)); |
| 3400 | Handle<Object> constant(descs->GetConstant(i), isolate()); |
| 3401 | JSObject::AddProperty(to, key, constant, details.attributes()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3402 | break; |
| 3403 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3404 | case ACCESSOR: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3405 | UNREACHABLE(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3406 | case ACCESSOR_CONSTANT: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3407 | Handle<Name> key(descs->GetKey(i)); |
| 3408 | LookupIterator it(to, key, LookupIterator::OWN_SKIP_INTERCEPTOR); |
| 3409 | CHECK_NE(LookupIterator::ACCESS_CHECK, it.state()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3410 | // If the property is already there we skip it |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3411 | if (it.IsFound()) continue; |
| 3412 | HandleScope inner(isolate()); |
| 3413 | DCHECK(!to->HasFastProperties()); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 3414 | // Add to dictionary. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3415 | Handle<Object> callbacks(descs->GetCallbacksObject(i), isolate()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3416 | PropertyDetails d(details.attributes(), ACCESSOR_CONSTANT, i + 1, |
| 3417 | PropertyCellType::kMutable); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3418 | JSObject::SetNormalizedProperty(to, key, callbacks, d); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3419 | break; |
| 3420 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3421 | } |
| 3422 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3423 | } else if (from->IsJSGlobalObject()) { |
| 3424 | Handle<GlobalDictionary> properties = |
| 3425 | Handle<GlobalDictionary>(from->global_dictionary()); |
| 3426 | int capacity = properties->Capacity(); |
| 3427 | for (int i = 0; i < capacity; i++) { |
| 3428 | Object* raw_key(properties->KeyAt(i)); |
| 3429 | if (properties->IsKey(raw_key)) { |
| 3430 | DCHECK(raw_key->IsName()); |
| 3431 | // If the property is already there we skip it. |
| 3432 | Handle<Name> key(Name::cast(raw_key)); |
| 3433 | LookupIterator it(to, key, LookupIterator::OWN_SKIP_INTERCEPTOR); |
| 3434 | CHECK_NE(LookupIterator::ACCESS_CHECK, it.state()); |
| 3435 | if (it.IsFound()) continue; |
| 3436 | // Set the property. |
| 3437 | DCHECK(properties->ValueAt(i)->IsPropertyCell()); |
| 3438 | Handle<PropertyCell> cell(PropertyCell::cast(properties->ValueAt(i))); |
| 3439 | Handle<Object> value(cell->value(), isolate()); |
| 3440 | if (value->IsTheHole()) continue; |
| 3441 | PropertyDetails details = cell->property_details(); |
| 3442 | DCHECK_EQ(kData, details.kind()); |
| 3443 | JSObject::AddProperty(to, key, value, details.attributes()); |
| 3444 | } |
| 3445 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3446 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3447 | Handle<NameDictionary> properties = |
| 3448 | Handle<NameDictionary>(from->property_dictionary()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3449 | int capacity = properties->Capacity(); |
| 3450 | for (int i = 0; i < capacity; i++) { |
| 3451 | Object* raw_key(properties->KeyAt(i)); |
| 3452 | if (properties->IsKey(raw_key)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3453 | DCHECK(raw_key->IsName()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3454 | // If the property is already there we skip it. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3455 | Handle<Name> key(Name::cast(raw_key)); |
| 3456 | LookupIterator it(to, key, LookupIterator::OWN_SKIP_INTERCEPTOR); |
| 3457 | CHECK_NE(LookupIterator::ACCESS_CHECK, it.state()); |
| 3458 | if (it.IsFound()) continue; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3459 | // Set the property. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3460 | Handle<Object> value = Handle<Object>(properties->ValueAt(i), |
| 3461 | isolate()); |
| 3462 | DCHECK(!value->IsCell()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3463 | DCHECK(!value->IsTheHole()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3464 | PropertyDetails details = properties->DetailsAt(i); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3465 | DCHECK_EQ(kData, details.kind()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3466 | JSObject::AddProperty(to, key, value, details.attributes()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3467 | } |
| 3468 | } |
| 3469 | } |
| 3470 | } |
| 3471 | |
| 3472 | |
| 3473 | void Genesis::TransferIndexedProperties(Handle<JSObject> from, |
| 3474 | Handle<JSObject> to) { |
| 3475 | // Cloning the elements array is sufficient. |
| 3476 | Handle<FixedArray> from_elements = |
| 3477 | Handle<FixedArray>(FixedArray::cast(from->elements())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3478 | Handle<FixedArray> to_elements = factory()->CopyFixedArray(from_elements); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3479 | to->set_elements(*to_elements); |
| 3480 | } |
| 3481 | |
| 3482 | |
| 3483 | void Genesis::TransferObject(Handle<JSObject> from, Handle<JSObject> to) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3484 | HandleScope outer(isolate()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3485 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3486 | DCHECK(!from->IsJSArray()); |
| 3487 | DCHECK(!to->IsJSArray()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3488 | |
| 3489 | TransferNamedProperties(from, to); |
| 3490 | TransferIndexedProperties(from, to); |
| 3491 | |
| 3492 | // Transfer the prototype (new map is needed). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3493 | Handle<Object> proto(from->map()->prototype(), isolate()); |
| 3494 | SetObjectPrototype(to, proto); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3495 | } |
| 3496 | |
| 3497 | |
| 3498 | void Genesis::MakeFunctionInstancePrototypeWritable() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3499 | // The maps with writable prototype are created in CreateEmptyFunction |
| 3500 | // and CreateStrictModeFunctionMaps respectively. Initially the maps are |
| 3501 | // created with read-only prototype for JS builtins processing. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3502 | DCHECK(!sloppy_function_map_writable_prototype_.is_null()); |
| 3503 | DCHECK(!strict_function_map_writable_prototype_.is_null()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3504 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3505 | // Replace function instance maps to make prototype writable. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3506 | native_context()->set_sloppy_function_map( |
| 3507 | *sloppy_function_map_writable_prototype_); |
| 3508 | native_context()->set_strict_function_map( |
| 3509 | *strict_function_map_writable_prototype_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3510 | } |
| 3511 | |
| 3512 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3513 | class NoTrackDoubleFieldsForSerializerScope { |
| 3514 | public: |
| 3515 | explicit NoTrackDoubleFieldsForSerializerScope(Isolate* isolate) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3516 | : flag_(FLAG_track_double_fields), enabled_(false) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3517 | if (isolate->serializer_enabled()) { |
| 3518 | // Disable tracking double fields because heap numbers treated as |
| 3519 | // immutable by the serializer. |
| 3520 | FLAG_track_double_fields = false; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3521 | enabled_ = true; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3522 | } |
| 3523 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3524 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3525 | ~NoTrackDoubleFieldsForSerializerScope() { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3526 | if (enabled_) { |
| 3527 | FLAG_track_double_fields = flag_; |
| 3528 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3529 | } |
| 3530 | |
| 3531 | private: |
| 3532 | bool flag_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3533 | bool enabled_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3534 | }; |
| 3535 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3536 | Genesis::Genesis(Isolate* isolate, |
| 3537 | MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3538 | v8::Local<v8::ObjectTemplate> global_proxy_template, |
| 3539 | v8::ExtensionConfiguration* extensions, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 3540 | GlobalContextType context_type) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3541 | : isolate_(isolate), active_(isolate->bootstrapper()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3542 | NoTrackDoubleFieldsForSerializerScope disable_scope(isolate); |
| 3543 | result_ = Handle<Context>::null(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3544 | // Before creating the roots we must save the context and restore it |
| 3545 | // on all function exits. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3546 | SaveContext saved_context(isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3547 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3548 | // During genesis, the boilerplate for stack overflow won't work until the |
| 3549 | // environment has been at least partially initialized. Add a stack check |
| 3550 | // before entering JS code to catch overflow early. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3551 | StackLimitCheck check(isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3552 | if (check.HasOverflowed()) { |
| 3553 | isolate->StackOverflow(); |
| 3554 | return; |
| 3555 | } |
| 3556 | |
| 3557 | // The deserializer needs to hook up references to the global proxy. |
| 3558 | // Create an uninitialized global proxy now if we don't have one |
| 3559 | // and initialize it later in CreateNewGlobals. |
| 3560 | Handle<JSGlobalProxy> global_proxy; |
| 3561 | if (!maybe_global_proxy.ToHandle(&global_proxy)) { |
| 3562 | global_proxy = isolate->factory()->NewUninitializedJSGlobalProxy(); |
| 3563 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3564 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3565 | // We can only de-serialize a context if the isolate was initialized from |
| 3566 | // a snapshot. Otherwise we have to build the context from scratch. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3567 | // Also create a context from scratch to expose natives, if required by flag. |
| 3568 | if (!isolate->initialized_from_snapshot() || |
| 3569 | !Snapshot::NewContextFromSnapshot(isolate, global_proxy) |
| 3570 | .ToHandle(&native_context_)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3571 | native_context_ = Handle<Context>(); |
| 3572 | } |
| 3573 | |
| 3574 | if (!native_context().is_null()) { |
| 3575 | AddToWeakNativeContextList(*native_context()); |
| 3576 | isolate->set_context(*native_context()); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3577 | isolate->counters()->contexts_created_by_snapshot()->Increment(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3578 | #if TRACE_MAPS |
| 3579 | if (FLAG_trace_maps) { |
| 3580 | Handle<JSFunction> object_fun = isolate->object_function(); |
| 3581 | PrintF("[TraceMap: InitialMap map= %p SFI= %d_Object ]\n", |
| 3582 | reinterpret_cast<void*>(object_fun->initial_map()), |
| 3583 | object_fun->shared()->unique_id()); |
| 3584 | Map::TraceAllTransitions(object_fun->initial_map()); |
| 3585 | } |
| 3586 | #endif |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3587 | Handle<JSGlobalObject> global_object = |
| 3588 | CreateNewGlobals(global_proxy_template, global_proxy); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 3589 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3590 | HookUpGlobalProxy(global_object, global_proxy); |
| 3591 | HookUpGlobalObject(global_object); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 3592 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3593 | if (!ConfigureGlobalObjects(global_proxy_template)) return; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 3594 | } else { |
| 3595 | // We get here if there was no context snapshot. |
| 3596 | CreateRoots(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3597 | Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3598 | CreateStrictModeFunctionMaps(empty_function); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3599 | CreateStrongModeFunctionMaps(empty_function); |
| 3600 | CreateIteratorMaps(); |
| 3601 | Handle<JSGlobalObject> global_object = |
| 3602 | CreateNewGlobals(global_proxy_template, global_proxy); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3603 | HookUpGlobalProxy(global_object, global_proxy); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3604 | InitializeGlobal(global_object, empty_function, context_type); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3605 | InitializeNormalizedMapCaches(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3606 | |
| 3607 | if (!InstallNatives(context_type)) return; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3608 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 3609 | MakeFunctionInstancePrototypeWritable(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3610 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3611 | if (context_type != THIN_CONTEXT) { |
| 3612 | if (!InstallExtraNatives()) return; |
| 3613 | if (!ConfigureGlobalObjects(global_proxy_template)) return; |
| 3614 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3615 | isolate->counters()->contexts_created_from_scratch()->Increment(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3616 | // Re-initialize the counter because it got incremented during snapshot |
| 3617 | // creation. |
| 3618 | isolate->native_context()->set_errors_thrown(Smi::FromInt(0)); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 3619 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3620 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3621 | // Install experimental natives. Do not include them into the |
| 3622 | // snapshot as we should be able to turn them off at runtime. Re-installing |
| 3623 | // them after they have already been deserialized would also fail. |
| 3624 | if (context_type == FULL_CONTEXT) { |
| 3625 | if (!isolate->serializer_enabled()) { |
| 3626 | InitializeExperimentalGlobal(); |
| 3627 | if (!InstallExperimentalNatives()) return; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3628 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3629 | if (FLAG_experimental_extras) { |
| 3630 | if (!InstallExperimentalExtraNatives()) return; |
| 3631 | } |
| 3632 | } |
| 3633 | // The serializer cannot serialize typed arrays. Reset those typed arrays |
| 3634 | // for each new context. |
| 3635 | } else if (context_type == DEBUG_CONTEXT) { |
| 3636 | DCHECK(!isolate->serializer_enabled()); |
| 3637 | InitializeExperimentalGlobal(); |
| 3638 | if (!InstallDebuggerNatives()) return; |
| 3639 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3640 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3641 | ConfigureUtilsObject(context_type); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3642 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3643 | // Check that the script context table is empty except for the 'this' binding. |
| 3644 | // We do not need script contexts for native scripts. |
| 3645 | if (!FLAG_global_var_shortcuts) { |
| 3646 | DCHECK_EQ(1, native_context()->script_context_table()->used()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3647 | } |
| 3648 | |
| 3649 | result_ = native_context(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3650 | } |
| 3651 | |
| 3652 | |
| 3653 | // Support for thread preemption. |
| 3654 | |
| 3655 | // Reserve space for statics needing saving and restoring. |
| 3656 | int Bootstrapper::ArchiveSpacePerThread() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3657 | return sizeof(NestingCounterType); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3658 | } |
| 3659 | |
| 3660 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3661 | // Archive statics that are thread-local. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3662 | char* Bootstrapper::ArchiveState(char* to) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3663 | *reinterpret_cast<NestingCounterType*>(to) = nesting_; |
| 3664 | nesting_ = 0; |
| 3665 | return to + sizeof(NestingCounterType); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3666 | } |
| 3667 | |
| 3668 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3669 | // Restore statics that are thread-local. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3670 | char* Bootstrapper::RestoreState(char* from) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3671 | nesting_ = *reinterpret_cast<NestingCounterType*>(from); |
| 3672 | return from + sizeof(NestingCounterType); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3673 | } |
| 3674 | |
| 3675 | |
| 3676 | // Called when the top-level V8 mutex is destroyed. |
| 3677 | void Bootstrapper::FreeThreadResources() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3678 | DCHECK(!IsActive()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3679 | } |
| 3680 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3681 | } // namespace internal |
| 3682 | } // namespace v8 |