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