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