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