danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
| 30 | #include "accessors.h" |
| 31 | #include "api.h" |
| 32 | #include "bootstrapper.h" |
| 33 | #include "compiler.h" |
| 34 | #include "debug.h" |
| 35 | #include "execution.h" |
| 36 | #include "global-handles.h" |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 37 | #include "isolate-inl.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 38 | #include "macro-assembler.h" |
| 39 | #include "natives.h" |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 40 | #include "objects-visiting.h" |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 41 | #include "platform.h" |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 42 | #include "snapshot.h" |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 43 | #include "extensions/externalize-string-extension.h" |
| 44 | #include "extensions/gc-extension.h" |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 45 | #include "extensions/statistics-extension.h" |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 46 | #include "code-stubs.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 47 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 48 | namespace v8 { |
| 49 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 50 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 51 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 52 | NativesExternalStringResource::NativesExternalStringResource( |
| 53 | Bootstrapper* bootstrapper, |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 54 | const char* source, |
| 55 | size_t length) |
| 56 | : data_(source), length_(length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 57 | if (bootstrapper->delete_these_non_arrays_on_tear_down_ == NULL) { |
| 58 | bootstrapper->delete_these_non_arrays_on_tear_down_ = new List<char*>(2); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 59 | } |
| 60 | // The resources are small objects and we only make a fixed number of |
| 61 | // them, but let's clean them up on exit for neatness. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 62 | bootstrapper->delete_these_non_arrays_on_tear_down_-> |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 63 | Add(reinterpret_cast<char*>(this)); |
| 64 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 65 | |
| 66 | |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 67 | Bootstrapper::Bootstrapper(Isolate* isolate) |
| 68 | : isolate_(isolate), |
| 69 | nesting_(0), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 70 | extensions_cache_(Script::TYPE_EXTENSION), |
| 71 | delete_these_non_arrays_on_tear_down_(NULL), |
| 72 | delete_these_arrays_on_tear_down_(NULL) { |
| 73 | } |
| 74 | |
| 75 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 76 | Handle<String> Bootstrapper::NativesSourceLookup(int index) { |
| 77 | ASSERT(0 <= index && index < Natives::GetBuiltinsCount()); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 78 | Heap* heap = isolate_->heap(); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 79 | if (heap->natives_source_cache()->get(index)->IsUndefined()) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 80 | // We can use external strings for the natives. |
| 81 | Vector<const char> source = Natives::GetRawScriptSource(index); |
| 82 | NativesExternalStringResource* resource = |
| 83 | new NativesExternalStringResource(this, |
| 84 | source.start(), |
| 85 | source.length()); |
| 86 | Handle<String> source_code = |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 87 | isolate_->factory()->NewExternalStringFromAscii(resource); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 88 | heap->natives_source_cache()->set(index, *source_code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 89 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 90 | Handle<Object> cached_source(heap->natives_source_cache()->get(index), |
| 91 | isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 92 | return Handle<String>::cast(cached_source); |
| 93 | } |
| 94 | |
| 95 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 96 | void Bootstrapper::Initialize(bool create_heap_objects) { |
dslomov@chromium.org | e97852d | 2013-09-12 09:02:59 +0000 | [diff] [blame] | 97 | extensions_cache_.Initialize(isolate_, create_heap_objects); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | |
| 101 | void Bootstrapper::InitializeOncePerProcess() { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 102 | GCExtension::Register(); |
| 103 | ExternalizeStringExtension::Register(); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 104 | StatisticsExtension::Register(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 108 | char* Bootstrapper::AllocateAutoDeletedArray(int bytes) { |
| 109 | char* memory = new char[bytes]; |
| 110 | if (memory != NULL) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 111 | if (delete_these_arrays_on_tear_down_ == NULL) { |
| 112 | delete_these_arrays_on_tear_down_ = new List<char*>(2); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 113 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 114 | delete_these_arrays_on_tear_down_->Add(memory); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 115 | } |
| 116 | return memory; |
| 117 | } |
| 118 | |
| 119 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 120 | void Bootstrapper::TearDown() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 121 | if (delete_these_non_arrays_on_tear_down_ != NULL) { |
| 122 | int len = delete_these_non_arrays_on_tear_down_->length(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 123 | ASSERT(len < 20); // Don't use this mechanism for unbounded allocations. |
| 124 | for (int i = 0; i < len; i++) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 125 | delete delete_these_non_arrays_on_tear_down_->at(i); |
| 126 | delete_these_non_arrays_on_tear_down_->at(i) = NULL; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 127 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 128 | delete delete_these_non_arrays_on_tear_down_; |
| 129 | delete_these_non_arrays_on_tear_down_ = NULL; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 130 | } |
| 131 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 132 | if (delete_these_arrays_on_tear_down_ != NULL) { |
| 133 | int len = delete_these_arrays_on_tear_down_->length(); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 134 | ASSERT(len < 1000); // Don't use this mechanism for unbounded allocations. |
| 135 | for (int i = 0; i < len; i++) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 136 | delete[] delete_these_arrays_on_tear_down_->at(i); |
| 137 | delete_these_arrays_on_tear_down_->at(i) = NULL; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 138 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 139 | delete delete_these_arrays_on_tear_down_; |
| 140 | delete_these_arrays_on_tear_down_ = NULL; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 141 | } |
| 142 | |
dslomov@chromium.org | e97852d | 2013-09-12 09:02:59 +0000 | [diff] [blame] | 143 | extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 147 | class Genesis BASE_EMBEDDED { |
| 148 | public: |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 149 | Genesis(Isolate* isolate, |
| 150 | Handle<Object> global_object, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 151 | v8::Handle<v8::ObjectTemplate> global_template, |
| 152 | v8::ExtensionConfiguration* extensions); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 153 | ~Genesis() { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 154 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 155 | Isolate* isolate() const { return isolate_; } |
| 156 | Factory* factory() const { return isolate_->factory(); } |
| 157 | Heap* heap() const { return isolate_->heap(); } |
| 158 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 159 | Handle<Context> result() { return result_; } |
jkummerow@chromium.org | 8718d73 | 2013-03-19 22:53:30 +0000 | [diff] [blame] | 160 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 161 | private: |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 162 | Handle<Context> native_context() { return native_context_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 163 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 164 | // Creates some basic objects. Used for creating a context from scratch. |
| 165 | void CreateRoots(); |
| 166 | // Creates the empty function. Used for creating a context from scratch. |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 167 | Handle<JSFunction> CreateEmptyFunction(Isolate* isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 168 | // Creates the ThrowTypeError function. ECMA 5th Ed. 13.2.3 |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 169 | Handle<JSFunction> GetThrowTypeErrorFunction(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 170 | |
| 171 | void CreateStrictModeFunctionMaps(Handle<JSFunction> empty); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 172 | |
| 173 | // Make the "arguments" and "caller" properties throw a TypeError on access. |
| 174 | void PoisonArgumentsAndCaller(Handle<Map> map); |
| 175 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 176 | // Creates the global objects using the global and the template passed in |
| 177 | // through the API. We call this regardless of whether we are building a |
| 178 | // context from scratch or using a deserialized one from the partial snapshot |
| 179 | // but in the latter case we don't use the objects it produces directly, as |
| 180 | // we have to used the deserialized ones that are linked together with the |
| 181 | // rest of the context snapshot. |
| 182 | Handle<JSGlobalProxy> CreateNewGlobals( |
| 183 | v8::Handle<v8::ObjectTemplate> global_template, |
| 184 | Handle<Object> global_object, |
| 185 | Handle<GlobalObject>* global_proxy_out); |
| 186 | // Hooks the given global proxy into the context. If the context was created |
| 187 | // by deserialization then this will unhook the global proxy that was |
| 188 | // deserialized, leaving the GC to pick it up. |
| 189 | void HookUpGlobalProxy(Handle<GlobalObject> inner_global, |
| 190 | Handle<JSGlobalProxy> global_proxy); |
| 191 | // Similarly, we want to use the inner global that has been created by the |
| 192 | // templates passed through the API. The inner global from the snapshot is |
| 193 | // detached from the other objects in the snapshot. |
| 194 | void HookUpInnerGlobal(Handle<GlobalObject> inner_global); |
| 195 | // New context initialization. Used for creating a context from scratch. |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 196 | void InitializeGlobal(Handle<GlobalObject> inner_global, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 197 | Handle<JSFunction> empty_function); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 198 | void InitializeExperimentalGlobal(); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 199 | // Installs the contents of the native .js files on the global objects. |
| 200 | // Used for creating a context from scratch. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 201 | void InstallNativeFunctions(); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 202 | void InstallExperimentalNativeFunctions(); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 203 | Handle<JSFunction> InstallInternalArray(Handle<JSBuiltinsObject> builtins, |
| 204 | const char* name, |
| 205 | ElementsKind elements_kind); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 206 | bool InstallNatives(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 207 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 208 | Handle<JSFunction> InstallTypedArray(const char* name, |
| 209 | ElementsKind elementsKind); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 210 | bool InstallExperimentalNatives(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 211 | void InstallBuiltinFunctionIds(); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 212 | void InstallJSFunctionResultCaches(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 213 | void InitializeNormalizedMapCaches(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 214 | |
| 215 | enum ExtensionTraversalState { |
| 216 | UNVISITED, VISITED, INSTALLED |
| 217 | }; |
| 218 | |
| 219 | class ExtensionStates { |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 220 | public: |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 221 | ExtensionStates(); |
| 222 | ExtensionTraversalState get_state(RegisteredExtension* extension); |
| 223 | void set_state(RegisteredExtension* extension, |
| 224 | ExtensionTraversalState state); |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 225 | private: |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 226 | HashMap map_; |
| 227 | DISALLOW_COPY_AND_ASSIGN(ExtensionStates); |
| 228 | }; |
| 229 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 230 | // Used both for deserialized and from-scratch contexts to add the extensions |
| 231 | // provided. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 232 | static bool InstallExtensions(Handle<Context> native_context, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 233 | v8::ExtensionConfiguration* extensions); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 234 | static bool InstallExtension(Isolate* isolate, |
| 235 | const char* name, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 236 | ExtensionStates* extension_states); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 237 | static bool InstallExtension(Isolate* isolate, |
| 238 | v8::RegisteredExtension* current, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 239 | ExtensionStates* extension_states); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 240 | static void InstallSpecialObjects(Handle<Context> native_context); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 241 | bool InstallJSBuiltins(Handle<JSBuiltinsObject> builtins); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 242 | bool ConfigureApiObject(Handle<JSObject> object, |
| 243 | Handle<ObjectTemplateInfo> object_template); |
| 244 | bool ConfigureGlobalObjects(v8::Handle<v8::ObjectTemplate> global_template); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 245 | |
| 246 | // Migrates all properties from the 'from' object to the 'to' |
| 247 | // object and overrides the prototype in 'to' with the one from |
| 248 | // 'from'. |
| 249 | void TransferObject(Handle<JSObject> from, Handle<JSObject> to); |
| 250 | void TransferNamedProperties(Handle<JSObject> from, Handle<JSObject> to); |
| 251 | void TransferIndexedProperties(Handle<JSObject> from, Handle<JSObject> to); |
| 252 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 253 | enum PrototypePropertyMode { |
| 254 | DONT_ADD_PROTOTYPE, |
| 255 | ADD_READONLY_PROTOTYPE, |
| 256 | ADD_WRITEABLE_PROTOTYPE |
| 257 | }; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 258 | |
| 259 | Handle<Map> CreateFunctionMap(PrototypePropertyMode prototype_mode); |
| 260 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 261 | void SetFunctionInstanceDescriptor(Handle<Map> map, |
| 262 | PrototypePropertyMode prototypeMode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 263 | void MakeFunctionInstancePrototypeWritable(); |
| 264 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 265 | Handle<Map> CreateStrictModeFunctionMap( |
| 266 | PrototypePropertyMode prototype_mode, |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 267 | Handle<JSFunction> empty_function); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 268 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 269 | void SetStrictFunctionInstanceDescriptor(Handle<Map> map, |
| 270 | PrototypePropertyMode propertyMode); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 271 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 272 | static bool CompileBuiltin(Isolate* isolate, int index); |
| 273 | static bool CompileExperimentalBuiltin(Isolate* isolate, int index); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 274 | static bool CompileNative(Isolate* isolate, |
| 275 | Vector<const char> name, |
| 276 | Handle<String> source); |
| 277 | static bool CompileScriptCached(Isolate* isolate, |
| 278 | Vector<const char> name, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 279 | Handle<String> source, |
| 280 | SourceCodeCache* cache, |
| 281 | v8::Extension* extension, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 282 | Handle<Context> top_context, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 283 | bool use_runtime_context); |
| 284 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 285 | Isolate* isolate_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 286 | Handle<Context> result_; |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 287 | Handle<Context> native_context_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 288 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 289 | // Function maps. Function maps are created initially with a read only |
| 290 | // prototype for the processing of JS builtins. Later the function maps are |
| 291 | // replaced in order to make prototype writable. These are the final, writable |
| 292 | // prototype, maps. |
| 293 | Handle<Map> function_map_writable_prototype_; |
| 294 | Handle<Map> strict_mode_function_map_writable_prototype_; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 295 | Handle<JSFunction> throw_type_error_function; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 296 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 297 | BootstrapperActive active_; |
| 298 | friend class Bootstrapper; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 299 | }; |
| 300 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 301 | |
| 302 | void Bootstrapper::Iterate(ObjectVisitor* v) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 303 | extensions_cache_.Iterate(v); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 304 | v->Synchronize(VisitorSynchronization::kExtensions); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 308 | Handle<Context> Bootstrapper::CreateEnvironment( |
| 309 | Handle<Object> global_object, |
| 310 | v8::Handle<v8::ObjectTemplate> global_template, |
| 311 | v8::ExtensionConfiguration* extensions) { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 312 | HandleScope scope(isolate_); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 313 | Genesis genesis(isolate_, global_object, global_template, extensions); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 314 | Handle<Context> env = genesis.result(); |
| 315 | if (env.is_null() || !InstallExtensions(env, extensions)) { |
| 316 | return Handle<Context>(); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 317 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 318 | return scope.CloseAndEscape(env); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 322 | static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) { |
| 323 | // object.__proto__ = proto; |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 324 | Factory* factory = object->GetIsolate()->factory(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 325 | Handle<Map> old_to_map = Handle<Map>(object->map()); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 326 | Handle<Map> new_to_map = factory->CopyMap(old_to_map); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 327 | new_to_map->set_prototype(*proto); |
| 328 | object->set_map(*new_to_map); |
| 329 | } |
| 330 | |
| 331 | |
| 332 | void Bootstrapper::DetachGlobal(Handle<Context> env) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 333 | Factory* factory = env->GetIsolate()->factory(); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 334 | Handle<JSGlobalProxy> global_proxy(JSGlobalProxy::cast(env->global_proxy())); |
| 335 | global_proxy->set_native_context(*factory->null_value()); |
| 336 | SetObjectPrototype(global_proxy, factory->null_value()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 337 | env->set_global_proxy(env->global_object()); |
| 338 | env->global_object()->set_global_receiver(env->global_object()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 342 | void Bootstrapper::ReattachGlobal(Handle<Context> env, |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 343 | Handle<JSGlobalProxy> global_proxy) { |
| 344 | env->global_object()->set_global_receiver(*global_proxy); |
| 345 | env->set_global_proxy(*global_proxy); |
| 346 | SetObjectPrototype(global_proxy, Handle<JSObject>(env->global_object())); |
| 347 | global_proxy->set_native_context(*env); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 351 | static Handle<JSFunction> InstallFunction(Handle<JSObject> target, |
| 352 | const char* name, |
| 353 | InstanceType type, |
| 354 | int instance_size, |
| 355 | Handle<JSObject> prototype, |
| 356 | Builtins::Name call, |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 357 | bool install_initial_map, |
| 358 | bool set_instance_class_name) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 359 | Isolate* isolate = target->GetIsolate(); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 360 | Factory* factory = isolate->factory(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 361 | Handle<String> internalized_name = factory->InternalizeUtf8String(name); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 362 | Handle<Code> call_code = Handle<Code>(isolate->builtins()->builtin(call)); |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 363 | Handle<JSFunction> function = prototype.is_null() ? |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 364 | factory->NewFunctionWithoutPrototype(internalized_name, call_code) : |
| 365 | factory->NewFunctionWithPrototype(internalized_name, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 366 | type, |
| 367 | instance_size, |
| 368 | prototype, |
| 369 | call_code, |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 370 | install_initial_map); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 371 | PropertyAttributes attributes; |
| 372 | if (target->IsJSBuiltinsObject()) { |
| 373 | attributes = |
| 374 | static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 375 | } else { |
| 376 | attributes = DONT_ENUM; |
| 377 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 378 | CHECK_NOT_EMPTY_HANDLE(isolate, |
| 379 | JSObject::SetLocalPropertyIgnoreAttributes( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 380 | target, internalized_name, function, attributes)); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 381 | if (set_instance_class_name) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 382 | function->shared()->set_instance_class_name(*internalized_name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 383 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 384 | function->shared()->set_native(true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 385 | return function; |
| 386 | } |
| 387 | |
| 388 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 389 | void Genesis::SetFunctionInstanceDescriptor( |
| 390 | Handle<Map> map, PrototypePropertyMode prototypeMode) { |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 391 | int size = (prototypeMode == DONT_ADD_PROTOTYPE) ? 4 : 5; |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 392 | Handle<DescriptorArray> descriptors(factory()->NewDescriptorArray(0, size)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 393 | DescriptorArray::WhitenessWitness witness(*descriptors); |
| 394 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 395 | Handle<Foreign> length(factory()->NewForeign(&Accessors::FunctionLength)); |
| 396 | Handle<Foreign> name(factory()->NewForeign(&Accessors::FunctionName)); |
| 397 | Handle<Foreign> args(factory()->NewForeign(&Accessors::FunctionArguments)); |
| 398 | Handle<Foreign> caller(factory()->NewForeign(&Accessors::FunctionCaller)); |
| 399 | Handle<Foreign> prototype; |
| 400 | if (prototypeMode != DONT_ADD_PROTOTYPE) { |
| 401 | prototype = factory()->NewForeign(&Accessors::FunctionPrototype); |
| 402 | } |
| 403 | PropertyAttributes attribs = static_cast<PropertyAttributes>( |
| 404 | DONT_ENUM | DONT_DELETE | READ_ONLY); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 405 | map->set_instance_descriptors(*descriptors); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 406 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 407 | { // Add length. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 408 | CallbacksDescriptor d(*factory()->length_string(), *length, attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 409 | map->AppendDescriptor(&d, witness); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 410 | } |
| 411 | { // Add name. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 412 | CallbacksDescriptor d(*factory()->name_string(), *name, attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 413 | map->AppendDescriptor(&d, witness); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 414 | } |
| 415 | { // Add arguments. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 416 | CallbacksDescriptor d(*factory()->arguments_string(), *args, attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 417 | map->AppendDescriptor(&d, witness); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 418 | } |
| 419 | { // Add caller. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 420 | CallbacksDescriptor d(*factory()->caller_string(), *caller, attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 421 | map->AppendDescriptor(&d, witness); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 422 | } |
| 423 | if (prototypeMode != DONT_ADD_PROTOTYPE) { |
| 424 | // Add prototype. |
| 425 | if (prototypeMode == ADD_WRITEABLE_PROTOTYPE) { |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 426 | attribs = static_cast<PropertyAttributes>(attribs & ~READ_ONLY); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 427 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 428 | CallbacksDescriptor d(*factory()->prototype_string(), *prototype, attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 429 | map->AppendDescriptor(&d, witness); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 430 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 431 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 432 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 433 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 434 | Handle<Map> Genesis::CreateFunctionMap(PrototypePropertyMode prototype_mode) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 435 | Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 436 | SetFunctionInstanceDescriptor(map, prototype_mode); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 437 | map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE); |
| 438 | return map; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 442 | Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 443 | // Allocate the map for function instances. Maps are allocated first and their |
| 444 | // prototypes patched later, once empty function is created. |
| 445 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 446 | // Functions with this map will not have a 'prototype' property, and |
| 447 | // can not be used as constructors. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 448 | Handle<Map> function_without_prototype_map = |
| 449 | CreateFunctionMap(DONT_ADD_PROTOTYPE); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 450 | native_context()->set_function_without_prototype_map( |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 451 | *function_without_prototype_map); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 452 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 453 | // Allocate the function map. This map is temporary, used only for processing |
| 454 | // of builtins. |
| 455 | // Later the map is replaced with writable prototype map, allocated below. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 456 | Handle<Map> function_map = CreateFunctionMap(ADD_READONLY_PROTOTYPE); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 457 | native_context()->set_function_map(*function_map); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 458 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 459 | // The final map for functions. Writeable prototype. |
| 460 | // This map is installed in MakeFunctionInstancePrototypeWritable. |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 461 | function_map_writable_prototype_ = CreateFunctionMap(ADD_WRITEABLE_PROTOTYPE); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 462 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 463 | Factory* factory = isolate->factory(); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 464 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 465 | Handle<String> object_name = factory->Object_string(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 466 | |
| 467 | { // --- O b j e c t --- |
| 468 | Handle<JSFunction> object_fun = |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 469 | factory->NewFunction(object_name, factory->null_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 470 | Handle<Map> object_function_map = |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 471 | factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 472 | object_fun->set_initial_map(*object_function_map); |
| 473 | object_function_map->set_constructor(*object_fun); |
| 474 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 475 | native_context()->set_object_function(*object_fun); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 476 | |
| 477 | // Allocate a new prototype for the object function. |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 478 | Handle<JSObject> prototype = factory->NewJSObject( |
| 479 | isolate->object_function(), |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 480 | TENURED); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 481 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 482 | native_context()->set_initial_object_prototype(*prototype); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 483 | // For bootstrapping set the array prototype to be the same as the object |
| 484 | // prototype, otherwise the missing initial_array_prototype will cause |
| 485 | // assertions during startup. |
| 486 | native_context()->set_initial_array_prototype(*prototype); |
rossberg@chromium.org | ebeba02 | 2013-08-19 09:36:44 +0000 | [diff] [blame] | 487 | Accessors::FunctionSetPrototype(object_fun, prototype); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | // Allocate the empty function as the prototype for function ECMAScript |
| 491 | // 262 15.3.4. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 492 | Handle<String> empty_string = |
| 493 | factory->InternalizeOneByteString(STATIC_ASCII_VECTOR("Empty")); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 494 | Handle<JSFunction> empty_function = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 495 | factory->NewFunctionWithoutPrototype(empty_string, CLASSIC_MODE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 496 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 497 | // --- E m p t y --- |
| 498 | Handle<Code> code = |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 499 | Handle<Code>(isolate->builtins()->builtin( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 500 | Builtins::kEmptyFunction)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 501 | empty_function->set_code(*code); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 502 | empty_function->shared()->set_code(*code); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 503 | Handle<String> source = |
| 504 | factory->NewStringFromOneByte(STATIC_ASCII_VECTOR("() {}")); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 505 | Handle<Script> script = factory->NewScript(source); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 506 | script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
| 507 | empty_function->shared()->set_script(*script); |
| 508 | empty_function->shared()->set_start_position(0); |
| 509 | empty_function->shared()->set_end_position(source->length()); |
| 510 | empty_function->shared()->DontAdaptArguments(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 511 | |
| 512 | // Set prototypes for the function maps. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 513 | native_context()->function_map()->set_prototype(*empty_function); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 514 | native_context()->function_without_prototype_map()-> |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 515 | set_prototype(*empty_function); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 516 | function_map_writable_prototype_->set_prototype(*empty_function); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 517 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 518 | // Allocate the function map first and then patch the prototype later |
yangguo@chromium.org | 5f0b8ea | 2012-05-16 12:37:04 +0000 | [diff] [blame] | 519 | Handle<Map> empty_function_map = CreateFunctionMap(DONT_ADD_PROTOTYPE); |
| 520 | empty_function_map->set_prototype( |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 521 | native_context()->object_function()->prototype()); |
yangguo@chromium.org | 5f0b8ea | 2012-05-16 12:37:04 +0000 | [diff] [blame] | 522 | empty_function->set_map(*empty_function_map); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 523 | return empty_function; |
| 524 | } |
| 525 | |
| 526 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 527 | void Genesis::SetStrictFunctionInstanceDescriptor( |
| 528 | Handle<Map> map, PrototypePropertyMode prototypeMode) { |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 529 | int size = (prototypeMode == DONT_ADD_PROTOTYPE) ? 4 : 5; |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 530 | Handle<DescriptorArray> descriptors(factory()->NewDescriptorArray(0, size)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 531 | DescriptorArray::WhitenessWitness witness(*descriptors); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 532 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 533 | Handle<Foreign> length(factory()->NewForeign(&Accessors::FunctionLength)); |
| 534 | Handle<Foreign> name(factory()->NewForeign(&Accessors::FunctionName)); |
| 535 | Handle<AccessorPair> arguments(factory()->NewAccessorPair()); |
| 536 | Handle<AccessorPair> caller(factory()->NewAccessorPair()); |
| 537 | Handle<Foreign> prototype; |
| 538 | if (prototypeMode != DONT_ADD_PROTOTYPE) { |
| 539 | prototype = factory()->NewForeign(&Accessors::FunctionPrototype); |
| 540 | } |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 541 | PropertyAttributes rw_attribs = |
| 542 | static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); |
| 543 | PropertyAttributes ro_attribs = |
| 544 | static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 545 | map->set_instance_descriptors(*descriptors); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 546 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 547 | { // Add length. |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 548 | CallbacksDescriptor d(*factory()->length_string(), *length, ro_attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 549 | map->AppendDescriptor(&d, witness); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 550 | } |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 551 | { // Add name. |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 552 | CallbacksDescriptor d(*factory()->name_string(), *name, rw_attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 553 | map->AppendDescriptor(&d, witness); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 554 | } |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 555 | { // Add arguments. |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 556 | CallbacksDescriptor d(*factory()->arguments_string(), *arguments, |
| 557 | rw_attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 558 | map->AppendDescriptor(&d, witness); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 559 | } |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 560 | { // Add caller. |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 561 | CallbacksDescriptor d(*factory()->caller_string(), *caller, rw_attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 562 | map->AppendDescriptor(&d, witness); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 563 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 564 | if (prototypeMode != DONT_ADD_PROTOTYPE) { |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 565 | // Add prototype. |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 566 | PropertyAttributes attribs = |
| 567 | prototypeMode == ADD_WRITEABLE_PROTOTYPE ? rw_attribs : ro_attribs; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 568 | CallbacksDescriptor d(*factory()->prototype_string(), *prototype, attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 569 | map->AppendDescriptor(&d, witness); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 570 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | |
| 574 | // ECMAScript 5th Edition, 13.2.3 |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 575 | Handle<JSFunction> Genesis::GetThrowTypeErrorFunction() { |
| 576 | if (throw_type_error_function.is_null()) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 577 | Handle<String> name = factory()->InternalizeOneByteString( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 578 | STATIC_ASCII_VECTOR("ThrowTypeError")); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 579 | throw_type_error_function = |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 580 | factory()->NewFunctionWithoutPrototype(name, CLASSIC_MODE); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 581 | Handle<Code> code(isolate()->builtins()->builtin( |
| 582 | Builtins::kStrictModePoisonPill)); |
| 583 | throw_type_error_function->set_map( |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 584 | native_context()->function_map()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 585 | throw_type_error_function->set_code(*code); |
| 586 | throw_type_error_function->shared()->set_code(*code); |
| 587 | throw_type_error_function->shared()->DontAdaptArguments(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 588 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 589 | JSObject::PreventExtensions(throw_type_error_function); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 590 | } |
| 591 | return throw_type_error_function; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | |
| 595 | Handle<Map> Genesis::CreateStrictModeFunctionMap( |
| 596 | PrototypePropertyMode prototype_mode, |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 597 | Handle<JSFunction> empty_function) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 598 | Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 599 | SetStrictFunctionInstanceDescriptor(map, prototype_mode); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 600 | map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE); |
| 601 | map->set_prototype(*empty_function); |
| 602 | return map; |
| 603 | } |
| 604 | |
| 605 | |
| 606 | void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 607 | // Allocate map for the prototype-less strict mode instances. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 608 | Handle<Map> strict_mode_function_without_prototype_map = |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 609 | CreateStrictModeFunctionMap(DONT_ADD_PROTOTYPE, empty); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 610 | native_context()->set_strict_mode_function_without_prototype_map( |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 611 | *strict_mode_function_without_prototype_map); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 612 | |
| 613 | // Allocate map for the strict mode functions. This map is temporary, used |
| 614 | // only for processing of builtins. |
| 615 | // Later the map is replaced with writable prototype map, allocated below. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 616 | Handle<Map> strict_mode_function_map = |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 617 | CreateStrictModeFunctionMap(ADD_READONLY_PROTOTYPE, empty); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 618 | native_context()->set_strict_mode_function_map( |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 619 | *strict_mode_function_map); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 620 | |
| 621 | // The final map for the strict mode functions. Writeable prototype. |
| 622 | // This map is installed in MakeFunctionInstancePrototypeWritable. |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 623 | strict_mode_function_map_writable_prototype_ = |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 624 | CreateStrictModeFunctionMap(ADD_WRITEABLE_PROTOTYPE, empty); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 625 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 626 | // Complete the callbacks. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 627 | PoisonArgumentsAndCaller(strict_mode_function_without_prototype_map); |
| 628 | PoisonArgumentsAndCaller(strict_mode_function_map); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 629 | PoisonArgumentsAndCaller(strict_mode_function_map_writable_prototype_); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | |
| 633 | static void SetAccessors(Handle<Map> map, |
| 634 | Handle<String> name, |
| 635 | Handle<JSFunction> func) { |
| 636 | DescriptorArray* descs = map->instance_descriptors(); |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 637 | int number = descs->SearchWithCache(*name, *map); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 638 | AccessorPair* accessors = AccessorPair::cast(descs->GetValue(number)); |
| 639 | accessors->set_getter(*func); |
| 640 | accessors->set_setter(*func); |
| 641 | } |
| 642 | |
| 643 | |
| 644 | void Genesis::PoisonArgumentsAndCaller(Handle<Map> map) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 645 | SetAccessors(map, factory()->arguments_string(), GetThrowTypeErrorFunction()); |
| 646 | SetAccessors(map, factory()->caller_string(), GetThrowTypeErrorFunction()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 650 | static void AddToWeakNativeContextList(Context* context) { |
| 651 | ASSERT(context->IsNativeContext()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 652 | Heap* heap = context->GetIsolate()->heap(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 653 | #ifdef DEBUG |
| 654 | { // NOLINT |
| 655 | ASSERT(context->get(Context::NEXT_CONTEXT_LINK)->IsUndefined()); |
| 656 | // Check that context is not in the list yet. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 657 | for (Object* current = heap->native_contexts_list(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 658 | !current->IsUndefined(); |
| 659 | current = Context::cast(current)->get(Context::NEXT_CONTEXT_LINK)) { |
| 660 | ASSERT(current != context); |
| 661 | } |
| 662 | } |
| 663 | #endif |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 664 | context->set(Context::NEXT_CONTEXT_LINK, heap->native_contexts_list()); |
| 665 | heap->set_native_contexts_list(context); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 669 | void Genesis::CreateRoots() { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 670 | // Allocate the native context FixedArray first and then patch the |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 671 | // closure and extension object later (we need the empty function |
| 672 | // and the global object, but in order to create those, we need the |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 673 | // native context). |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 674 | native_context_ = factory()->NewNativeContext(); |
| 675 | AddToWeakNativeContextList(*native_context()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 676 | isolate()->set_context(*native_context()); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 677 | |
| 678 | // Allocate the message listeners object. |
| 679 | { |
| 680 | v8::NeanderArray listeners; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 681 | native_context()->set_message_listeners(*listeners.value()); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 682 | } |
| 683 | } |
| 684 | |
| 685 | |
| 686 | Handle<JSGlobalProxy> Genesis::CreateNewGlobals( |
| 687 | v8::Handle<v8::ObjectTemplate> global_template, |
| 688 | Handle<Object> global_object, |
| 689 | Handle<GlobalObject>* inner_global_out) { |
| 690 | // The argument global_template aka data is an ObjectTemplateInfo. |
| 691 | // It has a constructor pointer that points at global_constructor which is a |
| 692 | // FunctionTemplateInfo. |
| 693 | // The global_constructor is used to create or reinitialize the global_proxy. |
| 694 | // The global_constructor also has a prototype_template pointer that points at |
| 695 | // js_global_template which is an ObjectTemplateInfo. |
| 696 | // That in turn has a constructor pointer that points at |
| 697 | // js_global_constructor which is a FunctionTemplateInfo. |
| 698 | // js_global_constructor is used to make js_global_function |
| 699 | // js_global_function is used to make the new inner_global. |
| 700 | // |
| 701 | // --- G l o b a l --- |
| 702 | // Step 1: Create a fresh inner JSGlobalObject. |
| 703 | Handle<JSFunction> js_global_function; |
| 704 | Handle<ObjectTemplateInfo> js_global_template; |
| 705 | if (!global_template.IsEmpty()) { |
| 706 | // Get prototype template of the global_template. |
| 707 | Handle<ObjectTemplateInfo> data = |
| 708 | v8::Utils::OpenHandle(*global_template); |
| 709 | Handle<FunctionTemplateInfo> global_constructor = |
| 710 | Handle<FunctionTemplateInfo>( |
| 711 | FunctionTemplateInfo::cast(data->constructor())); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 712 | Handle<Object> proto_template(global_constructor->prototype_template(), |
| 713 | isolate()); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 714 | if (!proto_template->IsUndefined()) { |
| 715 | js_global_template = |
| 716 | Handle<ObjectTemplateInfo>::cast(proto_template); |
| 717 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 718 | } |
| 719 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 720 | if (js_global_template.is_null()) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 721 | Handle<String> name = Handle<String>(heap()->empty_string()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 722 | Handle<Code> code = Handle<Code>(isolate()->builtins()->builtin( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 723 | Builtins::kIllegal)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 724 | js_global_function = |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 725 | factory()->NewFunction(name, JS_GLOBAL_OBJECT_TYPE, |
| 726 | JSGlobalObject::kSize, code, true); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 727 | // Change the constructor property of the prototype of the |
| 728 | // hidden global function to refer to the Object function. |
| 729 | Handle<JSObject> prototype = |
| 730 | Handle<JSObject>( |
| 731 | JSObject::cast(js_global_function->instance_prototype())); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 732 | CHECK_NOT_EMPTY_HANDLE(isolate(), |
| 733 | JSObject::SetLocalPropertyIgnoreAttributes( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 734 | prototype, factory()->constructor_string(), |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 735 | isolate()->object_function(), NONE)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 736 | } else { |
| 737 | Handle<FunctionTemplateInfo> js_global_constructor( |
| 738 | FunctionTemplateInfo::cast(js_global_template->constructor())); |
| 739 | js_global_function = |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 740 | factory()->CreateApiFunction(js_global_constructor, |
| 741 | factory()->InnerGlobalObject); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 742 | } |
| 743 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 744 | js_global_function->initial_map()->set_is_hidden_prototype(); |
erik.corry@gmail.com | 8876724 | 2012-08-08 14:43:45 +0000 | [diff] [blame] | 745 | js_global_function->initial_map()->set_dictionary_map(true); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 746 | Handle<GlobalObject> inner_global = |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 747 | factory()->NewGlobalObject(js_global_function); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 748 | if (inner_global_out != NULL) { |
| 749 | *inner_global_out = inner_global; |
| 750 | } |
| 751 | |
| 752 | // Step 2: create or re-initialize the global proxy object. |
| 753 | Handle<JSFunction> global_proxy_function; |
| 754 | if (global_template.IsEmpty()) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 755 | Handle<String> name = Handle<String>(heap()->empty_string()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 756 | Handle<Code> code = Handle<Code>(isolate()->builtins()->builtin( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 757 | Builtins::kIllegal)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 758 | global_proxy_function = |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 759 | factory()->NewFunction(name, JS_GLOBAL_PROXY_TYPE, |
| 760 | JSGlobalProxy::kSize, code, true); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 761 | } else { |
| 762 | Handle<ObjectTemplateInfo> data = |
| 763 | v8::Utils::OpenHandle(*global_template); |
| 764 | Handle<FunctionTemplateInfo> global_constructor( |
| 765 | FunctionTemplateInfo::cast(data->constructor())); |
| 766 | global_proxy_function = |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 767 | factory()->CreateApiFunction(global_constructor, |
| 768 | factory()->OuterGlobalObject); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 769 | } |
| 770 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 771 | Handle<String> global_name = factory()->InternalizeOneByteString( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 772 | STATIC_ASCII_VECTOR("global")); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 773 | global_proxy_function->shared()->set_instance_class_name(*global_name); |
| 774 | global_proxy_function->initial_map()->set_is_access_check_needed(true); |
| 775 | |
| 776 | // Set global_proxy.__proto__ to js_global after ConfigureGlobalObjects |
| 777 | // Return the global proxy. |
| 778 | |
| 779 | if (global_object.location() != NULL) { |
| 780 | ASSERT(global_object->IsJSGlobalProxy()); |
| 781 | return ReinitializeJSGlobalProxy( |
| 782 | global_proxy_function, |
| 783 | Handle<JSGlobalProxy>::cast(global_object)); |
| 784 | } else { |
| 785 | return Handle<JSGlobalProxy>::cast( |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 786 | factory()->NewJSObject(global_proxy_function, TENURED)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 787 | } |
| 788 | } |
| 789 | |
| 790 | |
| 791 | void Genesis::HookUpGlobalProxy(Handle<GlobalObject> inner_global, |
| 792 | Handle<JSGlobalProxy> global_proxy) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 793 | // Set the native context for the global object. |
| 794 | inner_global->set_native_context(*native_context()); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 795 | inner_global->set_global_context(*native_context()); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 796 | inner_global->set_global_receiver(*global_proxy); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 797 | global_proxy->set_native_context(*native_context()); |
| 798 | native_context()->set_global_proxy(*global_proxy); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | |
| 802 | void Genesis::HookUpInnerGlobal(Handle<GlobalObject> inner_global) { |
| 803 | Handle<GlobalObject> inner_global_from_snapshot( |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 804 | GlobalObject::cast(native_context()->extension())); |
| 805 | Handle<JSBuiltinsObject> builtins_global(native_context()->builtins()); |
| 806 | native_context()->set_extension(*inner_global); |
| 807 | native_context()->set_global_object(*inner_global); |
| 808 | native_context()->set_security_token(*inner_global); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 809 | static const PropertyAttributes attributes = |
| 810 | static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); |
| 811 | ForceSetProperty(builtins_global, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 812 | factory()->InternalizeOneByteString( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 813 | STATIC_ASCII_VECTOR("global")), |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 814 | inner_global, |
| 815 | attributes); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 816 | // Set up the reference from the global object to the builtins object. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 817 | JSGlobalObject::cast(*inner_global)->set_builtins(*builtins_global); |
| 818 | TransferNamedProperties(inner_global_from_snapshot, inner_global); |
| 819 | TransferIndexedProperties(inner_global_from_snapshot, inner_global); |
| 820 | } |
| 821 | |
| 822 | |
| 823 | // This is only called if we are not using snapshots. The equivalent |
| 824 | // work in the snapshot case is done in HookUpInnerGlobal. |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 825 | void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 826 | Handle<JSFunction> empty_function) { |
mstarzinger@chromium.org | a2e1a40 | 2013-10-15 08:25:05 +0000 | [diff] [blame] | 827 | // --- N a t i v e C o n t e x t --- |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 828 | // Use the empty function as closure (no scope info). |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 829 | native_context()->set_closure(*empty_function); |
| 830 | native_context()->set_previous(NULL); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 831 | // Set extension and global object. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 832 | native_context()->set_extension(*inner_global); |
| 833 | native_context()->set_global_object(*inner_global); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 834 | // Security setup: Set the security token of the global object to |
| 835 | // its the inner global. This makes the security check between two |
| 836 | // different contexts fail by default even in case of global |
| 837 | // object reinitialization. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 838 | native_context()->set_security_token(*inner_global); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 839 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 840 | Isolate* isolate = inner_global->GetIsolate(); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 841 | Factory* factory = isolate->factory(); |
| 842 | Heap* heap = isolate->heap(); |
| 843 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 844 | Handle<String> object_name = factory->Object_string(); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 845 | CHECK_NOT_EMPTY_HANDLE(isolate, |
| 846 | JSObject::SetLocalPropertyIgnoreAttributes( |
| 847 | inner_global, object_name, |
| 848 | isolate->object_function(), DONT_ENUM)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 849 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 850 | Handle<JSObject> global = Handle<JSObject>(native_context()->global_object()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 851 | |
| 852 | // Install global Function object |
| 853 | InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 854 | empty_function, Builtins::kIllegal, true, true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 855 | |
| 856 | { // --- A r r a y --- |
| 857 | Handle<JSFunction> array_function = |
| 858 | InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 859 | isolate->initial_object_prototype(), |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 860 | Builtins::kArrayCode, true, true); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 861 | array_function->shared()->DontAdaptArguments(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 862 | array_function->shared()->set_function_data(Smi::FromInt(kArrayCode)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 863 | |
| 864 | // This seems a bit hackish, but we need to make sure Array.length |
| 865 | // is 1. |
| 866 | array_function->shared()->set_length(1); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 867 | |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 868 | Handle<Map> initial_map(array_function->initial_map()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 869 | |
| 870 | // This assert protects an optimization in |
| 871 | // HGraphBuilder::JSArrayBuilder::EmitMapCode() |
| 872 | ASSERT(initial_map->elements_kind() == GetInitialFastElementsKind()); |
| 873 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 874 | Handle<DescriptorArray> array_descriptors( |
| 875 | factory->NewDescriptorArray(0, 1)); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 876 | DescriptorArray::WhitenessWitness witness(*array_descriptors); |
| 877 | |
| 878 | Handle<Foreign> array_length(factory->NewForeign(&Accessors::ArrayLength)); |
| 879 | PropertyAttributes attribs = static_cast<PropertyAttributes>( |
| 880 | DONT_ENUM | DONT_DELETE); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 881 | initial_map->set_instance_descriptors(*array_descriptors); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 882 | |
| 883 | { // Add length. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 884 | CallbacksDescriptor d(*factory->length_string(), *array_length, attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 885 | array_function->initial_map()->AppendDescriptor(&d, witness); |
| 886 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 887 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 888 | // array_function is used internally. JS code creating array object should |
| 889 | // search for the 'Array' property on the global object and use that one |
| 890 | // as the constructor. 'Array' property on a global object can be |
| 891 | // overwritten by JS code. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 892 | native_context()->set_array_function(*array_function); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 893 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 894 | // Cache the array maps, needed by ArrayConstructorStub |
| 895 | CacheInitialJSArrayMaps(native_context(), initial_map); |
| 896 | ArrayConstructorStub array_constructor_stub(isolate); |
| 897 | Handle<Code> code = array_constructor_stub.GetCode(isolate); |
| 898 | array_function->shared()->set_construct_stub(*code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | { // --- N u m b e r --- |
| 902 | Handle<JSFunction> number_fun = |
| 903 | InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 904 | isolate->initial_object_prototype(), |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 905 | Builtins::kIllegal, true, true); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 906 | native_context()->set_number_function(*number_fun); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | { // --- B o o l e a n --- |
| 910 | Handle<JSFunction> boolean_fun = |
| 911 | InstallFunction(global, "Boolean", JS_VALUE_TYPE, JSValue::kSize, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 912 | isolate->initial_object_prototype(), |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 913 | Builtins::kIllegal, true, true); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 914 | native_context()->set_boolean_function(*boolean_fun); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | { // --- S t r i n g --- |
| 918 | Handle<JSFunction> string_fun = |
| 919 | InstallFunction(global, "String", JS_VALUE_TYPE, JSValue::kSize, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 920 | isolate->initial_object_prototype(), |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 921 | Builtins::kIllegal, true, true); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 922 | string_fun->shared()->set_construct_stub( |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 923 | isolate->builtins()->builtin(Builtins::kStringConstructCode)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 924 | native_context()->set_string_function(*string_fun); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 925 | |
| 926 | Handle<Map> string_map = |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 927 | Handle<Map>(native_context()->string_function()->initial_map()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 928 | Handle<DescriptorArray> string_descriptors( |
| 929 | factory->NewDescriptorArray(0, 1)); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 930 | DescriptorArray::WhitenessWitness witness(*string_descriptors); |
| 931 | |
| 932 | Handle<Foreign> string_length( |
| 933 | factory->NewForeign(&Accessors::StringLength)); |
| 934 | PropertyAttributes attribs = static_cast<PropertyAttributes>( |
| 935 | DONT_ENUM | DONT_DELETE | READ_ONLY); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 936 | string_map->set_instance_descriptors(*string_descriptors); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 937 | |
| 938 | { // Add length. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 939 | CallbacksDescriptor d(*factory->length_string(), *string_length, attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 940 | string_map->AppendDescriptor(&d, witness); |
| 941 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | { // --- D a t e --- |
| 945 | // Builtin functions for Date.prototype. |
| 946 | Handle<JSFunction> date_fun = |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 947 | InstallFunction(global, "Date", JS_DATE_TYPE, JSDate::kSize, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 948 | isolate->initial_object_prototype(), |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 949 | Builtins::kIllegal, true, true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 950 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 951 | native_context()->set_date_function(*date_fun); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | |
| 955 | { // -- R e g E x p |
| 956 | // Builtin functions for RegExp.prototype. |
| 957 | Handle<JSFunction> regexp_fun = |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 958 | InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 959 | isolate->initial_object_prototype(), |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 960 | Builtins::kIllegal, true, true); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 961 | native_context()->set_regexp_function(*regexp_fun); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 962 | |
| 963 | ASSERT(regexp_fun->has_initial_map()); |
| 964 | Handle<Map> initial_map(regexp_fun->initial_map()); |
| 965 | |
| 966 | ASSERT_EQ(0, initial_map->inobject_properties()); |
| 967 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 968 | PropertyAttributes final = |
| 969 | static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 970 | Handle<DescriptorArray> descriptors = factory->NewDescriptorArray(0, 5); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 971 | DescriptorArray::WhitenessWitness witness(*descriptors); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 972 | initial_map->set_instance_descriptors(*descriptors); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 973 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 974 | { |
| 975 | // ECMA-262, section 15.10.7.1. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 976 | FieldDescriptor field(heap->source_string(), |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 977 | JSRegExp::kSourceFieldIndex, |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 978 | final, |
| 979 | Representation::Tagged()); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 980 | initial_map->AppendDescriptor(&field, witness); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 981 | } |
| 982 | { |
| 983 | // ECMA-262, section 15.10.7.2. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 984 | FieldDescriptor field(heap->global_string(), |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 985 | JSRegExp::kGlobalFieldIndex, |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 986 | final, |
| 987 | Representation::Tagged()); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 988 | initial_map->AppendDescriptor(&field, witness); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 989 | } |
| 990 | { |
| 991 | // ECMA-262, section 15.10.7.3. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 992 | FieldDescriptor field(heap->ignore_case_string(), |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 993 | JSRegExp::kIgnoreCaseFieldIndex, |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 994 | final, |
| 995 | Representation::Tagged()); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 996 | initial_map->AppendDescriptor(&field, witness); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 997 | } |
| 998 | { |
| 999 | // ECMA-262, section 15.10.7.4. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1000 | FieldDescriptor field(heap->multiline_string(), |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 1001 | JSRegExp::kMultilineFieldIndex, |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1002 | final, |
| 1003 | Representation::Tagged()); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1004 | initial_map->AppendDescriptor(&field, witness); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 1005 | } |
| 1006 | { |
| 1007 | // ECMA-262, section 15.10.7.5. |
| 1008 | PropertyAttributes writable = |
| 1009 | static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1010 | FieldDescriptor field(heap->last_index_string(), |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 1011 | JSRegExp::kLastIndexFieldIndex, |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1012 | writable, |
| 1013 | Representation::Tagged()); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1014 | initial_map->AppendDescriptor(&field, witness); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 1015 | } |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 1016 | |
| 1017 | initial_map->set_inobject_properties(5); |
| 1018 | initial_map->set_pre_allocated_property_fields(5); |
| 1019 | initial_map->set_unused_property_fields(0); |
| 1020 | initial_map->set_instance_size( |
| 1021 | initial_map->instance_size() + 5 * kPointerSize); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1022 | initial_map->set_visitor_id(StaticVisitorBase::GetVisitorId(*initial_map)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1023 | |
| 1024 | // RegExp prototype object is itself a RegExp. |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 1025 | Handle<Map> proto_map = factory->CopyMap(initial_map); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1026 | proto_map->set_prototype(native_context()->initial_object_prototype()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1027 | Handle<JSObject> proto = factory->NewJSObjectFromMap(proto_map); |
| 1028 | proto->InObjectPropertyAtPut(JSRegExp::kSourceFieldIndex, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1029 | heap->query_colon_string()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1030 | proto->InObjectPropertyAtPut(JSRegExp::kGlobalFieldIndex, |
| 1031 | heap->false_value()); |
| 1032 | proto->InObjectPropertyAtPut(JSRegExp::kIgnoreCaseFieldIndex, |
| 1033 | heap->false_value()); |
| 1034 | proto->InObjectPropertyAtPut(JSRegExp::kMultilineFieldIndex, |
| 1035 | heap->false_value()); |
| 1036 | proto->InObjectPropertyAtPut(JSRegExp::kLastIndexFieldIndex, |
| 1037 | Smi::FromInt(0), |
| 1038 | SKIP_WRITE_BARRIER); // It's a Smi. |
| 1039 | initial_map->set_prototype(*proto); |
| 1040 | factory->SetRegExpIrregexpData(Handle<JSRegExp>::cast(proto), |
| 1041 | JSRegExp::IRREGEXP, factory->empty_string(), |
| 1042 | JSRegExp::Flags(0), 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1043 | } |
| 1044 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 1045 | { // -- J S O N |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 1046 | Handle<String> name = factory->InternalizeUtf8String("JSON"); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1047 | Handle<JSFunction> cons = factory->NewFunction(name, |
| 1048 | factory->the_hole_value()); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1049 | JSFunction::SetInstancePrototype(cons, |
| 1050 | Handle<Object>(native_context()->initial_object_prototype(), isolate)); |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 1051 | cons->SetInstanceClassName(*name); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1052 | Handle<JSObject> json_object = factory->NewJSObject(cons, TENURED); |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 1053 | ASSERT(json_object->IsJSObject()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1054 | CHECK_NOT_EMPTY_HANDLE(isolate, |
| 1055 | JSObject::SetLocalPropertyIgnoreAttributes( |
| 1056 | global, name, json_object, DONT_ENUM)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1057 | native_context()->set_json_object(*json_object); |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 1058 | } |
| 1059 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 1060 | { // -- A r r a y B u f f e r |
| 1061 | Handle<JSFunction> array_buffer_fun = |
| 1062 | InstallFunction( |
| 1063 | global, "ArrayBuffer", JS_ARRAY_BUFFER_TYPE, |
| 1064 | JSArrayBuffer::kSizeWithInternalFields, |
| 1065 | isolate->initial_object_prototype(), |
| 1066 | Builtins::kIllegal, true, true); |
| 1067 | native_context()->set_array_buffer_fun(*array_buffer_fun); |
| 1068 | } |
| 1069 | |
| 1070 | { // -- T y p e d A r r a y s |
| 1071 | Handle<JSFunction> int8_fun = InstallTypedArray("Int8Array", |
| 1072 | EXTERNAL_BYTE_ELEMENTS); |
| 1073 | native_context()->set_int8_array_fun(*int8_fun); |
| 1074 | Handle<JSFunction> uint8_fun = InstallTypedArray("Uint8Array", |
| 1075 | EXTERNAL_UNSIGNED_BYTE_ELEMENTS); |
| 1076 | native_context()->set_uint8_array_fun(*uint8_fun); |
| 1077 | Handle<JSFunction> int16_fun = InstallTypedArray("Int16Array", |
| 1078 | EXTERNAL_SHORT_ELEMENTS); |
| 1079 | native_context()->set_int16_array_fun(*int16_fun); |
| 1080 | Handle<JSFunction> uint16_fun = InstallTypedArray("Uint16Array", |
| 1081 | EXTERNAL_UNSIGNED_SHORT_ELEMENTS); |
| 1082 | native_context()->set_uint16_array_fun(*uint16_fun); |
| 1083 | Handle<JSFunction> int32_fun = InstallTypedArray("Int32Array", |
| 1084 | EXTERNAL_INT_ELEMENTS); |
| 1085 | native_context()->set_int32_array_fun(*int32_fun); |
| 1086 | Handle<JSFunction> uint32_fun = InstallTypedArray("Uint32Array", |
| 1087 | EXTERNAL_UNSIGNED_INT_ELEMENTS); |
| 1088 | native_context()->set_uint32_array_fun(*uint32_fun); |
| 1089 | Handle<JSFunction> float_fun = InstallTypedArray("Float32Array", |
| 1090 | EXTERNAL_FLOAT_ELEMENTS); |
| 1091 | native_context()->set_float_array_fun(*float_fun); |
| 1092 | Handle<JSFunction> double_fun = InstallTypedArray("Float64Array", |
| 1093 | EXTERNAL_DOUBLE_ELEMENTS); |
| 1094 | native_context()->set_double_array_fun(*double_fun); |
| 1095 | Handle<JSFunction> uint8c_fun = InstallTypedArray("Uint8ClampedArray", |
| 1096 | EXTERNAL_PIXEL_ELEMENTS); |
| 1097 | native_context()->set_uint8c_array_fun(*uint8c_fun); |
| 1098 | |
| 1099 | Handle<JSFunction> data_view_fun = |
| 1100 | InstallFunction( |
| 1101 | global, "DataView", JS_DATA_VIEW_TYPE, |
| 1102 | JSDataView::kSizeWithInternalFields, |
| 1103 | isolate->initial_object_prototype(), |
| 1104 | Builtins::kIllegal, true, true); |
| 1105 | native_context()->set_data_view_fun(*data_view_fun); |
| 1106 | } |
| 1107 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1108 | { // --- arguments_boilerplate_ |
| 1109 | // Make sure we can recognize argument objects at runtime. |
| 1110 | // This is done by introducing an anonymous function with |
| 1111 | // class_name equals 'Arguments'. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1112 | Handle<String> arguments_string = factory->InternalizeOneByteString( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1113 | STATIC_ASCII_VECTOR("Arguments")); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1114 | Handle<Code> code = Handle<Code>( |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1115 | isolate->builtins()->builtin(Builtins::kIllegal)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1116 | Handle<JSObject> prototype = |
| 1117 | Handle<JSObject>( |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1118 | JSObject::cast(native_context()->object_function()->prototype())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1119 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1120 | Handle<JSFunction> function = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1121 | factory->NewFunctionWithPrototype(arguments_string, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1122 | JS_OBJECT_TYPE, |
| 1123 | JSObject::kHeaderSize, |
| 1124 | prototype, |
| 1125 | code, |
| 1126 | false); |
| 1127 | ASSERT(!function->has_initial_map()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1128 | function->shared()->set_instance_class_name(*arguments_string); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1129 | function->shared()->set_expected_nof_properties(2); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1130 | Handle<JSObject> result = factory->NewJSObject(function); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1131 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1132 | native_context()->set_arguments_boilerplate(*result); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1133 | // Note: length must be added as the first property and |
| 1134 | // callee must be added as the second property. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1135 | CHECK_NOT_EMPTY_HANDLE(isolate, |
| 1136 | JSObject::SetLocalPropertyIgnoreAttributes( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1137 | result, factory->length_string(), |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1138 | factory->undefined_value(), DONT_ENUM, |
rossberg@chromium.org | 9259716 | 2013-08-23 13:28:00 +0000 | [diff] [blame] | 1139 | Object::FORCE_TAGGED, FORCE_FIELD)); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1140 | CHECK_NOT_EMPTY_HANDLE(isolate, |
| 1141 | JSObject::SetLocalPropertyIgnoreAttributes( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1142 | result, factory->callee_string(), |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1143 | factory->undefined_value(), DONT_ENUM, |
rossberg@chromium.org | 9259716 | 2013-08-23 13:28:00 +0000 | [diff] [blame] | 1144 | Object::FORCE_TAGGED, FORCE_FIELD)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1145 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1146 | #ifdef DEBUG |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1147 | LookupResult lookup(isolate); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1148 | result->LocalLookup(heap->callee_string(), &lookup); |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 1149 | ASSERT(lookup.IsField()); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 1150 | ASSERT(lookup.GetFieldIndex().field_index() == Heap::kArgumentsCalleeIndex); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1151 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1152 | result->LocalLookup(heap->length_string(), &lookup); |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 1153 | ASSERT(lookup.IsField()); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 1154 | ASSERT(lookup.GetFieldIndex().field_index() == Heap::kArgumentsLengthIndex); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1155 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1156 | ASSERT(result->map()->inobject_properties() > Heap::kArgumentsCalleeIndex); |
| 1157 | ASSERT(result->map()->inobject_properties() > Heap::kArgumentsLengthIndex); |
| 1158 | |
| 1159 | // Check the state of the object. |
| 1160 | ASSERT(result->HasFastProperties()); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1161 | ASSERT(result->HasFastObjectElements()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1162 | #endif |
| 1163 | } |
| 1164 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1165 | { // --- aliased_arguments_boilerplate_ |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1166 | // Set up a well-formed parameter map to make assertions happy. |
| 1167 | Handle<FixedArray> elements = factory->NewFixedArray(2); |
| 1168 | elements->set_map(heap->non_strict_arguments_elements_map()); |
| 1169 | Handle<FixedArray> array; |
| 1170 | array = factory->NewFixedArray(0); |
| 1171 | elements->set(0, *array); |
| 1172 | array = factory->NewFixedArray(0); |
| 1173 | elements->set(1, *array); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1174 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1175 | Handle<Map> old_map(native_context()->arguments_boilerplate()->map()); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 1176 | Handle<Map> new_map = factory->CopyMap(old_map); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1177 | new_map->set_pre_allocated_property_fields(2); |
| 1178 | Handle<JSObject> result = factory->NewJSObjectFromMap(new_map); |
| 1179 | // Set elements kind after allocating the object because |
| 1180 | // NewJSObjectFromMap assumes a fast elements map. |
| 1181 | new_map->set_elements_kind(NON_STRICT_ARGUMENTS_ELEMENTS); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1182 | result->set_elements(*elements); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1183 | ASSERT(result->HasNonStrictArgumentsElements()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1184 | native_context()->set_aliased_arguments_boilerplate(*result); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1185 | } |
| 1186 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1187 | { // --- strict mode arguments boilerplate |
| 1188 | const PropertyAttributes attributes = |
| 1189 | static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 1190 | |
| 1191 | // Create the ThrowTypeError functions. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1192 | Handle<AccessorPair> callee = factory->NewAccessorPair(); |
| 1193 | Handle<AccessorPair> caller = factory->NewAccessorPair(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1194 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1195 | Handle<JSFunction> throw_function = |
| 1196 | GetThrowTypeErrorFunction(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1197 | |
| 1198 | // Install the ThrowTypeError functions. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1199 | callee->set_getter(*throw_function); |
| 1200 | callee->set_setter(*throw_function); |
| 1201 | caller->set_getter(*throw_function); |
| 1202 | caller->set_setter(*throw_function); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1203 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1204 | // Create the map. Allocate one in-object field for length. |
| 1205 | Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, |
| 1206 | Heap::kArgumentsObjectSizeStrict); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1207 | // Create the descriptor array for the arguments object. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1208 | Handle<DescriptorArray> descriptors = factory->NewDescriptorArray(0, 3); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1209 | DescriptorArray::WhitenessWitness witness(*descriptors); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 1210 | map->set_instance_descriptors(*descriptors); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1211 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1212 | { // length |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1213 | FieldDescriptor d( |
| 1214 | *factory->length_string(), 0, DONT_ENUM, Representation::Tagged()); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1215 | map->AppendDescriptor(&d, witness); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1216 | } |
| 1217 | { // callee |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1218 | CallbacksDescriptor d(*factory->callee_string(), |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 1219 | *callee, |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 1220 | attributes); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1221 | map->AppendDescriptor(&d, witness); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1222 | } |
| 1223 | { // caller |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1224 | CallbacksDescriptor d(*factory->caller_string(), |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 1225 | *caller, |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 1226 | attributes); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1227 | map->AppendDescriptor(&d, witness); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1228 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1229 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1230 | map->set_function_with_prototype(true); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1231 | map->set_prototype(native_context()->object_function()->prototype()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1232 | map->set_pre_allocated_property_fields(1); |
| 1233 | map->set_inobject_properties(1); |
| 1234 | |
| 1235 | // Copy constructor from the non-strict arguments boilerplate. |
| 1236 | map->set_constructor( |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1237 | native_context()->arguments_boilerplate()->map()->constructor()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1238 | |
| 1239 | // Allocate the arguments boilerplate object. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1240 | Handle<JSObject> result = factory->NewJSObjectFromMap(map); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1241 | native_context()->set_strict_mode_arguments_boilerplate(*result); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1242 | |
| 1243 | // Add length property only for strict mode boilerplate. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1244 | CHECK_NOT_EMPTY_HANDLE(isolate, |
| 1245 | JSObject::SetLocalPropertyIgnoreAttributes( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1246 | result, factory->length_string(), |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1247 | factory->undefined_value(), DONT_ENUM)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1248 | |
| 1249 | #ifdef DEBUG |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1250 | LookupResult lookup(isolate); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1251 | result->LocalLookup(heap->length_string(), &lookup); |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 1252 | ASSERT(lookup.IsField()); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 1253 | ASSERT(lookup.GetFieldIndex().field_index() == Heap::kArgumentsLengthIndex); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1254 | |
| 1255 | ASSERT(result->map()->inobject_properties() > Heap::kArgumentsLengthIndex); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1256 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1257 | // Check the state of the object. |
| 1258 | ASSERT(result->HasFastProperties()); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1259 | ASSERT(result->HasFastObjectElements()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1260 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | { // --- context extension |
| 1264 | // Create a function for the context extension objects. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1265 | Handle<Code> code = Handle<Code>( |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1266 | isolate->builtins()->builtin(Builtins::kIllegal)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1267 | Handle<JSFunction> context_extension_fun = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1268 | factory->NewFunction(factory->empty_string(), |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1269 | JS_CONTEXT_EXTENSION_OBJECT_TYPE, |
| 1270 | JSObject::kHeaderSize, |
| 1271 | code, |
| 1272 | true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1273 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1274 | Handle<String> name = factory->InternalizeOneByteString( |
| 1275 | STATIC_ASCII_VECTOR("context_extension")); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1276 | context_extension_fun->shared()->set_instance_class_name(*name); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1277 | native_context()->set_context_extension_function(*context_extension_fun); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1278 | } |
| 1279 | |
sgjesse@chromium.org | 05521fc | 2009-05-21 07:37:44 +0000 | [diff] [blame] | 1280 | |
| 1281 | { |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1282 | // Set up the call-as-function delegate. |
sgjesse@chromium.org | 05521fc | 2009-05-21 07:37:44 +0000 | [diff] [blame] | 1283 | Handle<Code> code = |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1284 | Handle<Code>(isolate->builtins()->builtin( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1285 | Builtins::kHandleApiCallAsFunction)); |
sgjesse@chromium.org | 05521fc | 2009-05-21 07:37:44 +0000 | [diff] [blame] | 1286 | Handle<JSFunction> delegate = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1287 | factory->NewFunction(factory->empty_string(), JS_OBJECT_TYPE, |
sgjesse@chromium.org | 05521fc | 2009-05-21 07:37:44 +0000 | [diff] [blame] | 1288 | JSObject::kHeaderSize, code, true); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1289 | native_context()->set_call_as_function_delegate(*delegate); |
sgjesse@chromium.org | 05521fc | 2009-05-21 07:37:44 +0000 | [diff] [blame] | 1290 | delegate->shared()->DontAdaptArguments(); |
| 1291 | } |
| 1292 | |
| 1293 | { |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1294 | // Set up the call-as-constructor delegate. |
sgjesse@chromium.org | 05521fc | 2009-05-21 07:37:44 +0000 | [diff] [blame] | 1295 | Handle<Code> code = |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1296 | Handle<Code>(isolate->builtins()->builtin( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1297 | Builtins::kHandleApiCallAsConstructor)); |
sgjesse@chromium.org | 05521fc | 2009-05-21 07:37:44 +0000 | [diff] [blame] | 1298 | Handle<JSFunction> delegate = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1299 | factory->NewFunction(factory->empty_string(), JS_OBJECT_TYPE, |
sgjesse@chromium.org | 05521fc | 2009-05-21 07:37:44 +0000 | [diff] [blame] | 1300 | JSObject::kHeaderSize, code, true); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1301 | native_context()->set_call_as_constructor_delegate(*delegate); |
sgjesse@chromium.org | 05521fc | 2009-05-21 07:37:44 +0000 | [diff] [blame] | 1302 | delegate->shared()->DontAdaptArguments(); |
| 1303 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1304 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1305 | // Initialize the out of memory slot. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1306 | native_context()->set_out_of_memory(heap->false_value()); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1307 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 1308 | // Initialize the embedder data slot. |
| 1309 | Handle<FixedArray> embedder_data = factory->NewFixedArray(2); |
| 1310 | native_context()->set_embedder_data(*embedder_data); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1311 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 1312 | // Allocate the random seed slot. |
| 1313 | Handle<ByteArray> random_seed = factory->NewByteArray(kRandomStateSize); |
| 1314 | native_context()->set_random_seed(*random_seed); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1318 | Handle<JSFunction> Genesis::InstallTypedArray( |
| 1319 | const char* name, ElementsKind elementsKind) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1320 | Handle<JSObject> global = Handle<JSObject>(native_context()->global_object()); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1321 | Handle<JSFunction> result = InstallFunction(global, name, JS_TYPED_ARRAY_TYPE, |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1322 | JSTypedArray::kSize, isolate()->initial_object_prototype(), |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1323 | Builtins::kIllegal, false, true); |
| 1324 | |
| 1325 | Handle<Map> initial_map = isolate()->factory()->NewMap( |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 1326 | JS_TYPED_ARRAY_TYPE, JSTypedArray::kSizeWithInternalFields, elementsKind); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1327 | result->set_initial_map(*initial_map); |
| 1328 | initial_map->set_constructor(*result); |
| 1329 | return result; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1333 | void Genesis::InitializeExperimentalGlobal() { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1334 | Handle<JSObject> global = Handle<JSObject>(native_context()->global_object()); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1335 | |
| 1336 | // TODO(mstarzinger): Move this into Genesis::InitializeGlobal once we no |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1337 | // longer need to live behind flags, so functions get added to the snapshot. |
| 1338 | |
| 1339 | if (FLAG_harmony_symbols) { |
| 1340 | // --- S y m b o l --- |
| 1341 | Handle<JSFunction> symbol_fun = |
| 1342 | InstallFunction(global, "Symbol", JS_VALUE_TYPE, JSValue::kSize, |
| 1343 | isolate()->initial_object_prototype(), |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1344 | Builtins::kIllegal, true, true); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1345 | native_context()->set_symbol_function(*symbol_fun); |
| 1346 | } |
| 1347 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1348 | if (FLAG_harmony_collections) { |
| 1349 | { // -- S e t |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1350 | InstallFunction(global, "Set", JS_SET_TYPE, JSSet::kSize, |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1351 | isolate()->initial_object_prototype(), |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1352 | Builtins::kIllegal, true, true); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1353 | } |
| 1354 | { // -- M a p |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1355 | InstallFunction(global, "Map", JS_MAP_TYPE, JSMap::kSize, |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1356 | isolate()->initial_object_prototype(), |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1357 | Builtins::kIllegal, true, true); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1358 | } |
| 1359 | { // -- W e a k M a p |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1360 | InstallFunction(global, "WeakMap", JS_WEAK_MAP_TYPE, JSWeakMap::kSize, |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1361 | isolate()->initial_object_prototype(), |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1362 | Builtins::kIllegal, true, true); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1363 | } |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1364 | { // -- W e a k S e t |
| 1365 | InstallFunction(global, "WeakSet", JS_WEAK_SET_TYPE, JSWeakSet::kSize, |
| 1366 | isolate()->initial_object_prototype(), |
| 1367 | Builtins::kIllegal, true, true); |
| 1368 | } |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1369 | } |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1370 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1371 | if (FLAG_harmony_generators) { |
| 1372 | // Create generator meta-objects and install them on the builtins object. |
| 1373 | Handle<JSObject> builtins(native_context()->builtins()); |
| 1374 | Handle<JSObject> generator_object_prototype = |
| 1375 | factory()->NewJSObject(isolate()->object_function(), TENURED); |
| 1376 | Handle<JSFunction> generator_function_prototype = |
| 1377 | InstallFunction(builtins, "GeneratorFunctionPrototype", |
| 1378 | JS_FUNCTION_TYPE, JSFunction::kHeaderSize, |
| 1379 | generator_object_prototype, Builtins::kIllegal, |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1380 | false, false); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1381 | InstallFunction(builtins, "GeneratorFunction", |
| 1382 | JS_FUNCTION_TYPE, JSFunction::kSize, |
| 1383 | generator_function_prototype, Builtins::kIllegal, |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1384 | false, false); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1385 | |
| 1386 | // Create maps for generator functions and their prototypes. Store those |
| 1387 | // maps in the native context. |
| 1388 | Handle<Map> function_map(native_context()->function_map()); |
| 1389 | Handle<Map> generator_function_map = factory()->CopyMap(function_map); |
| 1390 | generator_function_map->set_prototype(*generator_function_prototype); |
| 1391 | native_context()->set_generator_function_map(*generator_function_map); |
| 1392 | |
| 1393 | Handle<Map> strict_mode_function_map( |
| 1394 | native_context()->strict_mode_function_map()); |
| 1395 | Handle<Map> strict_mode_generator_function_map = factory()->CopyMap( |
| 1396 | strict_mode_function_map); |
| 1397 | strict_mode_generator_function_map->set_prototype( |
| 1398 | *generator_function_prototype); |
| 1399 | native_context()->set_strict_mode_generator_function_map( |
| 1400 | *strict_mode_generator_function_map); |
| 1401 | |
| 1402 | Handle<Map> object_map(native_context()->object_function()->initial_map()); |
| 1403 | Handle<Map> generator_object_prototype_map = factory()->CopyMap( |
| 1404 | object_map, 0); |
| 1405 | generator_object_prototype_map->set_prototype( |
| 1406 | *generator_object_prototype); |
| 1407 | native_context()->set_generator_object_prototype_map( |
| 1408 | *generator_object_prototype_map); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1409 | |
| 1410 | // Create a map for generator result objects. |
| 1411 | ASSERT(object_map->inobject_properties() == 0); |
| 1412 | STATIC_ASSERT(JSGeneratorObject::kResultPropertyCount == 2); |
| 1413 | Handle<Map> generator_result_map = factory()->CopyMap(object_map, |
| 1414 | JSGeneratorObject::kResultPropertyCount); |
| 1415 | ASSERT(generator_result_map->inobject_properties() == |
| 1416 | JSGeneratorObject::kResultPropertyCount); |
| 1417 | |
| 1418 | Handle<DescriptorArray> descriptors = factory()->NewDescriptorArray(0, |
| 1419 | JSGeneratorObject::kResultPropertyCount); |
| 1420 | DescriptorArray::WhitenessWitness witness(*descriptors); |
| 1421 | generator_result_map->set_instance_descriptors(*descriptors); |
| 1422 | |
| 1423 | Handle<String> value_string = factory()->InternalizeOneByteString( |
| 1424 | STATIC_ASCII_VECTOR("value")); |
| 1425 | FieldDescriptor value_descr(*value_string, |
| 1426 | JSGeneratorObject::kResultValuePropertyIndex, |
| 1427 | NONE, |
| 1428 | Representation::Tagged()); |
| 1429 | generator_result_map->AppendDescriptor(&value_descr, witness); |
| 1430 | |
| 1431 | Handle<String> done_string = factory()->InternalizeOneByteString( |
| 1432 | STATIC_ASCII_VECTOR("done")); |
| 1433 | FieldDescriptor done_descr(*done_string, |
| 1434 | JSGeneratorObject::kResultDonePropertyIndex, |
| 1435 | NONE, |
| 1436 | Representation::Tagged()); |
| 1437 | generator_result_map->AppendDescriptor(&done_descr, witness); |
| 1438 | |
| 1439 | generator_result_map->set_unused_property_fields(0); |
| 1440 | ASSERT_EQ(JSGeneratorObject::kResultSize, |
| 1441 | generator_result_map->instance_size()); |
| 1442 | native_context()->set_generator_result_map(*generator_result_map); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1443 | } |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1444 | } |
| 1445 | |
| 1446 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1447 | bool Genesis::CompileBuiltin(Isolate* isolate, int index) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1448 | Vector<const char> name = Natives::GetScriptName(index); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1449 | Handle<String> source_code = |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1450 | isolate->bootstrapper()->NativesSourceLookup(index); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1451 | return CompileNative(isolate, name, source_code); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | |
| 1455 | bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) { |
| 1456 | Vector<const char> name = ExperimentalNatives::GetScriptName(index); |
| 1457 | Factory* factory = isolate->factory(); |
| 1458 | Handle<String> source_code = |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1459 | factory->NewStringFromAscii( |
| 1460 | ExperimentalNatives::GetRawScriptSource(index)); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1461 | return CompileNative(isolate, name, source_code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1465 | bool Genesis::CompileNative(Isolate* isolate, |
| 1466 | Vector<const char> name, |
| 1467 | Handle<String> source) { |
| 1468 | HandleScope scope(isolate); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1469 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1470 | isolate->debugger()->set_compiling_natives(true); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1471 | #endif |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 1472 | // During genesis, the boilerplate for stack overflow won't work until the |
| 1473 | // environment has been at least partially initialized. Add a stack check |
| 1474 | // before entering JS code to catch overflow early. |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1475 | StackLimitCheck check(isolate); |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 1476 | if (check.HasOverflowed()) return false; |
| 1477 | |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1478 | bool result = CompileScriptCached(isolate, |
| 1479 | name, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1480 | source, |
| 1481 | NULL, |
| 1482 | NULL, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1483 | Handle<Context>(isolate->context()), |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1484 | true); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1485 | ASSERT(isolate->has_pending_exception() != result); |
| 1486 | if (!result) isolate->clear_pending_exception(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1487 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1488 | isolate->debugger()->set_compiling_natives(false); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1489 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1490 | return result; |
| 1491 | } |
| 1492 | |
| 1493 | |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1494 | bool Genesis::CompileScriptCached(Isolate* isolate, |
| 1495 | Vector<const char> name, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1496 | Handle<String> source, |
| 1497 | SourceCodeCache* cache, |
| 1498 | v8::Extension* extension, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1499 | Handle<Context> top_context, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1500 | bool use_runtime_context) { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1501 | Factory* factory = isolate->factory(); |
| 1502 | HandleScope scope(isolate); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1503 | Handle<SharedFunctionInfo> function_info; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1504 | |
| 1505 | // If we can't find the function in the cache, we compile a new |
| 1506 | // function and insert it into the cache. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1507 | if (cache == NULL || !cache->Lookup(name, &function_info)) { |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 1508 | ASSERT(source->IsOneByteRepresentation()); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1509 | Handle<String> script_name = factory->NewStringFromUtf8(name); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1510 | function_info = Compiler::Compile( |
| 1511 | source, |
| 1512 | script_name, |
| 1513 | 0, |
| 1514 | 0, |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1515 | false, |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1516 | top_context, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1517 | extension, |
| 1518 | NULL, |
| 1519 | Handle<String>::null(), |
| 1520 | use_runtime_context ? NATIVES_CODE : NOT_NATIVES_CODE); |
| 1521 | if (function_info.is_null()) return false; |
| 1522 | if (cache != NULL) cache->Add(name, function_info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1523 | } |
| 1524 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1525 | // Set up the function context. Conceptually, we should clone the |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1526 | // function before overwriting the context but since we're in a |
| 1527 | // single-threaded environment it is not strictly necessary. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1528 | ASSERT(top_context->IsNativeContext()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1529 | Handle<Context> context = |
| 1530 | Handle<Context>(use_runtime_context |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1531 | ? Handle<Context>(top_context->runtime_context()) |
| 1532 | : top_context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1533 | Handle<JSFunction> fun = |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1534 | factory->NewFunctionFromSharedFunctionInfo(function_info, context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1535 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1536 | // Call function using either the runtime object or the global |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1537 | // object as the receiver. Provide no parameters. |
| 1538 | Handle<Object> receiver = |
| 1539 | Handle<Object>(use_runtime_context |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1540 | ? top_context->builtins() |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1541 | : top_context->global_object(), |
| 1542 | isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1543 | bool has_pending_exception; |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 1544 | Execution::Call(isolate, fun, receiver, 0, NULL, &has_pending_exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1545 | if (has_pending_exception) return false; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1546 | return true; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1550 | #define INSTALL_NATIVE(Type, name, var) \ |
| 1551 | Handle<String> var##_name = \ |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1552 | factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR(name)); \ |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1553 | Object* var##_native = \ |
| 1554 | native_context()->builtins()->GetPropertyNoExceptionThrown( \ |
| 1555 | *var##_name); \ |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1556 | native_context()->set_##var(Type::cast(var##_native)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1557 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1558 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1559 | void Genesis::InstallNativeFunctions() { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1560 | HandleScope scope(isolate()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1561 | INSTALL_NATIVE(JSFunction, "CreateDate", create_date_fun); |
| 1562 | INSTALL_NATIVE(JSFunction, "ToNumber", to_number_fun); |
| 1563 | INSTALL_NATIVE(JSFunction, "ToString", to_string_fun); |
| 1564 | INSTALL_NATIVE(JSFunction, "ToDetailString", to_detail_string_fun); |
| 1565 | INSTALL_NATIVE(JSFunction, "ToObject", to_object_fun); |
| 1566 | INSTALL_NATIVE(JSFunction, "ToInteger", to_integer_fun); |
| 1567 | INSTALL_NATIVE(JSFunction, "ToUint32", to_uint32_fun); |
| 1568 | INSTALL_NATIVE(JSFunction, "ToInt32", to_int32_fun); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1569 | INSTALL_NATIVE(JSFunction, "GlobalEval", global_eval_fun); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1570 | INSTALL_NATIVE(JSFunction, "Instantiate", instantiate_fun); |
| 1571 | INSTALL_NATIVE(JSFunction, "ConfigureTemplateInstance", |
| 1572 | configure_instance_fun); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1573 | INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun); |
| 1574 | INSTALL_NATIVE(JSObject, "functionCache", function_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1575 | INSTALL_NATIVE(JSFunction, "ToCompletePropertyDescriptor", |
| 1576 | to_complete_property_descriptor); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1577 | } |
| 1578 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 1579 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1580 | void Genesis::InstallExperimentalNativeFunctions() { |
| 1581 | if (FLAG_harmony_proxies) { |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1582 | INSTALL_NATIVE(JSFunction, "DerivedHasTrap", derived_has_trap); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1583 | INSTALL_NATIVE(JSFunction, "DerivedGetTrap", derived_get_trap); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1584 | INSTALL_NATIVE(JSFunction, "DerivedSetTrap", derived_set_trap); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1585 | INSTALL_NATIVE(JSFunction, "ProxyEnumerate", proxy_enumerate); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1586 | } |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 1587 | if (FLAG_harmony_observation) { |
| 1588 | INSTALL_NATIVE(JSFunction, "NotifyChange", observers_notify_change); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1589 | INSTALL_NATIVE(JSFunction, "EnqueueSpliceRecord", observers_enqueue_splice); |
| 1590 | INSTALL_NATIVE(JSFunction, "BeginPerformSplice", |
| 1591 | observers_begin_perform_splice); |
| 1592 | INSTALL_NATIVE(JSFunction, "EndPerformSplice", |
| 1593 | observers_end_perform_splice); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 1594 | INSTALL_NATIVE(JSFunction, "DeliverChangeRecords", |
| 1595 | observers_deliver_changes); |
| 1596 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1597 | } |
| 1598 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1599 | #undef INSTALL_NATIVE |
| 1600 | |
| 1601 | |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1602 | Handle<JSFunction> Genesis::InstallInternalArray( |
| 1603 | Handle<JSBuiltinsObject> builtins, |
| 1604 | const char* name, |
| 1605 | ElementsKind elements_kind) { |
| 1606 | // --- I n t e r n a l A r r a y --- |
| 1607 | // An array constructor on the builtins object that works like |
| 1608 | // the public Array constructor, except that its prototype |
| 1609 | // doesn't inherit from Object.prototype. |
| 1610 | // To be used only for internal work by builtins. Instances |
| 1611 | // must not be leaked to user code. |
| 1612 | Handle<JSFunction> array_function = |
| 1613 | InstallFunction(builtins, |
| 1614 | name, |
| 1615 | JS_ARRAY_TYPE, |
| 1616 | JSArray::kSize, |
| 1617 | isolate()->initial_object_prototype(), |
| 1618 | Builtins::kInternalArrayCode, |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1619 | true, true); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1620 | Handle<JSObject> prototype = |
| 1621 | factory()->NewJSObject(isolate()->object_function(), TENURED); |
rossberg@chromium.org | ebeba02 | 2013-08-19 09:36:44 +0000 | [diff] [blame] | 1622 | Accessors::FunctionSetPrototype(array_function, prototype); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1623 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1624 | InternalArrayConstructorStub internal_array_constructor_stub(isolate()); |
| 1625 | Handle<Code> code = internal_array_constructor_stub.GetCode(isolate()); |
| 1626 | array_function->shared()->set_construct_stub(*code); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1627 | array_function->shared()->DontAdaptArguments(); |
| 1628 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 1629 | Handle<Map> original_map(array_function->initial_map()); |
| 1630 | Handle<Map> initial_map = factory()->CopyMap(original_map); |
| 1631 | initial_map->set_elements_kind(elements_kind); |
| 1632 | array_function->set_initial_map(*initial_map); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1633 | |
| 1634 | // Make "length" magic on instances. |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1635 | Handle<DescriptorArray> array_descriptors( |
| 1636 | factory()->NewDescriptorArray(0, 1)); |
| 1637 | DescriptorArray::WhitenessWitness witness(*array_descriptors); |
| 1638 | |
| 1639 | Handle<Foreign> array_length(factory()->NewForeign( |
| 1640 | &Accessors::ArrayLength)); |
| 1641 | PropertyAttributes attribs = static_cast<PropertyAttributes>( |
| 1642 | DONT_ENUM | DONT_DELETE); |
| 1643 | initial_map->set_instance_descriptors(*array_descriptors); |
| 1644 | |
| 1645 | { // Add length. |
| 1646 | CallbacksDescriptor d( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1647 | *factory()->length_string(), *array_length, attribs); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1648 | array_function->initial_map()->AppendDescriptor(&d, witness); |
| 1649 | } |
| 1650 | |
| 1651 | return array_function; |
| 1652 | } |
| 1653 | |
| 1654 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1655 | bool Genesis::InstallNatives() { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1656 | HandleScope scope(isolate()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1657 | |
| 1658 | // Create a function for the builtins object. Allocate space for the |
| 1659 | // JavaScript builtins, a reference to the builtins object |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1660 | // (itself) and a reference to the native_context directly in the object. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1661 | Handle<Code> code = Handle<Code>( |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1662 | isolate()->builtins()->builtin(Builtins::kIllegal)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1663 | Handle<JSFunction> builtins_fun = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1664 | factory()->NewFunction(factory()->empty_string(), |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1665 | JS_BUILTINS_OBJECT_TYPE, |
| 1666 | JSBuiltinsObject::kSize, code, true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1667 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1668 | Handle<String> name = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1669 | factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("builtins")); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1670 | builtins_fun->shared()->set_instance_class_name(*name); |
erik.corry@gmail.com | 8876724 | 2012-08-08 14:43:45 +0000 | [diff] [blame] | 1671 | builtins_fun->initial_map()->set_dictionary_map(true); |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 1672 | builtins_fun->initial_map()->set_prototype(heap()->null_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1673 | |
| 1674 | // Allocate the builtins object. |
| 1675 | Handle<JSBuiltinsObject> builtins = |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1676 | Handle<JSBuiltinsObject>::cast(factory()->NewGlobalObject(builtins_fun)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1677 | builtins->set_builtins(*builtins); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1678 | builtins->set_native_context(*native_context()); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1679 | builtins->set_global_context(*native_context()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1680 | builtins->set_global_receiver(*builtins); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1681 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1682 | // Set up the 'global' properties of the builtins object. The |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1683 | // 'global' property that refers to the global object is the only |
| 1684 | // way to get from code running in the builtins context to the |
| 1685 | // global object. |
| 1686 | static const PropertyAttributes attributes = |
| 1687 | static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1688 | Handle<String> global_string = |
| 1689 | factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("global")); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1690 | Handle<Object> global_obj(native_context()->global_object(), isolate()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1691 | CHECK_NOT_EMPTY_HANDLE(isolate(), |
| 1692 | JSObject::SetLocalPropertyIgnoreAttributes( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1693 | builtins, global_string, global_obj, attributes)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1694 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1695 | // Set up the reference from the global object to the builtins object. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1696 | JSGlobalObject::cast(native_context()->global_object())-> |
| 1697 | set_builtins(*builtins); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1698 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1699 | // Create a bridge function that has context in the native context. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1700 | Handle<JSFunction> bridge = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1701 | factory()->NewFunction(factory()->empty_string(), |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1702 | factory()->undefined_value()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1703 | ASSERT(bridge->context() == *isolate()->native_context()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1704 | |
| 1705 | // Allocate the builtins context. |
| 1706 | Handle<Context> context = |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1707 | factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1708 | context->set_global_object(*builtins); // override builtins global object |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1709 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1710 | native_context()->set_runtime_context(*context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1711 | |
| 1712 | { // -- S c r i p t |
| 1713 | // Builtin functions for Script. |
| 1714 | Handle<JSFunction> script_fun = |
| 1715 | InstallFunction(builtins, "Script", JS_VALUE_TYPE, JSValue::kSize, |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1716 | isolate()->initial_object_prototype(), |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1717 | Builtins::kIllegal, false, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1718 | Handle<JSObject> prototype = |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1719 | factory()->NewJSObject(isolate()->object_function(), TENURED); |
rossberg@chromium.org | ebeba02 | 2013-08-19 09:36:44 +0000 | [diff] [blame] | 1720 | Accessors::FunctionSetPrototype(script_fun, prototype); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1721 | native_context()->set_script_function(*script_fun); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1722 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1723 | Handle<Map> script_map = Handle<Map>(script_fun->initial_map()); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1724 | |
| 1725 | Handle<DescriptorArray> script_descriptors( |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1726 | factory()->NewDescriptorArray(0, 13)); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1727 | DescriptorArray::WhitenessWitness witness(*script_descriptors); |
| 1728 | |
| 1729 | Handle<Foreign> script_source( |
| 1730 | factory()->NewForeign(&Accessors::ScriptSource)); |
| 1731 | Handle<Foreign> script_name(factory()->NewForeign(&Accessors::ScriptName)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1732 | Handle<String> id_string(factory()->InternalizeOneByteString( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1733 | STATIC_ASCII_VECTOR("id"))); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1734 | Handle<Foreign> script_id(factory()->NewForeign(&Accessors::ScriptId)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1735 | Handle<String> line_offset_string( |
| 1736 | factory()->InternalizeOneByteString( |
| 1737 | STATIC_ASCII_VECTOR("line_offset"))); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1738 | Handle<Foreign> script_line_offset( |
| 1739 | factory()->NewForeign(&Accessors::ScriptLineOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1740 | Handle<String> column_offset_string( |
| 1741 | factory()->InternalizeOneByteString( |
| 1742 | STATIC_ASCII_VECTOR("column_offset"))); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1743 | Handle<Foreign> script_column_offset( |
| 1744 | factory()->NewForeign(&Accessors::ScriptColumnOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1745 | Handle<String> data_string(factory()->InternalizeOneByteString( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1746 | STATIC_ASCII_VECTOR("data"))); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1747 | Handle<Foreign> script_data(factory()->NewForeign(&Accessors::ScriptData)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1748 | Handle<String> type_string(factory()->InternalizeOneByteString( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1749 | STATIC_ASCII_VECTOR("type"))); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1750 | Handle<Foreign> script_type(factory()->NewForeign(&Accessors::ScriptType)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1751 | Handle<String> compilation_type_string( |
| 1752 | factory()->InternalizeOneByteString( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1753 | STATIC_ASCII_VECTOR("compilation_type"))); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1754 | Handle<Foreign> script_compilation_type( |
| 1755 | factory()->NewForeign(&Accessors::ScriptCompilationType)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1756 | Handle<String> line_ends_string(factory()->InternalizeOneByteString( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1757 | STATIC_ASCII_VECTOR("line_ends"))); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1758 | Handle<Foreign> script_line_ends( |
| 1759 | factory()->NewForeign(&Accessors::ScriptLineEnds)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1760 | Handle<String> context_data_string( |
| 1761 | factory()->InternalizeOneByteString( |
| 1762 | STATIC_ASCII_VECTOR("context_data"))); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1763 | Handle<Foreign> script_context_data( |
| 1764 | factory()->NewForeign(&Accessors::ScriptContextData)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1765 | Handle<String> eval_from_script_string( |
| 1766 | factory()->InternalizeOneByteString( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1767 | STATIC_ASCII_VECTOR("eval_from_script"))); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1768 | Handle<Foreign> script_eval_from_script( |
| 1769 | factory()->NewForeign(&Accessors::ScriptEvalFromScript)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1770 | Handle<String> eval_from_script_position_string( |
| 1771 | factory()->InternalizeOneByteString( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1772 | STATIC_ASCII_VECTOR("eval_from_script_position"))); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1773 | Handle<Foreign> script_eval_from_script_position( |
| 1774 | factory()->NewForeign(&Accessors::ScriptEvalFromScriptPosition)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1775 | Handle<String> eval_from_function_name_string( |
| 1776 | factory()->InternalizeOneByteString( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1777 | STATIC_ASCII_VECTOR("eval_from_function_name"))); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1778 | Handle<Foreign> script_eval_from_function_name( |
| 1779 | factory()->NewForeign(&Accessors::ScriptEvalFromFunctionName)); |
| 1780 | PropertyAttributes attribs = |
| 1781 | static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 1782 | script_map->set_instance_descriptors(*script_descriptors); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1783 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1784 | { |
| 1785 | CallbacksDescriptor d( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1786 | *factory()->source_string(), *script_source, attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1787 | script_map->AppendDescriptor(&d, witness); |
| 1788 | } |
| 1789 | |
| 1790 | { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1791 | CallbacksDescriptor d(*factory()->name_string(), *script_name, attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1792 | script_map->AppendDescriptor(&d, witness); |
| 1793 | } |
| 1794 | |
| 1795 | { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1796 | CallbacksDescriptor d(*id_string, *script_id, attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1797 | script_map->AppendDescriptor(&d, witness); |
| 1798 | } |
| 1799 | |
| 1800 | { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1801 | CallbacksDescriptor d(*line_offset_string, *script_line_offset, attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1802 | script_map->AppendDescriptor(&d, witness); |
| 1803 | } |
| 1804 | |
| 1805 | { |
| 1806 | CallbacksDescriptor d( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1807 | *column_offset_string, *script_column_offset, attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1808 | script_map->AppendDescriptor(&d, witness); |
| 1809 | } |
| 1810 | |
| 1811 | { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1812 | CallbacksDescriptor d(*data_string, *script_data, attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1813 | script_map->AppendDescriptor(&d, witness); |
| 1814 | } |
| 1815 | |
| 1816 | { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1817 | CallbacksDescriptor d(*type_string, *script_type, attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1818 | script_map->AppendDescriptor(&d, witness); |
| 1819 | } |
| 1820 | |
| 1821 | { |
| 1822 | CallbacksDescriptor d( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1823 | *compilation_type_string, *script_compilation_type, attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1824 | script_map->AppendDescriptor(&d, witness); |
| 1825 | } |
| 1826 | |
| 1827 | { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1828 | CallbacksDescriptor d(*line_ends_string, *script_line_ends, attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1829 | script_map->AppendDescriptor(&d, witness); |
| 1830 | } |
| 1831 | |
| 1832 | { |
| 1833 | CallbacksDescriptor d( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1834 | *context_data_string, *script_context_data, attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1835 | script_map->AppendDescriptor(&d, witness); |
| 1836 | } |
| 1837 | |
| 1838 | { |
| 1839 | CallbacksDescriptor d( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1840 | *eval_from_script_string, *script_eval_from_script, attribs); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1841 | script_map->AppendDescriptor(&d, witness); |
| 1842 | } |
| 1843 | |
| 1844 | { |
| 1845 | CallbacksDescriptor d( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1846 | *eval_from_script_position_string, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1847 | *script_eval_from_script_position, |
| 1848 | attribs); |
| 1849 | script_map->AppendDescriptor(&d, witness); |
| 1850 | } |
| 1851 | |
| 1852 | { |
| 1853 | CallbacksDescriptor d( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1854 | *eval_from_function_name_string, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1855 | *script_eval_from_function_name, |
| 1856 | attribs); |
| 1857 | script_map->AppendDescriptor(&d, witness); |
| 1858 | } |
| 1859 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1860 | // Allocate the empty script. |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1861 | Handle<Script> script = factory()->NewScript(factory()->empty_string()); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1862 | script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1863 | heap()->public_set_empty_script(*script); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1864 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1865 | { |
| 1866 | // Builtin function for OpaqueReference -- a JSValue-based object, |
| 1867 | // that keeps its field isolated from JavaScript code. It may store |
| 1868 | // objects, that JavaScript code may not access. |
| 1869 | Handle<JSFunction> opaque_reference_fun = |
| 1870 | InstallFunction(builtins, "OpaqueReference", JS_VALUE_TYPE, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1871 | JSValue::kSize, |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1872 | isolate()->initial_object_prototype(), |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1873 | Builtins::kIllegal, false, false); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1874 | Handle<JSObject> prototype = |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1875 | factory()->NewJSObject(isolate()->object_function(), TENURED); |
rossberg@chromium.org | ebeba02 | 2013-08-19 09:36:44 +0000 | [diff] [blame] | 1876 | Accessors::FunctionSetPrototype(opaque_reference_fun, prototype); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1877 | native_context()->set_opaque_reference_function(*opaque_reference_fun); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1878 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1879 | |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1880 | // InternalArrays should not use Smi-Only array optimizations. There are too |
| 1881 | // many places in the C++ runtime code (e.g. RegEx) that assume that |
| 1882 | // elements in InternalArrays can be set to non-Smi values without going |
| 1883 | // through a common bottleneck that would make the SMI_ONLY -> FAST_ELEMENT |
| 1884 | // transition easy to trap. Moreover, they rarely are smi-only. |
| 1885 | { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1886 | Handle<JSFunction> array_function = |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1887 | InstallInternalArray(builtins, "InternalArray", FAST_HOLEY_ELEMENTS); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1888 | native_context()->set_internal_array_function(*array_function); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1889 | } |
| 1890 | |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1891 | { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 1892 | InstallInternalArray(builtins, "InternalPackedArray", FAST_ELEMENTS); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1893 | } |
| 1894 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1895 | if (FLAG_disable_native_files) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1896 | PrintF("Warning: Running without installed natives!\n"); |
| 1897 | return true; |
| 1898 | } |
| 1899 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1900 | // Install natives. |
| 1901 | for (int i = Natives::GetDebuggerCount(); |
| 1902 | i < Natives::GetBuiltinsCount(); |
| 1903 | i++) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1904 | if (!CompileBuiltin(isolate(), i)) return false; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1905 | // TODO(ager): We really only need to install the JS builtin |
| 1906 | // functions on the builtins object after compiling and running |
| 1907 | // runtime.js. |
| 1908 | if (!InstallJSBuiltins(builtins)) return false; |
| 1909 | } |
| 1910 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1911 | InstallNativeFunctions(); |
| 1912 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1913 | // Store the map for the string prototype after the natives has been compiled |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1914 | // and the String function has been set up. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1915 | Handle<JSFunction> string_function(native_context()->string_function()); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1916 | ASSERT(JSObject::cast( |
| 1917 | string_function->initial_map()->prototype())->HasFastProperties()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1918 | native_context()->set_string_function_prototype_map( |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1919 | HeapObject::cast(string_function->initial_map()->prototype())->map()); |
| 1920 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1921 | // Install Function.prototype.call and apply. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1922 | { Handle<String> key = factory()->function_class_string(); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1923 | Handle<JSFunction> function = |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1924 | Handle<JSFunction>::cast( |
| 1925 | GetProperty(isolate(), isolate()->global_object(), key)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1926 | Handle<JSObject> proto = |
| 1927 | Handle<JSObject>(JSObject::cast(function->instance_prototype())); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1928 | |
| 1929 | // Install the call and the apply functions. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1930 | Handle<JSFunction> call = |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1931 | InstallFunction(proto, "call", JS_OBJECT_TYPE, JSObject::kHeaderSize, |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 1932 | Handle<JSObject>::null(), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1933 | Builtins::kFunctionCall, |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1934 | false, false); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1935 | Handle<JSFunction> apply = |
| 1936 | InstallFunction(proto, "apply", JS_OBJECT_TYPE, JSObject::kHeaderSize, |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 1937 | Handle<JSObject>::null(), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1938 | Builtins::kFunctionApply, |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1939 | false, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1940 | |
| 1941 | // Make sure that Function.prototype.call appears to be compiled. |
| 1942 | // The code will never be called, but inline caching for call will |
| 1943 | // only work if it appears to be compiled. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1944 | call->shared()->DontAdaptArguments(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1945 | ASSERT(call->is_compiled()); |
| 1946 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1947 | // Set the expected parameters for apply to 2; required by builtin. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1948 | apply->shared()->set_formal_parameter_count(2); |
| 1949 | |
| 1950 | // Set the lengths for the functions to satisfy ECMA-262. |
| 1951 | call->shared()->set_length(1); |
| 1952 | apply->shared()->set_length(2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1953 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1954 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1955 | InstallBuiltinFunctionIds(); |
| 1956 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1957 | // Create a constructor for RegExp results (a variant of Array that |
| 1958 | // predefines the two properties index and match). |
| 1959 | { |
| 1960 | // RegExpResult initial map. |
| 1961 | |
| 1962 | // Find global.Array.prototype to inherit from. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1963 | Handle<JSFunction> array_constructor(native_context()->array_function()); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1964 | Handle<JSObject> array_prototype( |
| 1965 | JSObject::cast(array_constructor->instance_prototype())); |
| 1966 | |
| 1967 | // Add initial map. |
| 1968 | Handle<Map> initial_map = |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1969 | factory()->NewMap(JS_ARRAY_TYPE, JSRegExpResult::kSize); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1970 | initial_map->set_constructor(*array_constructor); |
| 1971 | |
| 1972 | // Set prototype on map. |
| 1973 | initial_map->set_non_instance_prototype(false); |
| 1974 | initial_map->set_prototype(*array_prototype); |
| 1975 | |
| 1976 | // Update map with length accessor from Array and add "index" and "input". |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1977 | Handle<DescriptorArray> reresult_descriptors = |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1978 | factory()->NewDescriptorArray(0, 3); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1979 | DescriptorArray::WhitenessWitness witness(*reresult_descriptors); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 1980 | initial_map->set_instance_descriptors(*reresult_descriptors); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1981 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1982 | { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1983 | JSFunction* array_function = native_context()->array_function(); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1984 | Handle<DescriptorArray> array_descriptors( |
| 1985 | array_function->initial_map()->instance_descriptors()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1986 | String* length = heap()->length_string(); |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 1987 | int old = array_descriptors->SearchWithCache( |
| 1988 | length, array_function->initial_map()); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1989 | ASSERT(old != DescriptorArray::kNotFound); |
| 1990 | CallbacksDescriptor desc(length, |
| 1991 | array_descriptors->GetValue(old), |
| 1992 | array_descriptors->GetDetails(old).attributes()); |
| 1993 | initial_map->AppendDescriptor(&desc, witness); |
| 1994 | } |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1995 | { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1996 | FieldDescriptor index_field(heap()->index_string(), |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1997 | JSRegExpResult::kIndexIndex, |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1998 | NONE, |
| 1999 | Representation::Tagged()); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 2000 | initial_map->AppendDescriptor(&index_field, witness); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2004 | FieldDescriptor input_field(heap()->input_string(), |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 2005 | JSRegExpResult::kInputIndex, |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2006 | NONE, |
| 2007 | Representation::Tagged()); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 2008 | initial_map->AppendDescriptor(&input_field, witness); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 2009 | } |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 2010 | |
| 2011 | initial_map->set_inobject_properties(2); |
| 2012 | initial_map->set_pre_allocated_property_fields(2); |
| 2013 | initial_map->set_unused_property_fields(0); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 2014 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2015 | native_context()->set_regexp_result_map(*initial_map); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2018 | #ifdef VERIFY_HEAP |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2019 | builtins->Verify(); |
| 2020 | #endif |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2021 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2022 | return true; |
| 2023 | } |
| 2024 | |
| 2025 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2026 | bool Genesis::InstallExperimentalNatives() { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2027 | for (int i = ExperimentalNatives::GetDebuggerCount(); |
| 2028 | i < ExperimentalNatives::GetBuiltinsCount(); |
| 2029 | i++) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2030 | if (FLAG_harmony_symbols && |
| 2031 | strcmp(ExperimentalNatives::GetScriptName(i).start(), |
| 2032 | "native symbol.js") == 0) { |
| 2033 | if (!CompileExperimentalBuiltin(isolate(), i)) return false; |
| 2034 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2035 | if (FLAG_harmony_proxies && |
| 2036 | strcmp(ExperimentalNatives::GetScriptName(i).start(), |
| 2037 | "native proxy.js") == 0) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2038 | if (!CompileExperimentalBuiltin(isolate(), i)) return false; |
| 2039 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2040 | if (FLAG_harmony_collections && |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2041 | strcmp(ExperimentalNatives::GetScriptName(i).start(), |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2042 | "native collection.js") == 0) { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2043 | if (!CompileExperimentalBuiltin(isolate(), i)) return false; |
| 2044 | } |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 2045 | if (FLAG_harmony_observation && |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 2046 | strcmp(ExperimentalNatives::GetScriptName(i).start(), |
| 2047 | "native object-observe.js") == 0) { |
| 2048 | if (!CompileExperimentalBuiltin(isolate(), i)) return false; |
| 2049 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2050 | if (FLAG_harmony_generators && |
| 2051 | strcmp(ExperimentalNatives::GetScriptName(i).start(), |
| 2052 | "native generator.js") == 0) { |
| 2053 | if (!CompileExperimentalBuiltin(isolate(), i)) return false; |
| 2054 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2055 | if (FLAG_harmony_iteration && |
| 2056 | strcmp(ExperimentalNatives::GetScriptName(i).start(), |
| 2057 | "native array-iterator.js") == 0) { |
| 2058 | if (!CompileExperimentalBuiltin(isolate(), i)) return false; |
| 2059 | } |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2060 | if (FLAG_harmony_strings && |
| 2061 | strcmp(ExperimentalNatives::GetScriptName(i).start(), |
| 2062 | "native harmony-string.js") == 0) { |
| 2063 | if (!CompileExperimentalBuiltin(isolate(), i)) return false; |
| 2064 | } |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2065 | if (FLAG_harmony_arrays && |
| 2066 | strcmp(ExperimentalNatives::GetScriptName(i).start(), |
| 2067 | "native harmony-array.js") == 0) { |
| 2068 | if (!CompileExperimentalBuiltin(isolate(), i)) return false; |
| 2069 | } |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2070 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2071 | |
| 2072 | InstallExperimentalNativeFunctions(); |
| 2073 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2074 | return true; |
| 2075 | } |
| 2076 | |
| 2077 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2078 | static Handle<JSObject> ResolveBuiltinIdHolder( |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2079 | Handle<Context> native_context, |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2080 | const char* holder_expr) { |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2081 | Isolate* isolate = native_context->GetIsolate(); |
| 2082 | Factory* factory = isolate->factory(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2083 | Handle<GlobalObject> global(native_context->global_object()); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2084 | const char* period_pos = strchr(holder_expr, '.'); |
| 2085 | if (period_pos == NULL) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2086 | return Handle<JSObject>::cast(GetProperty( |
| 2087 | isolate, global, factory->InternalizeUtf8String(holder_expr))); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2088 | } |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2089 | ASSERT_EQ(".prototype", period_pos); |
| 2090 | Vector<const char> property(holder_expr, |
| 2091 | static_cast<int>(period_pos - holder_expr)); |
| 2092 | Handle<JSFunction> function = Handle<JSFunction>::cast( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2093 | GetProperty(isolate, global, factory->InternalizeUtf8String(property))); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2094 | return Handle<JSObject>(JSObject::cast(function->prototype())); |
| 2095 | } |
| 2096 | |
| 2097 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2098 | static void InstallBuiltinFunctionId(Handle<JSObject> holder, |
| 2099 | const char* function_name, |
| 2100 | BuiltinFunctionId id) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2101 | Factory* factory = holder->GetIsolate()->factory(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2102 | Handle<String> name = factory->InternalizeUtf8String(function_name); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2103 | Object* function_object = holder->GetProperty(*name)->ToObjectUnchecked(); |
| 2104 | Handle<JSFunction> function(JSFunction::cast(function_object)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2105 | function->shared()->set_function_data(Smi::FromInt(id)); |
| 2106 | } |
| 2107 | |
| 2108 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2109 | void Genesis::InstallBuiltinFunctionIds() { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2110 | HandleScope scope(isolate()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2111 | #define INSTALL_BUILTIN_ID(holder_expr, fun_name, name) \ |
| 2112 | { \ |
| 2113 | Handle<JSObject> holder = ResolveBuiltinIdHolder( \ |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2114 | native_context(), #holder_expr); \ |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2115 | BuiltinFunctionId id = k##name; \ |
| 2116 | InstallBuiltinFunctionId(holder, #fun_name, id); \ |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2117 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2118 | FUNCTIONS_WITH_ID_LIST(INSTALL_BUILTIN_ID) |
| 2119 | #undef INSTALL_BUILTIN_ID |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2120 | } |
| 2121 | |
| 2122 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2123 | // Do not forget to update macros.py with named constant |
| 2124 | // of cache id. |
| 2125 | #define JSFUNCTION_RESULT_CACHE_LIST(F) \ |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2126 | F(16, native_context()->regexp_function()) |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2127 | |
| 2128 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2129 | static FixedArray* CreateCache(int size, Handle<JSFunction> factory_function) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2130 | Factory* factory = factory_function->GetIsolate()->factory(); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2131 | // Caches are supposed to live for a long time, allocate in old space. |
| 2132 | int array_size = JSFunctionResultCache::kEntriesIndex + 2 * size; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2133 | // Cannot use cast as object is not fully initialized yet. |
| 2134 | JSFunctionResultCache* cache = reinterpret_cast<JSFunctionResultCache*>( |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2135 | *factory->NewFixedArrayWithHoles(array_size, TENURED)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2136 | cache->set(JSFunctionResultCache::kFactoryIndex, *factory_function); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2137 | cache->MakeZeroSize(); |
| 2138 | return cache; |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | |
| 2142 | void Genesis::InstallJSFunctionResultCaches() { |
| 2143 | const int kNumberOfCaches = 0 + |
| 2144 | #define F(size, func) + 1 |
| 2145 | JSFUNCTION_RESULT_CACHE_LIST(F) |
| 2146 | #undef F |
| 2147 | ; |
| 2148 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 2149 | Handle<FixedArray> caches = |
| 2150 | factory()->NewFixedArray(kNumberOfCaches, TENURED); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2151 | |
| 2152 | int index = 0; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2153 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2154 | #define F(size, func) do { \ |
| 2155 | FixedArray* cache = CreateCache((size), Handle<JSFunction>(func)); \ |
| 2156 | caches->set(index++, cache); \ |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2157 | } while (false) |
| 2158 | |
| 2159 | JSFUNCTION_RESULT_CACHE_LIST(F); |
| 2160 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2161 | #undef F |
| 2162 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2163 | native_context()->set_jsfunction_result_caches(*caches); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2164 | } |
| 2165 | |
| 2166 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2167 | void Genesis::InitializeNormalizedMapCaches() { |
| 2168 | Handle<FixedArray> array( |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 2169 | factory()->NewFixedArray(NormalizedMapCache::kEntries, TENURED)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2170 | native_context()->set_normalized_map_cache(NormalizedMapCache::cast(*array)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2171 | } |
| 2172 | |
| 2173 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2174 | bool Bootstrapper::InstallExtensions(Handle<Context> native_context, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2175 | v8::ExtensionConfiguration* extensions) { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2176 | BootstrapperActive active(this); |
| 2177 | SaveContext saved_context(isolate_); |
| 2178 | isolate_->set_context(*native_context); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2179 | if (!Genesis::InstallExtensions(native_context, extensions)) return false; |
| 2180 | Genesis::InstallSpecialObjects(native_context); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2181 | return true; |
| 2182 | } |
| 2183 | |
| 2184 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2185 | void Genesis::InstallSpecialObjects(Handle<Context> native_context) { |
| 2186 | Isolate* isolate = native_context->GetIsolate(); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2187 | Factory* factory = isolate->factory(); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2188 | HandleScope scope(isolate); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2189 | Handle<JSGlobalObject> global(JSGlobalObject::cast( |
| 2190 | native_context->global_object())); |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 2191 | // Expose the natives in global if a name for it is specified. |
| 2192 | if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2193 | Handle<String> natives = |
| 2194 | factory->InternalizeUtf8String(FLAG_expose_natives_as); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2195 | CHECK_NOT_EMPTY_HANDLE(isolate, |
| 2196 | JSObject::SetLocalPropertyIgnoreAttributes( |
| 2197 | global, natives, |
| 2198 | Handle<JSObject>(global->builtins()), |
| 2199 | DONT_ENUM)); |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 2200 | } |
| 2201 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2202 | Handle<Object> Error = GetProperty(global, "Error"); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2203 | if (Error->IsJSObject()) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2204 | Handle<String> name = factory->InternalizeOneByteString( |
| 2205 | STATIC_ASCII_VECTOR("stackTraceLimit")); |
| 2206 | Handle<Smi> stack_trace_limit( |
| 2207 | Smi::FromInt(FLAG_stack_trace_limit), isolate); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2208 | CHECK_NOT_EMPTY_HANDLE(isolate, |
| 2209 | JSObject::SetLocalPropertyIgnoreAttributes( |
| 2210 | Handle<JSObject>::cast(Error), name, |
| 2211 | stack_trace_limit, NONE)); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2212 | } |
| 2213 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2214 | #ifdef ENABLE_DEBUGGER_SUPPORT |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 2215 | // Expose the debug global object in global if a name for it is specified. |
| 2216 | if (FLAG_expose_debug_as != NULL && strlen(FLAG_expose_debug_as) != 0) { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2217 | Debug* debug = isolate->debug(); |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 2218 | // If loading fails we just bail out without installing the |
| 2219 | // debugger but without tanking the whole context. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2220 | if (!debug->Load()) return; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2221 | // Set the security token for the debugger context to the same as |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2222 | // the shell native context to allow calling between these (otherwise |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2223 | // exposing debug global object doesn't make much sense). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2224 | debug->debug_context()->set_security_token( |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2225 | native_context->security_token()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2226 | |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 2227 | Handle<String> debug_string = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2228 | factory->InternalizeUtf8String(FLAG_expose_debug_as); |
| 2229 | Handle<Object> global_proxy( |
| 2230 | debug->debug_context()->global_proxy(), isolate); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2231 | CHECK_NOT_EMPTY_HANDLE(isolate, |
| 2232 | JSObject::SetLocalPropertyIgnoreAttributes( |
| 2233 | global, debug_string, global_proxy, DONT_ENUM)); |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 2234 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2235 | #endif |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 2236 | } |
| 2237 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2238 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2239 | static uint32_t Hash(RegisteredExtension* extension) { |
| 2240 | return v8::internal::ComputePointerHash(extension); |
| 2241 | } |
| 2242 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2243 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2244 | static bool MatchRegisteredExtensions(void* key1, void* key2) { |
| 2245 | return key1 == key2; |
| 2246 | } |
| 2247 | |
| 2248 | Genesis::ExtensionStates::ExtensionStates() |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 2249 | : map_(MatchRegisteredExtensions, 8) { } |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2250 | |
| 2251 | Genesis::ExtensionTraversalState Genesis::ExtensionStates::get_state( |
| 2252 | RegisteredExtension* extension) { |
| 2253 | i::HashMap::Entry* entry = map_.Lookup(extension, Hash(extension), false); |
| 2254 | if (entry == NULL) { |
| 2255 | return UNVISITED; |
| 2256 | } |
| 2257 | return static_cast<ExtensionTraversalState>( |
| 2258 | reinterpret_cast<intptr_t>(entry->value)); |
| 2259 | } |
| 2260 | |
| 2261 | void Genesis::ExtensionStates::set_state(RegisteredExtension* extension, |
| 2262 | ExtensionTraversalState state) { |
| 2263 | map_.Lookup(extension, Hash(extension), true)->value = |
| 2264 | reinterpret_cast<void*>(static_cast<intptr_t>(state)); |
| 2265 | } |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 2266 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2267 | bool Genesis::InstallExtensions(Handle<Context> native_context, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2268 | v8::ExtensionConfiguration* extensions) { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2269 | Isolate* isolate = native_context->GetIsolate(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2270 | ExtensionStates extension_states; // All extensions have state UNVISITED. |
| 2271 | // Install auto extensions. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2272 | v8::RegisteredExtension* current = v8::RegisteredExtension::first_extension(); |
| 2273 | while (current != NULL) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2274 | if (current->extension()->auto_enable()) |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2275 | InstallExtension(isolate, current, &extension_states); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2276 | current = current->next(); |
| 2277 | } |
| 2278 | |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2279 | if (FLAG_expose_gc) InstallExtension(isolate, "v8/gc", &extension_states); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2280 | if (FLAG_expose_externalize_string) { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2281 | InstallExtension(isolate, "v8/externalize", &extension_states); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2282 | } |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 2283 | if (FLAG_track_gc_object_stats) { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2284 | InstallExtension(isolate, "v8/statistics", &extension_states); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 2285 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2286 | |
| 2287 | if (extensions == NULL) return true; |
| 2288 | // Install required extensions |
| 2289 | int count = v8::ImplementationUtilities::GetNameCount(extensions); |
| 2290 | const char** names = v8::ImplementationUtilities::GetNames(extensions); |
| 2291 | for (int i = 0; i < count; i++) { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2292 | if (!InstallExtension(isolate, names[i], &extension_states)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2293 | return false; |
| 2294 | } |
| 2295 | |
| 2296 | return true; |
| 2297 | } |
| 2298 | |
| 2299 | |
| 2300 | // Installs a named extension. This methods is unoptimized and does |
| 2301 | // not scale well if we want to support a large number of extensions. |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2302 | bool Genesis::InstallExtension(Isolate* isolate, |
| 2303 | const char* name, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2304 | ExtensionStates* extension_states) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2305 | v8::RegisteredExtension* current = v8::RegisteredExtension::first_extension(); |
| 2306 | // Loop until we find the relevant extension |
| 2307 | while (current != NULL) { |
| 2308 | if (strcmp(name, current->extension()->name()) == 0) break; |
| 2309 | current = current->next(); |
| 2310 | } |
| 2311 | // Didn't find the extension; fail. |
| 2312 | if (current == NULL) { |
| 2313 | v8::Utils::ReportApiFailure( |
| 2314 | "v8::Context::New()", "Cannot find required extension"); |
| 2315 | return false; |
| 2316 | } |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2317 | return InstallExtension(isolate, current, extension_states); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2318 | } |
| 2319 | |
| 2320 | |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2321 | bool Genesis::InstallExtension(Isolate* isolate, |
| 2322 | v8::RegisteredExtension* current, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2323 | ExtensionStates* extension_states) { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2324 | HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2325 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2326 | if (extension_states->get_state(current) == INSTALLED) return true; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2327 | // The current node has already been visited so there must be a |
| 2328 | // cycle in the dependency graph; fail. |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2329 | if (extension_states->get_state(current) == VISITED) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2330 | v8::Utils::ReportApiFailure( |
| 2331 | "v8::Context::New()", "Circular extension dependency"); |
| 2332 | return false; |
| 2333 | } |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2334 | ASSERT(extension_states->get_state(current) == UNVISITED); |
| 2335 | extension_states->set_state(current, VISITED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2336 | v8::Extension* extension = current->extension(); |
| 2337 | // Install the extension's dependencies |
| 2338 | for (int i = 0; i < extension->dependency_count(); i++) { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2339 | if (!InstallExtension(isolate, |
| 2340 | extension->dependencies()[i], |
| 2341 | extension_states)) { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2342 | return false; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2343 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2344 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2345 | Handle<String> source_code = |
| 2346 | isolate->factory()->NewExternalStringFromAscii(extension->source()); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2347 | bool result = CompileScriptCached(isolate, |
| 2348 | CStrVector(extension->name()), |
| 2349 | source_code, |
| 2350 | isolate->bootstrapper()->extensions_cache(), |
| 2351 | extension, |
| 2352 | Handle<Context>(isolate->context()), |
| 2353 | false); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2354 | ASSERT(isolate->has_pending_exception() != result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2355 | if (!result) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2356 | // We print out the name of the extension that fail to install. |
| 2357 | // When an error is thrown during bootstrapping we automatically print |
| 2358 | // the line number at which this happened to the console in the isolate |
| 2359 | // error throwing functionality. |
| 2360 | OS::PrintError("Error installing extension '%s'.\n", |
| 2361 | current->extension()->name()); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2362 | isolate->clear_pending_exception(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2363 | } |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2364 | extension_states->set_state(current, INSTALLED); |
| 2365 | isolate->NotifyExtensionInstalled(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2366 | return result; |
| 2367 | } |
| 2368 | |
| 2369 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2370 | bool Genesis::InstallJSBuiltins(Handle<JSBuiltinsObject> builtins) { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2371 | HandleScope scope(isolate()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2372 | for (int i = 0; i < Builtins::NumberOfJavaScriptBuiltins(); i++) { |
| 2373 | Builtins::JavaScript id = static_cast<Builtins::JavaScript>(i); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2374 | Handle<String> name = |
| 2375 | factory()->InternalizeUtf8String(Builtins::GetName(id)); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2376 | Object* function_object = builtins->GetPropertyNoExceptionThrown(*name); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2377 | Handle<JSFunction> function |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2378 | = Handle<JSFunction>(JSFunction::cast(function_object)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2379 | builtins->set_javascript_builtin(id, *function); |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2380 | if (!JSFunction::CompileLazy(function, CLEAR_EXCEPTION)) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2381 | return false; |
| 2382 | } |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2383 | builtins->set_javascript_builtin_code(id, function->shared()->code()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2384 | } |
| 2385 | return true; |
| 2386 | } |
| 2387 | |
| 2388 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2389 | bool Genesis::ConfigureGlobalObjects( |
| 2390 | v8::Handle<v8::ObjectTemplate> global_proxy_template) { |
| 2391 | Handle<JSObject> global_proxy( |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2392 | JSObject::cast(native_context()->global_proxy())); |
| 2393 | Handle<JSObject> inner_global( |
| 2394 | JSObject::cast(native_context()->global_object())); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2395 | |
| 2396 | if (!global_proxy_template.IsEmpty()) { |
| 2397 | // Configure the global proxy object. |
| 2398 | Handle<ObjectTemplateInfo> proxy_data = |
| 2399 | v8::Utils::OpenHandle(*global_proxy_template); |
| 2400 | if (!ConfigureApiObject(global_proxy, proxy_data)) return false; |
| 2401 | |
| 2402 | // Configure the inner global object. |
| 2403 | Handle<FunctionTemplateInfo> proxy_constructor( |
| 2404 | FunctionTemplateInfo::cast(proxy_data->constructor())); |
| 2405 | if (!proxy_constructor->prototype_template()->IsUndefined()) { |
| 2406 | Handle<ObjectTemplateInfo> inner_data( |
| 2407 | ObjectTemplateInfo::cast(proxy_constructor->prototype_template())); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2408 | if (!ConfigureApiObject(inner_global, inner_data)) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2409 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2410 | } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2411 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2412 | SetObjectPrototype(global_proxy, inner_global); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 2413 | |
| 2414 | native_context()->set_initial_array_prototype( |
| 2415 | JSArray::cast(native_context()->array_function()->prototype())); |
| 2416 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2417 | return true; |
| 2418 | } |
| 2419 | |
| 2420 | |
| 2421 | bool Genesis::ConfigureApiObject(Handle<JSObject> object, |
| 2422 | Handle<ObjectTemplateInfo> object_template) { |
| 2423 | ASSERT(!object_template.is_null()); |
| 2424 | ASSERT(object->IsInstanceOf( |
| 2425 | FunctionTemplateInfo::cast(object_template->constructor()))); |
| 2426 | |
| 2427 | bool pending_exception = false; |
| 2428 | Handle<JSObject> obj = |
| 2429 | Execution::InstantiateObject(object_template, &pending_exception); |
| 2430 | if (pending_exception) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2431 | ASSERT(isolate()->has_pending_exception()); |
| 2432 | isolate()->clear_pending_exception(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2433 | return false; |
| 2434 | } |
| 2435 | TransferObject(obj, object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2436 | return true; |
| 2437 | } |
| 2438 | |
| 2439 | |
| 2440 | void Genesis::TransferNamedProperties(Handle<JSObject> from, |
| 2441 | Handle<JSObject> to) { |
| 2442 | if (from->HasFastProperties()) { |
| 2443 | Handle<DescriptorArray> descs = |
| 2444 | Handle<DescriptorArray>(from->map()->instance_descriptors()); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2445 | for (int i = 0; i < from->map()->NumberOfOwnDescriptors(); i++) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 2446 | PropertyDetails details = descs->GetDetails(i); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2447 | switch (details.type()) { |
| 2448 | case FIELD: { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2449 | HandleScope inner(isolate()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2450 | Handle<Name> key = Handle<Name>(descs->GetKey(i)); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2451 | int index = descs->GetFieldIndex(i); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2452 | ASSERT(!descs->GetDetails(i).representation().IsDouble()); |
| 2453 | Handle<Object> value = Handle<Object>(from->RawFastPropertyAt(index), |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2454 | isolate()); |
| 2455 | CHECK_NOT_EMPTY_HANDLE(isolate(), |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2456 | JSObject::SetLocalPropertyIgnoreAttributes( |
| 2457 | to, key, value, details.attributes())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2458 | break; |
| 2459 | } |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2460 | case CONSTANT: { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2461 | HandleScope inner(isolate()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2462 | Handle<Name> key = Handle<Name>(descs->GetKey(i)); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2463 | Handle<Object> constant(descs->GetConstant(i), isolate()); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2464 | CHECK_NOT_EMPTY_HANDLE(isolate(), |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2465 | JSObject::SetLocalPropertyIgnoreAttributes( |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2466 | to, key, constant, details.attributes())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2467 | break; |
| 2468 | } |
| 2469 | case CALLBACKS: { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2470 | LookupResult result(isolate()); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2471 | to->LocalLookup(descs->GetKey(i), &result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2472 | // If the property is already there we skip it |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 2473 | if (result.IsFound()) continue; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2474 | HandleScope inner(isolate()); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2475 | ASSERT(!to->HasFastProperties()); |
| 2476 | // Add to dictionary. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2477 | Handle<Name> key = Handle<Name>(descs->GetKey(i)); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2478 | Handle<Object> callbacks(descs->GetCallbacksObject(i), isolate()); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2479 | PropertyDetails d = PropertyDetails( |
| 2480 | details.attributes(), CALLBACKS, i + 1); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2481 | JSObject::SetNormalizedProperty(to, key, callbacks, d); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2482 | break; |
| 2483 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2484 | case NORMAL: |
| 2485 | // Do not occur since the from object has fast properties. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2486 | case HANDLER: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2487 | case INTERCEPTOR: |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 2488 | case TRANSITION: |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2489 | case NONEXISTENT: |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2490 | // No element in instance descriptors have proxy or interceptor type. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2491 | UNREACHABLE(); |
| 2492 | break; |
| 2493 | } |
| 2494 | } |
| 2495 | } else { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2496 | Handle<NameDictionary> properties = |
| 2497 | Handle<NameDictionary>(from->property_dictionary()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2498 | int capacity = properties->Capacity(); |
| 2499 | for (int i = 0; i < capacity; i++) { |
| 2500 | Object* raw_key(properties->KeyAt(i)); |
| 2501 | if (properties->IsKey(raw_key)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2502 | ASSERT(raw_key->IsName()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2503 | // If the property is already there we skip it. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2504 | LookupResult result(isolate()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2505 | to->LocalLookup(Name::cast(raw_key), &result); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 2506 | if (result.IsFound()) continue; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2507 | // Set the property. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2508 | Handle<Name> key = Handle<Name>(Name::cast(raw_key)); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2509 | Handle<Object> value = Handle<Object>(properties->ValueAt(i), |
| 2510 | isolate()); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2511 | ASSERT(!value->IsCell()); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 2512 | if (value->IsPropertyCell()) { |
| 2513 | value = Handle<Object>(PropertyCell::cast(*value)->value(), |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2514 | isolate()); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2515 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2516 | PropertyDetails details = properties->DetailsAt(i); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2517 | CHECK_NOT_EMPTY_HANDLE(isolate(), |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2518 | JSObject::SetLocalPropertyIgnoreAttributes( |
| 2519 | to, key, value, details.attributes())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2520 | } |
| 2521 | } |
| 2522 | } |
| 2523 | } |
| 2524 | |
| 2525 | |
| 2526 | void Genesis::TransferIndexedProperties(Handle<JSObject> from, |
| 2527 | Handle<JSObject> to) { |
| 2528 | // Cloning the elements array is sufficient. |
| 2529 | Handle<FixedArray> from_elements = |
| 2530 | Handle<FixedArray>(FixedArray::cast(from->elements())); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 2531 | Handle<FixedArray> to_elements = factory()->CopyFixedArray(from_elements); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2532 | to->set_elements(*to_elements); |
| 2533 | } |
| 2534 | |
| 2535 | |
| 2536 | void Genesis::TransferObject(Handle<JSObject> from, Handle<JSObject> to) { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2537 | HandleScope outer(isolate()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2538 | |
| 2539 | ASSERT(!from->IsJSArray()); |
| 2540 | ASSERT(!to->IsJSArray()); |
| 2541 | |
| 2542 | TransferNamedProperties(from, to); |
| 2543 | TransferIndexedProperties(from, to); |
| 2544 | |
| 2545 | // Transfer the prototype (new map is needed). |
| 2546 | Handle<Map> old_to_map = Handle<Map>(to->map()); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 2547 | Handle<Map> new_to_map = factory()->CopyMap(old_to_map); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2548 | new_to_map->set_prototype(from->map()->prototype()); |
| 2549 | to->set_map(*new_to_map); |
| 2550 | } |
| 2551 | |
| 2552 | |
| 2553 | void Genesis::MakeFunctionInstancePrototypeWritable() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2554 | // The maps with writable prototype are created in CreateEmptyFunction |
| 2555 | // and CreateStrictModeFunctionMaps respectively. Initially the maps are |
| 2556 | // created with read-only prototype for JS builtins processing. |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 2557 | ASSERT(!function_map_writable_prototype_.is_null()); |
| 2558 | ASSERT(!strict_mode_function_map_writable_prototype_.is_null()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2559 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2560 | // Replace function instance maps to make prototype writable. |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 2561 | native_context()->set_function_map(*function_map_writable_prototype_); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2562 | native_context()->set_strict_mode_function_map( |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 2563 | *strict_mode_function_map_writable_prototype_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2564 | } |
| 2565 | |
| 2566 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2567 | Genesis::Genesis(Isolate* isolate, |
| 2568 | Handle<Object> global_object, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2569 | v8::Handle<v8::ObjectTemplate> global_template, |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2570 | v8::ExtensionConfiguration* extensions) |
| 2571 | : isolate_(isolate), |
| 2572 | active_(isolate->bootstrapper()) { |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2573 | result_ = Handle<Context>::null(); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2574 | // If V8 cannot be initialized, just return. |
| 2575 | if (!V8::Initialize(NULL)) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2576 | |
| 2577 | // Before creating the roots we must save the context and restore it |
| 2578 | // on all function exits. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2579 | SaveContext saved_context(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2580 | |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 2581 | // During genesis, the boilerplate for stack overflow won't work until the |
| 2582 | // environment has been at least partially initialized. Add a stack check |
| 2583 | // before entering JS code to catch overflow early. |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 2584 | StackLimitCheck check(isolate); |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 2585 | if (check.HasOverflowed()) return; |
| 2586 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2587 | // We can only de-serialize a context if the isolate was initialized from |
| 2588 | // a snapshot. Otherwise we have to build the context from scratch. |
| 2589 | if (isolate->initialized_from_snapshot()) { |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 2590 | native_context_ = Snapshot::NewContextFromSnapshot(isolate); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2591 | } else { |
| 2592 | native_context_ = Handle<Context>(); |
| 2593 | } |
| 2594 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 2595 | if (!native_context().is_null()) { |
| 2596 | AddToWeakNativeContextList(*native_context()); |
| 2597 | isolate->set_context(*native_context()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2598 | isolate->counters()->contexts_created_by_snapshot()->Increment(); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2599 | Handle<GlobalObject> inner_global; |
| 2600 | Handle<JSGlobalProxy> global_proxy = |
| 2601 | CreateNewGlobals(global_template, |
| 2602 | global_object, |
| 2603 | &inner_global); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2604 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2605 | HookUpGlobalProxy(inner_global, global_proxy); |
| 2606 | HookUpInnerGlobal(inner_global); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2607 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2608 | if (!ConfigureGlobalObjects(global_template)) return; |
| 2609 | } else { |
| 2610 | // We get here if there was no context snapshot. |
| 2611 | CreateRoots(); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2612 | Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2613 | CreateStrictModeFunctionMaps(empty_function); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2614 | Handle<GlobalObject> inner_global; |
| 2615 | Handle<JSGlobalProxy> global_proxy = |
| 2616 | CreateNewGlobals(global_template, global_object, &inner_global); |
| 2617 | HookUpGlobalProxy(inner_global, global_proxy); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 2618 | InitializeGlobal(inner_global, empty_function); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2619 | InstallJSFunctionResultCaches(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2620 | InitializeNormalizedMapCaches(); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2621 | if (!InstallNatives()) return; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2622 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2623 | MakeFunctionInstancePrototypeWritable(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2624 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2625 | if (!ConfigureGlobalObjects(global_template)) return; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2626 | isolate->counters()->contexts_created_from_scratch()->Increment(); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2627 | } |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 2628 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2629 | // Initialize experimental globals and install experimental natives. |
| 2630 | InitializeExperimentalGlobal(); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2631 | if (!InstallExperimentalNatives()) return; |
| 2632 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 2633 | // Initially seed the per-context random number generator |
| 2634 | // using the per-isolate random number generator. |
| 2635 | uint32_t* state = reinterpret_cast<uint32_t*>( |
| 2636 | native_context()->random_seed()->GetDataStartAddress()); |
| 2637 | do { |
| 2638 | isolate->random_number_generator()->NextBytes(state, kRandomStateSize); |
| 2639 | } while (state[0] == 0 || state[1] == 0); |
| 2640 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 2641 | result_ = native_context(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2642 | } |
| 2643 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 2644 | |
| 2645 | // Support for thread preemption. |
| 2646 | |
| 2647 | // Reserve space for statics needing saving and restoring. |
| 2648 | int Bootstrapper::ArchiveSpacePerThread() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2649 | return sizeof(NestingCounterType); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 2650 | } |
| 2651 | |
| 2652 | |
| 2653 | // Archive statics that are thread local. |
| 2654 | char* Bootstrapper::ArchiveState(char* to) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2655 | *reinterpret_cast<NestingCounterType*>(to) = nesting_; |
| 2656 | nesting_ = 0; |
| 2657 | return to + sizeof(NestingCounterType); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 2658 | } |
| 2659 | |
| 2660 | |
| 2661 | // Restore statics that are thread local. |
| 2662 | char* Bootstrapper::RestoreState(char* from) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2663 | nesting_ = *reinterpret_cast<NestingCounterType*>(from); |
| 2664 | return from + sizeof(NestingCounterType); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 2665 | } |
| 2666 | |
| 2667 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2668 | // Called when the top-level V8 mutex is destroyed. |
| 2669 | void Bootstrapper::FreeThreadResources() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2670 | ASSERT(!IsActive()); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 2671 | } |
| 2672 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2673 | } } // namespace v8::internal |