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