| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 #include "macro-assembler.h" | 37 #include "macro-assembler.h" |
| 38 #include "natives.h" | 38 #include "natives.h" |
| 39 #include "objects-visiting.h" | 39 #include "objects-visiting.h" |
| 40 #include "snapshot.h" | 40 #include "snapshot.h" |
| 41 #include "extensions/externalize-string-extension.h" | 41 #include "extensions/externalize-string-extension.h" |
| 42 #include "extensions/gc-extension.h" | 42 #include "extensions/gc-extension.h" |
| 43 | 43 |
| 44 namespace v8 { | 44 namespace v8 { |
| 45 namespace internal { | 45 namespace internal { |
| 46 | 46 |
| 47 // A SourceCodeCache uses a FixedArray to store pairs of | |
| 48 // (AsciiString*, JSFunction*), mapping names of native code files | |
| 49 // (runtime.js, etc.) to precompiled functions. Instead of mapping | |
| 50 // names to functions it might make sense to let the JS2C tool | |
| 51 // generate an index for each native JS file. | |
| 52 class SourceCodeCache BASE_EMBEDDED { | |
| 53 public: | |
| 54 explicit SourceCodeCache(Script::Type type): type_(type), cache_(NULL) { } | |
| 55 | 47 |
| 56 void Initialize(bool create_heap_objects) { | 48 NativesExternalStringResource::NativesExternalStringResource( |
| 57 cache_ = create_heap_objects ? Heap::empty_fixed_array() : NULL; | 49 Bootstrapper* bootstrapper, |
| 58 } | 50 const char* source) |
| 59 | |
| 60 void Iterate(ObjectVisitor* v) { | |
| 61 v->VisitPointer(BitCast<Object**>(&cache_)); | |
| 62 } | |
| 63 | |
| 64 | |
| 65 bool Lookup(Vector<const char> name, Handle<SharedFunctionInfo>* handle) { | |
| 66 for (int i = 0; i < cache_->length(); i+=2) { | |
| 67 SeqAsciiString* str = SeqAsciiString::cast(cache_->get(i)); | |
| 68 if (str->IsEqualTo(name)) { | |
| 69 *handle = Handle<SharedFunctionInfo>( | |
| 70 SharedFunctionInfo::cast(cache_->get(i + 1))); | |
| 71 return true; | |
| 72 } | |
| 73 } | |
| 74 return false; | |
| 75 } | |
| 76 | |
| 77 | |
| 78 void Add(Vector<const char> name, Handle<SharedFunctionInfo> shared) { | |
| 79 HandleScope scope; | |
| 80 int length = cache_->length(); | |
| 81 Handle<FixedArray> new_array = | |
| 82 Factory::NewFixedArray(length + 2, TENURED); | |
| 83 cache_->CopyTo(0, *new_array, 0, cache_->length()); | |
| 84 cache_ = *new_array; | |
| 85 Handle<String> str = Factory::NewStringFromAscii(name, TENURED); | |
| 86 cache_->set(length, *str); | |
| 87 cache_->set(length + 1, *shared); | |
| 88 Script::cast(shared->script())->set_type(Smi::FromInt(type_)); | |
| 89 } | |
| 90 | |
| 91 private: | |
| 92 Script::Type type_; | |
| 93 FixedArray* cache_; | |
| 94 DISALLOW_COPY_AND_ASSIGN(SourceCodeCache); | |
| 95 }; | |
| 96 | |
| 97 static SourceCodeCache extensions_cache(Script::TYPE_EXTENSION); | |
| 98 // This is for delete, not delete[]. | |
| 99 static List<char*>* delete_these_non_arrays_on_tear_down = NULL; | |
| 100 // This is for delete[] | |
| 101 static List<char*>* delete_these_arrays_on_tear_down = NULL; | |
| 102 | |
| 103 | |
| 104 NativesExternalStringResource::NativesExternalStringResource(const char* source) | |
| 105 : data_(source), length_(StrLength(source)) { | 51 : data_(source), length_(StrLength(source)) { |
| 106 if (delete_these_non_arrays_on_tear_down == NULL) { | 52 if (bootstrapper->delete_these_non_arrays_on_tear_down_ == NULL) { |
| 107 delete_these_non_arrays_on_tear_down = new List<char*>(2); | 53 bootstrapper->delete_these_non_arrays_on_tear_down_ = new List<char*>(2); |
| 108 } | 54 } |
| 109 // The resources are small objects and we only make a fixed number of | 55 // The resources are small objects and we only make a fixed number of |
| 110 // them, but let's clean them up on exit for neatness. | 56 // them, but let's clean them up on exit for neatness. |
| 111 delete_these_non_arrays_on_tear_down-> | 57 bootstrapper->delete_these_non_arrays_on_tear_down_-> |
| 112 Add(reinterpret_cast<char*>(this)); | 58 Add(reinterpret_cast<char*>(this)); |
| 113 } | 59 } |
| 114 | 60 |
| 115 | 61 |
| 62 Bootstrapper::Bootstrapper() |
| 63 : nesting_(0), |
| 64 extensions_cache_(Script::TYPE_EXTENSION), |
| 65 delete_these_non_arrays_on_tear_down_(NULL), |
| 66 delete_these_arrays_on_tear_down_(NULL) { |
| 67 } |
| 68 |
| 69 |
| 116 Handle<String> Bootstrapper::NativesSourceLookup(int index) { | 70 Handle<String> Bootstrapper::NativesSourceLookup(int index) { |
| 117 ASSERT(0 <= index && index < Natives::GetBuiltinsCount()); | 71 ASSERT(0 <= index && index < Natives::GetBuiltinsCount()); |
| 118 if (Heap::natives_source_cache()->get(index)->IsUndefined()) { | 72 if (HEAP->natives_source_cache()->get(index)->IsUndefined()) { |
| 119 if (!Snapshot::IsEnabled() || FLAG_new_snapshot) { | 73 if (!Snapshot::IsEnabled() || FLAG_new_snapshot) { |
| 120 // We can use external strings for the natives. | 74 // We can use external strings for the natives. |
| 121 NativesExternalStringResource* resource = | 75 NativesExternalStringResource* resource = |
| 122 new NativesExternalStringResource( | 76 new NativesExternalStringResource(this, |
| 123 Natives::GetScriptSource(index).start()); | 77 Natives::GetScriptSource(index).start()); |
| 124 Handle<String> source_code = | 78 Handle<String> source_code = |
| 125 Factory::NewExternalStringFromAscii(resource); | 79 FACTORY->NewExternalStringFromAscii(resource); |
| 126 Heap::natives_source_cache()->set(index, *source_code); | 80 HEAP->natives_source_cache()->set(index, *source_code); |
| 127 } else { | 81 } else { |
| 128 // Old snapshot code can't cope with external strings at all. | 82 // Old snapshot code can't cope with external strings at all. |
| 129 Handle<String> source_code = | 83 Handle<String> source_code = |
| 130 Factory::NewStringFromAscii(Natives::GetScriptSource(index)); | 84 FACTORY->NewStringFromAscii(Natives::GetScriptSource(index)); |
| 131 Heap::natives_source_cache()->set(index, *source_code); | 85 HEAP->natives_source_cache()->set(index, *source_code); |
| 132 } | 86 } |
| 133 } | 87 } |
| 134 Handle<Object> cached_source(Heap::natives_source_cache()->get(index)); | 88 Handle<Object> cached_source(HEAP->natives_source_cache()->get(index)); |
| 135 return Handle<String>::cast(cached_source); | 89 return Handle<String>::cast(cached_source); |
| 136 } | 90 } |
| 137 | 91 |
| 138 | 92 |
| 139 void Bootstrapper::Initialize(bool create_heap_objects) { | 93 void Bootstrapper::Initialize(bool create_heap_objects) { |
| 140 extensions_cache.Initialize(create_heap_objects); | 94 extensions_cache_.Initialize(create_heap_objects); |
| 141 GCExtension::Register(); | 95 GCExtension::Register(); |
| 142 ExternalizeStringExtension::Register(); | 96 ExternalizeStringExtension::Register(); |
| 143 } | 97 } |
| 144 | 98 |
| 145 | 99 |
| 146 char* Bootstrapper::AllocateAutoDeletedArray(int bytes) { | 100 char* Bootstrapper::AllocateAutoDeletedArray(int bytes) { |
| 147 char* memory = new char[bytes]; | 101 char* memory = new char[bytes]; |
| 148 if (memory != NULL) { | 102 if (memory != NULL) { |
| 149 if (delete_these_arrays_on_tear_down == NULL) { | 103 if (delete_these_arrays_on_tear_down_ == NULL) { |
| 150 delete_these_arrays_on_tear_down = new List<char*>(2); | 104 delete_these_arrays_on_tear_down_ = new List<char*>(2); |
| 151 } | 105 } |
| 152 delete_these_arrays_on_tear_down->Add(memory); | 106 delete_these_arrays_on_tear_down_->Add(memory); |
| 153 } | 107 } |
| 154 return memory; | 108 return memory; |
| 155 } | 109 } |
| 156 | 110 |
| 157 | 111 |
| 158 void Bootstrapper::TearDown() { | 112 void Bootstrapper::TearDown() { |
| 159 if (delete_these_non_arrays_on_tear_down != NULL) { | 113 if (delete_these_non_arrays_on_tear_down_ != NULL) { |
| 160 int len = delete_these_non_arrays_on_tear_down->length(); | 114 int len = delete_these_non_arrays_on_tear_down_->length(); |
| 161 ASSERT(len < 20); // Don't use this mechanism for unbounded allocations. | 115 ASSERT(len < 20); // Don't use this mechanism for unbounded allocations. |
| 162 for (int i = 0; i < len; i++) { | 116 for (int i = 0; i < len; i++) { |
| 163 delete delete_these_non_arrays_on_tear_down->at(i); | 117 delete delete_these_non_arrays_on_tear_down_->at(i); |
| 164 delete_these_non_arrays_on_tear_down->at(i) = NULL; | 118 delete_these_non_arrays_on_tear_down_->at(i) = NULL; |
| 165 } | 119 } |
| 166 delete delete_these_non_arrays_on_tear_down; | 120 delete delete_these_non_arrays_on_tear_down_; |
| 167 delete_these_non_arrays_on_tear_down = NULL; | 121 delete_these_non_arrays_on_tear_down_ = NULL; |
| 168 } | 122 } |
| 169 | 123 |
| 170 if (delete_these_arrays_on_tear_down != NULL) { | 124 if (delete_these_arrays_on_tear_down_ != NULL) { |
| 171 int len = delete_these_arrays_on_tear_down->length(); | 125 int len = delete_these_arrays_on_tear_down_->length(); |
| 172 ASSERT(len < 1000); // Don't use this mechanism for unbounded allocations. | 126 ASSERT(len < 1000); // Don't use this mechanism for unbounded allocations. |
| 173 for (int i = 0; i < len; i++) { | 127 for (int i = 0; i < len; i++) { |
| 174 delete[] delete_these_arrays_on_tear_down->at(i); | 128 delete[] delete_these_arrays_on_tear_down_->at(i); |
| 175 delete_these_arrays_on_tear_down->at(i) = NULL; | 129 delete_these_arrays_on_tear_down_->at(i) = NULL; |
| 176 } | 130 } |
| 177 delete delete_these_arrays_on_tear_down; | 131 delete delete_these_arrays_on_tear_down_; |
| 178 delete_these_arrays_on_tear_down = NULL; | 132 delete_these_arrays_on_tear_down_ = NULL; |
| 179 } | 133 } |
| 180 | 134 |
| 181 extensions_cache.Initialize(false); // Yes, symmetrical | 135 extensions_cache_.Initialize(false); // Yes, symmetrical |
| 182 } | 136 } |
| 183 | 137 |
| 184 | 138 |
| 185 class Genesis BASE_EMBEDDED { | 139 class Genesis BASE_EMBEDDED { |
| 186 public: | 140 public: |
| 187 Genesis(Handle<Object> global_object, | 141 Genesis(Handle<Object> global_object, |
| 188 v8::Handle<v8::ObjectTemplate> global_template, | 142 v8::Handle<v8::ObjectTemplate> global_template, |
| 189 v8::ExtensionConfiguration* extensions); | 143 v8::ExtensionConfiguration* extensions); |
| 190 ~Genesis() { } | 144 ~Genesis() { } |
| 191 | 145 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 // These are the final, writable prototype, maps. | 253 // These are the final, writable prototype, maps. |
| 300 Handle<Map> function_instance_map_writable_prototype_; | 254 Handle<Map> function_instance_map_writable_prototype_; |
| 301 Handle<Map> strict_mode_function_instance_map_writable_prototype_; | 255 Handle<Map> strict_mode_function_instance_map_writable_prototype_; |
| 302 | 256 |
| 303 BootstrapperActive active_; | 257 BootstrapperActive active_; |
| 304 friend class Bootstrapper; | 258 friend class Bootstrapper; |
| 305 }; | 259 }; |
| 306 | 260 |
| 307 | 261 |
| 308 void Bootstrapper::Iterate(ObjectVisitor* v) { | 262 void Bootstrapper::Iterate(ObjectVisitor* v) { |
| 309 extensions_cache.Iterate(v); | 263 extensions_cache_.Iterate(v); |
| 310 v->Synchronize("Extensions"); | 264 v->Synchronize("Extensions"); |
| 311 } | 265 } |
| 312 | 266 |
| 313 | 267 |
| 314 Handle<Context> Bootstrapper::CreateEnvironment( | 268 Handle<Context> Bootstrapper::CreateEnvironment( |
| 315 Handle<Object> global_object, | 269 Handle<Object> global_object, |
| 316 v8::Handle<v8::ObjectTemplate> global_template, | 270 v8::Handle<v8::ObjectTemplate> global_template, |
| 317 v8::ExtensionConfiguration* extensions) { | 271 v8::ExtensionConfiguration* extensions) { |
| 318 HandleScope scope; | 272 HandleScope scope; |
| 319 Handle<Context> env; | 273 Handle<Context> env; |
| 320 Genesis genesis(global_object, global_template, extensions); | 274 Genesis genesis(global_object, global_template, extensions); |
| 321 env = genesis.result(); | 275 env = genesis.result(); |
| 322 if (!env.is_null()) { | 276 if (!env.is_null()) { |
| 323 if (InstallExtensions(env, extensions)) { | 277 if (InstallExtensions(env, extensions)) { |
| 324 return env; | 278 return env; |
| 325 } | 279 } |
| 326 } | 280 } |
| 327 return Handle<Context>(); | 281 return Handle<Context>(); |
| 328 } | 282 } |
| 329 | 283 |
| 330 | 284 |
| 331 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) { | 285 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) { |
| 332 // object.__proto__ = proto; | 286 // object.__proto__ = proto; |
| 333 Handle<Map> old_to_map = Handle<Map>(object->map()); | 287 Handle<Map> old_to_map = Handle<Map>(object->map()); |
| 334 Handle<Map> new_to_map = Factory::CopyMapDropTransitions(old_to_map); | 288 Handle<Map> new_to_map = FACTORY->CopyMapDropTransitions(old_to_map); |
| 335 new_to_map->set_prototype(*proto); | 289 new_to_map->set_prototype(*proto); |
| 336 object->set_map(*new_to_map); | 290 object->set_map(*new_to_map); |
| 337 } | 291 } |
| 338 | 292 |
| 339 | 293 |
| 340 void Bootstrapper::DetachGlobal(Handle<Context> env) { | 294 void Bootstrapper::DetachGlobal(Handle<Context> env) { |
| 341 JSGlobalProxy::cast(env->global_proxy())->set_context(*Factory::null_value()); | 295 JSGlobalProxy::cast(env->global_proxy())->set_context(*FACTORY->null_value()); |
| 342 SetObjectPrototype(Handle<JSObject>(env->global_proxy()), | 296 SetObjectPrototype(Handle<JSObject>(env->global_proxy()), |
| 343 Factory::null_value()); | 297 FACTORY->null_value()); |
| 344 env->set_global_proxy(env->global()); | 298 env->set_global_proxy(env->global()); |
| 345 env->global()->set_global_receiver(env->global()); | 299 env->global()->set_global_receiver(env->global()); |
| 346 } | 300 } |
| 347 | 301 |
| 348 | 302 |
| 349 void Bootstrapper::ReattachGlobal(Handle<Context> env, | 303 void Bootstrapper::ReattachGlobal(Handle<Context> env, |
| 350 Handle<Object> global_object) { | 304 Handle<Object> global_object) { |
| 351 ASSERT(global_object->IsJSGlobalProxy()); | 305 ASSERT(global_object->IsJSGlobalProxy()); |
| 352 Handle<JSGlobalProxy> global = Handle<JSGlobalProxy>::cast(global_object); | 306 Handle<JSGlobalProxy> global = Handle<JSGlobalProxy>::cast(global_object); |
| 353 env->global()->set_global_receiver(*global); | 307 env->global()->set_global_receiver(*global); |
| 354 env->set_global_proxy(*global); | 308 env->set_global_proxy(*global); |
| 355 SetObjectPrototype(global, Handle<JSObject>(env->global())); | 309 SetObjectPrototype(global, Handle<JSObject>(env->global())); |
| 356 global->set_context(*env); | 310 global->set_context(*env); |
| 357 } | 311 } |
| 358 | 312 |
| 359 | 313 |
| 360 static Handle<JSFunction> InstallFunction(Handle<JSObject> target, | 314 static Handle<JSFunction> InstallFunction(Handle<JSObject> target, |
| 361 const char* name, | 315 const char* name, |
| 362 InstanceType type, | 316 InstanceType type, |
| 363 int instance_size, | 317 int instance_size, |
| 364 Handle<JSObject> prototype, | 318 Handle<JSObject> prototype, |
| 365 Builtins::Name call, | 319 Builtins::Name call, |
| 366 bool is_ecma_native) { | 320 bool is_ecma_native) { |
| 367 Handle<String> symbol = Factory::LookupAsciiSymbol(name); | 321 Handle<String> symbol = FACTORY->LookupAsciiSymbol(name); |
| 368 Handle<Code> call_code = Handle<Code>(Builtins::builtin(call)); | 322 Handle<Code> call_code = Handle<Code>( |
| 323 Isolate::Current()->builtins()->builtin(call)); |
| 369 Handle<JSFunction> function = prototype.is_null() ? | 324 Handle<JSFunction> function = prototype.is_null() ? |
| 370 Factory::NewFunctionWithoutPrototype(symbol, call_code) : | 325 FACTORY->NewFunctionWithoutPrototype(symbol, call_code) : |
| 371 Factory::NewFunctionWithPrototype(symbol, | 326 FACTORY->NewFunctionWithPrototype(symbol, |
| 372 type, | 327 type, |
| 373 instance_size, | 328 instance_size, |
| 374 prototype, | 329 prototype, |
| 375 call_code, | 330 call_code, |
| 376 is_ecma_native); | 331 is_ecma_native); |
| 377 SetLocalPropertyNoThrow(target, symbol, function, DONT_ENUM); | 332 SetLocalPropertyNoThrow(target, symbol, function, DONT_ENUM); |
| 378 if (is_ecma_native) { | 333 if (is_ecma_native) { |
| 379 function->shared()->set_instance_class_name(*symbol); | 334 function->shared()->set_instance_class_name(*symbol); |
| 380 } | 335 } |
| 381 return function; | 336 return function; |
| 382 } | 337 } |
| 383 | 338 |
| 384 | 339 |
| 385 Handle<DescriptorArray> Genesis::ComputeFunctionInstanceDescriptor( | 340 Handle<DescriptorArray> Genesis::ComputeFunctionInstanceDescriptor( |
| 386 PrototypePropertyMode prototypeMode) { | 341 PrototypePropertyMode prototypeMode) { |
| 387 Handle<DescriptorArray> descriptors = | 342 Handle<DescriptorArray> descriptors = |
| 388 Factory::NewDescriptorArray(prototypeMode == DONT_ADD_PROTOTYPE ? 4 : 5); | 343 FACTORY->NewDescriptorArray(prototypeMode == DONT_ADD_PROTOTYPE ? 4 : 5); |
| 389 PropertyAttributes attributes = | 344 PropertyAttributes attributes = |
| 390 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | 345 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 391 | 346 |
| 392 { // Add length. | 347 { // Add length. |
| 393 Handle<Proxy> proxy = Factory::NewProxy(&Accessors::FunctionLength); | 348 Handle<Proxy> proxy = FACTORY->NewProxy(&Accessors::FunctionLength); |
| 394 CallbacksDescriptor d(*Factory::length_symbol(), *proxy, attributes); | 349 CallbacksDescriptor d(*FACTORY->length_symbol(), *proxy, attributes); |
| 395 descriptors->Set(0, &d); | 350 descriptors->Set(0, &d); |
| 396 } | 351 } |
| 397 { // Add name. | 352 { // Add name. |
| 398 Handle<Proxy> proxy = Factory::NewProxy(&Accessors::FunctionName); | 353 Handle<Proxy> proxy = FACTORY->NewProxy(&Accessors::FunctionName); |
| 399 CallbacksDescriptor d(*Factory::name_symbol(), *proxy, attributes); | 354 CallbacksDescriptor d(*FACTORY->name_symbol(), *proxy, attributes); |
| 400 descriptors->Set(1, &d); | 355 descriptors->Set(1, &d); |
| 401 } | 356 } |
| 402 { // Add arguments. | 357 { // Add arguments. |
| 403 Handle<Proxy> proxy = Factory::NewProxy(&Accessors::FunctionArguments); | 358 Handle<Proxy> proxy = FACTORY->NewProxy(&Accessors::FunctionArguments); |
| 404 CallbacksDescriptor d(*Factory::arguments_symbol(), *proxy, attributes); | 359 CallbacksDescriptor d(*FACTORY->arguments_symbol(), *proxy, attributes); |
| 405 descriptors->Set(2, &d); | 360 descriptors->Set(2, &d); |
| 406 } | 361 } |
| 407 { // Add caller. | 362 { // Add caller. |
| 408 Handle<Proxy> proxy = Factory::NewProxy(&Accessors::FunctionCaller); | 363 Handle<Proxy> proxy = FACTORY->NewProxy(&Accessors::FunctionCaller); |
| 409 CallbacksDescriptor d(*Factory::caller_symbol(), *proxy, attributes); | 364 CallbacksDescriptor d(*FACTORY->caller_symbol(), *proxy, attributes); |
| 410 descriptors->Set(3, &d); | 365 descriptors->Set(3, &d); |
| 411 } | 366 } |
| 412 if (prototypeMode != DONT_ADD_PROTOTYPE) { | 367 if (prototypeMode != DONT_ADD_PROTOTYPE) { |
| 413 // Add prototype. | 368 // Add prototype. |
| 414 if (prototypeMode == ADD_WRITEABLE_PROTOTYPE) { | 369 if (prototypeMode == ADD_WRITEABLE_PROTOTYPE) { |
| 415 attributes = static_cast<PropertyAttributes>(attributes & ~READ_ONLY); | 370 attributes = static_cast<PropertyAttributes>(attributes & ~READ_ONLY); |
| 416 } | 371 } |
| 417 Handle<Proxy> proxy = Factory::NewProxy(&Accessors::FunctionPrototype); | 372 Handle<Proxy> proxy = FACTORY->NewProxy(&Accessors::FunctionPrototype); |
| 418 CallbacksDescriptor d(*Factory::prototype_symbol(), *proxy, attributes); | 373 CallbacksDescriptor d(*FACTORY->prototype_symbol(), *proxy, attributes); |
| 419 descriptors->Set(4, &d); | 374 descriptors->Set(4, &d); |
| 420 } | 375 } |
| 421 descriptors->Sort(); | 376 descriptors->Sort(); |
| 422 return descriptors; | 377 return descriptors; |
| 423 } | 378 } |
| 424 | 379 |
| 425 | 380 |
| 426 Handle<Map> Genesis::CreateFunctionMap(PrototypePropertyMode prototype_mode) { | 381 Handle<Map> Genesis::CreateFunctionMap(PrototypePropertyMode prototype_mode) { |
| 427 Handle<Map> map = Factory::NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); | 382 Handle<Map> map = FACTORY->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); |
| 428 Handle<DescriptorArray> descriptors = | 383 Handle<DescriptorArray> descriptors = |
| 429 ComputeFunctionInstanceDescriptor(prototype_mode); | 384 ComputeFunctionInstanceDescriptor(prototype_mode); |
| 430 map->set_instance_descriptors(*descriptors); | 385 map->set_instance_descriptors(*descriptors); |
| 431 map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE); | 386 map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE); |
| 432 return map; | 387 return map; |
| 433 } | 388 } |
| 434 | 389 |
| 435 | 390 |
| 436 Handle<JSFunction> Genesis::CreateEmptyFunction() { | 391 Handle<JSFunction> Genesis::CreateEmptyFunction() { |
| 437 // Allocate the map for function instances. Maps are allocated first and their | 392 // Allocate the map for function instances. Maps are allocated first and their |
| (...skipping 13 matching lines...) Expand all Loading... |
| 451 // of builtins. | 406 // of builtins. |
| 452 // Later the map is replaced with writable prototype map, allocated below. | 407 // Later the map is replaced with writable prototype map, allocated below. |
| 453 global_context()->set_function_map( | 408 global_context()->set_function_map( |
| 454 *CreateFunctionMap(ADD_READONLY_PROTOTYPE)); | 409 *CreateFunctionMap(ADD_READONLY_PROTOTYPE)); |
| 455 | 410 |
| 456 // The final map for functions. Writeable prototype. | 411 // The final map for functions. Writeable prototype. |
| 457 // This map is installed in MakeFunctionInstancePrototypeWritable. | 412 // This map is installed in MakeFunctionInstancePrototypeWritable. |
| 458 function_instance_map_writable_prototype_ = | 413 function_instance_map_writable_prototype_ = |
| 459 CreateFunctionMap(ADD_WRITEABLE_PROTOTYPE); | 414 CreateFunctionMap(ADD_WRITEABLE_PROTOTYPE); |
| 460 | 415 |
| 461 Handle<String> object_name = Handle<String>(Heap::Object_symbol()); | 416 Handle<String> object_name = Handle<String>(HEAP->Object_symbol()); |
| 462 | 417 |
| 463 { // --- O b j e c t --- | 418 { // --- O b j e c t --- |
| 464 Handle<JSFunction> object_fun = | 419 Handle<JSFunction> object_fun = |
| 465 Factory::NewFunction(object_name, Factory::null_value()); | 420 FACTORY->NewFunction(object_name, FACTORY->null_value()); |
| 466 Handle<Map> object_function_map = | 421 Handle<Map> object_function_map = |
| 467 Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 422 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
| 468 object_fun->set_initial_map(*object_function_map); | 423 object_fun->set_initial_map(*object_function_map); |
| 469 object_function_map->set_constructor(*object_fun); | 424 object_function_map->set_constructor(*object_fun); |
| 470 | 425 |
| 471 global_context()->set_object_function(*object_fun); | 426 global_context()->set_object_function(*object_fun); |
| 472 | 427 |
| 473 // Allocate a new prototype for the object function. | 428 // Allocate a new prototype for the object function. |
| 474 Handle<JSObject> prototype = Factory::NewJSObject(Top::object_function(), | 429 Handle<JSObject> prototype = FACTORY->NewJSObject( |
| 475 TENURED); | 430 Isolate::Current()->object_function(), |
| 431 TENURED); |
| 476 | 432 |
| 477 global_context()->set_initial_object_prototype(*prototype); | 433 global_context()->set_initial_object_prototype(*prototype); |
| 478 SetPrototype(object_fun, prototype); | 434 SetPrototype(object_fun, prototype); |
| 479 object_function_map-> | 435 object_function_map-> |
| 480 set_instance_descriptors(Heap::empty_descriptor_array()); | 436 set_instance_descriptors(HEAP->empty_descriptor_array()); |
| 481 } | 437 } |
| 482 | 438 |
| 483 // Allocate the empty function as the prototype for function ECMAScript | 439 // Allocate the empty function as the prototype for function ECMAScript |
| 484 // 262 15.3.4. | 440 // 262 15.3.4. |
| 485 Handle<String> symbol = Factory::LookupAsciiSymbol("Empty"); | 441 Handle<String> symbol = FACTORY->LookupAsciiSymbol("Empty"); |
| 486 Handle<JSFunction> empty_function = | 442 Handle<JSFunction> empty_function = |
| 487 Factory::NewFunctionWithoutPrototype(symbol, kNonStrictMode); | 443 FACTORY->NewFunctionWithoutPrototype(symbol, kNonStrictMode); |
| 488 | 444 |
| 489 // --- E m p t y --- | 445 // --- E m p t y --- |
| 490 Handle<Code> code = | 446 Handle<Code> code = |
| 491 Handle<Code>(Builtins::builtin(Builtins::EmptyFunction)); | 447 Handle<Code>(Isolate::Current()->builtins()->builtin( |
| 448 Builtins::EmptyFunction)); |
| 492 empty_function->set_code(*code); | 449 empty_function->set_code(*code); |
| 493 empty_function->shared()->set_code(*code); | 450 empty_function->shared()->set_code(*code); |
| 494 Handle<String> source = Factory::NewStringFromAscii(CStrVector("() {}")); | 451 Handle<String> source = FACTORY->NewStringFromAscii(CStrVector("() {}")); |
| 495 Handle<Script> script = Factory::NewScript(source); | 452 Handle<Script> script = FACTORY->NewScript(source); |
| 496 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); | 453 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
| 497 empty_function->shared()->set_script(*script); | 454 empty_function->shared()->set_script(*script); |
| 498 empty_function->shared()->set_start_position(0); | 455 empty_function->shared()->set_start_position(0); |
| 499 empty_function->shared()->set_end_position(source->length()); | 456 empty_function->shared()->set_end_position(source->length()); |
| 500 empty_function->shared()->DontAdaptArguments(); | 457 empty_function->shared()->DontAdaptArguments(); |
| 501 | 458 |
| 502 // Set prototypes for the function maps. | 459 // Set prototypes for the function maps. |
| 503 global_context()->function_map()->set_prototype(*empty_function); | 460 global_context()->function_map()->set_prototype(*empty_function); |
| 504 global_context()->function_instance_map()->set_prototype(*empty_function); | 461 global_context()->function_instance_map()->set_prototype(*empty_function); |
| 505 global_context()->function_without_prototype_map()-> | 462 global_context()->function_without_prototype_map()-> |
| 506 set_prototype(*empty_function); | 463 set_prototype(*empty_function); |
| 507 function_instance_map_writable_prototype_->set_prototype(*empty_function); | 464 function_instance_map_writable_prototype_->set_prototype(*empty_function); |
| 508 | 465 |
| 509 // Allocate the function map first and then patch the prototype later | 466 // Allocate the function map first and then patch the prototype later |
| 510 Handle<Map> function_without_prototype_map( | 467 Handle<Map> function_without_prototype_map( |
| 511 global_context()->function_without_prototype_map()); | 468 global_context()->function_without_prototype_map()); |
| 512 Handle<Map> empty_fm = Factory::CopyMapDropDescriptors( | 469 Handle<Map> empty_fm = FACTORY->CopyMapDropDescriptors( |
| 513 function_without_prototype_map); | 470 function_without_prototype_map); |
| 514 empty_fm->set_instance_descriptors( | 471 empty_fm->set_instance_descriptors( |
| 515 function_without_prototype_map->instance_descriptors()); | 472 function_without_prototype_map->instance_descriptors()); |
| 516 empty_fm->set_prototype(global_context()->object_function()->prototype()); | 473 empty_fm->set_prototype(global_context()->object_function()->prototype()); |
| 517 empty_function->set_map(*empty_fm); | 474 empty_function->set_map(*empty_fm); |
| 518 return empty_function; | 475 return empty_function; |
| 519 } | 476 } |
| 520 | 477 |
| 521 | 478 |
| 522 Handle<DescriptorArray> Genesis::ComputeStrictFunctionInstanceDescriptor( | 479 Handle<DescriptorArray> Genesis::ComputeStrictFunctionInstanceDescriptor( |
| 523 PrototypePropertyMode prototypeMode, | 480 PrototypePropertyMode prototypeMode, |
| 524 Handle<FixedArray> arguments, | 481 Handle<FixedArray> arguments, |
| 525 Handle<FixedArray> caller) { | 482 Handle<FixedArray> caller) { |
| 526 Handle<DescriptorArray> descriptors = | 483 Handle<DescriptorArray> descriptors = |
| 527 Factory::NewDescriptorArray(prototypeMode == DONT_ADD_PROTOTYPE ? 4 : 5); | 484 FACTORY->NewDescriptorArray(prototypeMode == DONT_ADD_PROTOTYPE ? 4 : 5); |
| 528 PropertyAttributes attributes = static_cast<PropertyAttributes>( | 485 PropertyAttributes attributes = static_cast<PropertyAttributes>( |
| 529 DONT_ENUM | DONT_DELETE | READ_ONLY); | 486 DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 530 | 487 |
| 531 { // length | 488 { // length |
| 532 Handle<Proxy> proxy = Factory::NewProxy(&Accessors::FunctionLength); | 489 Handle<Proxy> proxy = FACTORY->NewProxy(&Accessors::FunctionLength); |
| 533 CallbacksDescriptor d(*Factory::length_symbol(), *proxy, attributes); | 490 CallbacksDescriptor d(*FACTORY->length_symbol(), *proxy, attributes); |
| 534 descriptors->Set(0, &d); | 491 descriptors->Set(0, &d); |
| 535 } | 492 } |
| 536 { // name | 493 { // name |
| 537 Handle<Proxy> proxy = Factory::NewProxy(&Accessors::FunctionName); | 494 Handle<Proxy> proxy = FACTORY->NewProxy(&Accessors::FunctionName); |
| 538 CallbacksDescriptor d(*Factory::name_symbol(), *proxy, attributes); | 495 CallbacksDescriptor d(*FACTORY->name_symbol(), *proxy, attributes); |
| 539 descriptors->Set(1, &d); | 496 descriptors->Set(1, &d); |
| 540 } | 497 } |
| 541 { // arguments | 498 { // arguments |
| 542 CallbacksDescriptor d(*Factory::arguments_symbol(), *arguments, attributes); | 499 CallbacksDescriptor d(*FACTORY->arguments_symbol(), *arguments, attributes); |
| 543 descriptors->Set(2, &d); | 500 descriptors->Set(2, &d); |
| 544 } | 501 } |
| 545 { // caller | 502 { // caller |
| 546 CallbacksDescriptor d(*Factory::caller_symbol(), *caller, attributes); | 503 CallbacksDescriptor d(*FACTORY->caller_symbol(), *caller, attributes); |
| 547 descriptors->Set(3, &d); | 504 descriptors->Set(3, &d); |
| 548 } | 505 } |
| 549 | 506 |
| 550 // prototype | 507 // prototype |
| 551 if (prototypeMode != DONT_ADD_PROTOTYPE) { | 508 if (prototypeMode != DONT_ADD_PROTOTYPE) { |
| 552 if (prototypeMode == ADD_WRITEABLE_PROTOTYPE) { | 509 if (prototypeMode == ADD_WRITEABLE_PROTOTYPE) { |
| 553 attributes = static_cast<PropertyAttributes>(attributes & ~READ_ONLY); | 510 attributes = static_cast<PropertyAttributes>(attributes & ~READ_ONLY); |
| 554 } | 511 } |
| 555 Handle<Proxy> proxy = Factory::NewProxy(&Accessors::FunctionPrototype); | 512 Handle<Proxy> proxy = FACTORY->NewProxy(&Accessors::FunctionPrototype); |
| 556 CallbacksDescriptor d(*Factory::prototype_symbol(), *proxy, attributes); | 513 CallbacksDescriptor d(*FACTORY->prototype_symbol(), *proxy, attributes); |
| 557 descriptors->Set(4, &d); | 514 descriptors->Set(4, &d); |
| 558 } | 515 } |
| 559 | 516 |
| 560 descriptors->Sort(); | 517 descriptors->Sort(); |
| 561 return descriptors; | 518 return descriptors; |
| 562 } | 519 } |
| 563 | 520 |
| 564 | 521 |
| 565 // ECMAScript 5th Edition, 13.2.3 | 522 // ECMAScript 5th Edition, 13.2.3 |
| 566 Handle<JSFunction> Genesis::CreateThrowTypeErrorFunction( | 523 Handle<JSFunction> Genesis::CreateThrowTypeErrorFunction( |
| 567 Builtins::Name builtin) { | 524 Builtins::Name builtin) { |
| 568 Handle<String> name = Factory::LookupAsciiSymbol("ThrowTypeError"); | 525 Handle<String> name = FACTORY->LookupAsciiSymbol("ThrowTypeError"); |
| 569 Handle<JSFunction> throw_type_error = | 526 Handle<JSFunction> throw_type_error = |
| 570 Factory::NewFunctionWithoutPrototype(name, kStrictMode); | 527 FACTORY->NewFunctionWithoutPrototype(name, kStrictMode); |
| 571 Handle<Code> code = Handle<Code>(Builtins::builtin(builtin)); | 528 Handle<Code> code = Handle<Code>( |
| 529 Isolate::Current()->builtins()->builtin(builtin)); |
| 572 | 530 |
| 573 throw_type_error->set_map(global_context()->strict_mode_function_map()); | 531 throw_type_error->set_map(global_context()->strict_mode_function_map()); |
| 574 throw_type_error->set_code(*code); | 532 throw_type_error->set_code(*code); |
| 575 throw_type_error->shared()->set_code(*code); | 533 throw_type_error->shared()->set_code(*code); |
| 576 throw_type_error->shared()->DontAdaptArguments(); | 534 throw_type_error->shared()->DontAdaptArguments(); |
| 577 | 535 |
| 578 PreventExtensions(throw_type_error); | 536 PreventExtensions(throw_type_error); |
| 579 | 537 |
| 580 return throw_type_error; | 538 return throw_type_error; |
| 581 } | 539 } |
| 582 | 540 |
| 583 | 541 |
| 584 Handle<Map> Genesis::CreateStrictModeFunctionMap( | 542 Handle<Map> Genesis::CreateStrictModeFunctionMap( |
| 585 PrototypePropertyMode prototype_mode, | 543 PrototypePropertyMode prototype_mode, |
| 586 Handle<JSFunction> empty_function, | 544 Handle<JSFunction> empty_function, |
| 587 Handle<FixedArray> arguments_callbacks, | 545 Handle<FixedArray> arguments_callbacks, |
| 588 Handle<FixedArray> caller_callbacks) { | 546 Handle<FixedArray> caller_callbacks) { |
| 589 Handle<Map> map = Factory::NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); | 547 Handle<Map> map = FACTORY->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); |
| 590 Handle<DescriptorArray> descriptors = | 548 Handle<DescriptorArray> descriptors = |
| 591 ComputeStrictFunctionInstanceDescriptor(prototype_mode, | 549 ComputeStrictFunctionInstanceDescriptor(prototype_mode, |
| 592 arguments_callbacks, | 550 arguments_callbacks, |
| 593 caller_callbacks); | 551 caller_callbacks); |
| 594 map->set_instance_descriptors(*descriptors); | 552 map->set_instance_descriptors(*descriptors); |
| 595 map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE); | 553 map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE); |
| 596 map->set_prototype(*empty_function); | 554 map->set_prototype(*empty_function); |
| 597 return map; | 555 return map; |
| 598 } | 556 } |
| 599 | 557 |
| 600 | 558 |
| 601 void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) { | 559 void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) { |
| 602 // Create the callbacks arrays for ThrowTypeError functions. | 560 // Create the callbacks arrays for ThrowTypeError functions. |
| 603 // The get/set callacks are filled in after the maps are created below. | 561 // The get/set callacks are filled in after the maps are created below. |
| 604 Handle<FixedArray> arguments = Factory::NewFixedArray(2, TENURED); | 562 Handle<FixedArray> arguments = FACTORY->NewFixedArray(2, TENURED); |
| 605 Handle<FixedArray> caller = Factory::NewFixedArray(2, TENURED); | 563 Handle<FixedArray> caller = FACTORY->NewFixedArray(2, TENURED); |
| 606 | 564 |
| 607 // Allocate map for the strict mode function instances. | 565 // Allocate map for the strict mode function instances. |
| 608 global_context()->set_strict_mode_function_instance_map( | 566 global_context()->set_strict_mode_function_instance_map( |
| 609 *CreateStrictModeFunctionMap( | 567 *CreateStrictModeFunctionMap( |
| 610 ADD_WRITEABLE_PROTOTYPE, empty, arguments, caller)); | 568 ADD_WRITEABLE_PROTOTYPE, empty, arguments, caller)); |
| 611 | 569 |
| 612 // Allocate map for the prototype-less strict mode instances. | 570 // Allocate map for the prototype-less strict mode instances. |
| 613 global_context()->set_strict_mode_function_without_prototype_map( | 571 global_context()->set_strict_mode_function_without_prototype_map( |
| 614 *CreateStrictModeFunctionMap( | 572 *CreateStrictModeFunctionMap( |
| 615 DONT_ADD_PROTOTYPE, empty, arguments, caller)); | 573 DONT_ADD_PROTOTYPE, empty, arguments, caller)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 636 // Complete the callback fixed arrays. | 594 // Complete the callback fixed arrays. |
| 637 arguments->set(0, *arguments_throw); | 595 arguments->set(0, *arguments_throw); |
| 638 arguments->set(1, *arguments_throw); | 596 arguments->set(1, *arguments_throw); |
| 639 caller->set(0, *caller_throw); | 597 caller->set(0, *caller_throw); |
| 640 caller->set(1, *caller_throw); | 598 caller->set(1, *caller_throw); |
| 641 } | 599 } |
| 642 | 600 |
| 643 | 601 |
| 644 static void AddToWeakGlobalContextList(Context* context) { | 602 static void AddToWeakGlobalContextList(Context* context) { |
| 645 ASSERT(context->IsGlobalContext()); | 603 ASSERT(context->IsGlobalContext()); |
| 604 Heap* heap = Isolate::Current()->heap(); |
| 646 #ifdef DEBUG | 605 #ifdef DEBUG |
| 647 { // NOLINT | 606 { // NOLINT |
| 648 ASSERT(context->get(Context::NEXT_CONTEXT_LINK)->IsUndefined()); | 607 ASSERT(context->get(Context::NEXT_CONTEXT_LINK)->IsUndefined()); |
| 649 // Check that context is not in the list yet. | 608 // Check that context is not in the list yet. |
| 650 for (Object* current = Heap::global_contexts_list(); | 609 for (Object* current = heap->global_contexts_list(); |
| 651 !current->IsUndefined(); | 610 !current->IsUndefined(); |
| 652 current = Context::cast(current)->get(Context::NEXT_CONTEXT_LINK)) { | 611 current = Context::cast(current)->get(Context::NEXT_CONTEXT_LINK)) { |
| 653 ASSERT(current != context); | 612 ASSERT(current != context); |
| 654 } | 613 } |
| 655 } | 614 } |
| 656 #endif | 615 #endif |
| 657 context->set(Context::NEXT_CONTEXT_LINK, Heap::global_contexts_list()); | 616 context->set(Context::NEXT_CONTEXT_LINK, heap->global_contexts_list()); |
| 658 Heap::set_global_contexts_list(context); | 617 heap->set_global_contexts_list(context); |
| 659 } | 618 } |
| 660 | 619 |
| 661 | 620 |
| 662 void Genesis::CreateRoots() { | 621 void Genesis::CreateRoots() { |
| 622 Isolate* isolate = Isolate::Current(); |
| 663 // Allocate the global context FixedArray first and then patch the | 623 // Allocate the global context FixedArray first and then patch the |
| 664 // closure and extension object later (we need the empty function | 624 // closure and extension object later (we need the empty function |
| 665 // and the global object, but in order to create those, we need the | 625 // and the global object, but in order to create those, we need the |
| 666 // global context). | 626 // global context). |
| 667 global_context_ = | 627 global_context_ = Handle<Context>::cast(isolate->global_handles()->Create( |
| 668 Handle<Context>::cast( | 628 *isolate->factory()->NewGlobalContext())); |
| 669 GlobalHandles::Create(*Factory::NewGlobalContext())); | |
| 670 AddToWeakGlobalContextList(*global_context_); | 629 AddToWeakGlobalContextList(*global_context_); |
| 671 Top::set_context(*global_context()); | 630 isolate->set_context(*global_context()); |
| 672 | 631 |
| 673 // Allocate the message listeners object. | 632 // Allocate the message listeners object. |
| 674 { | 633 { |
| 675 v8::NeanderArray listeners; | 634 v8::NeanderArray listeners; |
| 676 global_context()->set_message_listeners(*listeners.value()); | 635 global_context()->set_message_listeners(*listeners.value()); |
| 677 } | 636 } |
| 678 } | 637 } |
| 679 | 638 |
| 680 | 639 |
| 681 Handle<JSGlobalProxy> Genesis::CreateNewGlobals( | 640 Handle<JSGlobalProxy> Genesis::CreateNewGlobals( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 705 Handle<FunctionTemplateInfo>( | 664 Handle<FunctionTemplateInfo>( |
| 706 FunctionTemplateInfo::cast(data->constructor())); | 665 FunctionTemplateInfo::cast(data->constructor())); |
| 707 Handle<Object> proto_template(global_constructor->prototype_template()); | 666 Handle<Object> proto_template(global_constructor->prototype_template()); |
| 708 if (!proto_template->IsUndefined()) { | 667 if (!proto_template->IsUndefined()) { |
| 709 js_global_template = | 668 js_global_template = |
| 710 Handle<ObjectTemplateInfo>::cast(proto_template); | 669 Handle<ObjectTemplateInfo>::cast(proto_template); |
| 711 } | 670 } |
| 712 } | 671 } |
| 713 | 672 |
| 714 if (js_global_template.is_null()) { | 673 if (js_global_template.is_null()) { |
| 715 Handle<String> name = Handle<String>(Heap::empty_symbol()); | 674 Handle<String> name = Handle<String>(HEAP->empty_symbol()); |
| 716 Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::Illegal)); | 675 Handle<Code> code = Handle<Code>(Isolate::Current()->builtins()->builtin( |
| 676 Builtins::Illegal)); |
| 717 js_global_function = | 677 js_global_function = |
| 718 Factory::NewFunction(name, JS_GLOBAL_OBJECT_TYPE, | 678 FACTORY->NewFunction(name, JS_GLOBAL_OBJECT_TYPE, |
| 719 JSGlobalObject::kSize, code, true); | 679 JSGlobalObject::kSize, code, true); |
| 720 // Change the constructor property of the prototype of the | 680 // Change the constructor property of the prototype of the |
| 721 // hidden global function to refer to the Object function. | 681 // hidden global function to refer to the Object function. |
| 722 Handle<JSObject> prototype = | 682 Handle<JSObject> prototype = |
| 723 Handle<JSObject>( | 683 Handle<JSObject>( |
| 724 JSObject::cast(js_global_function->instance_prototype())); | 684 JSObject::cast(js_global_function->instance_prototype())); |
| 725 SetLocalPropertyNoThrow( | 685 SetLocalPropertyNoThrow( |
| 726 prototype, Factory::constructor_symbol(), Top::object_function(), NONE); | 686 prototype, |
| 687 FACTORY->constructor_symbol(), |
| 688 Isolate::Current()->object_function(), |
| 689 NONE); |
| 727 } else { | 690 } else { |
| 728 Handle<FunctionTemplateInfo> js_global_constructor( | 691 Handle<FunctionTemplateInfo> js_global_constructor( |
| 729 FunctionTemplateInfo::cast(js_global_template->constructor())); | 692 FunctionTemplateInfo::cast(js_global_template->constructor())); |
| 730 js_global_function = | 693 js_global_function = |
| 731 Factory::CreateApiFunction(js_global_constructor, | 694 FACTORY->CreateApiFunction(js_global_constructor, |
| 732 Factory::InnerGlobalObject); | 695 FACTORY->InnerGlobalObject); |
| 733 } | 696 } |
| 734 | 697 |
| 735 js_global_function->initial_map()->set_is_hidden_prototype(); | 698 js_global_function->initial_map()->set_is_hidden_prototype(); |
| 736 Handle<GlobalObject> inner_global = | 699 Handle<GlobalObject> inner_global = |
| 737 Factory::NewGlobalObject(js_global_function); | 700 FACTORY->NewGlobalObject(js_global_function); |
| 738 if (inner_global_out != NULL) { | 701 if (inner_global_out != NULL) { |
| 739 *inner_global_out = inner_global; | 702 *inner_global_out = inner_global; |
| 740 } | 703 } |
| 741 | 704 |
| 742 // Step 2: create or re-initialize the global proxy object. | 705 // Step 2: create or re-initialize the global proxy object. |
| 743 Handle<JSFunction> global_proxy_function; | 706 Handle<JSFunction> global_proxy_function; |
| 744 if (global_template.IsEmpty()) { | 707 if (global_template.IsEmpty()) { |
| 745 Handle<String> name = Handle<String>(Heap::empty_symbol()); | 708 Handle<String> name = Handle<String>(HEAP->empty_symbol()); |
| 746 Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::Illegal)); | 709 Handle<Code> code = Handle<Code>(Isolate::Current()->builtins()->builtin( |
| 710 Builtins::Illegal)); |
| 747 global_proxy_function = | 711 global_proxy_function = |
| 748 Factory::NewFunction(name, JS_GLOBAL_PROXY_TYPE, | 712 FACTORY->NewFunction(name, JS_GLOBAL_PROXY_TYPE, |
| 749 JSGlobalProxy::kSize, code, true); | 713 JSGlobalProxy::kSize, code, true); |
| 750 } else { | 714 } else { |
| 751 Handle<ObjectTemplateInfo> data = | 715 Handle<ObjectTemplateInfo> data = |
| 752 v8::Utils::OpenHandle(*global_template); | 716 v8::Utils::OpenHandle(*global_template); |
| 753 Handle<FunctionTemplateInfo> global_constructor( | 717 Handle<FunctionTemplateInfo> global_constructor( |
| 754 FunctionTemplateInfo::cast(data->constructor())); | 718 FunctionTemplateInfo::cast(data->constructor())); |
| 755 global_proxy_function = | 719 global_proxy_function = |
| 756 Factory::CreateApiFunction(global_constructor, | 720 FACTORY->CreateApiFunction(global_constructor, |
| 757 Factory::OuterGlobalObject); | 721 FACTORY->OuterGlobalObject); |
| 758 } | 722 } |
| 759 | 723 |
| 760 Handle<String> global_name = Factory::LookupAsciiSymbol("global"); | 724 Handle<String> global_name = FACTORY->LookupAsciiSymbol("global"); |
| 761 global_proxy_function->shared()->set_instance_class_name(*global_name); | 725 global_proxy_function->shared()->set_instance_class_name(*global_name); |
| 762 global_proxy_function->initial_map()->set_is_access_check_needed(true); | 726 global_proxy_function->initial_map()->set_is_access_check_needed(true); |
| 763 | 727 |
| 764 // Set global_proxy.__proto__ to js_global after ConfigureGlobalObjects | 728 // Set global_proxy.__proto__ to js_global after ConfigureGlobalObjects |
| 765 // Return the global proxy. | 729 // Return the global proxy. |
| 766 | 730 |
| 767 if (global_object.location() != NULL) { | 731 if (global_object.location() != NULL) { |
| 768 ASSERT(global_object->IsJSGlobalProxy()); | 732 ASSERT(global_object->IsJSGlobalProxy()); |
| 769 return ReinitializeJSGlobalProxy( | 733 return ReinitializeJSGlobalProxy( |
| 770 global_proxy_function, | 734 global_proxy_function, |
| 771 Handle<JSGlobalProxy>::cast(global_object)); | 735 Handle<JSGlobalProxy>::cast(global_object)); |
| 772 } else { | 736 } else { |
| 773 return Handle<JSGlobalProxy>::cast( | 737 return Handle<JSGlobalProxy>::cast( |
| 774 Factory::NewJSObject(global_proxy_function, TENURED)); | 738 FACTORY->NewJSObject(global_proxy_function, TENURED)); |
| 775 } | 739 } |
| 776 } | 740 } |
| 777 | 741 |
| 778 | 742 |
| 779 void Genesis::HookUpGlobalProxy(Handle<GlobalObject> inner_global, | 743 void Genesis::HookUpGlobalProxy(Handle<GlobalObject> inner_global, |
| 780 Handle<JSGlobalProxy> global_proxy) { | 744 Handle<JSGlobalProxy> global_proxy) { |
| 781 // Set the global context for the global object. | 745 // Set the global context for the global object. |
| 782 inner_global->set_global_context(*global_context()); | 746 inner_global->set_global_context(*global_context()); |
| 783 inner_global->set_global_receiver(*global_proxy); | 747 inner_global->set_global_receiver(*global_proxy); |
| 784 global_proxy->set_context(*global_context()); | 748 global_proxy->set_context(*global_context()); |
| 785 global_context()->set_global_proxy(*global_proxy); | 749 global_context()->set_global_proxy(*global_proxy); |
| 786 } | 750 } |
| 787 | 751 |
| 788 | 752 |
| 789 void Genesis::HookUpInnerGlobal(Handle<GlobalObject> inner_global) { | 753 void Genesis::HookUpInnerGlobal(Handle<GlobalObject> inner_global) { |
| 790 Handle<GlobalObject> inner_global_from_snapshot( | 754 Handle<GlobalObject> inner_global_from_snapshot( |
| 791 GlobalObject::cast(global_context_->extension())); | 755 GlobalObject::cast(global_context_->extension())); |
| 792 Handle<JSBuiltinsObject> builtins_global(global_context_->builtins()); | 756 Handle<JSBuiltinsObject> builtins_global(global_context_->builtins()); |
| 793 global_context_->set_extension(*inner_global); | 757 global_context_->set_extension(*inner_global); |
| 794 global_context_->set_global(*inner_global); | 758 global_context_->set_global(*inner_global); |
| 795 global_context_->set_security_token(*inner_global); | 759 global_context_->set_security_token(*inner_global); |
| 796 static const PropertyAttributes attributes = | 760 static const PropertyAttributes attributes = |
| 797 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); | 761 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); |
| 798 ForceSetProperty(builtins_global, | 762 ForceSetProperty(builtins_global, |
| 799 Factory::LookupAsciiSymbol("global"), | 763 FACTORY->LookupAsciiSymbol("global"), |
| 800 inner_global, | 764 inner_global, |
| 801 attributes); | 765 attributes); |
| 802 // Setup the reference from the global object to the builtins object. | 766 // Setup the reference from the global object to the builtins object. |
| 803 JSGlobalObject::cast(*inner_global)->set_builtins(*builtins_global); | 767 JSGlobalObject::cast(*inner_global)->set_builtins(*builtins_global); |
| 804 TransferNamedProperties(inner_global_from_snapshot, inner_global); | 768 TransferNamedProperties(inner_global_from_snapshot, inner_global); |
| 805 TransferIndexedProperties(inner_global_from_snapshot, inner_global); | 769 TransferIndexedProperties(inner_global_from_snapshot, inner_global); |
| 806 } | 770 } |
| 807 | 771 |
| 808 | 772 |
| 809 // This is only called if we are not using snapshots. The equivalent | 773 // This is only called if we are not using snapshots. The equivalent |
| 810 // work in the snapshot case is done in HookUpInnerGlobal. | 774 // work in the snapshot case is done in HookUpInnerGlobal. |
| 811 void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global, | 775 void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global, |
| 812 Handle<JSFunction> empty_function) { | 776 Handle<JSFunction> empty_function) { |
| 813 // --- G l o b a l C o n t e x t --- | 777 // --- G l o b a l C o n t e x t --- |
| 814 // Use the empty function as closure (no scope info). | 778 // Use the empty function as closure (no scope info). |
| 815 global_context()->set_closure(*empty_function); | 779 global_context()->set_closure(*empty_function); |
| 816 global_context()->set_fcontext(*global_context()); | 780 global_context()->set_fcontext(*global_context()); |
| 817 global_context()->set_previous(NULL); | 781 global_context()->set_previous(NULL); |
| 818 // Set extension and global object. | 782 // Set extension and global object. |
| 819 global_context()->set_extension(*inner_global); | 783 global_context()->set_extension(*inner_global); |
| 820 global_context()->set_global(*inner_global); | 784 global_context()->set_global(*inner_global); |
| 821 // Security setup: Set the security token of the global object to | 785 // Security setup: Set the security token of the global object to |
| 822 // its the inner global. This makes the security check between two | 786 // its the inner global. This makes the security check between two |
| 823 // different contexts fail by default even in case of global | 787 // different contexts fail by default even in case of global |
| 824 // object reinitialization. | 788 // object reinitialization. |
| 825 global_context()->set_security_token(*inner_global); | 789 global_context()->set_security_token(*inner_global); |
| 826 | 790 |
| 827 Handle<String> object_name = Handle<String>(Heap::Object_symbol()); | 791 Handle<String> object_name = Handle<String>(HEAP->Object_symbol()); |
| 828 SetLocalPropertyNoThrow(inner_global, object_name, | 792 SetLocalPropertyNoThrow(inner_global, object_name, |
| 829 Top::object_function(), DONT_ENUM); | 793 Isolate::Current()->object_function(), DONT_ENUM); |
| 830 | 794 |
| 831 Handle<JSObject> global = Handle<JSObject>(global_context()->global()); | 795 Handle<JSObject> global = Handle<JSObject>(global_context()->global()); |
| 832 | 796 |
| 833 // Install global Function object | 797 // Install global Function object |
| 834 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, | 798 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, |
| 835 empty_function, Builtins::Illegal, true); // ECMA native. | 799 empty_function, Builtins::Illegal, true); // ECMA native. |
| 836 | 800 |
| 837 { // --- A r r a y --- | 801 { // --- A r r a y --- |
| 838 Handle<JSFunction> array_function = | 802 Handle<JSFunction> array_function = |
| 839 InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize, | 803 InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize, |
| 840 Top::initial_object_prototype(), Builtins::ArrayCode, | 804 Isolate::Current()->initial_object_prototype(), |
| 841 true); | 805 Builtins::ArrayCode, true); |
| 842 array_function->shared()->set_construct_stub( | 806 array_function->shared()->set_construct_stub( |
| 843 Builtins::builtin(Builtins::ArrayConstructCode)); | 807 Isolate::Current()->builtins()->builtin(Builtins::ArrayConstructCode)); |
| 844 array_function->shared()->DontAdaptArguments(); | 808 array_function->shared()->DontAdaptArguments(); |
| 845 | 809 |
| 846 // This seems a bit hackish, but we need to make sure Array.length | 810 // This seems a bit hackish, but we need to make sure Array.length |
| 847 // is 1. | 811 // is 1. |
| 848 array_function->shared()->set_length(1); | 812 array_function->shared()->set_length(1); |
| 849 Handle<DescriptorArray> array_descriptors = | 813 Handle<DescriptorArray> array_descriptors = |
| 850 Factory::CopyAppendProxyDescriptor( | 814 FACTORY->CopyAppendProxyDescriptor( |
| 851 Factory::empty_descriptor_array(), | 815 FACTORY->empty_descriptor_array(), |
| 852 Factory::length_symbol(), | 816 FACTORY->length_symbol(), |
| 853 Factory::NewProxy(&Accessors::ArrayLength), | 817 FACTORY->NewProxy(&Accessors::ArrayLength), |
| 854 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE)); | 818 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE)); |
| 855 | 819 |
| 856 // Cache the fast JavaScript array map | 820 // Cache the fast JavaScript array map |
| 857 global_context()->set_js_array_map(array_function->initial_map()); | 821 global_context()->set_js_array_map(array_function->initial_map()); |
| 858 global_context()->js_array_map()->set_instance_descriptors( | 822 global_context()->js_array_map()->set_instance_descriptors( |
| 859 *array_descriptors); | 823 *array_descriptors); |
| 860 // array_function is used internally. JS code creating array object should | 824 // array_function is used internally. JS code creating array object should |
| 861 // search for the 'Array' property on the global object and use that one | 825 // search for the 'Array' property on the global object and use that one |
| 862 // as the constructor. 'Array' property on a global object can be | 826 // as the constructor. 'Array' property on a global object can be |
| 863 // overwritten by JS code. | 827 // overwritten by JS code. |
| 864 global_context()->set_array_function(*array_function); | 828 global_context()->set_array_function(*array_function); |
| 865 } | 829 } |
| 866 | 830 |
| 867 { // --- N u m b e r --- | 831 { // --- N u m b e r --- |
| 868 Handle<JSFunction> number_fun = | 832 Handle<JSFunction> number_fun = |
| 869 InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize, | 833 InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize, |
| 870 Top::initial_object_prototype(), Builtins::Illegal, | 834 Isolate::Current()->initial_object_prototype(), |
| 871 true); | 835 Builtins::Illegal, true); |
| 872 global_context()->set_number_function(*number_fun); | 836 global_context()->set_number_function(*number_fun); |
| 873 } | 837 } |
| 874 | 838 |
| 875 { // --- B o o l e a n --- | 839 { // --- B o o l e a n --- |
| 876 Handle<JSFunction> boolean_fun = | 840 Handle<JSFunction> boolean_fun = |
| 877 InstallFunction(global, "Boolean", JS_VALUE_TYPE, JSValue::kSize, | 841 InstallFunction(global, "Boolean", JS_VALUE_TYPE, JSValue::kSize, |
| 878 Top::initial_object_prototype(), Builtins::Illegal, | 842 Isolate::Current()->initial_object_prototype(), |
| 879 true); | 843 Builtins::Illegal, true); |
| 880 global_context()->set_boolean_function(*boolean_fun); | 844 global_context()->set_boolean_function(*boolean_fun); |
| 881 } | 845 } |
| 882 | 846 |
| 883 { // --- S t r i n g --- | 847 { // --- S t r i n g --- |
| 884 Handle<JSFunction> string_fun = | 848 Handle<JSFunction> string_fun = |
| 885 InstallFunction(global, "String", JS_VALUE_TYPE, JSValue::kSize, | 849 InstallFunction(global, "String", JS_VALUE_TYPE, JSValue::kSize, |
| 886 Top::initial_object_prototype(), Builtins::Illegal, | 850 Isolate::Current()->initial_object_prototype(), |
| 887 true); | 851 Builtins::Illegal, true); |
| 888 string_fun->shared()->set_construct_stub( | 852 string_fun->shared()->set_construct_stub( |
| 889 Builtins::builtin(Builtins::StringConstructCode)); | 853 Isolate::Current()->builtins()->builtin(Builtins::StringConstructCode)); |
| 890 global_context()->set_string_function(*string_fun); | 854 global_context()->set_string_function(*string_fun); |
| 891 // Add 'length' property to strings. | 855 // Add 'length' property to strings. |
| 892 Handle<DescriptorArray> string_descriptors = | 856 Handle<DescriptorArray> string_descriptors = |
| 893 Factory::CopyAppendProxyDescriptor( | 857 FACTORY->CopyAppendProxyDescriptor( |
| 894 Factory::empty_descriptor_array(), | 858 FACTORY->empty_descriptor_array(), |
| 895 Factory::length_symbol(), | 859 FACTORY->length_symbol(), |
| 896 Factory::NewProxy(&Accessors::StringLength), | 860 FACTORY->NewProxy(&Accessors::StringLength), |
| 897 static_cast<PropertyAttributes>(DONT_ENUM | | 861 static_cast<PropertyAttributes>(DONT_ENUM | |
| 898 DONT_DELETE | | 862 DONT_DELETE | |
| 899 READ_ONLY)); | 863 READ_ONLY)); |
| 900 | 864 |
| 901 Handle<Map> string_map = | 865 Handle<Map> string_map = |
| 902 Handle<Map>(global_context()->string_function()->initial_map()); | 866 Handle<Map>(global_context()->string_function()->initial_map()); |
| 903 string_map->set_instance_descriptors(*string_descriptors); | 867 string_map->set_instance_descriptors(*string_descriptors); |
| 904 } | 868 } |
| 905 | 869 |
| 906 { // --- D a t e --- | 870 { // --- D a t e --- |
| 907 // Builtin functions for Date.prototype. | 871 // Builtin functions for Date.prototype. |
| 908 Handle<JSFunction> date_fun = | 872 Handle<JSFunction> date_fun = |
| 909 InstallFunction(global, "Date", JS_VALUE_TYPE, JSValue::kSize, | 873 InstallFunction(global, "Date", JS_VALUE_TYPE, JSValue::kSize, |
| 910 Top::initial_object_prototype(), Builtins::Illegal, | 874 Isolate::Current()->initial_object_prototype(), |
| 911 true); | 875 Builtins::Illegal, true); |
| 912 | 876 |
| 913 global_context()->set_date_function(*date_fun); | 877 global_context()->set_date_function(*date_fun); |
| 914 } | 878 } |
| 915 | 879 |
| 916 | 880 |
| 917 { // -- R e g E x p | 881 { // -- R e g E x p |
| 918 // Builtin functions for RegExp.prototype. | 882 // Builtin functions for RegExp.prototype. |
| 919 Handle<JSFunction> regexp_fun = | 883 Handle<JSFunction> regexp_fun = |
| 920 InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize, | 884 InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize, |
| 921 Top::initial_object_prototype(), Builtins::Illegal, | 885 Isolate::Current()->initial_object_prototype(), |
| 922 true); | 886 Builtins::Illegal, true); |
| 923 global_context()->set_regexp_function(*regexp_fun); | 887 global_context()->set_regexp_function(*regexp_fun); |
| 924 | 888 |
| 925 ASSERT(regexp_fun->has_initial_map()); | 889 ASSERT(regexp_fun->has_initial_map()); |
| 926 Handle<Map> initial_map(regexp_fun->initial_map()); | 890 Handle<Map> initial_map(regexp_fun->initial_map()); |
| 927 | 891 |
| 928 ASSERT_EQ(0, initial_map->inobject_properties()); | 892 ASSERT_EQ(0, initial_map->inobject_properties()); |
| 929 | 893 |
| 930 Handle<DescriptorArray> descriptors = Factory::NewDescriptorArray(5); | 894 Handle<DescriptorArray> descriptors = FACTORY->NewDescriptorArray(5); |
| 931 PropertyAttributes final = | 895 PropertyAttributes final = |
| 932 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | 896 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 933 int enum_index = 0; | 897 int enum_index = 0; |
| 934 { | 898 { |
| 935 // ECMA-262, section 15.10.7.1. | 899 // ECMA-262, section 15.10.7.1. |
| 936 FieldDescriptor field(Heap::source_symbol(), | 900 FieldDescriptor field(HEAP->source_symbol(), |
| 937 JSRegExp::kSourceFieldIndex, | 901 JSRegExp::kSourceFieldIndex, |
| 938 final, | 902 final, |
| 939 enum_index++); | 903 enum_index++); |
| 940 descriptors->Set(0, &field); | 904 descriptors->Set(0, &field); |
| 941 } | 905 } |
| 942 { | 906 { |
| 943 // ECMA-262, section 15.10.7.2. | 907 // ECMA-262, section 15.10.7.2. |
| 944 FieldDescriptor field(Heap::global_symbol(), | 908 FieldDescriptor field(HEAP->global_symbol(), |
| 945 JSRegExp::kGlobalFieldIndex, | 909 JSRegExp::kGlobalFieldIndex, |
| 946 final, | 910 final, |
| 947 enum_index++); | 911 enum_index++); |
| 948 descriptors->Set(1, &field); | 912 descriptors->Set(1, &field); |
| 949 } | 913 } |
| 950 { | 914 { |
| 951 // ECMA-262, section 15.10.7.3. | 915 // ECMA-262, section 15.10.7.3. |
| 952 FieldDescriptor field(Heap::ignore_case_symbol(), | 916 FieldDescriptor field(HEAP->ignore_case_symbol(), |
| 953 JSRegExp::kIgnoreCaseFieldIndex, | 917 JSRegExp::kIgnoreCaseFieldIndex, |
| 954 final, | 918 final, |
| 955 enum_index++); | 919 enum_index++); |
| 956 descriptors->Set(2, &field); | 920 descriptors->Set(2, &field); |
| 957 } | 921 } |
| 958 { | 922 { |
| 959 // ECMA-262, section 15.10.7.4. | 923 // ECMA-262, section 15.10.7.4. |
| 960 FieldDescriptor field(Heap::multiline_symbol(), | 924 FieldDescriptor field(HEAP->multiline_symbol(), |
| 961 JSRegExp::kMultilineFieldIndex, | 925 JSRegExp::kMultilineFieldIndex, |
| 962 final, | 926 final, |
| 963 enum_index++); | 927 enum_index++); |
| 964 descriptors->Set(3, &field); | 928 descriptors->Set(3, &field); |
| 965 } | 929 } |
| 966 { | 930 { |
| 967 // ECMA-262, section 15.10.7.5. | 931 // ECMA-262, section 15.10.7.5. |
| 968 PropertyAttributes writable = | 932 PropertyAttributes writable = |
| 969 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); | 933 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); |
| 970 FieldDescriptor field(Heap::last_index_symbol(), | 934 FieldDescriptor field(HEAP->last_index_symbol(), |
| 971 JSRegExp::kLastIndexFieldIndex, | 935 JSRegExp::kLastIndexFieldIndex, |
| 972 writable, | 936 writable, |
| 973 enum_index++); | 937 enum_index++); |
| 974 descriptors->Set(4, &field); | 938 descriptors->Set(4, &field); |
| 975 } | 939 } |
| 976 descriptors->SetNextEnumerationIndex(enum_index); | 940 descriptors->SetNextEnumerationIndex(enum_index); |
| 977 descriptors->Sort(); | 941 descriptors->Sort(); |
| 978 | 942 |
| 979 initial_map->set_inobject_properties(5); | 943 initial_map->set_inobject_properties(5); |
| 980 initial_map->set_pre_allocated_property_fields(5); | 944 initial_map->set_pre_allocated_property_fields(5); |
| 981 initial_map->set_unused_property_fields(0); | 945 initial_map->set_unused_property_fields(0); |
| 982 initial_map->set_instance_size( | 946 initial_map->set_instance_size( |
| 983 initial_map->instance_size() + 5 * kPointerSize); | 947 initial_map->instance_size() + 5 * kPointerSize); |
| 984 initial_map->set_instance_descriptors(*descriptors); | 948 initial_map->set_instance_descriptors(*descriptors); |
| 985 initial_map->set_visitor_id(StaticVisitorBase::GetVisitorId(*initial_map)); | 949 initial_map->set_visitor_id(StaticVisitorBase::GetVisitorId(*initial_map)); |
| 986 } | 950 } |
| 987 | 951 |
| 988 { // -- J S O N | 952 { // -- J S O N |
| 989 Handle<String> name = Factory::NewStringFromAscii(CStrVector("JSON")); | 953 Handle<String> name = FACTORY->NewStringFromAscii(CStrVector("JSON")); |
| 990 Handle<JSFunction> cons = Factory::NewFunction( | 954 Handle<JSFunction> cons = FACTORY->NewFunction( |
| 991 name, | 955 name, |
| 992 Factory::the_hole_value()); | 956 FACTORY->the_hole_value()); |
| 993 cons->SetInstancePrototype(global_context()->initial_object_prototype()); | 957 cons->SetInstancePrototype(global_context()->initial_object_prototype()); |
| 994 cons->SetInstanceClassName(*name); | 958 cons->SetInstanceClassName(*name); |
| 995 Handle<JSObject> json_object = Factory::NewJSObject(cons, TENURED); | 959 Handle<JSObject> json_object = FACTORY->NewJSObject(cons, TENURED); |
| 996 ASSERT(json_object->IsJSObject()); | 960 ASSERT(json_object->IsJSObject()); |
| 997 SetLocalPropertyNoThrow(global, name, json_object, DONT_ENUM); | 961 SetLocalPropertyNoThrow(global, name, json_object, DONT_ENUM); |
| 998 global_context()->set_json_object(*json_object); | 962 global_context()->set_json_object(*json_object); |
| 999 } | 963 } |
| 1000 | 964 |
| 1001 { // --- arguments_boilerplate_ | 965 { // --- arguments_boilerplate_ |
| 1002 // Make sure we can recognize argument objects at runtime. | 966 // Make sure we can recognize argument objects at runtime. |
| 1003 // This is done by introducing an anonymous function with | 967 // This is done by introducing an anonymous function with |
| 1004 // class_name equals 'Arguments'. | 968 // class_name equals 'Arguments'. |
| 1005 Handle<String> symbol = Factory::LookupAsciiSymbol("Arguments"); | 969 Handle<String> symbol = FACTORY->LookupAsciiSymbol("Arguments"); |
| 1006 Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::Illegal)); | 970 Handle<Code> code = Handle<Code>( |
| 971 Isolate::Current()->builtins()->builtin(Builtins::Illegal)); |
| 1007 Handle<JSObject> prototype = | 972 Handle<JSObject> prototype = |
| 1008 Handle<JSObject>( | 973 Handle<JSObject>( |
| 1009 JSObject::cast(global_context()->object_function()->prototype())); | 974 JSObject::cast(global_context()->object_function()->prototype())); |
| 1010 | 975 |
| 1011 Handle<JSFunction> function = | 976 Handle<JSFunction> function = |
| 1012 Factory::NewFunctionWithPrototype(symbol, | 977 FACTORY->NewFunctionWithPrototype(symbol, |
| 1013 JS_OBJECT_TYPE, | 978 JS_OBJECT_TYPE, |
| 1014 JSObject::kHeaderSize, | 979 JSObject::kHeaderSize, |
| 1015 prototype, | 980 prototype, |
| 1016 code, | 981 code, |
| 1017 false); | 982 false); |
| 1018 ASSERT(!function->has_initial_map()); | 983 ASSERT(!function->has_initial_map()); |
| 1019 function->shared()->set_instance_class_name(*symbol); | 984 function->shared()->set_instance_class_name(*symbol); |
| 1020 function->shared()->set_expected_nof_properties(2); | 985 function->shared()->set_expected_nof_properties(2); |
| 1021 Handle<JSObject> result = Factory::NewJSObject(function); | 986 Handle<JSObject> result = FACTORY->NewJSObject(function); |
| 1022 | 987 |
| 1023 global_context()->set_arguments_boilerplate(*result); | 988 global_context()->set_arguments_boilerplate(*result); |
| 1024 // Note: length must be added as the first property and | 989 // Note: length must be added as the first property and |
| 1025 // callee must be added as the second property. | 990 // callee must be added as the second property. |
| 1026 SetLocalPropertyNoThrow(result, Factory::length_symbol(), | 991 SetLocalPropertyNoThrow(result, FACTORY->length_symbol(), |
| 1027 Factory::undefined_value(), | 992 FACTORY->undefined_value(), |
| 1028 DONT_ENUM); | 993 DONT_ENUM); |
| 1029 SetLocalPropertyNoThrow(result, Factory::callee_symbol(), | 994 SetLocalPropertyNoThrow(result, FACTORY->callee_symbol(), |
| 1030 Factory::undefined_value(), | 995 FACTORY->undefined_value(), |
| 1031 DONT_ENUM); | 996 DONT_ENUM); |
| 1032 | 997 |
| 1033 #ifdef DEBUG | 998 #ifdef DEBUG |
| 1034 LookupResult lookup; | 999 LookupResult lookup; |
| 1035 result->LocalLookup(Heap::callee_symbol(), &lookup); | 1000 result->LocalLookup(HEAP->callee_symbol(), &lookup); |
| 1036 ASSERT(lookup.IsProperty() && (lookup.type() == FIELD)); | 1001 ASSERT(lookup.IsProperty() && (lookup.type() == FIELD)); |
| 1037 ASSERT(lookup.GetFieldIndex() == Heap::kArgumentsCalleeIndex); | 1002 ASSERT(lookup.GetFieldIndex() == Heap::kArgumentsCalleeIndex); |
| 1038 | 1003 |
| 1039 result->LocalLookup(Heap::length_symbol(), &lookup); | 1004 result->LocalLookup(HEAP->length_symbol(), &lookup); |
| 1040 ASSERT(lookup.IsProperty() && (lookup.type() == FIELD)); | 1005 ASSERT(lookup.IsProperty() && (lookup.type() == FIELD)); |
| 1041 ASSERT(lookup.GetFieldIndex() == Heap::kArgumentsLengthIndex); | 1006 ASSERT(lookup.GetFieldIndex() == Heap::kArgumentsLengthIndex); |
| 1042 | 1007 |
| 1043 ASSERT(result->map()->inobject_properties() > Heap::kArgumentsCalleeIndex); | 1008 ASSERT(result->map()->inobject_properties() > Heap::kArgumentsCalleeIndex); |
| 1044 ASSERT(result->map()->inobject_properties() > Heap::kArgumentsLengthIndex); | 1009 ASSERT(result->map()->inobject_properties() > Heap::kArgumentsLengthIndex); |
| 1045 | 1010 |
| 1046 // Check the state of the object. | 1011 // Check the state of the object. |
| 1047 ASSERT(result->HasFastProperties()); | 1012 ASSERT(result->HasFastProperties()); |
| 1048 ASSERT(result->HasFastElements()); | 1013 ASSERT(result->HasFastElements()); |
| 1049 #endif | 1014 #endif |
| 1050 } | 1015 } |
| 1051 | 1016 |
| 1052 { // --- strict mode arguments boilerplate | 1017 { // --- strict mode arguments boilerplate |
| 1053 const PropertyAttributes attributes = | 1018 const PropertyAttributes attributes = |
| 1054 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | 1019 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 1055 | 1020 |
| 1056 // Create the ThrowTypeError functions. | 1021 // Create the ThrowTypeError functions. |
| 1057 Handle<FixedArray> callee = Factory::NewFixedArray(2, TENURED); | 1022 Handle<FixedArray> callee = FACTORY->NewFixedArray(2, TENURED); |
| 1058 Handle<FixedArray> caller = Factory::NewFixedArray(2, TENURED); | 1023 Handle<FixedArray> caller = FACTORY->NewFixedArray(2, TENURED); |
| 1059 | 1024 |
| 1060 Handle<JSFunction> callee_throw = | 1025 Handle<JSFunction> callee_throw = |
| 1061 CreateThrowTypeErrorFunction(Builtins::StrictArgumentsCallee); | 1026 CreateThrowTypeErrorFunction(Builtins::StrictArgumentsCallee); |
| 1062 Handle<JSFunction> caller_throw = | 1027 Handle<JSFunction> caller_throw = |
| 1063 CreateThrowTypeErrorFunction(Builtins::StrictArgumentsCaller); | 1028 CreateThrowTypeErrorFunction(Builtins::StrictArgumentsCaller); |
| 1064 | 1029 |
| 1065 // Install the ThrowTypeError functions. | 1030 // Install the ThrowTypeError functions. |
| 1066 callee->set(0, *callee_throw); | 1031 callee->set(0, *callee_throw); |
| 1067 callee->set(1, *callee_throw); | 1032 callee->set(1, *callee_throw); |
| 1068 caller->set(0, *caller_throw); | 1033 caller->set(0, *caller_throw); |
| 1069 caller->set(1, *caller_throw); | 1034 caller->set(1, *caller_throw); |
| 1070 | 1035 |
| 1071 // Create the descriptor array for the arguments object. | 1036 // Create the descriptor array for the arguments object. |
| 1072 Handle<DescriptorArray> descriptors = Factory::NewDescriptorArray(3); | 1037 Handle<DescriptorArray> descriptors = FACTORY->NewDescriptorArray(3); |
| 1073 { // length | 1038 { // length |
| 1074 FieldDescriptor d(*Factory::length_symbol(), 0, DONT_ENUM); | 1039 FieldDescriptor d(*FACTORY->length_symbol(), 0, DONT_ENUM); |
| 1075 descriptors->Set(0, &d); | 1040 descriptors->Set(0, &d); |
| 1076 } | 1041 } |
| 1077 { // callee | 1042 { // callee |
| 1078 CallbacksDescriptor d(*Factory::callee_symbol(), *callee, attributes); | 1043 CallbacksDescriptor d(*FACTORY->callee_symbol(), *callee, attributes); |
| 1079 descriptors->Set(1, &d); | 1044 descriptors->Set(1, &d); |
| 1080 } | 1045 } |
| 1081 { // caller | 1046 { // caller |
| 1082 CallbacksDescriptor d(*Factory::caller_symbol(), *caller, attributes); | 1047 CallbacksDescriptor d(*FACTORY->caller_symbol(), *caller, attributes); |
| 1083 descriptors->Set(2, &d); | 1048 descriptors->Set(2, &d); |
| 1084 } | 1049 } |
| 1085 descriptors->Sort(); | 1050 descriptors->Sort(); |
| 1086 | 1051 |
| 1087 // Create the map. Allocate one in-object field for length. | 1052 // Create the map. Allocate one in-object field for length. |
| 1088 Handle<Map> map = Factory::NewMap(JS_OBJECT_TYPE, | 1053 Handle<Map> map = FACTORY->NewMap(JS_OBJECT_TYPE, |
| 1089 Heap::kArgumentsObjectSizeStrict); | 1054 Heap::kArgumentsObjectSizeStrict); |
| 1090 map->set_instance_descriptors(*descriptors); | 1055 map->set_instance_descriptors(*descriptors); |
| 1091 map->set_function_with_prototype(true); | 1056 map->set_function_with_prototype(true); |
| 1092 map->set_prototype(global_context()->object_function()->prototype()); | 1057 map->set_prototype(global_context()->object_function()->prototype()); |
| 1093 map->set_pre_allocated_property_fields(1); | 1058 map->set_pre_allocated_property_fields(1); |
| 1094 map->set_inobject_properties(1); | 1059 map->set_inobject_properties(1); |
| 1095 | 1060 |
| 1096 // Copy constructor from the non-strict arguments boilerplate. | 1061 // Copy constructor from the non-strict arguments boilerplate. |
| 1097 map->set_constructor( | 1062 map->set_constructor( |
| 1098 global_context()->arguments_boilerplate()->map()->constructor()); | 1063 global_context()->arguments_boilerplate()->map()->constructor()); |
| 1099 | 1064 |
| 1100 // Allocate the arguments boilerplate object. | 1065 // Allocate the arguments boilerplate object. |
| 1101 Handle<JSObject> result = Factory::NewJSObjectFromMap(map); | 1066 Handle<JSObject> result = FACTORY->NewJSObjectFromMap(map); |
| 1102 global_context()->set_strict_mode_arguments_boilerplate(*result); | 1067 global_context()->set_strict_mode_arguments_boilerplate(*result); |
| 1103 | 1068 |
| 1104 // Add length property only for strict mode boilerplate. | 1069 // Add length property only for strict mode boilerplate. |
| 1105 SetLocalPropertyNoThrow(result, Factory::length_symbol(), | 1070 SetLocalPropertyNoThrow(result, FACTORY->length_symbol(), |
| 1106 Factory::undefined_value(), | 1071 FACTORY->undefined_value(), |
| 1107 DONT_ENUM); | 1072 DONT_ENUM); |
| 1108 | 1073 |
| 1109 #ifdef DEBUG | 1074 #ifdef DEBUG |
| 1110 LookupResult lookup; | 1075 LookupResult lookup; |
| 1111 result->LocalLookup(Heap::length_symbol(), &lookup); | 1076 result->LocalLookup(HEAP->length_symbol(), &lookup); |
| 1112 ASSERT(lookup.IsProperty() && (lookup.type() == FIELD)); | 1077 ASSERT(lookup.IsProperty() && (lookup.type() == FIELD)); |
| 1113 ASSERT(lookup.GetFieldIndex() == Heap::kArgumentsLengthIndex); | 1078 ASSERT(lookup.GetFieldIndex() == Heap::kArgumentsLengthIndex); |
| 1114 | 1079 |
| 1115 ASSERT(result->map()->inobject_properties() > Heap::kArgumentsLengthIndex); | 1080 ASSERT(result->map()->inobject_properties() > Heap::kArgumentsLengthIndex); |
| 1116 | 1081 |
| 1117 // Check the state of the object. | 1082 // Check the state of the object. |
| 1118 ASSERT(result->HasFastProperties()); | 1083 ASSERT(result->HasFastProperties()); |
| 1119 ASSERT(result->HasFastElements()); | 1084 ASSERT(result->HasFastElements()); |
| 1120 #endif | 1085 #endif |
| 1121 } | 1086 } |
| 1122 | 1087 |
| 1123 { // --- context extension | 1088 { // --- context extension |
| 1124 // Create a function for the context extension objects. | 1089 // Create a function for the context extension objects. |
| 1125 Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::Illegal)); | 1090 Handle<Code> code = Handle<Code>( |
| 1091 Isolate::Current()->builtins()->builtin(Builtins::Illegal)); |
| 1126 Handle<JSFunction> context_extension_fun = | 1092 Handle<JSFunction> context_extension_fun = |
| 1127 Factory::NewFunction(Factory::empty_symbol(), | 1093 FACTORY->NewFunction(FACTORY->empty_symbol(), |
| 1128 JS_CONTEXT_EXTENSION_OBJECT_TYPE, | 1094 JS_CONTEXT_EXTENSION_OBJECT_TYPE, |
| 1129 JSObject::kHeaderSize, | 1095 JSObject::kHeaderSize, |
| 1130 code, | 1096 code, |
| 1131 true); | 1097 true); |
| 1132 | 1098 |
| 1133 Handle<String> name = Factory::LookupAsciiSymbol("context_extension"); | 1099 Handle<String> name = FACTORY->LookupAsciiSymbol("context_extension"); |
| 1134 context_extension_fun->shared()->set_instance_class_name(*name); | 1100 context_extension_fun->shared()->set_instance_class_name(*name); |
| 1135 global_context()->set_context_extension_function(*context_extension_fun); | 1101 global_context()->set_context_extension_function(*context_extension_fun); |
| 1136 } | 1102 } |
| 1137 | 1103 |
| 1138 | 1104 |
| 1139 { | 1105 { |
| 1140 // Setup the call-as-function delegate. | 1106 // Setup the call-as-function delegate. |
| 1141 Handle<Code> code = | 1107 Handle<Code> code = |
| 1142 Handle<Code>(Builtins::builtin(Builtins::HandleApiCallAsFunction)); | 1108 Handle<Code>(Isolate::Current()->builtins()->builtin( |
| 1109 Builtins::HandleApiCallAsFunction)); |
| 1143 Handle<JSFunction> delegate = | 1110 Handle<JSFunction> delegate = |
| 1144 Factory::NewFunction(Factory::empty_symbol(), JS_OBJECT_TYPE, | 1111 FACTORY->NewFunction(FACTORY->empty_symbol(), JS_OBJECT_TYPE, |
| 1145 JSObject::kHeaderSize, code, true); | 1112 JSObject::kHeaderSize, code, true); |
| 1146 global_context()->set_call_as_function_delegate(*delegate); | 1113 global_context()->set_call_as_function_delegate(*delegate); |
| 1147 delegate->shared()->DontAdaptArguments(); | 1114 delegate->shared()->DontAdaptArguments(); |
| 1148 } | 1115 } |
| 1149 | 1116 |
| 1150 { | 1117 { |
| 1151 // Setup the call-as-constructor delegate. | 1118 // Setup the call-as-constructor delegate. |
| 1152 Handle<Code> code = | 1119 Handle<Code> code = |
| 1153 Handle<Code>(Builtins::builtin(Builtins::HandleApiCallAsConstructor)); | 1120 Handle<Code>(Isolate::Current()->builtins()->builtin( |
| 1121 Builtins::HandleApiCallAsConstructor)); |
| 1154 Handle<JSFunction> delegate = | 1122 Handle<JSFunction> delegate = |
| 1155 Factory::NewFunction(Factory::empty_symbol(), JS_OBJECT_TYPE, | 1123 FACTORY->NewFunction(FACTORY->empty_symbol(), JS_OBJECT_TYPE, |
| 1156 JSObject::kHeaderSize, code, true); | 1124 JSObject::kHeaderSize, code, true); |
| 1157 global_context()->set_call_as_constructor_delegate(*delegate); | 1125 global_context()->set_call_as_constructor_delegate(*delegate); |
| 1158 delegate->shared()->DontAdaptArguments(); | 1126 delegate->shared()->DontAdaptArguments(); |
| 1159 } | 1127 } |
| 1160 | 1128 |
| 1161 // Initialize the out of memory slot. | 1129 // Initialize the out of memory slot. |
| 1162 global_context()->set_out_of_memory(Heap::false_value()); | 1130 global_context()->set_out_of_memory(HEAP->false_value()); |
| 1163 | 1131 |
| 1164 // Initialize the data slot. | 1132 // Initialize the data slot. |
| 1165 global_context()->set_data(Heap::undefined_value()); | 1133 global_context()->set_data(HEAP->undefined_value()); |
| 1166 } | 1134 } |
| 1167 | 1135 |
| 1168 | 1136 |
| 1169 bool Genesis::CompileBuiltin(int index) { | 1137 bool Genesis::CompileBuiltin(int index) { |
| 1170 Vector<const char> name = Natives::GetScriptName(index); | 1138 Vector<const char> name = Natives::GetScriptName(index); |
| 1171 Handle<String> source_code = Bootstrapper::NativesSourceLookup(index); | 1139 Handle<String> source_code = |
| 1140 Isolate::Current()->bootstrapper()->NativesSourceLookup(index); |
| 1172 return CompileNative(name, source_code); | 1141 return CompileNative(name, source_code); |
| 1173 } | 1142 } |
| 1174 | 1143 |
| 1175 | 1144 |
| 1176 bool Genesis::CompileNative(Vector<const char> name, Handle<String> source) { | 1145 bool Genesis::CompileNative(Vector<const char> name, Handle<String> source) { |
| 1177 HandleScope scope; | 1146 HandleScope scope; |
| 1147 Isolate* isolate = Isolate::Current(); |
| 1178 #ifdef ENABLE_DEBUGGER_SUPPORT | 1148 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1179 Debugger::set_compiling_natives(true); | 1149 isolate->debugger()->set_compiling_natives(true); |
| 1180 #endif | 1150 #endif |
| 1181 bool result = CompileScriptCached(name, | 1151 bool result = CompileScriptCached(name, |
| 1182 source, | 1152 source, |
| 1183 NULL, | 1153 NULL, |
| 1184 NULL, | 1154 NULL, |
| 1185 Handle<Context>(Top::context()), | 1155 Handle<Context>(isolate->context()), |
| 1186 true); | 1156 true); |
| 1187 ASSERT(Top::has_pending_exception() != result); | 1157 ASSERT(isolate->has_pending_exception() != result); |
| 1188 if (!result) Top::clear_pending_exception(); | 1158 if (!result) isolate->clear_pending_exception(); |
| 1189 #ifdef ENABLE_DEBUGGER_SUPPORT | 1159 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1190 Debugger::set_compiling_natives(false); | 1160 isolate->debugger()->set_compiling_natives(false); |
| 1191 #endif | 1161 #endif |
| 1192 return result; | 1162 return result; |
| 1193 } | 1163 } |
| 1194 | 1164 |
| 1195 | 1165 |
| 1196 bool Genesis::CompileScriptCached(Vector<const char> name, | 1166 bool Genesis::CompileScriptCached(Vector<const char> name, |
| 1197 Handle<String> source, | 1167 Handle<String> source, |
| 1198 SourceCodeCache* cache, | 1168 SourceCodeCache* cache, |
| 1199 v8::Extension* extension, | 1169 v8::Extension* extension, |
| 1200 Handle<Context> top_context, | 1170 Handle<Context> top_context, |
| 1201 bool use_runtime_context) { | 1171 bool use_runtime_context) { |
| 1202 HandleScope scope; | 1172 HandleScope scope; |
| 1203 Handle<SharedFunctionInfo> function_info; | 1173 Handle<SharedFunctionInfo> function_info; |
| 1204 | 1174 |
| 1205 // If we can't find the function in the cache, we compile a new | 1175 // If we can't find the function in the cache, we compile a new |
| 1206 // function and insert it into the cache. | 1176 // function and insert it into the cache. |
| 1207 if (cache == NULL || !cache->Lookup(name, &function_info)) { | 1177 if (cache == NULL || !cache->Lookup(name, &function_info)) { |
| 1208 ASSERT(source->IsAsciiRepresentation()); | 1178 ASSERT(source->IsAsciiRepresentation()); |
| 1209 Handle<String> script_name = Factory::NewStringFromUtf8(name); | 1179 Handle<String> script_name = FACTORY->NewStringFromUtf8(name); |
| 1210 function_info = Compiler::Compile( | 1180 function_info = Compiler::Compile( |
| 1211 source, | 1181 source, |
| 1212 script_name, | 1182 script_name, |
| 1213 0, | 1183 0, |
| 1214 0, | 1184 0, |
| 1215 extension, | 1185 extension, |
| 1216 NULL, | 1186 NULL, |
| 1217 Handle<String>::null(), | 1187 Handle<String>::null(), |
| 1218 use_runtime_context ? NATIVES_CODE : NOT_NATIVES_CODE); | 1188 use_runtime_context ? NATIVES_CODE : NOT_NATIVES_CODE); |
| 1219 if (function_info.is_null()) return false; | 1189 if (function_info.is_null()) return false; |
| 1220 if (cache != NULL) cache->Add(name, function_info); | 1190 if (cache != NULL) cache->Add(name, function_info); |
| 1221 } | 1191 } |
| 1222 | 1192 |
| 1223 // Setup the function context. Conceptually, we should clone the | 1193 // Setup the function context. Conceptually, we should clone the |
| 1224 // function before overwriting the context but since we're in a | 1194 // function before overwriting the context but since we're in a |
| 1225 // single-threaded environment it is not strictly necessary. | 1195 // single-threaded environment it is not strictly necessary. |
| 1226 ASSERT(top_context->IsGlobalContext()); | 1196 ASSERT(top_context->IsGlobalContext()); |
| 1227 Handle<Context> context = | 1197 Handle<Context> context = |
| 1228 Handle<Context>(use_runtime_context | 1198 Handle<Context>(use_runtime_context |
| 1229 ? Handle<Context>(top_context->runtime_context()) | 1199 ? Handle<Context>(top_context->runtime_context()) |
| 1230 : top_context); | 1200 : top_context); |
| 1231 Handle<JSFunction> fun = | 1201 Handle<JSFunction> fun = |
| 1232 Factory::NewFunctionFromSharedFunctionInfo(function_info, context); | 1202 FACTORY->NewFunctionFromSharedFunctionInfo(function_info, context); |
| 1233 | 1203 |
| 1234 // Call function using either the runtime object or the global | 1204 // Call function using either the runtime object or the global |
| 1235 // object as the receiver. Provide no parameters. | 1205 // object as the receiver. Provide no parameters. |
| 1236 Handle<Object> receiver = | 1206 Handle<Object> receiver = |
| 1237 Handle<Object>(use_runtime_context | 1207 Handle<Object>(use_runtime_context |
| 1238 ? top_context->builtins() | 1208 ? top_context->builtins() |
| 1239 : top_context->global()); | 1209 : top_context->global()); |
| 1240 bool has_pending_exception; | 1210 bool has_pending_exception; |
| 1241 Handle<Object> result = | 1211 Handle<Object> result = |
| 1242 Execution::Call(fun, receiver, 0, NULL, &has_pending_exception); | 1212 Execution::Call(fun, receiver, 0, NULL, &has_pending_exception); |
| 1243 if (has_pending_exception) return false; | 1213 if (has_pending_exception) return false; |
| 1244 return true; | 1214 return true; |
| 1245 } | 1215 } |
| 1246 | 1216 |
| 1247 | 1217 |
| 1248 #define INSTALL_NATIVE(Type, name, var) \ | 1218 #define INSTALL_NATIVE(Type, name, var) \ |
| 1249 Handle<String> var##_name = Factory::LookupAsciiSymbol(name); \ | 1219 Handle<String> var##_name = FACTORY->LookupAsciiSymbol(name); \ |
| 1250 global_context()->set_##var(Type::cast( \ | 1220 global_context()->set_##var(Type::cast( \ |
| 1251 global_context()->builtins()->GetPropertyNoExceptionThrown(*var##_name))); | 1221 global_context()->builtins()->GetPropertyNoExceptionThrown(*var##_name))); |
| 1252 | 1222 |
| 1223 |
| 1253 void Genesis::InstallNativeFunctions() { | 1224 void Genesis::InstallNativeFunctions() { |
| 1254 HandleScope scope; | 1225 HandleScope scope; |
| 1255 INSTALL_NATIVE(JSFunction, "CreateDate", create_date_fun); | 1226 INSTALL_NATIVE(JSFunction, "CreateDate", create_date_fun); |
| 1256 INSTALL_NATIVE(JSFunction, "ToNumber", to_number_fun); | 1227 INSTALL_NATIVE(JSFunction, "ToNumber", to_number_fun); |
| 1257 INSTALL_NATIVE(JSFunction, "ToString", to_string_fun); | 1228 INSTALL_NATIVE(JSFunction, "ToString", to_string_fun); |
| 1258 INSTALL_NATIVE(JSFunction, "ToDetailString", to_detail_string_fun); | 1229 INSTALL_NATIVE(JSFunction, "ToDetailString", to_detail_string_fun); |
| 1259 INSTALL_NATIVE(JSFunction, "ToObject", to_object_fun); | 1230 INSTALL_NATIVE(JSFunction, "ToObject", to_object_fun); |
| 1260 INSTALL_NATIVE(JSFunction, "ToInteger", to_integer_fun); | 1231 INSTALL_NATIVE(JSFunction, "ToInteger", to_integer_fun); |
| 1261 INSTALL_NATIVE(JSFunction, "ToUint32", to_uint32_fun); | 1232 INSTALL_NATIVE(JSFunction, "ToUint32", to_uint32_fun); |
| 1262 INSTALL_NATIVE(JSFunction, "ToInt32", to_int32_fun); | 1233 INSTALL_NATIVE(JSFunction, "ToInt32", to_int32_fun); |
| 1263 INSTALL_NATIVE(JSFunction, "GlobalEval", global_eval_fun); | 1234 INSTALL_NATIVE(JSFunction, "GlobalEval", global_eval_fun); |
| 1264 INSTALL_NATIVE(JSFunction, "Instantiate", instantiate_fun); | 1235 INSTALL_NATIVE(JSFunction, "Instantiate", instantiate_fun); |
| 1265 INSTALL_NATIVE(JSFunction, "ConfigureTemplateInstance", | 1236 INSTALL_NATIVE(JSFunction, "ConfigureTemplateInstance", |
| 1266 configure_instance_fun); | 1237 configure_instance_fun); |
| 1267 INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun); | 1238 INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun); |
| 1268 INSTALL_NATIVE(JSObject, "functionCache", function_cache); | 1239 INSTALL_NATIVE(JSObject, "functionCache", function_cache); |
| 1269 } | 1240 } |
| 1270 | 1241 |
| 1271 #undef INSTALL_NATIVE | 1242 #undef INSTALL_NATIVE |
| 1272 | 1243 |
| 1273 | 1244 |
| 1274 bool Genesis::InstallNatives() { | 1245 bool Genesis::InstallNatives() { |
| 1275 HandleScope scope; | 1246 HandleScope scope; |
| 1247 Isolate* isolate = Isolate::Current(); |
| 1248 Factory* factory = isolate->factory(); |
| 1276 | 1249 |
| 1277 // Create a function for the builtins object. Allocate space for the | 1250 // Create a function for the builtins object. Allocate space for the |
| 1278 // JavaScript builtins, a reference to the builtins object | 1251 // JavaScript builtins, a reference to the builtins object |
| 1279 // (itself) and a reference to the global_context directly in the object. | 1252 // (itself) and a reference to the global_context directly in the object. |
| 1280 Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::Illegal)); | 1253 Handle<Code> code = Handle<Code>( |
| 1254 isolate->builtins()->builtin(Builtins::Illegal)); |
| 1281 Handle<JSFunction> builtins_fun = | 1255 Handle<JSFunction> builtins_fun = |
| 1282 Factory::NewFunction(Factory::empty_symbol(), JS_BUILTINS_OBJECT_TYPE, | 1256 factory->NewFunction(factory->empty_symbol(), JS_BUILTINS_OBJECT_TYPE, |
| 1283 JSBuiltinsObject::kSize, code, true); | 1257 JSBuiltinsObject::kSize, code, true); |
| 1284 | 1258 |
| 1285 Handle<String> name = Factory::LookupAsciiSymbol("builtins"); | 1259 Handle<String> name = factory->LookupAsciiSymbol("builtins"); |
| 1286 builtins_fun->shared()->set_instance_class_name(*name); | 1260 builtins_fun->shared()->set_instance_class_name(*name); |
| 1287 | 1261 |
| 1288 // Allocate the builtins object. | 1262 // Allocate the builtins object. |
| 1289 Handle<JSBuiltinsObject> builtins = | 1263 Handle<JSBuiltinsObject> builtins = |
| 1290 Handle<JSBuiltinsObject>::cast(Factory::NewGlobalObject(builtins_fun)); | 1264 Handle<JSBuiltinsObject>::cast(factory->NewGlobalObject(builtins_fun)); |
| 1291 builtins->set_builtins(*builtins); | 1265 builtins->set_builtins(*builtins); |
| 1292 builtins->set_global_context(*global_context()); | 1266 builtins->set_global_context(*global_context()); |
| 1293 builtins->set_global_receiver(*builtins); | 1267 builtins->set_global_receiver(*builtins); |
| 1294 | 1268 |
| 1295 // Setup the 'global' properties of the builtins object. The | 1269 // Setup the 'global' properties of the builtins object. The |
| 1296 // 'global' property that refers to the global object is the only | 1270 // 'global' property that refers to the global object is the only |
| 1297 // way to get from code running in the builtins context to the | 1271 // way to get from code running in the builtins context to the |
| 1298 // global object. | 1272 // global object. |
| 1299 static const PropertyAttributes attributes = | 1273 static const PropertyAttributes attributes = |
| 1300 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); | 1274 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); |
| 1301 Handle<String> global_symbol = Factory::LookupAsciiSymbol("global"); | 1275 Handle<String> global_symbol = factory->LookupAsciiSymbol("global"); |
| 1302 Handle<Object> global_obj(global_context()->global()); | 1276 Handle<Object> global_obj(global_context()->global()); |
| 1303 SetLocalPropertyNoThrow(builtins, global_symbol, global_obj, attributes); | 1277 SetLocalPropertyNoThrow(builtins, global_symbol, global_obj, attributes); |
| 1304 | 1278 |
| 1305 // Setup the reference from the global object to the builtins object. | 1279 // Setup the reference from the global object to the builtins object. |
| 1306 JSGlobalObject::cast(global_context()->global())->set_builtins(*builtins); | 1280 JSGlobalObject::cast(global_context()->global())->set_builtins(*builtins); |
| 1307 | 1281 |
| 1308 // Create a bridge function that has context in the global context. | 1282 // Create a bridge function that has context in the global context. |
| 1309 Handle<JSFunction> bridge = | 1283 Handle<JSFunction> bridge = |
| 1310 Factory::NewFunction(Factory::empty_symbol(), Factory::undefined_value()); | 1284 factory->NewFunction(factory->empty_symbol(), factory->undefined_value()); |
| 1311 ASSERT(bridge->context() == *Top::global_context()); | 1285 ASSERT(bridge->context() == *isolate->global_context()); |
| 1312 | 1286 |
| 1313 // Allocate the builtins context. | 1287 // Allocate the builtins context. |
| 1314 Handle<Context> context = | 1288 Handle<Context> context = |
| 1315 Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge); | 1289 factory->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge); |
| 1316 context->set_global(*builtins); // override builtins global object | 1290 context->set_global(*builtins); // override builtins global object |
| 1317 | 1291 |
| 1318 global_context()->set_runtime_context(*context); | 1292 global_context()->set_runtime_context(*context); |
| 1319 | 1293 |
| 1320 { // -- S c r i p t | 1294 { // -- S c r i p t |
| 1321 // Builtin functions for Script. | 1295 // Builtin functions for Script. |
| 1322 Handle<JSFunction> script_fun = | 1296 Handle<JSFunction> script_fun = |
| 1323 InstallFunction(builtins, "Script", JS_VALUE_TYPE, JSValue::kSize, | 1297 InstallFunction(builtins, "Script", JS_VALUE_TYPE, JSValue::kSize, |
| 1324 Top::initial_object_prototype(), Builtins::Illegal, | 1298 isolate->initial_object_prototype(), |
| 1325 false); | 1299 Builtins::Illegal, false); |
| 1326 Handle<JSObject> prototype = | 1300 Handle<JSObject> prototype = |
| 1327 Factory::NewJSObject(Top::object_function(), TENURED); | 1301 factory->NewJSObject(isolate->object_function(), TENURED); |
| 1328 SetPrototype(script_fun, prototype); | 1302 SetPrototype(script_fun, prototype); |
| 1329 global_context()->set_script_function(*script_fun); | 1303 global_context()->set_script_function(*script_fun); |
| 1330 | 1304 |
| 1331 // Add 'source' and 'data' property to scripts. | 1305 // Add 'source' and 'data' property to scripts. |
| 1332 PropertyAttributes common_attributes = | 1306 PropertyAttributes common_attributes = |
| 1333 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | 1307 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 1334 Handle<Proxy> proxy_source = Factory::NewProxy(&Accessors::ScriptSource); | 1308 Handle<Proxy> proxy_source = factory->NewProxy(&Accessors::ScriptSource); |
| 1335 Handle<DescriptorArray> script_descriptors = | 1309 Handle<DescriptorArray> script_descriptors = |
| 1336 Factory::CopyAppendProxyDescriptor( | 1310 factory->CopyAppendProxyDescriptor( |
| 1337 Factory::empty_descriptor_array(), | 1311 factory->empty_descriptor_array(), |
| 1338 Factory::LookupAsciiSymbol("source"), | 1312 factory->LookupAsciiSymbol("source"), |
| 1339 proxy_source, | 1313 proxy_source, |
| 1340 common_attributes); | 1314 common_attributes); |
| 1341 Handle<Proxy> proxy_name = Factory::NewProxy(&Accessors::ScriptName); | 1315 Handle<Proxy> proxy_name = factory->NewProxy(&Accessors::ScriptName); |
| 1342 script_descriptors = | 1316 script_descriptors = |
| 1343 Factory::CopyAppendProxyDescriptor( | 1317 factory->CopyAppendProxyDescriptor( |
| 1344 script_descriptors, | 1318 script_descriptors, |
| 1345 Factory::LookupAsciiSymbol("name"), | 1319 factory->LookupAsciiSymbol("name"), |
| 1346 proxy_name, | 1320 proxy_name, |
| 1347 common_attributes); | 1321 common_attributes); |
| 1348 Handle<Proxy> proxy_id = Factory::NewProxy(&Accessors::ScriptId); | 1322 Handle<Proxy> proxy_id = factory->NewProxy(&Accessors::ScriptId); |
| 1349 script_descriptors = | 1323 script_descriptors = |
| 1350 Factory::CopyAppendProxyDescriptor( | 1324 factory->CopyAppendProxyDescriptor( |
| 1351 script_descriptors, | 1325 script_descriptors, |
| 1352 Factory::LookupAsciiSymbol("id"), | 1326 factory->LookupAsciiSymbol("id"), |
| 1353 proxy_id, | 1327 proxy_id, |
| 1354 common_attributes); | 1328 common_attributes); |
| 1355 Handle<Proxy> proxy_line_offset = | 1329 Handle<Proxy> proxy_line_offset = |
| 1356 Factory::NewProxy(&Accessors::ScriptLineOffset); | 1330 factory->NewProxy(&Accessors::ScriptLineOffset); |
| 1357 script_descriptors = | 1331 script_descriptors = |
| 1358 Factory::CopyAppendProxyDescriptor( | 1332 factory->CopyAppendProxyDescriptor( |
| 1359 script_descriptors, | 1333 script_descriptors, |
| 1360 Factory::LookupAsciiSymbol("line_offset"), | 1334 factory->LookupAsciiSymbol("line_offset"), |
| 1361 proxy_line_offset, | 1335 proxy_line_offset, |
| 1362 common_attributes); | 1336 common_attributes); |
| 1363 Handle<Proxy> proxy_column_offset = | 1337 Handle<Proxy> proxy_column_offset = |
| 1364 Factory::NewProxy(&Accessors::ScriptColumnOffset); | 1338 factory->NewProxy(&Accessors::ScriptColumnOffset); |
| 1365 script_descriptors = | 1339 script_descriptors = |
| 1366 Factory::CopyAppendProxyDescriptor( | 1340 factory->CopyAppendProxyDescriptor( |
| 1367 script_descriptors, | 1341 script_descriptors, |
| 1368 Factory::LookupAsciiSymbol("column_offset"), | 1342 factory->LookupAsciiSymbol("column_offset"), |
| 1369 proxy_column_offset, | 1343 proxy_column_offset, |
| 1370 common_attributes); | 1344 common_attributes); |
| 1371 Handle<Proxy> proxy_data = Factory::NewProxy(&Accessors::ScriptData); | 1345 Handle<Proxy> proxy_data = factory->NewProxy(&Accessors::ScriptData); |
| 1372 script_descriptors = | 1346 script_descriptors = |
| 1373 Factory::CopyAppendProxyDescriptor( | 1347 factory->CopyAppendProxyDescriptor( |
| 1374 script_descriptors, | 1348 script_descriptors, |
| 1375 Factory::LookupAsciiSymbol("data"), | 1349 factory->LookupAsciiSymbol("data"), |
| 1376 proxy_data, | 1350 proxy_data, |
| 1377 common_attributes); | 1351 common_attributes); |
| 1378 Handle<Proxy> proxy_type = Factory::NewProxy(&Accessors::ScriptType); | 1352 Handle<Proxy> proxy_type = factory->NewProxy(&Accessors::ScriptType); |
| 1379 script_descriptors = | 1353 script_descriptors = |
| 1380 Factory::CopyAppendProxyDescriptor( | 1354 factory->CopyAppendProxyDescriptor( |
| 1381 script_descriptors, | 1355 script_descriptors, |
| 1382 Factory::LookupAsciiSymbol("type"), | 1356 factory->LookupAsciiSymbol("type"), |
| 1383 proxy_type, | 1357 proxy_type, |
| 1384 common_attributes); | 1358 common_attributes); |
| 1385 Handle<Proxy> proxy_compilation_type = | 1359 Handle<Proxy> proxy_compilation_type = |
| 1386 Factory::NewProxy(&Accessors::ScriptCompilationType); | 1360 factory->NewProxy(&Accessors::ScriptCompilationType); |
| 1387 script_descriptors = | 1361 script_descriptors = |
| 1388 Factory::CopyAppendProxyDescriptor( | 1362 factory->CopyAppendProxyDescriptor( |
| 1389 script_descriptors, | 1363 script_descriptors, |
| 1390 Factory::LookupAsciiSymbol("compilation_type"), | 1364 factory->LookupAsciiSymbol("compilation_type"), |
| 1391 proxy_compilation_type, | 1365 proxy_compilation_type, |
| 1392 common_attributes); | 1366 common_attributes); |
| 1393 Handle<Proxy> proxy_line_ends = | 1367 Handle<Proxy> proxy_line_ends = |
| 1394 Factory::NewProxy(&Accessors::ScriptLineEnds); | 1368 factory->NewProxy(&Accessors::ScriptLineEnds); |
| 1395 script_descriptors = | 1369 script_descriptors = |
| 1396 Factory::CopyAppendProxyDescriptor( | 1370 factory->CopyAppendProxyDescriptor( |
| 1397 script_descriptors, | 1371 script_descriptors, |
| 1398 Factory::LookupAsciiSymbol("line_ends"), | 1372 factory->LookupAsciiSymbol("line_ends"), |
| 1399 proxy_line_ends, | 1373 proxy_line_ends, |
| 1400 common_attributes); | 1374 common_attributes); |
| 1401 Handle<Proxy> proxy_context_data = | 1375 Handle<Proxy> proxy_context_data = |
| 1402 Factory::NewProxy(&Accessors::ScriptContextData); | 1376 factory->NewProxy(&Accessors::ScriptContextData); |
| 1403 script_descriptors = | 1377 script_descriptors = |
| 1404 Factory::CopyAppendProxyDescriptor( | 1378 factory->CopyAppendProxyDescriptor( |
| 1405 script_descriptors, | 1379 script_descriptors, |
| 1406 Factory::LookupAsciiSymbol("context_data"), | 1380 factory->LookupAsciiSymbol("context_data"), |
| 1407 proxy_context_data, | 1381 proxy_context_data, |
| 1408 common_attributes); | 1382 common_attributes); |
| 1409 Handle<Proxy> proxy_eval_from_script = | 1383 Handle<Proxy> proxy_eval_from_script = |
| 1410 Factory::NewProxy(&Accessors::ScriptEvalFromScript); | 1384 factory->NewProxy(&Accessors::ScriptEvalFromScript); |
| 1411 script_descriptors = | 1385 script_descriptors = |
| 1412 Factory::CopyAppendProxyDescriptor( | 1386 factory->CopyAppendProxyDescriptor( |
| 1413 script_descriptors, | 1387 script_descriptors, |
| 1414 Factory::LookupAsciiSymbol("eval_from_script"), | 1388 factory->LookupAsciiSymbol("eval_from_script"), |
| 1415 proxy_eval_from_script, | 1389 proxy_eval_from_script, |
| 1416 common_attributes); | 1390 common_attributes); |
| 1417 Handle<Proxy> proxy_eval_from_script_position = | 1391 Handle<Proxy> proxy_eval_from_script_position = |
| 1418 Factory::NewProxy(&Accessors::ScriptEvalFromScriptPosition); | 1392 factory->NewProxy(&Accessors::ScriptEvalFromScriptPosition); |
| 1419 script_descriptors = | 1393 script_descriptors = |
| 1420 Factory::CopyAppendProxyDescriptor( | 1394 factory->CopyAppendProxyDescriptor( |
| 1421 script_descriptors, | 1395 script_descriptors, |
| 1422 Factory::LookupAsciiSymbol("eval_from_script_position"), | 1396 factory->LookupAsciiSymbol("eval_from_script_position"), |
| 1423 proxy_eval_from_script_position, | 1397 proxy_eval_from_script_position, |
| 1424 common_attributes); | 1398 common_attributes); |
| 1425 Handle<Proxy> proxy_eval_from_function_name = | 1399 Handle<Proxy> proxy_eval_from_function_name = |
| 1426 Factory::NewProxy(&Accessors::ScriptEvalFromFunctionName); | 1400 factory->NewProxy(&Accessors::ScriptEvalFromFunctionName); |
| 1427 script_descriptors = | 1401 script_descriptors = |
| 1428 Factory::CopyAppendProxyDescriptor( | 1402 factory->CopyAppendProxyDescriptor( |
| 1429 script_descriptors, | 1403 script_descriptors, |
| 1430 Factory::LookupAsciiSymbol("eval_from_function_name"), | 1404 factory->LookupAsciiSymbol("eval_from_function_name"), |
| 1431 proxy_eval_from_function_name, | 1405 proxy_eval_from_function_name, |
| 1432 common_attributes); | 1406 common_attributes); |
| 1433 | 1407 |
| 1434 Handle<Map> script_map = Handle<Map>(script_fun->initial_map()); | 1408 Handle<Map> script_map = Handle<Map>(script_fun->initial_map()); |
| 1435 script_map->set_instance_descriptors(*script_descriptors); | 1409 script_map->set_instance_descriptors(*script_descriptors); |
| 1436 | 1410 |
| 1437 // Allocate the empty script. | 1411 // Allocate the empty script. |
| 1438 Handle<Script> script = Factory::NewScript(Factory::empty_string()); | 1412 Handle<Script> script = factory->NewScript(factory->empty_string()); |
| 1439 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); | 1413 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
| 1440 Heap::public_set_empty_script(*script); | 1414 HEAP->public_set_empty_script(*script); |
| 1441 } | 1415 } |
| 1442 { | 1416 { |
| 1443 // Builtin function for OpaqueReference -- a JSValue-based object, | 1417 // Builtin function for OpaqueReference -- a JSValue-based object, |
| 1444 // that keeps its field isolated from JavaScript code. It may store | 1418 // that keeps its field isolated from JavaScript code. It may store |
| 1445 // objects, that JavaScript code may not access. | 1419 // objects, that JavaScript code may not access. |
| 1446 Handle<JSFunction> opaque_reference_fun = | 1420 Handle<JSFunction> opaque_reference_fun = |
| 1447 InstallFunction(builtins, "OpaqueReference", JS_VALUE_TYPE, | 1421 InstallFunction(builtins, "OpaqueReference", JS_VALUE_TYPE, |
| 1448 JSValue::kSize, Top::initial_object_prototype(), | 1422 JSValue::kSize, |
| 1423 isolate->initial_object_prototype(), |
| 1449 Builtins::Illegal, false); | 1424 Builtins::Illegal, false); |
| 1450 Handle<JSObject> prototype = | 1425 Handle<JSObject> prototype = |
| 1451 Factory::NewJSObject(Top::object_function(), TENURED); | 1426 factory->NewJSObject(isolate->object_function(), TENURED); |
| 1452 SetPrototype(opaque_reference_fun, prototype); | 1427 SetPrototype(opaque_reference_fun, prototype); |
| 1453 global_context()->set_opaque_reference_function(*opaque_reference_fun); | 1428 global_context()->set_opaque_reference_function(*opaque_reference_fun); |
| 1454 } | 1429 } |
| 1455 | 1430 |
| 1456 { // --- I n t e r n a l A r r a y --- | 1431 { // --- I n t e r n a l A r r a y --- |
| 1457 // An array constructor on the builtins object that works like | 1432 // An array constructor on the builtins object that works like |
| 1458 // the public Array constructor, except that its prototype | 1433 // the public Array constructor, except that its prototype |
| 1459 // doesn't inherit from Object.prototype. | 1434 // doesn't inherit from Object.prototype. |
| 1460 // To be used only for internal work by builtins. Instances | 1435 // To be used only for internal work by builtins. Instances |
| 1461 // must not be leaked to user code. | 1436 // must not be leaked to user code. |
| 1462 // Only works correctly when called as a constructor. The normal | 1437 // Only works correctly when called as a constructor. The normal |
| 1463 // Array code uses Array.prototype as prototype when called as | 1438 // Array code uses Array.prototype as prototype when called as |
| 1464 // a function. | 1439 // a function. |
| 1465 Handle<JSFunction> array_function = | 1440 Handle<JSFunction> array_function = |
| 1466 InstallFunction(builtins, | 1441 InstallFunction(builtins, |
| 1467 "InternalArray", | 1442 "InternalArray", |
| 1468 JS_ARRAY_TYPE, | 1443 JS_ARRAY_TYPE, |
| 1469 JSArray::kSize, | 1444 JSArray::kSize, |
| 1470 Top::initial_object_prototype(), | 1445 isolate->initial_object_prototype(), |
| 1471 Builtins::ArrayCode, | 1446 Builtins::ArrayCode, |
| 1472 true); | 1447 true); |
| 1473 Handle<JSObject> prototype = | 1448 Handle<JSObject> prototype = |
| 1474 Factory::NewJSObject(Top::object_function(), TENURED); | 1449 factory->NewJSObject(isolate->object_function(), TENURED); |
| 1475 SetPrototype(array_function, prototype); | 1450 SetPrototype(array_function, prototype); |
| 1476 | 1451 |
| 1477 array_function->shared()->set_construct_stub( | 1452 array_function->shared()->set_construct_stub( |
| 1478 Builtins::builtin(Builtins::ArrayConstructCode)); | 1453 isolate->builtins()->builtin(Builtins::ArrayConstructCode)); |
| 1479 array_function->shared()->DontAdaptArguments(); | 1454 array_function->shared()->DontAdaptArguments(); |
| 1480 | 1455 |
| 1481 // Make "length" magic on instances. | 1456 // Make "length" magic on instances. |
| 1482 Handle<DescriptorArray> array_descriptors = | 1457 Handle<DescriptorArray> array_descriptors = |
| 1483 Factory::CopyAppendProxyDescriptor( | 1458 factory->CopyAppendProxyDescriptor( |
| 1484 Factory::empty_descriptor_array(), | 1459 factory->empty_descriptor_array(), |
| 1485 Factory::length_symbol(), | 1460 factory->length_symbol(), |
| 1486 Factory::NewProxy(&Accessors::ArrayLength), | 1461 factory->NewProxy(&Accessors::ArrayLength), |
| 1487 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE)); | 1462 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE)); |
| 1488 | 1463 |
| 1489 array_function->initial_map()->set_instance_descriptors( | 1464 array_function->initial_map()->set_instance_descriptors( |
| 1490 *array_descriptors); | 1465 *array_descriptors); |
| 1491 } | 1466 } |
| 1492 | 1467 |
| 1493 if (FLAG_disable_native_files) { | 1468 if (FLAG_disable_native_files) { |
| 1494 PrintF("Warning: Running without installed natives!\n"); | 1469 PrintF("Warning: Running without installed natives!\n"); |
| 1495 return true; | 1470 return true; |
| 1496 } | 1471 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1513 // and the String function has been setup. | 1488 // and the String function has been setup. |
| 1514 Handle<JSFunction> string_function(global_context()->string_function()); | 1489 Handle<JSFunction> string_function(global_context()->string_function()); |
| 1515 ASSERT(JSObject::cast( | 1490 ASSERT(JSObject::cast( |
| 1516 string_function->initial_map()->prototype())->HasFastProperties()); | 1491 string_function->initial_map()->prototype())->HasFastProperties()); |
| 1517 global_context()->set_string_function_prototype_map( | 1492 global_context()->set_string_function_prototype_map( |
| 1518 HeapObject::cast(string_function->initial_map()->prototype())->map()); | 1493 HeapObject::cast(string_function->initial_map()->prototype())->map()); |
| 1519 | 1494 |
| 1520 InstallBuiltinFunctionIds(); | 1495 InstallBuiltinFunctionIds(); |
| 1521 | 1496 |
| 1522 // Install Function.prototype.call and apply. | 1497 // Install Function.prototype.call and apply. |
| 1523 { Handle<String> key = Factory::function_class_symbol(); | 1498 { Handle<String> key = factory->function_class_symbol(); |
| 1524 Handle<JSFunction> function = | 1499 Handle<JSFunction> function = |
| 1525 Handle<JSFunction>::cast(GetProperty(Top::global(), key)); | 1500 Handle<JSFunction>::cast(GetProperty(isolate->global(), key)); |
| 1526 Handle<JSObject> proto = | 1501 Handle<JSObject> proto = |
| 1527 Handle<JSObject>(JSObject::cast(function->instance_prototype())); | 1502 Handle<JSObject>(JSObject::cast(function->instance_prototype())); |
| 1528 | 1503 |
| 1529 // Install the call and the apply functions. | 1504 // Install the call and the apply functions. |
| 1530 Handle<JSFunction> call = | 1505 Handle<JSFunction> call = |
| 1531 InstallFunction(proto, "call", JS_OBJECT_TYPE, JSObject::kHeaderSize, | 1506 InstallFunction(proto, "call", JS_OBJECT_TYPE, JSObject::kHeaderSize, |
| 1532 Handle<JSObject>::null(), | 1507 Handle<JSObject>::null(), |
| 1533 Builtins::FunctionCall, | 1508 Builtins::FunctionCall, |
| 1534 false); | 1509 false); |
| 1535 Handle<JSFunction> apply = | 1510 Handle<JSFunction> apply = |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1557 { | 1532 { |
| 1558 // RegExpResult initial map. | 1533 // RegExpResult initial map. |
| 1559 | 1534 |
| 1560 // Find global.Array.prototype to inherit from. | 1535 // Find global.Array.prototype to inherit from. |
| 1561 Handle<JSFunction> array_constructor(global_context()->array_function()); | 1536 Handle<JSFunction> array_constructor(global_context()->array_function()); |
| 1562 Handle<JSObject> array_prototype( | 1537 Handle<JSObject> array_prototype( |
| 1563 JSObject::cast(array_constructor->instance_prototype())); | 1538 JSObject::cast(array_constructor->instance_prototype())); |
| 1564 | 1539 |
| 1565 // Add initial map. | 1540 // Add initial map. |
| 1566 Handle<Map> initial_map = | 1541 Handle<Map> initial_map = |
| 1567 Factory::NewMap(JS_ARRAY_TYPE, JSRegExpResult::kSize); | 1542 factory->NewMap(JS_ARRAY_TYPE, JSRegExpResult::kSize); |
| 1568 initial_map->set_constructor(*array_constructor); | 1543 initial_map->set_constructor(*array_constructor); |
| 1569 | 1544 |
| 1570 // Set prototype on map. | 1545 // Set prototype on map. |
| 1571 initial_map->set_non_instance_prototype(false); | 1546 initial_map->set_non_instance_prototype(false); |
| 1572 initial_map->set_prototype(*array_prototype); | 1547 initial_map->set_prototype(*array_prototype); |
| 1573 | 1548 |
| 1574 // Update map with length accessor from Array and add "index" and "input". | 1549 // Update map with length accessor from Array and add "index" and "input". |
| 1575 Handle<Map> array_map(global_context()->js_array_map()); | 1550 Handle<Map> array_map(global_context()->js_array_map()); |
| 1576 Handle<DescriptorArray> array_descriptors( | 1551 Handle<DescriptorArray> array_descriptors( |
| 1577 array_map->instance_descriptors()); | 1552 array_map->instance_descriptors()); |
| 1578 ASSERT_EQ(1, array_descriptors->number_of_descriptors()); | 1553 ASSERT_EQ(1, array_descriptors->number_of_descriptors()); |
| 1579 | 1554 |
| 1580 Handle<DescriptorArray> reresult_descriptors = | 1555 Handle<DescriptorArray> reresult_descriptors = |
| 1581 Factory::NewDescriptorArray(3); | 1556 factory->NewDescriptorArray(3); |
| 1582 | 1557 |
| 1583 reresult_descriptors->CopyFrom(0, *array_descriptors, 0); | 1558 reresult_descriptors->CopyFrom(0, *array_descriptors, 0); |
| 1584 | 1559 |
| 1585 int enum_index = 0; | 1560 int enum_index = 0; |
| 1586 { | 1561 { |
| 1587 FieldDescriptor index_field(Heap::index_symbol(), | 1562 FieldDescriptor index_field(HEAP->index_symbol(), |
| 1588 JSRegExpResult::kIndexIndex, | 1563 JSRegExpResult::kIndexIndex, |
| 1589 NONE, | 1564 NONE, |
| 1590 enum_index++); | 1565 enum_index++); |
| 1591 reresult_descriptors->Set(1, &index_field); | 1566 reresult_descriptors->Set(1, &index_field); |
| 1592 } | 1567 } |
| 1593 | 1568 |
| 1594 { | 1569 { |
| 1595 FieldDescriptor input_field(Heap::input_symbol(), | 1570 FieldDescriptor input_field(HEAP->input_symbol(), |
| 1596 JSRegExpResult::kInputIndex, | 1571 JSRegExpResult::kInputIndex, |
| 1597 NONE, | 1572 NONE, |
| 1598 enum_index++); | 1573 enum_index++); |
| 1599 reresult_descriptors->Set(2, &input_field); | 1574 reresult_descriptors->Set(2, &input_field); |
| 1600 } | 1575 } |
| 1601 reresult_descriptors->Sort(); | 1576 reresult_descriptors->Sort(); |
| 1602 | 1577 |
| 1603 initial_map->set_inobject_properties(2); | 1578 initial_map->set_inobject_properties(2); |
| 1604 initial_map->set_pre_allocated_property_fields(2); | 1579 initial_map->set_pre_allocated_property_fields(2); |
| 1605 initial_map->set_unused_property_fields(0); | 1580 initial_map->set_unused_property_fields(0); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1617 } | 1592 } |
| 1618 | 1593 |
| 1619 | 1594 |
| 1620 static Handle<JSObject> ResolveBuiltinIdHolder( | 1595 static Handle<JSObject> ResolveBuiltinIdHolder( |
| 1621 Handle<Context> global_context, | 1596 Handle<Context> global_context, |
| 1622 const char* holder_expr) { | 1597 const char* holder_expr) { |
| 1623 Handle<GlobalObject> global(global_context->global()); | 1598 Handle<GlobalObject> global(global_context->global()); |
| 1624 const char* period_pos = strchr(holder_expr, '.'); | 1599 const char* period_pos = strchr(holder_expr, '.'); |
| 1625 if (period_pos == NULL) { | 1600 if (period_pos == NULL) { |
| 1626 return Handle<JSObject>::cast( | 1601 return Handle<JSObject>::cast( |
| 1627 GetProperty(global, Factory::LookupAsciiSymbol(holder_expr))); | 1602 GetProperty(global, FACTORY->LookupAsciiSymbol(holder_expr))); |
| 1628 } | 1603 } |
| 1629 ASSERT_EQ(".prototype", period_pos); | 1604 ASSERT_EQ(".prototype", period_pos); |
| 1630 Vector<const char> property(holder_expr, | 1605 Vector<const char> property(holder_expr, |
| 1631 static_cast<int>(period_pos - holder_expr)); | 1606 static_cast<int>(period_pos - holder_expr)); |
| 1632 Handle<JSFunction> function = Handle<JSFunction>::cast( | 1607 Handle<JSFunction> function = Handle<JSFunction>::cast( |
| 1633 GetProperty(global, Factory::LookupSymbol(property))); | 1608 GetProperty(global, FACTORY->LookupSymbol(property))); |
| 1634 return Handle<JSObject>(JSObject::cast(function->prototype())); | 1609 return Handle<JSObject>(JSObject::cast(function->prototype())); |
| 1635 } | 1610 } |
| 1636 | 1611 |
| 1637 | 1612 |
| 1638 static void InstallBuiltinFunctionId(Handle<JSObject> holder, | 1613 static void InstallBuiltinFunctionId(Handle<JSObject> holder, |
| 1639 const char* function_name, | 1614 const char* function_name, |
| 1640 BuiltinFunctionId id) { | 1615 BuiltinFunctionId id) { |
| 1641 Handle<String> name = Factory::LookupAsciiSymbol(function_name); | 1616 Handle<String> name = FACTORY->LookupAsciiSymbol(function_name); |
| 1642 Object* function_object = holder->GetProperty(*name)->ToObjectUnchecked(); | 1617 Object* function_object = holder->GetProperty(*name)->ToObjectUnchecked(); |
| 1643 Handle<JSFunction> function(JSFunction::cast(function_object)); | 1618 Handle<JSFunction> function(JSFunction::cast(function_object)); |
| 1644 function->shared()->set_function_data(Smi::FromInt(id)); | 1619 function->shared()->set_function_data(Smi::FromInt(id)); |
| 1645 } | 1620 } |
| 1646 | 1621 |
| 1647 | 1622 |
| 1648 void Genesis::InstallBuiltinFunctionIds() { | 1623 void Genesis::InstallBuiltinFunctionIds() { |
| 1649 HandleScope scope; | 1624 HandleScope scope; |
| 1650 #define INSTALL_BUILTIN_ID(holder_expr, fun_name, name) \ | 1625 #define INSTALL_BUILTIN_ID(holder_expr, fun_name, name) \ |
| 1651 { \ | 1626 { \ |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1663 // of cache id. | 1638 // of cache id. |
| 1664 #define JSFUNCTION_RESULT_CACHE_LIST(F) \ | 1639 #define JSFUNCTION_RESULT_CACHE_LIST(F) \ |
| 1665 F(16, global_context()->regexp_function()) | 1640 F(16, global_context()->regexp_function()) |
| 1666 | 1641 |
| 1667 | 1642 |
| 1668 static FixedArray* CreateCache(int size, JSFunction* factory) { | 1643 static FixedArray* CreateCache(int size, JSFunction* factory) { |
| 1669 // Caches are supposed to live for a long time, allocate in old space. | 1644 // Caches are supposed to live for a long time, allocate in old space. |
| 1670 int array_size = JSFunctionResultCache::kEntriesIndex + 2 * size; | 1645 int array_size = JSFunctionResultCache::kEntriesIndex + 2 * size; |
| 1671 // Cannot use cast as object is not fully initialized yet. | 1646 // Cannot use cast as object is not fully initialized yet. |
| 1672 JSFunctionResultCache* cache = reinterpret_cast<JSFunctionResultCache*>( | 1647 JSFunctionResultCache* cache = reinterpret_cast<JSFunctionResultCache*>( |
| 1673 *Factory::NewFixedArrayWithHoles(array_size, TENURED)); | 1648 *FACTORY->NewFixedArrayWithHoles(array_size, TENURED)); |
| 1674 cache->set(JSFunctionResultCache::kFactoryIndex, factory); | 1649 cache->set(JSFunctionResultCache::kFactoryIndex, factory); |
| 1675 cache->MakeZeroSize(); | 1650 cache->MakeZeroSize(); |
| 1676 return cache; | 1651 return cache; |
| 1677 } | 1652 } |
| 1678 | 1653 |
| 1679 | 1654 |
| 1680 void Genesis::InstallJSFunctionResultCaches() { | 1655 void Genesis::InstallJSFunctionResultCaches() { |
| 1681 const int kNumberOfCaches = 0 + | 1656 const int kNumberOfCaches = 0 + |
| 1682 #define F(size, func) + 1 | 1657 #define F(size, func) + 1 |
| 1683 JSFUNCTION_RESULT_CACHE_LIST(F) | 1658 JSFUNCTION_RESULT_CACHE_LIST(F) |
| 1684 #undef F | 1659 #undef F |
| 1685 ; | 1660 ; |
| 1686 | 1661 |
| 1687 Handle<FixedArray> caches = Factory::NewFixedArray(kNumberOfCaches, TENURED); | 1662 Handle<FixedArray> caches = FACTORY->NewFixedArray(kNumberOfCaches, TENURED); |
| 1688 | 1663 |
| 1689 int index = 0; | 1664 int index = 0; |
| 1690 | 1665 |
| 1691 #define F(size, func) do { \ | 1666 #define F(size, func) do { \ |
| 1692 FixedArray* cache = CreateCache((size), (func)); \ | 1667 FixedArray* cache = CreateCache((size), (func)); \ |
| 1693 caches->set(index++, cache); \ | 1668 caches->set(index++, cache); \ |
| 1694 } while (false) | 1669 } while (false) |
| 1695 | 1670 |
| 1696 JSFUNCTION_RESULT_CACHE_LIST(F); | 1671 JSFUNCTION_RESULT_CACHE_LIST(F); |
| 1697 | 1672 |
| 1698 #undef F | 1673 #undef F |
| 1699 | 1674 |
| 1700 global_context()->set_jsfunction_result_caches(*caches); | 1675 global_context()->set_jsfunction_result_caches(*caches); |
| 1701 } | 1676 } |
| 1702 | 1677 |
| 1703 | 1678 |
| 1704 void Genesis::InitializeNormalizedMapCaches() { | 1679 void Genesis::InitializeNormalizedMapCaches() { |
| 1705 Handle<FixedArray> array( | 1680 Handle<FixedArray> array( |
| 1706 Factory::NewFixedArray(NormalizedMapCache::kEntries, TENURED)); | 1681 FACTORY->NewFixedArray(NormalizedMapCache::kEntries, TENURED)); |
| 1707 global_context()->set_normalized_map_cache(NormalizedMapCache::cast(*array)); | 1682 global_context()->set_normalized_map_cache(NormalizedMapCache::cast(*array)); |
| 1708 } | 1683 } |
| 1709 | 1684 |
| 1710 | 1685 |
| 1711 int BootstrapperActive::nesting_ = 0; | |
| 1712 | |
| 1713 | |
| 1714 bool Bootstrapper::InstallExtensions(Handle<Context> global_context, | 1686 bool Bootstrapper::InstallExtensions(Handle<Context> global_context, |
| 1715 v8::ExtensionConfiguration* extensions) { | 1687 v8::ExtensionConfiguration* extensions) { |
| 1688 Isolate* isolate = Isolate::Current(); |
| 1716 BootstrapperActive active; | 1689 BootstrapperActive active; |
| 1717 SaveContext saved_context; | 1690 SaveContext saved_context(isolate); |
| 1718 Top::set_context(*global_context); | 1691 isolate->set_context(*global_context); |
| 1719 if (!Genesis::InstallExtensions(global_context, extensions)) return false; | 1692 if (!Genesis::InstallExtensions(global_context, extensions)) return false; |
| 1720 Genesis::InstallSpecialObjects(global_context); | 1693 Genesis::InstallSpecialObjects(global_context); |
| 1721 return true; | 1694 return true; |
| 1722 } | 1695 } |
| 1723 | 1696 |
| 1724 | 1697 |
| 1725 void Genesis::InstallSpecialObjects(Handle<Context> global_context) { | 1698 void Genesis::InstallSpecialObjects(Handle<Context> global_context) { |
| 1726 HandleScope scope; | 1699 HandleScope scope; |
| 1727 Handle<JSGlobalObject> js_global( | 1700 Handle<JSGlobalObject> js_global( |
| 1728 JSGlobalObject::cast(global_context->global())); | 1701 JSGlobalObject::cast(global_context->global())); |
| 1729 // Expose the natives in global if a name for it is specified. | 1702 // Expose the natives in global if a name for it is specified. |
| 1730 if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) { | 1703 if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) { |
| 1731 Handle<String> natives_string = | 1704 Handle<String> natives_string = |
| 1732 Factory::LookupAsciiSymbol(FLAG_expose_natives_as); | 1705 FACTORY->LookupAsciiSymbol(FLAG_expose_natives_as); |
| 1733 SetLocalPropertyNoThrow(js_global, natives_string, | 1706 SetLocalPropertyNoThrow(js_global, natives_string, |
| 1734 Handle<JSObject>(js_global->builtins()), DONT_ENUM); | 1707 Handle<JSObject>(js_global->builtins()), DONT_ENUM); |
| 1735 } | 1708 } |
| 1736 | 1709 |
| 1737 Handle<Object> Error = GetProperty(js_global, "Error"); | 1710 Handle<Object> Error = GetProperty(js_global, "Error"); |
| 1738 if (Error->IsJSObject()) { | 1711 if (Error->IsJSObject()) { |
| 1739 Handle<String> name = Factory::LookupAsciiSymbol("stackTraceLimit"); | 1712 Handle<String> name = FACTORY->LookupAsciiSymbol("stackTraceLimit"); |
| 1740 SetLocalPropertyNoThrow(Handle<JSObject>::cast(Error), | 1713 SetLocalPropertyNoThrow(Handle<JSObject>::cast(Error), |
| 1741 name, | 1714 name, |
| 1742 Handle<Smi>(Smi::FromInt(FLAG_stack_trace_limit)), | 1715 Handle<Smi>(Smi::FromInt(FLAG_stack_trace_limit)), |
| 1743 NONE); | 1716 NONE); |
| 1744 } | 1717 } |
| 1745 | 1718 |
| 1746 #ifdef ENABLE_DEBUGGER_SUPPORT | 1719 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1747 // Expose the debug global object in global if a name for it is specified. | 1720 // Expose the debug global object in global if a name for it is specified. |
| 1748 if (FLAG_expose_debug_as != NULL && strlen(FLAG_expose_debug_as) != 0) { | 1721 if (FLAG_expose_debug_as != NULL && strlen(FLAG_expose_debug_as) != 0) { |
| 1722 Debug* debug = Isolate::Current()->debug(); |
| 1749 // If loading fails we just bail out without installing the | 1723 // If loading fails we just bail out without installing the |
| 1750 // debugger but without tanking the whole context. | 1724 // debugger but without tanking the whole context. |
| 1751 if (!Debug::Load()) return; | 1725 if (!debug->Load()) return; |
| 1752 // Set the security token for the debugger context to the same as | 1726 // Set the security token for the debugger context to the same as |
| 1753 // the shell global context to allow calling between these (otherwise | 1727 // the shell global context to allow calling between these (otherwise |
| 1754 // exposing debug global object doesn't make much sense). | 1728 // exposing debug global object doesn't make much sense). |
| 1755 Debug::debug_context()->set_security_token( | 1729 debug->debug_context()->set_security_token( |
| 1756 global_context->security_token()); | 1730 global_context->security_token()); |
| 1757 | 1731 |
| 1758 Handle<String> debug_string = | 1732 Handle<String> debug_string = |
| 1759 Factory::LookupAsciiSymbol(FLAG_expose_debug_as); | 1733 FACTORY->LookupAsciiSymbol(FLAG_expose_debug_as); |
| 1760 Handle<Object> global_proxy(Debug::debug_context()->global_proxy()); | 1734 Handle<Object> global_proxy(debug->debug_context()->global_proxy()); |
| 1761 SetLocalPropertyNoThrow(js_global, debug_string, global_proxy, DONT_ENUM); | 1735 SetLocalPropertyNoThrow(js_global, debug_string, global_proxy, DONT_ENUM); |
| 1762 } | 1736 } |
| 1763 #endif | 1737 #endif |
| 1764 } | 1738 } |
| 1765 | 1739 |
| 1766 | 1740 |
| 1767 bool Genesis::InstallExtensions(Handle<Context> global_context, | 1741 bool Genesis::InstallExtensions(Handle<Context> global_context, |
| 1768 v8::ExtensionConfiguration* extensions) { | 1742 v8::ExtensionConfiguration* extensions) { |
| 1743 // TODO(isolates): Extensions on multiple isolates may take a little more |
| 1744 // effort. (The external API reads 'ignore'-- does that mean |
| 1745 // we can break the interface?) |
| 1746 |
| 1769 // Clear coloring of extension list | 1747 // Clear coloring of extension list |
| 1770 v8::RegisteredExtension* current = v8::RegisteredExtension::first_extension(); | 1748 v8::RegisteredExtension* current = v8::RegisteredExtension::first_extension(); |
| 1771 while (current != NULL) { | 1749 while (current != NULL) { |
| 1772 current->set_state(v8::UNVISITED); | 1750 current->set_state(v8::UNVISITED); |
| 1773 current = current->next(); | 1751 current = current->next(); |
| 1774 } | 1752 } |
| 1775 // Install auto extensions. | 1753 // Install auto extensions. |
| 1776 current = v8::RegisteredExtension::first_extension(); | 1754 current = v8::RegisteredExtension::first_extension(); |
| 1777 while (current != NULL) { | 1755 while (current != NULL) { |
| 1778 if (current->extension()->auto_enable()) | 1756 if (current->extension()->auto_enable()) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1827 return false; | 1805 return false; |
| 1828 } | 1806 } |
| 1829 ASSERT(current->state() == v8::UNVISITED); | 1807 ASSERT(current->state() == v8::UNVISITED); |
| 1830 current->set_state(v8::VISITED); | 1808 current->set_state(v8::VISITED); |
| 1831 v8::Extension* extension = current->extension(); | 1809 v8::Extension* extension = current->extension(); |
| 1832 // Install the extension's dependencies | 1810 // Install the extension's dependencies |
| 1833 for (int i = 0; i < extension->dependency_count(); i++) { | 1811 for (int i = 0; i < extension->dependency_count(); i++) { |
| 1834 if (!InstallExtension(extension->dependencies()[i])) return false; | 1812 if (!InstallExtension(extension->dependencies()[i])) return false; |
| 1835 } | 1813 } |
| 1836 Vector<const char> source = CStrVector(extension->source()); | 1814 Vector<const char> source = CStrVector(extension->source()); |
| 1837 Handle<String> source_code = Factory::NewStringFromAscii(source); | 1815 Handle<String> source_code = FACTORY->NewStringFromAscii(source); |
| 1838 bool result = CompileScriptCached(CStrVector(extension->name()), | 1816 bool result = CompileScriptCached(CStrVector(extension->name()), |
| 1839 source_code, | 1817 source_code, |
| 1840 &extensions_cache, | 1818 Isolate::Current()->bootstrapper()-> |
| 1819 extensions_cache(), |
| 1841 extension, | 1820 extension, |
| 1842 Handle<Context>(Top::context()), | 1821 Handle<Context>( |
| 1822 Isolate::Current()->context()), |
| 1843 false); | 1823 false); |
| 1844 ASSERT(Top::has_pending_exception() != result); | 1824 ASSERT(Isolate::Current()->has_pending_exception() != result); |
| 1845 if (!result) { | 1825 if (!result) { |
| 1846 Top::clear_pending_exception(); | 1826 Isolate::Current()->clear_pending_exception(); |
| 1847 } | 1827 } |
| 1848 current->set_state(v8::INSTALLED); | 1828 current->set_state(v8::INSTALLED); |
| 1849 return result; | 1829 return result; |
| 1850 } | 1830 } |
| 1851 | 1831 |
| 1852 | 1832 |
| 1853 bool Genesis::InstallJSBuiltins(Handle<JSBuiltinsObject> builtins) { | 1833 bool Genesis::InstallJSBuiltins(Handle<JSBuiltinsObject> builtins) { |
| 1854 HandleScope scope; | 1834 HandleScope scope; |
| 1855 for (int i = 0; i < Builtins::NumberOfJavaScriptBuiltins(); i++) { | 1835 for (int i = 0; i < Builtins::NumberOfJavaScriptBuiltins(); i++) { |
| 1856 Builtins::JavaScript id = static_cast<Builtins::JavaScript>(i); | 1836 Builtins::JavaScript id = static_cast<Builtins::JavaScript>(i); |
| 1857 Handle<String> name = Factory::LookupAsciiSymbol(Builtins::GetName(id)); | 1837 Handle<String> name = FACTORY->LookupAsciiSymbol(Builtins::GetName(id)); |
| 1858 Object* function_object = builtins->GetPropertyNoExceptionThrown(*name); | 1838 Object* function_object = builtins->GetPropertyNoExceptionThrown(*name); |
| 1859 Handle<JSFunction> function | 1839 Handle<JSFunction> function |
| 1860 = Handle<JSFunction>(JSFunction::cast(function_object)); | 1840 = Handle<JSFunction>(JSFunction::cast(function_object)); |
| 1861 builtins->set_javascript_builtin(id, *function); | 1841 builtins->set_javascript_builtin(id, *function); |
| 1862 Handle<SharedFunctionInfo> shared | 1842 Handle<SharedFunctionInfo> shared |
| 1863 = Handle<SharedFunctionInfo>(function->shared()); | 1843 = Handle<SharedFunctionInfo>(function->shared()); |
| 1864 if (!EnsureCompiled(shared, CLEAR_EXCEPTION)) return false; | 1844 if (!EnsureCompiled(shared, CLEAR_EXCEPTION)) return false; |
| 1865 // Set the code object on the function object. | 1845 // Set the code object on the function object. |
| 1866 function->ReplaceCode(function->shared()->code()); | 1846 function->ReplaceCode(function->shared()->code()); |
| 1867 builtins->set_javascript_builtin_code(id, shared->code()); | 1847 builtins->set_javascript_builtin_code(id, shared->code()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1900 bool Genesis::ConfigureApiObject(Handle<JSObject> object, | 1880 bool Genesis::ConfigureApiObject(Handle<JSObject> object, |
| 1901 Handle<ObjectTemplateInfo> object_template) { | 1881 Handle<ObjectTemplateInfo> object_template) { |
| 1902 ASSERT(!object_template.is_null()); | 1882 ASSERT(!object_template.is_null()); |
| 1903 ASSERT(object->IsInstanceOf( | 1883 ASSERT(object->IsInstanceOf( |
| 1904 FunctionTemplateInfo::cast(object_template->constructor()))); | 1884 FunctionTemplateInfo::cast(object_template->constructor()))); |
| 1905 | 1885 |
| 1906 bool pending_exception = false; | 1886 bool pending_exception = false; |
| 1907 Handle<JSObject> obj = | 1887 Handle<JSObject> obj = |
| 1908 Execution::InstantiateObject(object_template, &pending_exception); | 1888 Execution::InstantiateObject(object_template, &pending_exception); |
| 1909 if (pending_exception) { | 1889 if (pending_exception) { |
| 1910 ASSERT(Top::has_pending_exception()); | 1890 ASSERT(Isolate::Current()->has_pending_exception()); |
| 1911 Top::clear_pending_exception(); | 1891 Isolate::Current()->clear_pending_exception(); |
| 1912 return false; | 1892 return false; |
| 1913 } | 1893 } |
| 1914 TransferObject(obj, object); | 1894 TransferObject(obj, object); |
| 1915 return true; | 1895 return true; |
| 1916 } | 1896 } |
| 1917 | 1897 |
| 1918 | 1898 |
| 1919 void Genesis::TransferNamedProperties(Handle<JSObject> from, | 1899 void Genesis::TransferNamedProperties(Handle<JSObject> from, |
| 1920 Handle<JSObject> to) { | 1900 Handle<JSObject> to) { |
| 1921 if (from->HasFastProperties()) { | 1901 if (from->HasFastProperties()) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1992 } | 1972 } |
| 1993 } | 1973 } |
| 1994 } | 1974 } |
| 1995 | 1975 |
| 1996 | 1976 |
| 1997 void Genesis::TransferIndexedProperties(Handle<JSObject> from, | 1977 void Genesis::TransferIndexedProperties(Handle<JSObject> from, |
| 1998 Handle<JSObject> to) { | 1978 Handle<JSObject> to) { |
| 1999 // Cloning the elements array is sufficient. | 1979 // Cloning the elements array is sufficient. |
| 2000 Handle<FixedArray> from_elements = | 1980 Handle<FixedArray> from_elements = |
| 2001 Handle<FixedArray>(FixedArray::cast(from->elements())); | 1981 Handle<FixedArray>(FixedArray::cast(from->elements())); |
| 2002 Handle<FixedArray> to_elements = Factory::CopyFixedArray(from_elements); | 1982 Handle<FixedArray> to_elements = FACTORY->CopyFixedArray(from_elements); |
| 2003 to->set_elements(*to_elements); | 1983 to->set_elements(*to_elements); |
| 2004 } | 1984 } |
| 2005 | 1985 |
| 2006 | 1986 |
| 2007 void Genesis::TransferObject(Handle<JSObject> from, Handle<JSObject> to) { | 1987 void Genesis::TransferObject(Handle<JSObject> from, Handle<JSObject> to) { |
| 2008 HandleScope outer; | 1988 HandleScope outer; |
| 2009 | 1989 |
| 2010 ASSERT(!from->IsJSArray()); | 1990 ASSERT(!from->IsJSArray()); |
| 2011 ASSERT(!to->IsJSArray()); | 1991 ASSERT(!to->IsJSArray()); |
| 2012 | 1992 |
| 2013 TransferNamedProperties(from, to); | 1993 TransferNamedProperties(from, to); |
| 2014 TransferIndexedProperties(from, to); | 1994 TransferIndexedProperties(from, to); |
| 2015 | 1995 |
| 2016 // Transfer the prototype (new map is needed). | 1996 // Transfer the prototype (new map is needed). |
| 2017 Handle<Map> old_to_map = Handle<Map>(to->map()); | 1997 Handle<Map> old_to_map = Handle<Map>(to->map()); |
| 2018 Handle<Map> new_to_map = Factory::CopyMapDropTransitions(old_to_map); | 1998 Handle<Map> new_to_map = FACTORY->CopyMapDropTransitions(old_to_map); |
| 2019 new_to_map->set_prototype(from->map()->prototype()); | 1999 new_to_map->set_prototype(from->map()->prototype()); |
| 2020 to->set_map(*new_to_map); | 2000 to->set_map(*new_to_map); |
| 2021 } | 2001 } |
| 2022 | 2002 |
| 2023 | 2003 |
| 2024 void Genesis::MakeFunctionInstancePrototypeWritable() { | 2004 void Genesis::MakeFunctionInstancePrototypeWritable() { |
| 2025 // The maps with writable prototype are created in CreateEmptyFunction | 2005 // The maps with writable prototype are created in CreateEmptyFunction |
| 2026 // and CreateStrictModeFunctionMaps respectively. Initially the maps are | 2006 // and CreateStrictModeFunctionMaps respectively. Initially the maps are |
| 2027 // created with read-only prototype for JS builtins processing. | 2007 // created with read-only prototype for JS builtins processing. |
| 2028 ASSERT(!function_instance_map_writable_prototype_.is_null()); | 2008 ASSERT(!function_instance_map_writable_prototype_.is_null()); |
| 2029 ASSERT(!strict_mode_function_instance_map_writable_prototype_.is_null()); | 2009 ASSERT(!strict_mode_function_instance_map_writable_prototype_.is_null()); |
| 2030 | 2010 |
| 2031 // Replace function instance maps to make prototype writable. | 2011 // Replace function instance maps to make prototype writable. |
| 2032 global_context()->set_function_map( | 2012 global_context()->set_function_map( |
| 2033 *function_instance_map_writable_prototype_); | 2013 *function_instance_map_writable_prototype_); |
| 2034 global_context()->set_strict_mode_function_map( | 2014 global_context()->set_strict_mode_function_map( |
| 2035 *strict_mode_function_instance_map_writable_prototype_); | 2015 *strict_mode_function_instance_map_writable_prototype_); |
| 2036 } | 2016 } |
| 2037 | 2017 |
| 2038 | 2018 |
| 2039 Genesis::Genesis(Handle<Object> global_object, | 2019 Genesis::Genesis(Handle<Object> global_object, |
| 2040 v8::Handle<v8::ObjectTemplate> global_template, | 2020 v8::Handle<v8::ObjectTemplate> global_template, |
| 2041 v8::ExtensionConfiguration* extensions) { | 2021 v8::ExtensionConfiguration* extensions) { |
| 2022 Isolate* isolate = Isolate::Current(); |
| 2042 result_ = Handle<Context>::null(); | 2023 result_ = Handle<Context>::null(); |
| 2043 // If V8 isn't running and cannot be initialized, just return. | 2024 // If V8 isn't running and cannot be initialized, just return. |
| 2044 if (!V8::IsRunning() && !V8::Initialize(NULL)) return; | 2025 if (!V8::IsRunning() && !V8::Initialize(NULL)) return; |
| 2045 | 2026 |
| 2046 // Before creating the roots we must save the context and restore it | 2027 // Before creating the roots we must save the context and restore it |
| 2047 // on all function exits. | 2028 // on all function exits. |
| 2048 HandleScope scope; | 2029 HandleScope scope; |
| 2049 SaveContext saved_context; | 2030 SaveContext saved_context(isolate); |
| 2050 | 2031 |
| 2051 Handle<Context> new_context = Snapshot::NewContextFromSnapshot(); | 2032 Handle<Context> new_context = Snapshot::NewContextFromSnapshot(); |
| 2052 if (!new_context.is_null()) { | 2033 if (!new_context.is_null()) { |
| 2053 global_context_ = | 2034 global_context_ = |
| 2054 Handle<Context>::cast(GlobalHandles::Create(*new_context)); | 2035 Handle<Context>::cast(isolate->global_handles()->Create(*new_context)); |
| 2055 AddToWeakGlobalContextList(*global_context_); | 2036 AddToWeakGlobalContextList(*global_context_); |
| 2056 Top::set_context(*global_context_); | 2037 isolate->set_context(*global_context_); |
| 2057 i::Counters::contexts_created_by_snapshot.Increment(); | 2038 isolate->counters()->contexts_created_by_snapshot()->Increment(); |
| 2058 Handle<GlobalObject> inner_global; | 2039 Handle<GlobalObject> inner_global; |
| 2059 Handle<JSGlobalProxy> global_proxy = | 2040 Handle<JSGlobalProxy> global_proxy = |
| 2060 CreateNewGlobals(global_template, | 2041 CreateNewGlobals(global_template, |
| 2061 global_object, | 2042 global_object, |
| 2062 &inner_global); | 2043 &inner_global); |
| 2063 | 2044 |
| 2064 HookUpGlobalProxy(inner_global, global_proxy); | 2045 HookUpGlobalProxy(inner_global, global_proxy); |
| 2065 HookUpInnerGlobal(inner_global); | 2046 HookUpInnerGlobal(inner_global); |
| 2066 | 2047 |
| 2067 if (!ConfigureGlobalObjects(global_template)) return; | 2048 if (!ConfigureGlobalObjects(global_template)) return; |
| 2068 } else { | 2049 } else { |
| 2069 // We get here if there was no context snapshot. | 2050 // We get here if there was no context snapshot. |
| 2070 CreateRoots(); | 2051 CreateRoots(); |
| 2071 Handle<JSFunction> empty_function = CreateEmptyFunction(); | 2052 Handle<JSFunction> empty_function = CreateEmptyFunction(); |
| 2072 CreateStrictModeFunctionMaps(empty_function); | 2053 CreateStrictModeFunctionMaps(empty_function); |
| 2073 Handle<GlobalObject> inner_global; | 2054 Handle<GlobalObject> inner_global; |
| 2074 Handle<JSGlobalProxy> global_proxy = | 2055 Handle<JSGlobalProxy> global_proxy = |
| 2075 CreateNewGlobals(global_template, global_object, &inner_global); | 2056 CreateNewGlobals(global_template, global_object, &inner_global); |
| 2076 HookUpGlobalProxy(inner_global, global_proxy); | 2057 HookUpGlobalProxy(inner_global, global_proxy); |
| 2077 InitializeGlobal(inner_global, empty_function); | 2058 InitializeGlobal(inner_global, empty_function); |
| 2078 InstallJSFunctionResultCaches(); | 2059 InstallJSFunctionResultCaches(); |
| 2079 InitializeNormalizedMapCaches(); | 2060 InitializeNormalizedMapCaches(); |
| 2080 if (!InstallNatives()) return; | 2061 if (!InstallNatives()) return; |
| 2081 | 2062 |
| 2082 MakeFunctionInstancePrototypeWritable(); | 2063 MakeFunctionInstancePrototypeWritable(); |
| 2083 | 2064 |
| 2084 if (!ConfigureGlobalObjects(global_template)) return; | 2065 if (!ConfigureGlobalObjects(global_template)) return; |
| 2085 i::Counters::contexts_created_from_scratch.Increment(); | 2066 isolate->counters()->contexts_created_from_scratch()->Increment(); |
| 2086 } | 2067 } |
| 2087 | 2068 |
| 2088 result_ = global_context_; | 2069 result_ = global_context_; |
| 2089 } | 2070 } |
| 2090 | 2071 |
| 2091 | 2072 |
| 2092 // Support for thread preemption. | 2073 // Support for thread preemption. |
| 2093 | 2074 |
| 2094 // Reserve space for statics needing saving and restoring. | 2075 // Reserve space for statics needing saving and restoring. |
| 2095 int Bootstrapper::ArchiveSpacePerThread() { | 2076 int Bootstrapper::ArchiveSpacePerThread() { |
| 2096 return BootstrapperActive::ArchiveSpacePerThread(); | 2077 return sizeof(NestingCounterType); |
| 2097 } | 2078 } |
| 2098 | 2079 |
| 2099 | 2080 |
| 2100 // Archive statics that are thread local. | 2081 // Archive statics that are thread local. |
| 2101 char* Bootstrapper::ArchiveState(char* to) { | 2082 char* Bootstrapper::ArchiveState(char* to) { |
| 2102 return BootstrapperActive::ArchiveState(to); | 2083 *reinterpret_cast<NestingCounterType*>(to) = nesting_; |
| 2084 nesting_ = 0; |
| 2085 return to + sizeof(NestingCounterType); |
| 2103 } | 2086 } |
| 2104 | 2087 |
| 2105 | 2088 |
| 2106 // Restore statics that are thread local. | 2089 // Restore statics that are thread local. |
| 2107 char* Bootstrapper::RestoreState(char* from) { | 2090 char* Bootstrapper::RestoreState(char* from) { |
| 2108 return BootstrapperActive::RestoreState(from); | 2091 nesting_ = *reinterpret_cast<NestingCounterType*>(from); |
| 2092 return from + sizeof(NestingCounterType); |
| 2109 } | 2093 } |
| 2110 | 2094 |
| 2111 | 2095 |
| 2112 // Called when the top-level V8 mutex is destroyed. | 2096 // Called when the top-level V8 mutex is destroyed. |
| 2113 void Bootstrapper::FreeThreadResources() { | 2097 void Bootstrapper::FreeThreadResources() { |
| 2114 ASSERT(!BootstrapperActive::IsActive()); | 2098 ASSERT(!IsActive()); |
| 2115 } | |
| 2116 | |
| 2117 | |
| 2118 // Reserve space for statics needing saving and restoring. | |
| 2119 int BootstrapperActive::ArchiveSpacePerThread() { | |
| 2120 return sizeof(nesting_); | |
| 2121 } | |
| 2122 | |
| 2123 | |
| 2124 // Archive statics that are thread local. | |
| 2125 char* BootstrapperActive::ArchiveState(char* to) { | |
| 2126 *reinterpret_cast<int*>(to) = nesting_; | |
| 2127 nesting_ = 0; | |
| 2128 return to + sizeof(nesting_); | |
| 2129 } | |
| 2130 | |
| 2131 | |
| 2132 // Restore statics that are thread local. | |
| 2133 char* BootstrapperActive::RestoreState(char* from) { | |
| 2134 nesting_ = *reinterpret_cast<int*>(from); | |
| 2135 return from + sizeof(nesting_); | |
| 2136 } | 2099 } |
| 2137 | 2100 |
| 2138 } } // namespace v8::internal | 2101 } } // namespace v8::internal |
| OLD | NEW |