Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: src/bootstrapper.cc

Issue 6759025: Version 3.2.6 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/atomicops_internals_mips_gcc.h ('k') | src/code-stubs.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 Bootstrapper::Bootstrapper() 62 Bootstrapper::Bootstrapper()
63 : nesting_(0), 63 : nesting_(0),
64 extensions_cache_(Script::TYPE_EXTENSION), 64 extensions_cache_(Script::TYPE_EXTENSION),
65 delete_these_non_arrays_on_tear_down_(NULL), 65 delete_these_non_arrays_on_tear_down_(NULL),
66 delete_these_arrays_on_tear_down_(NULL) { 66 delete_these_arrays_on_tear_down_(NULL) {
67 } 67 }
68 68
69 69
70 Handle<String> Bootstrapper::NativesSourceLookup(int index) { 70 Handle<String> Bootstrapper::NativesSourceLookup(int index) {
71 ASSERT(0 <= index && index < Natives::GetBuiltinsCount()); 71 ASSERT(0 <= index && index < Natives::GetBuiltinsCount());
72 if (HEAP->natives_source_cache()->get(index)->IsUndefined()) { 72 Isolate* isolate = Isolate::Current();
73 Factory* factory = isolate->factory();
74 Heap* heap = isolate->heap();
75 if (heap->natives_source_cache()->get(index)->IsUndefined()) {
73 if (!Snapshot::IsEnabled() || FLAG_new_snapshot) { 76 if (!Snapshot::IsEnabled() || FLAG_new_snapshot) {
74 // We can use external strings for the natives. 77 // We can use external strings for the natives.
75 NativesExternalStringResource* resource = 78 NativesExternalStringResource* resource =
76 new NativesExternalStringResource(this, 79 new NativesExternalStringResource(this,
77 Natives::GetScriptSource(index).start()); 80 Natives::GetScriptSource(index).start());
78 Handle<String> source_code = 81 Handle<String> source_code =
79 FACTORY->NewExternalStringFromAscii(resource); 82 factory->NewExternalStringFromAscii(resource);
80 HEAP->natives_source_cache()->set(index, *source_code); 83 heap->natives_source_cache()->set(index, *source_code);
81 } else { 84 } else {
82 // Old snapshot code can't cope with external strings at all. 85 // Old snapshot code can't cope with external strings at all.
83 Handle<String> source_code = 86 Handle<String> source_code =
84 FACTORY->NewStringFromAscii(Natives::GetScriptSource(index)); 87 factory->NewStringFromAscii(Natives::GetScriptSource(index));
85 HEAP->natives_source_cache()->set(index, *source_code); 88 heap->natives_source_cache()->set(index, *source_code);
86 } 89 }
87 } 90 }
88 Handle<Object> cached_source(HEAP->natives_source_cache()->get(index)); 91 Handle<Object> cached_source(heap->natives_source_cache()->get(index));
89 return Handle<String>::cast(cached_source); 92 return Handle<String>::cast(cached_source);
90 } 93 }
91 94
92 95
93 void Bootstrapper::Initialize(bool create_heap_objects) { 96 void Bootstrapper::Initialize(bool create_heap_objects) {
94 extensions_cache_.Initialize(create_heap_objects); 97 extensions_cache_.Initialize(create_heap_objects);
95 GCExtension::Register(); 98 GCExtension::Register();
96 ExternalizeStringExtension::Register(); 99 ExternalizeStringExtension::Register();
97 } 100 }
98 101
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) { 288 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) {
286 // object.__proto__ = proto; 289 // object.__proto__ = proto;
287 Handle<Map> old_to_map = Handle<Map>(object->map()); 290 Handle<Map> old_to_map = Handle<Map>(object->map());
288 Handle<Map> new_to_map = FACTORY->CopyMapDropTransitions(old_to_map); 291 Handle<Map> new_to_map = FACTORY->CopyMapDropTransitions(old_to_map);
289 new_to_map->set_prototype(*proto); 292 new_to_map->set_prototype(*proto);
290 object->set_map(*new_to_map); 293 object->set_map(*new_to_map);
291 } 294 }
292 295
293 296
294 void Bootstrapper::DetachGlobal(Handle<Context> env) { 297 void Bootstrapper::DetachGlobal(Handle<Context> env) {
295 JSGlobalProxy::cast(env->global_proxy())->set_context(*FACTORY->null_value()); 298 Factory* factory = Isolate::Current()->factory();
299 JSGlobalProxy::cast(env->global_proxy())->set_context(*factory->null_value());
296 SetObjectPrototype(Handle<JSObject>(env->global_proxy()), 300 SetObjectPrototype(Handle<JSObject>(env->global_proxy()),
297 FACTORY->null_value()); 301 factory->null_value());
298 env->set_global_proxy(env->global()); 302 env->set_global_proxy(env->global());
299 env->global()->set_global_receiver(env->global()); 303 env->global()->set_global_receiver(env->global());
300 } 304 }
301 305
302 306
303 void Bootstrapper::ReattachGlobal(Handle<Context> env, 307 void Bootstrapper::ReattachGlobal(Handle<Context> env,
304 Handle<Object> global_object) { 308 Handle<Object> global_object) {
305 ASSERT(global_object->IsJSGlobalProxy()); 309 ASSERT(global_object->IsJSGlobalProxy());
306 Handle<JSGlobalProxy> global = Handle<JSGlobalProxy>::cast(global_object); 310 Handle<JSGlobalProxy> global = Handle<JSGlobalProxy>::cast(global_object);
307 env->global()->set_global_receiver(*global); 311 env->global()->set_global_receiver(*global);
308 env->set_global_proxy(*global); 312 env->set_global_proxy(*global);
309 SetObjectPrototype(global, Handle<JSObject>(env->global())); 313 SetObjectPrototype(global, Handle<JSObject>(env->global()));
310 global->set_context(*env); 314 global->set_context(*env);
311 } 315 }
312 316
313 317
314 static Handle<JSFunction> InstallFunction(Handle<JSObject> target, 318 static Handle<JSFunction> InstallFunction(Handle<JSObject> target,
315 const char* name, 319 const char* name,
316 InstanceType type, 320 InstanceType type,
317 int instance_size, 321 int instance_size,
318 Handle<JSObject> prototype, 322 Handle<JSObject> prototype,
319 Builtins::Name call, 323 Builtins::Name call,
320 bool is_ecma_native) { 324 bool is_ecma_native) {
321 Handle<String> symbol = FACTORY->LookupAsciiSymbol(name); 325 Isolate* isolate = Isolate::Current();
322 Handle<Code> call_code = Handle<Code>( 326 Factory* factory = isolate->factory();
323 Isolate::Current()->builtins()->builtin(call)); 327 Handle<String> symbol = factory->LookupAsciiSymbol(name);
328 Handle<Code> call_code = Handle<Code>(isolate->builtins()->builtin(call));
324 Handle<JSFunction> function = prototype.is_null() ? 329 Handle<JSFunction> function = prototype.is_null() ?
325 FACTORY->NewFunctionWithoutPrototype(symbol, call_code) : 330 factory->NewFunctionWithoutPrototype(symbol, call_code) :
326 FACTORY->NewFunctionWithPrototype(symbol, 331 factory->NewFunctionWithPrototype(symbol,
327 type, 332 type,
328 instance_size, 333 instance_size,
329 prototype, 334 prototype,
330 call_code, 335 call_code,
331 is_ecma_native); 336 is_ecma_native);
332 SetLocalPropertyNoThrow(target, symbol, function, DONT_ENUM); 337 SetLocalPropertyNoThrow(target, symbol, function, DONT_ENUM);
333 if (is_ecma_native) { 338 if (is_ecma_native) {
334 function->shared()->set_instance_class_name(*symbol); 339 function->shared()->set_instance_class_name(*symbol);
335 } 340 }
336 return function; 341 return function;
337 } 342 }
338 343
339 344
340 Handle<DescriptorArray> Genesis::ComputeFunctionInstanceDescriptor( 345 Handle<DescriptorArray> Genesis::ComputeFunctionInstanceDescriptor(
341 PrototypePropertyMode prototypeMode) { 346 PrototypePropertyMode prototypeMode) {
347 Factory* factory = Isolate::Current()->factory();
342 Handle<DescriptorArray> descriptors = 348 Handle<DescriptorArray> descriptors =
343 FACTORY->NewDescriptorArray(prototypeMode == DONT_ADD_PROTOTYPE ? 4 : 5); 349 factory->NewDescriptorArray(prototypeMode == DONT_ADD_PROTOTYPE ? 4 : 5);
344 PropertyAttributes attributes = 350 PropertyAttributes attributes =
345 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); 351 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
346 352
347 { // Add length. 353 { // Add length.
348 Handle<Proxy> proxy = FACTORY->NewProxy(&Accessors::FunctionLength); 354 Handle<Proxy> proxy = factory->NewProxy(&Accessors::FunctionLength);
349 CallbacksDescriptor d(*FACTORY->length_symbol(), *proxy, attributes); 355 CallbacksDescriptor d(*factory->length_symbol(), *proxy, attributes);
350 descriptors->Set(0, &d); 356 descriptors->Set(0, &d);
351 } 357 }
352 { // Add name. 358 { // Add name.
353 Handle<Proxy> proxy = FACTORY->NewProxy(&Accessors::FunctionName); 359 Handle<Proxy> proxy = factory->NewProxy(&Accessors::FunctionName);
354 CallbacksDescriptor d(*FACTORY->name_symbol(), *proxy, attributes); 360 CallbacksDescriptor d(*factory->name_symbol(), *proxy, attributes);
355 descriptors->Set(1, &d); 361 descriptors->Set(1, &d);
356 } 362 }
357 { // Add arguments. 363 { // Add arguments.
358 Handle<Proxy> proxy = FACTORY->NewProxy(&Accessors::FunctionArguments); 364 Handle<Proxy> proxy = factory->NewProxy(&Accessors::FunctionArguments);
359 CallbacksDescriptor d(*FACTORY->arguments_symbol(), *proxy, attributes); 365 CallbacksDescriptor d(*factory->arguments_symbol(), *proxy, attributes);
360 descriptors->Set(2, &d); 366 descriptors->Set(2, &d);
361 } 367 }
362 { // Add caller. 368 { // Add caller.
363 Handle<Proxy> proxy = FACTORY->NewProxy(&Accessors::FunctionCaller); 369 Handle<Proxy> proxy = factory->NewProxy(&Accessors::FunctionCaller);
364 CallbacksDescriptor d(*FACTORY->caller_symbol(), *proxy, attributes); 370 CallbacksDescriptor d(*factory->caller_symbol(), *proxy, attributes);
365 descriptors->Set(3, &d); 371 descriptors->Set(3, &d);
366 } 372 }
367 if (prototypeMode != DONT_ADD_PROTOTYPE) { 373 if (prototypeMode != DONT_ADD_PROTOTYPE) {
368 // Add prototype. 374 // Add prototype.
369 if (prototypeMode == ADD_WRITEABLE_PROTOTYPE) { 375 if (prototypeMode == ADD_WRITEABLE_PROTOTYPE) {
370 attributes = static_cast<PropertyAttributes>(attributes & ~READ_ONLY); 376 attributes = static_cast<PropertyAttributes>(attributes & ~READ_ONLY);
371 } 377 }
372 Handle<Proxy> proxy = FACTORY->NewProxy(&Accessors::FunctionPrototype); 378 Handle<Proxy> proxy = factory->NewProxy(&Accessors::FunctionPrototype);
373 CallbacksDescriptor d(*FACTORY->prototype_symbol(), *proxy, attributes); 379 CallbacksDescriptor d(*factory->prototype_symbol(), *proxy, attributes);
374 descriptors->Set(4, &d); 380 descriptors->Set(4, &d);
375 } 381 }
376 descriptors->Sort(); 382 descriptors->Sort();
377 return descriptors; 383 return descriptors;
378 } 384 }
379 385
380 386
381 Handle<Map> Genesis::CreateFunctionMap(PrototypePropertyMode prototype_mode) { 387 Handle<Map> Genesis::CreateFunctionMap(PrototypePropertyMode prototype_mode) {
382 Handle<Map> map = FACTORY->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); 388 Handle<Map> map = FACTORY->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
383 Handle<DescriptorArray> descriptors = 389 Handle<DescriptorArray> descriptors =
(...skipping 22 matching lines...) Expand all
406 // of builtins. 412 // of builtins.
407 // Later the map is replaced with writable prototype map, allocated below. 413 // Later the map is replaced with writable prototype map, allocated below.
408 global_context()->set_function_map( 414 global_context()->set_function_map(
409 *CreateFunctionMap(ADD_READONLY_PROTOTYPE)); 415 *CreateFunctionMap(ADD_READONLY_PROTOTYPE));
410 416
411 // The final map for functions. Writeable prototype. 417 // The final map for functions. Writeable prototype.
412 // This map is installed in MakeFunctionInstancePrototypeWritable. 418 // This map is installed in MakeFunctionInstancePrototypeWritable.
413 function_instance_map_writable_prototype_ = 419 function_instance_map_writable_prototype_ =
414 CreateFunctionMap(ADD_WRITEABLE_PROTOTYPE); 420 CreateFunctionMap(ADD_WRITEABLE_PROTOTYPE);
415 421
416 Handle<String> object_name = Handle<String>(HEAP->Object_symbol()); 422 Isolate* isolate = Isolate::Current();
423 Factory* factory = isolate->factory();
424 Heap* heap = isolate->heap();
425
426 Handle<String> object_name = Handle<String>(heap->Object_symbol());
417 427
418 { // --- O b j e c t --- 428 { // --- O b j e c t ---
419 Handle<JSFunction> object_fun = 429 Handle<JSFunction> object_fun =
420 FACTORY->NewFunction(object_name, FACTORY->null_value()); 430 factory->NewFunction(object_name, factory->null_value());
421 Handle<Map> object_function_map = 431 Handle<Map> object_function_map =
422 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 432 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
423 object_fun->set_initial_map(*object_function_map); 433 object_fun->set_initial_map(*object_function_map);
424 object_function_map->set_constructor(*object_fun); 434 object_function_map->set_constructor(*object_fun);
425 435
426 global_context()->set_object_function(*object_fun); 436 global_context()->set_object_function(*object_fun);
427 437
428 // Allocate a new prototype for the object function. 438 // Allocate a new prototype for the object function.
429 Handle<JSObject> prototype = FACTORY->NewJSObject( 439 Handle<JSObject> prototype = factory->NewJSObject(
430 Isolate::Current()->object_function(), 440 isolate->object_function(),
431 TENURED); 441 TENURED);
432 442
433 global_context()->set_initial_object_prototype(*prototype); 443 global_context()->set_initial_object_prototype(*prototype);
434 SetPrototype(object_fun, prototype); 444 SetPrototype(object_fun, prototype);
435 object_function_map-> 445 object_function_map->
436 set_instance_descriptors(HEAP->empty_descriptor_array()); 446 set_instance_descriptors(heap->empty_descriptor_array());
437 } 447 }
438 448
439 // Allocate the empty function as the prototype for function ECMAScript 449 // Allocate the empty function as the prototype for function ECMAScript
440 // 262 15.3.4. 450 // 262 15.3.4.
441 Handle<String> symbol = FACTORY->LookupAsciiSymbol("Empty"); 451 Handle<String> symbol = factory->LookupAsciiSymbol("Empty");
442 Handle<JSFunction> empty_function = 452 Handle<JSFunction> empty_function =
443 FACTORY->NewFunctionWithoutPrototype(symbol, kNonStrictMode); 453 factory->NewFunctionWithoutPrototype(symbol, kNonStrictMode);
444 454
445 // --- E m p t y --- 455 // --- E m p t y ---
446 Handle<Code> code = 456 Handle<Code> code =
447 Handle<Code>(Isolate::Current()->builtins()->builtin( 457 Handle<Code>(isolate->builtins()->builtin(
448 Builtins::kEmptyFunction)); 458 Builtins::kEmptyFunction));
449 empty_function->set_code(*code); 459 empty_function->set_code(*code);
450 empty_function->shared()->set_code(*code); 460 empty_function->shared()->set_code(*code);
451 Handle<String> source = FACTORY->NewStringFromAscii(CStrVector("() {}")); 461 Handle<String> source = factory->NewStringFromAscii(CStrVector("() {}"));
452 Handle<Script> script = FACTORY->NewScript(source); 462 Handle<Script> script = factory->NewScript(source);
453 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); 463 script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
454 empty_function->shared()->set_script(*script); 464 empty_function->shared()->set_script(*script);
455 empty_function->shared()->set_start_position(0); 465 empty_function->shared()->set_start_position(0);
456 empty_function->shared()->set_end_position(source->length()); 466 empty_function->shared()->set_end_position(source->length());
457 empty_function->shared()->DontAdaptArguments(); 467 empty_function->shared()->DontAdaptArguments();
458 468
459 // Set prototypes for the function maps. 469 // Set prototypes for the function maps.
460 global_context()->function_map()->set_prototype(*empty_function); 470 global_context()->function_map()->set_prototype(*empty_function);
461 global_context()->function_instance_map()->set_prototype(*empty_function); 471 global_context()->function_instance_map()->set_prototype(*empty_function);
462 global_context()->function_without_prototype_map()-> 472 global_context()->function_without_prototype_map()->
463 set_prototype(*empty_function); 473 set_prototype(*empty_function);
464 function_instance_map_writable_prototype_->set_prototype(*empty_function); 474 function_instance_map_writable_prototype_->set_prototype(*empty_function);
465 475
466 // Allocate the function map first and then patch the prototype later 476 // Allocate the function map first and then patch the prototype later
467 Handle<Map> function_without_prototype_map( 477 Handle<Map> function_without_prototype_map(
468 global_context()->function_without_prototype_map()); 478 global_context()->function_without_prototype_map());
469 Handle<Map> empty_fm = FACTORY->CopyMapDropDescriptors( 479 Handle<Map> empty_fm = factory->CopyMapDropDescriptors(
470 function_without_prototype_map); 480 function_without_prototype_map);
471 empty_fm->set_instance_descriptors( 481 empty_fm->set_instance_descriptors(
472 function_without_prototype_map->instance_descriptors()); 482 function_without_prototype_map->instance_descriptors());
473 empty_fm->set_prototype(global_context()->object_function()->prototype()); 483 empty_fm->set_prototype(global_context()->object_function()->prototype());
474 empty_function->set_map(*empty_fm); 484 empty_function->set_map(*empty_fm);
475 return empty_function; 485 return empty_function;
476 } 486 }
477 487
478 488
479 Handle<DescriptorArray> Genesis::ComputeStrictFunctionInstanceDescriptor( 489 Handle<DescriptorArray> Genesis::ComputeStrictFunctionInstanceDescriptor(
480 PrototypePropertyMode prototypeMode, 490 PrototypePropertyMode prototypeMode,
481 Handle<FixedArray> arguments, 491 Handle<FixedArray> arguments,
482 Handle<FixedArray> caller) { 492 Handle<FixedArray> caller) {
493 Factory* factory = Isolate::Current()->factory();
483 Handle<DescriptorArray> descriptors = 494 Handle<DescriptorArray> descriptors =
484 FACTORY->NewDescriptorArray(prototypeMode == DONT_ADD_PROTOTYPE ? 4 : 5); 495 factory->NewDescriptorArray(prototypeMode == DONT_ADD_PROTOTYPE ? 4 : 5);
485 PropertyAttributes attributes = static_cast<PropertyAttributes>( 496 PropertyAttributes attributes = static_cast<PropertyAttributes>(
486 DONT_ENUM | DONT_DELETE | READ_ONLY); 497 DONT_ENUM | DONT_DELETE | READ_ONLY);
487 498
488 { // length 499 { // length
489 Handle<Proxy> proxy = FACTORY->NewProxy(&Accessors::FunctionLength); 500 Handle<Proxy> proxy = factory->NewProxy(&Accessors::FunctionLength);
490 CallbacksDescriptor d(*FACTORY->length_symbol(), *proxy, attributes); 501 CallbacksDescriptor d(*factory->length_symbol(), *proxy, attributes);
491 descriptors->Set(0, &d); 502 descriptors->Set(0, &d);
492 } 503 }
493 { // name 504 { // name
494 Handle<Proxy> proxy = FACTORY->NewProxy(&Accessors::FunctionName); 505 Handle<Proxy> proxy = factory->NewProxy(&Accessors::FunctionName);
495 CallbacksDescriptor d(*FACTORY->name_symbol(), *proxy, attributes); 506 CallbacksDescriptor d(*factory->name_symbol(), *proxy, attributes);
496 descriptors->Set(1, &d); 507 descriptors->Set(1, &d);
497 } 508 }
498 { // arguments 509 { // arguments
499 CallbacksDescriptor d(*FACTORY->arguments_symbol(), *arguments, attributes); 510 CallbacksDescriptor d(*factory->arguments_symbol(), *arguments, attributes);
500 descriptors->Set(2, &d); 511 descriptors->Set(2, &d);
501 } 512 }
502 { // caller 513 { // caller
503 CallbacksDescriptor d(*FACTORY->caller_symbol(), *caller, attributes); 514 CallbacksDescriptor d(*factory->caller_symbol(), *caller, attributes);
504 descriptors->Set(3, &d); 515 descriptors->Set(3, &d);
505 } 516 }
506 517
507 // prototype 518 // prototype
508 if (prototypeMode != DONT_ADD_PROTOTYPE) { 519 if (prototypeMode != DONT_ADD_PROTOTYPE) {
509 if (prototypeMode == ADD_WRITEABLE_PROTOTYPE) { 520 if (prototypeMode == ADD_WRITEABLE_PROTOTYPE) {
510 attributes = static_cast<PropertyAttributes>(attributes & ~READ_ONLY); 521 attributes = static_cast<PropertyAttributes>(attributes & ~READ_ONLY);
511 } 522 }
512 Handle<Proxy> proxy = FACTORY->NewProxy(&Accessors::FunctionPrototype); 523 Handle<Proxy> proxy = factory->NewProxy(&Accessors::FunctionPrototype);
513 CallbacksDescriptor d(*FACTORY->prototype_symbol(), *proxy, attributes); 524 CallbacksDescriptor d(*factory->prototype_symbol(), *proxy, attributes);
514 descriptors->Set(4, &d); 525 descriptors->Set(4, &d);
515 } 526 }
516 527
517 descriptors->Sort(); 528 descriptors->Sort();
518 return descriptors; 529 return descriptors;
519 } 530 }
520 531
521 532
522 // ECMAScript 5th Edition, 13.2.3 533 // ECMAScript 5th Edition, 13.2.3
523 Handle<JSFunction> Genesis::CreateThrowTypeErrorFunction( 534 Handle<JSFunction> Genesis::CreateThrowTypeErrorFunction(
524 Builtins::Name builtin) { 535 Builtins::Name builtin) {
525 Handle<String> name = FACTORY->LookupAsciiSymbol("ThrowTypeError"); 536 Isolate* isolate = Isolate::Current();
537 Factory* factory = isolate->factory();
538
539 Handle<String> name = factory->LookupAsciiSymbol("ThrowTypeError");
526 Handle<JSFunction> throw_type_error = 540 Handle<JSFunction> throw_type_error =
527 FACTORY->NewFunctionWithoutPrototype(name, kStrictMode); 541 factory->NewFunctionWithoutPrototype(name, kStrictMode);
528 Handle<Code> code = Handle<Code>( 542 Handle<Code> code = Handle<Code>(
529 Isolate::Current()->builtins()->builtin(builtin)); 543 isolate->builtins()->builtin(builtin));
530 544
531 throw_type_error->set_map(global_context()->strict_mode_function_map()); 545 throw_type_error->set_map(global_context()->strict_mode_function_map());
532 throw_type_error->set_code(*code); 546 throw_type_error->set_code(*code);
533 throw_type_error->shared()->set_code(*code); 547 throw_type_error->shared()->set_code(*code);
534 throw_type_error->shared()->DontAdaptArguments(); 548 throw_type_error->shared()->DontAdaptArguments();
535 549
536 PreventExtensions(throw_type_error); 550 PreventExtensions(throw_type_error);
537 551
538 return throw_type_error; 552 return throw_type_error;
539 } 553 }
(...skipping 12 matching lines...) Expand all
552 map->set_instance_descriptors(*descriptors); 566 map->set_instance_descriptors(*descriptors);
553 map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE); 567 map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE);
554 map->set_prototype(*empty_function); 568 map->set_prototype(*empty_function);
555 return map; 569 return map;
556 } 570 }
557 571
558 572
559 void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) { 573 void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) {
560 // Create the callbacks arrays for ThrowTypeError functions. 574 // Create the callbacks arrays for ThrowTypeError functions.
561 // The get/set callacks are filled in after the maps are created below. 575 // The get/set callacks are filled in after the maps are created below.
562 Handle<FixedArray> arguments = FACTORY->NewFixedArray(2, TENURED); 576 Factory* factory = Isolate::Current()->factory();
563 Handle<FixedArray> caller = FACTORY->NewFixedArray(2, TENURED); 577 Handle<FixedArray> arguments = factory->NewFixedArray(2, TENURED);
578 Handle<FixedArray> caller = factory->NewFixedArray(2, TENURED);
564 579
565 // Allocate map for the strict mode function instances. 580 // Allocate map for the strict mode function instances.
566 global_context()->set_strict_mode_function_instance_map( 581 global_context()->set_strict_mode_function_instance_map(
567 *CreateStrictModeFunctionMap( 582 *CreateStrictModeFunctionMap(
568 ADD_WRITEABLE_PROTOTYPE, empty, arguments, caller)); 583 ADD_WRITEABLE_PROTOTYPE, empty, arguments, caller));
569 584
570 // Allocate map for the prototype-less strict mode instances. 585 // Allocate map for the prototype-less strict mode instances.
571 global_context()->set_strict_mode_function_without_prototype_map( 586 global_context()->set_strict_mode_function_without_prototype_map(
572 *CreateStrictModeFunctionMap( 587 *CreateStrictModeFunctionMap(
573 DONT_ADD_PROTOTYPE, empty, arguments, caller)); 588 DONT_ADD_PROTOTYPE, empty, arguments, caller));
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 Handle<FunctionTemplateInfo> global_constructor = 678 Handle<FunctionTemplateInfo> global_constructor =
664 Handle<FunctionTemplateInfo>( 679 Handle<FunctionTemplateInfo>(
665 FunctionTemplateInfo::cast(data->constructor())); 680 FunctionTemplateInfo::cast(data->constructor()));
666 Handle<Object> proto_template(global_constructor->prototype_template()); 681 Handle<Object> proto_template(global_constructor->prototype_template());
667 if (!proto_template->IsUndefined()) { 682 if (!proto_template->IsUndefined()) {
668 js_global_template = 683 js_global_template =
669 Handle<ObjectTemplateInfo>::cast(proto_template); 684 Handle<ObjectTemplateInfo>::cast(proto_template);
670 } 685 }
671 } 686 }
672 687
688 Isolate* isolate = Isolate::Current();
689 Factory* factory = isolate->factory();
690 Heap* heap = isolate->heap();
691
673 if (js_global_template.is_null()) { 692 if (js_global_template.is_null()) {
674 Handle<String> name = Handle<String>(HEAP->empty_symbol()); 693 Handle<String> name = Handle<String>(heap->empty_symbol());
675 Handle<Code> code = Handle<Code>(Isolate::Current()->builtins()->builtin( 694 Handle<Code> code = Handle<Code>(isolate->builtins()->builtin(
676 Builtins::kIllegal)); 695 Builtins::kIllegal));
677 js_global_function = 696 js_global_function =
678 FACTORY->NewFunction(name, JS_GLOBAL_OBJECT_TYPE, 697 factory->NewFunction(name, JS_GLOBAL_OBJECT_TYPE,
679 JSGlobalObject::kSize, code, true); 698 JSGlobalObject::kSize, code, true);
680 // Change the constructor property of the prototype of the 699 // Change the constructor property of the prototype of the
681 // hidden global function to refer to the Object function. 700 // hidden global function to refer to the Object function.
682 Handle<JSObject> prototype = 701 Handle<JSObject> prototype =
683 Handle<JSObject>( 702 Handle<JSObject>(
684 JSObject::cast(js_global_function->instance_prototype())); 703 JSObject::cast(js_global_function->instance_prototype()));
685 SetLocalPropertyNoThrow( 704 SetLocalPropertyNoThrow(
686 prototype, 705 prototype,
687 FACTORY->constructor_symbol(), 706 factory->constructor_symbol(),
688 Isolate::Current()->object_function(), 707 isolate->object_function(),
689 NONE); 708 NONE);
690 } else { 709 } else {
691 Handle<FunctionTemplateInfo> js_global_constructor( 710 Handle<FunctionTemplateInfo> js_global_constructor(
692 FunctionTemplateInfo::cast(js_global_template->constructor())); 711 FunctionTemplateInfo::cast(js_global_template->constructor()));
693 js_global_function = 712 js_global_function =
694 FACTORY->CreateApiFunction(js_global_constructor, 713 factory->CreateApiFunction(js_global_constructor,
695 FACTORY->InnerGlobalObject); 714 factory->InnerGlobalObject);
696 } 715 }
697 716
698 js_global_function->initial_map()->set_is_hidden_prototype(); 717 js_global_function->initial_map()->set_is_hidden_prototype();
699 Handle<GlobalObject> inner_global = 718 Handle<GlobalObject> inner_global =
700 FACTORY->NewGlobalObject(js_global_function); 719 factory->NewGlobalObject(js_global_function);
701 if (inner_global_out != NULL) { 720 if (inner_global_out != NULL) {
702 *inner_global_out = inner_global; 721 *inner_global_out = inner_global;
703 } 722 }
704 723
705 // Step 2: create or re-initialize the global proxy object. 724 // Step 2: create or re-initialize the global proxy object.
706 Handle<JSFunction> global_proxy_function; 725 Handle<JSFunction> global_proxy_function;
707 if (global_template.IsEmpty()) { 726 if (global_template.IsEmpty()) {
708 Handle<String> name = Handle<String>(HEAP->empty_symbol()); 727 Handle<String> name = Handle<String>(heap->empty_symbol());
709 Handle<Code> code = Handle<Code>(Isolate::Current()->builtins()->builtin( 728 Handle<Code> code = Handle<Code>(isolate->builtins()->builtin(
710 Builtins::kIllegal)); 729 Builtins::kIllegal));
711 global_proxy_function = 730 global_proxy_function =
712 FACTORY->NewFunction(name, JS_GLOBAL_PROXY_TYPE, 731 factory->NewFunction(name, JS_GLOBAL_PROXY_TYPE,
713 JSGlobalProxy::kSize, code, true); 732 JSGlobalProxy::kSize, code, true);
714 } else { 733 } else {
715 Handle<ObjectTemplateInfo> data = 734 Handle<ObjectTemplateInfo> data =
716 v8::Utils::OpenHandle(*global_template); 735 v8::Utils::OpenHandle(*global_template);
717 Handle<FunctionTemplateInfo> global_constructor( 736 Handle<FunctionTemplateInfo> global_constructor(
718 FunctionTemplateInfo::cast(data->constructor())); 737 FunctionTemplateInfo::cast(data->constructor()));
719 global_proxy_function = 738 global_proxy_function =
720 FACTORY->CreateApiFunction(global_constructor, 739 factory->CreateApiFunction(global_constructor,
721 FACTORY->OuterGlobalObject); 740 factory->OuterGlobalObject);
722 } 741 }
723 742
724 Handle<String> global_name = FACTORY->LookupAsciiSymbol("global"); 743 Handle<String> global_name = factory->LookupAsciiSymbol("global");
725 global_proxy_function->shared()->set_instance_class_name(*global_name); 744 global_proxy_function->shared()->set_instance_class_name(*global_name);
726 global_proxy_function->initial_map()->set_is_access_check_needed(true); 745 global_proxy_function->initial_map()->set_is_access_check_needed(true);
727 746
728 // Set global_proxy.__proto__ to js_global after ConfigureGlobalObjects 747 // Set global_proxy.__proto__ to js_global after ConfigureGlobalObjects
729 // Return the global proxy. 748 // Return the global proxy.
730 749
731 if (global_object.location() != NULL) { 750 if (global_object.location() != NULL) {
732 ASSERT(global_object->IsJSGlobalProxy()); 751 ASSERT(global_object->IsJSGlobalProxy());
733 return ReinitializeJSGlobalProxy( 752 return ReinitializeJSGlobalProxy(
734 global_proxy_function, 753 global_proxy_function,
735 Handle<JSGlobalProxy>::cast(global_object)); 754 Handle<JSGlobalProxy>::cast(global_object));
736 } else { 755 } else {
737 return Handle<JSGlobalProxy>::cast( 756 return Handle<JSGlobalProxy>::cast(
738 FACTORY->NewJSObject(global_proxy_function, TENURED)); 757 factory->NewJSObject(global_proxy_function, TENURED));
739 } 758 }
740 } 759 }
741 760
742 761
743 void Genesis::HookUpGlobalProxy(Handle<GlobalObject> inner_global, 762 void Genesis::HookUpGlobalProxy(Handle<GlobalObject> inner_global,
744 Handle<JSGlobalProxy> global_proxy) { 763 Handle<JSGlobalProxy> global_proxy) {
745 // Set the global context for the global object. 764 // Set the global context for the global object.
746 inner_global->set_global_context(*global_context()); 765 inner_global->set_global_context(*global_context());
747 inner_global->set_global_receiver(*global_proxy); 766 inner_global->set_global_receiver(*global_proxy);
748 global_proxy->set_context(*global_context()); 767 global_proxy->set_context(*global_context());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 global_context()->set_previous(NULL); 800 global_context()->set_previous(NULL);
782 // Set extension and global object. 801 // Set extension and global object.
783 global_context()->set_extension(*inner_global); 802 global_context()->set_extension(*inner_global);
784 global_context()->set_global(*inner_global); 803 global_context()->set_global(*inner_global);
785 // Security setup: Set the security token of the global object to 804 // Security setup: Set the security token of the global object to
786 // its the inner global. This makes the security check between two 805 // its the inner global. This makes the security check between two
787 // different contexts fail by default even in case of global 806 // different contexts fail by default even in case of global
788 // object reinitialization. 807 // object reinitialization.
789 global_context()->set_security_token(*inner_global); 808 global_context()->set_security_token(*inner_global);
790 809
791 Handle<String> object_name = Handle<String>(HEAP->Object_symbol()); 810 Isolate* isolate = Isolate::Current();
811 Factory* factory = isolate->factory();
812 Heap* heap = isolate->heap();
813
814 Handle<String> object_name = Handle<String>(heap->Object_symbol());
792 SetLocalPropertyNoThrow(inner_global, object_name, 815 SetLocalPropertyNoThrow(inner_global, object_name,
793 Isolate::Current()->object_function(), DONT_ENUM); 816 isolate->object_function(), DONT_ENUM);
794 817
795 Handle<JSObject> global = Handle<JSObject>(global_context()->global()); 818 Handle<JSObject> global = Handle<JSObject>(global_context()->global());
796 819
797 // Install global Function object 820 // Install global Function object
798 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, 821 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize,
799 empty_function, Builtins::kIllegal, true); // ECMA native. 822 empty_function, Builtins::kIllegal, true); // ECMA native.
800 823
801 { // --- A r r a y --- 824 { // --- A r r a y ---
802 Handle<JSFunction> array_function = 825 Handle<JSFunction> array_function =
803 InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize, 826 InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize,
804 Isolate::Current()->initial_object_prototype(), 827 isolate->initial_object_prototype(),
805 Builtins::kArrayCode, true); 828 Builtins::kArrayCode, true);
806 array_function->shared()->set_construct_stub( 829 array_function->shared()->set_construct_stub(
807 Isolate::Current()->builtins()->builtin(Builtins::kArrayConstructCode)); 830 isolate->builtins()->builtin(Builtins::kArrayConstructCode));
808 array_function->shared()->DontAdaptArguments(); 831 array_function->shared()->DontAdaptArguments();
809 832
810 // This seems a bit hackish, but we need to make sure Array.length 833 // This seems a bit hackish, but we need to make sure Array.length
811 // is 1. 834 // is 1.
812 array_function->shared()->set_length(1); 835 array_function->shared()->set_length(1);
813 Handle<DescriptorArray> array_descriptors = 836 Handle<DescriptorArray> array_descriptors =
814 FACTORY->CopyAppendProxyDescriptor( 837 factory->CopyAppendProxyDescriptor(
815 FACTORY->empty_descriptor_array(), 838 factory->empty_descriptor_array(),
816 FACTORY->length_symbol(), 839 factory->length_symbol(),
817 FACTORY->NewProxy(&Accessors::ArrayLength), 840 factory->NewProxy(&Accessors::ArrayLength),
818 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE)); 841 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE));
819 842
820 // Cache the fast JavaScript array map 843 // Cache the fast JavaScript array map
821 global_context()->set_js_array_map(array_function->initial_map()); 844 global_context()->set_js_array_map(array_function->initial_map());
822 global_context()->js_array_map()->set_instance_descriptors( 845 global_context()->js_array_map()->set_instance_descriptors(
823 *array_descriptors); 846 *array_descriptors);
824 // array_function is used internally. JS code creating array object should 847 // array_function is used internally. JS code creating array object should
825 // search for the 'Array' property on the global object and use that one 848 // search for the 'Array' property on the global object and use that one
826 // as the constructor. 'Array' property on a global object can be 849 // as the constructor. 'Array' property on a global object can be
827 // overwritten by JS code. 850 // overwritten by JS code.
828 global_context()->set_array_function(*array_function); 851 global_context()->set_array_function(*array_function);
829 } 852 }
830 853
831 { // --- N u m b e r --- 854 { // --- N u m b e r ---
832 Handle<JSFunction> number_fun = 855 Handle<JSFunction> number_fun =
833 InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize, 856 InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize,
834 Isolate::Current()->initial_object_prototype(), 857 isolate->initial_object_prototype(),
835 Builtins::kIllegal, true); 858 Builtins::kIllegal, true);
836 global_context()->set_number_function(*number_fun); 859 global_context()->set_number_function(*number_fun);
837 } 860 }
838 861
839 { // --- B o o l e a n --- 862 { // --- B o o l e a n ---
840 Handle<JSFunction> boolean_fun = 863 Handle<JSFunction> boolean_fun =
841 InstallFunction(global, "Boolean", JS_VALUE_TYPE, JSValue::kSize, 864 InstallFunction(global, "Boolean", JS_VALUE_TYPE, JSValue::kSize,
842 Isolate::Current()->initial_object_prototype(), 865 isolate->initial_object_prototype(),
843 Builtins::kIllegal, true); 866 Builtins::kIllegal, true);
844 global_context()->set_boolean_function(*boolean_fun); 867 global_context()->set_boolean_function(*boolean_fun);
845 } 868 }
846 869
847 { // --- S t r i n g --- 870 { // --- S t r i n g ---
848 Handle<JSFunction> string_fun = 871 Handle<JSFunction> string_fun =
849 InstallFunction(global, "String", JS_VALUE_TYPE, JSValue::kSize, 872 InstallFunction(global, "String", JS_VALUE_TYPE, JSValue::kSize,
850 Isolate::Current()->initial_object_prototype(), 873 isolate->initial_object_prototype(),
851 Builtins::kIllegal, true); 874 Builtins::kIllegal, true);
852 string_fun->shared()->set_construct_stub( 875 string_fun->shared()->set_construct_stub(
853 Isolate::Current()->builtins()->builtin( 876 isolate->builtins()->builtin(Builtins::kStringConstructCode));
854 Builtins::kStringConstructCode));
855 global_context()->set_string_function(*string_fun); 877 global_context()->set_string_function(*string_fun);
856 // Add 'length' property to strings. 878 // Add 'length' property to strings.
857 Handle<DescriptorArray> string_descriptors = 879 Handle<DescriptorArray> string_descriptors =
858 FACTORY->CopyAppendProxyDescriptor( 880 factory->CopyAppendProxyDescriptor(
859 FACTORY->empty_descriptor_array(), 881 factory->empty_descriptor_array(),
860 FACTORY->length_symbol(), 882 factory->length_symbol(),
861 FACTORY->NewProxy(&Accessors::StringLength), 883 factory->NewProxy(&Accessors::StringLength),
862 static_cast<PropertyAttributes>(DONT_ENUM | 884 static_cast<PropertyAttributes>(DONT_ENUM |
863 DONT_DELETE | 885 DONT_DELETE |
864 READ_ONLY)); 886 READ_ONLY));
865 887
866 Handle<Map> string_map = 888 Handle<Map> string_map =
867 Handle<Map>(global_context()->string_function()->initial_map()); 889 Handle<Map>(global_context()->string_function()->initial_map());
868 string_map->set_instance_descriptors(*string_descriptors); 890 string_map->set_instance_descriptors(*string_descriptors);
869 } 891 }
870 892
871 { // --- D a t e --- 893 { // --- D a t e ---
872 // Builtin functions for Date.prototype. 894 // Builtin functions for Date.prototype.
873 Handle<JSFunction> date_fun = 895 Handle<JSFunction> date_fun =
874 InstallFunction(global, "Date", JS_VALUE_TYPE, JSValue::kSize, 896 InstallFunction(global, "Date", JS_VALUE_TYPE, JSValue::kSize,
875 Isolate::Current()->initial_object_prototype(), 897 isolate->initial_object_prototype(),
876 Builtins::kIllegal, true); 898 Builtins::kIllegal, true);
877 899
878 global_context()->set_date_function(*date_fun); 900 global_context()->set_date_function(*date_fun);
879 } 901 }
880 902
881 903
882 { // -- R e g E x p 904 { // -- R e g E x p
883 // Builtin functions for RegExp.prototype. 905 // Builtin functions for RegExp.prototype.
884 Handle<JSFunction> regexp_fun = 906 Handle<JSFunction> regexp_fun =
885 InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize, 907 InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize,
886 Isolate::Current()->initial_object_prototype(), 908 isolate->initial_object_prototype(),
887 Builtins::kIllegal, true); 909 Builtins::kIllegal, true);
888 global_context()->set_regexp_function(*regexp_fun); 910 global_context()->set_regexp_function(*regexp_fun);
889 911
890 ASSERT(regexp_fun->has_initial_map()); 912 ASSERT(regexp_fun->has_initial_map());
891 Handle<Map> initial_map(regexp_fun->initial_map()); 913 Handle<Map> initial_map(regexp_fun->initial_map());
892 914
893 ASSERT_EQ(0, initial_map->inobject_properties()); 915 ASSERT_EQ(0, initial_map->inobject_properties());
894 916
895 Handle<DescriptorArray> descriptors = FACTORY->NewDescriptorArray(5); 917 Handle<DescriptorArray> descriptors = factory->NewDescriptorArray(5);
896 PropertyAttributes final = 918 PropertyAttributes final =
897 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); 919 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
898 int enum_index = 0; 920 int enum_index = 0;
899 { 921 {
900 // ECMA-262, section 15.10.7.1. 922 // ECMA-262, section 15.10.7.1.
901 FieldDescriptor field(HEAP->source_symbol(), 923 FieldDescriptor field(heap->source_symbol(),
902 JSRegExp::kSourceFieldIndex, 924 JSRegExp::kSourceFieldIndex,
903 final, 925 final,
904 enum_index++); 926 enum_index++);
905 descriptors->Set(0, &field); 927 descriptors->Set(0, &field);
906 } 928 }
907 { 929 {
908 // ECMA-262, section 15.10.7.2. 930 // ECMA-262, section 15.10.7.2.
909 FieldDescriptor field(HEAP->global_symbol(), 931 FieldDescriptor field(heap->global_symbol(),
910 JSRegExp::kGlobalFieldIndex, 932 JSRegExp::kGlobalFieldIndex,
911 final, 933 final,
912 enum_index++); 934 enum_index++);
913 descriptors->Set(1, &field); 935 descriptors->Set(1, &field);
914 } 936 }
915 { 937 {
916 // ECMA-262, section 15.10.7.3. 938 // ECMA-262, section 15.10.7.3.
917 FieldDescriptor field(HEAP->ignore_case_symbol(), 939 FieldDescriptor field(heap->ignore_case_symbol(),
918 JSRegExp::kIgnoreCaseFieldIndex, 940 JSRegExp::kIgnoreCaseFieldIndex,
919 final, 941 final,
920 enum_index++); 942 enum_index++);
921 descriptors->Set(2, &field); 943 descriptors->Set(2, &field);
922 } 944 }
923 { 945 {
924 // ECMA-262, section 15.10.7.4. 946 // ECMA-262, section 15.10.7.4.
925 FieldDescriptor field(HEAP->multiline_symbol(), 947 FieldDescriptor field(heap->multiline_symbol(),
926 JSRegExp::kMultilineFieldIndex, 948 JSRegExp::kMultilineFieldIndex,
927 final, 949 final,
928 enum_index++); 950 enum_index++);
929 descriptors->Set(3, &field); 951 descriptors->Set(3, &field);
930 } 952 }
931 { 953 {
932 // ECMA-262, section 15.10.7.5. 954 // ECMA-262, section 15.10.7.5.
933 PropertyAttributes writable = 955 PropertyAttributes writable =
934 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); 956 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE);
935 FieldDescriptor field(HEAP->last_index_symbol(), 957 FieldDescriptor field(heap->last_index_symbol(),
936 JSRegExp::kLastIndexFieldIndex, 958 JSRegExp::kLastIndexFieldIndex,
937 writable, 959 writable,
938 enum_index++); 960 enum_index++);
939 descriptors->Set(4, &field); 961 descriptors->Set(4, &field);
940 } 962 }
941 descriptors->SetNextEnumerationIndex(enum_index); 963 descriptors->SetNextEnumerationIndex(enum_index);
942 descriptors->Sort(); 964 descriptors->Sort();
943 965
944 initial_map->set_inobject_properties(5); 966 initial_map->set_inobject_properties(5);
945 initial_map->set_pre_allocated_property_fields(5); 967 initial_map->set_pre_allocated_property_fields(5);
946 initial_map->set_unused_property_fields(0); 968 initial_map->set_unused_property_fields(0);
947 initial_map->set_instance_size( 969 initial_map->set_instance_size(
948 initial_map->instance_size() + 5 * kPointerSize); 970 initial_map->instance_size() + 5 * kPointerSize);
949 initial_map->set_instance_descriptors(*descriptors); 971 initial_map->set_instance_descriptors(*descriptors);
950 initial_map->set_visitor_id(StaticVisitorBase::GetVisitorId(*initial_map)); 972 initial_map->set_visitor_id(StaticVisitorBase::GetVisitorId(*initial_map));
951 } 973 }
952 974
953 { // -- J S O N 975 { // -- J S O N
954 Handle<String> name = FACTORY->NewStringFromAscii(CStrVector("JSON")); 976 Handle<String> name = factory->NewStringFromAscii(CStrVector("JSON"));
955 Handle<JSFunction> cons = FACTORY->NewFunction( 977 Handle<JSFunction> cons = factory->NewFunction(
956 name, 978 name,
957 FACTORY->the_hole_value()); 979 factory->the_hole_value());
958 cons->SetInstancePrototype(global_context()->initial_object_prototype()); 980 cons->SetInstancePrototype(global_context()->initial_object_prototype());
959 cons->SetInstanceClassName(*name); 981 cons->SetInstanceClassName(*name);
960 Handle<JSObject> json_object = FACTORY->NewJSObject(cons, TENURED); 982 Handle<JSObject> json_object = factory->NewJSObject(cons, TENURED);
961 ASSERT(json_object->IsJSObject()); 983 ASSERT(json_object->IsJSObject());
962 SetLocalPropertyNoThrow(global, name, json_object, DONT_ENUM); 984 SetLocalPropertyNoThrow(global, name, json_object, DONT_ENUM);
963 global_context()->set_json_object(*json_object); 985 global_context()->set_json_object(*json_object);
964 } 986 }
965 987
966 { // --- arguments_boilerplate_ 988 { // --- arguments_boilerplate_
967 // Make sure we can recognize argument objects at runtime. 989 // Make sure we can recognize argument objects at runtime.
968 // This is done by introducing an anonymous function with 990 // This is done by introducing an anonymous function with
969 // class_name equals 'Arguments'. 991 // class_name equals 'Arguments'.
970 Handle<String> symbol = FACTORY->LookupAsciiSymbol("Arguments"); 992 Handle<String> symbol = factory->LookupAsciiSymbol("Arguments");
971 Handle<Code> code = Handle<Code>( 993 Handle<Code> code = Handle<Code>(
972 Isolate::Current()->builtins()->builtin(Builtins::kIllegal)); 994 isolate->builtins()->builtin(Builtins::kIllegal));
973 Handle<JSObject> prototype = 995 Handle<JSObject> prototype =
974 Handle<JSObject>( 996 Handle<JSObject>(
975 JSObject::cast(global_context()->object_function()->prototype())); 997 JSObject::cast(global_context()->object_function()->prototype()));
976 998
977 Handle<JSFunction> function = 999 Handle<JSFunction> function =
978 FACTORY->NewFunctionWithPrototype(symbol, 1000 factory->NewFunctionWithPrototype(symbol,
979 JS_OBJECT_TYPE, 1001 JS_OBJECT_TYPE,
980 JSObject::kHeaderSize, 1002 JSObject::kHeaderSize,
981 prototype, 1003 prototype,
982 code, 1004 code,
983 false); 1005 false);
984 ASSERT(!function->has_initial_map()); 1006 ASSERT(!function->has_initial_map());
985 function->shared()->set_instance_class_name(*symbol); 1007 function->shared()->set_instance_class_name(*symbol);
986 function->shared()->set_expected_nof_properties(2); 1008 function->shared()->set_expected_nof_properties(2);
987 Handle<JSObject> result = FACTORY->NewJSObject(function); 1009 Handle<JSObject> result = factory->NewJSObject(function);
988 1010
989 global_context()->set_arguments_boilerplate(*result); 1011 global_context()->set_arguments_boilerplate(*result);
990 // Note: length must be added as the first property and 1012 // Note: length must be added as the first property and
991 // callee must be added as the second property. 1013 // callee must be added as the second property.
992 SetLocalPropertyNoThrow(result, FACTORY->length_symbol(), 1014 SetLocalPropertyNoThrow(result, factory->length_symbol(),
993 FACTORY->undefined_value(), 1015 factory->undefined_value(),
994 DONT_ENUM); 1016 DONT_ENUM);
995 SetLocalPropertyNoThrow(result, FACTORY->callee_symbol(), 1017 SetLocalPropertyNoThrow(result, factory->callee_symbol(),
996 FACTORY->undefined_value(), 1018 factory->undefined_value(),
997 DONT_ENUM); 1019 DONT_ENUM);
998 1020
999 #ifdef DEBUG 1021 #ifdef DEBUG
1000 LookupResult lookup; 1022 LookupResult lookup;
1001 result->LocalLookup(HEAP->callee_symbol(), &lookup); 1023 result->LocalLookup(heap->callee_symbol(), &lookup);
1002 ASSERT(lookup.IsProperty() && (lookup.type() == FIELD)); 1024 ASSERT(lookup.IsProperty() && (lookup.type() == FIELD));
1003 ASSERT(lookup.GetFieldIndex() == Heap::kArgumentsCalleeIndex); 1025 ASSERT(lookup.GetFieldIndex() == Heap::kArgumentsCalleeIndex);
1004 1026
1005 result->LocalLookup(HEAP->length_symbol(), &lookup); 1027 result->LocalLookup(heap->length_symbol(), &lookup);
1006 ASSERT(lookup.IsProperty() && (lookup.type() == FIELD)); 1028 ASSERT(lookup.IsProperty() && (lookup.type() == FIELD));
1007 ASSERT(lookup.GetFieldIndex() == Heap::kArgumentsLengthIndex); 1029 ASSERT(lookup.GetFieldIndex() == Heap::kArgumentsLengthIndex);
1008 1030
1009 ASSERT(result->map()->inobject_properties() > Heap::kArgumentsCalleeIndex); 1031 ASSERT(result->map()->inobject_properties() > Heap::kArgumentsCalleeIndex);
1010 ASSERT(result->map()->inobject_properties() > Heap::kArgumentsLengthIndex); 1032 ASSERT(result->map()->inobject_properties() > Heap::kArgumentsLengthIndex);
1011 1033
1012 // Check the state of the object. 1034 // Check the state of the object.
1013 ASSERT(result->HasFastProperties()); 1035 ASSERT(result->HasFastProperties());
1014 ASSERT(result->HasFastElements()); 1036 ASSERT(result->HasFastElements());
1015 #endif 1037 #endif
1016 } 1038 }
1017 1039
1018 { // --- strict mode arguments boilerplate 1040 { // --- strict mode arguments boilerplate
1019 const PropertyAttributes attributes = 1041 const PropertyAttributes attributes =
1020 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); 1042 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
1021 1043
1022 // Create the ThrowTypeError functions. 1044 // Create the ThrowTypeError functions.
1023 Handle<FixedArray> callee = FACTORY->NewFixedArray(2, TENURED); 1045 Handle<FixedArray> callee = factory->NewFixedArray(2, TENURED);
1024 Handle<FixedArray> caller = FACTORY->NewFixedArray(2, TENURED); 1046 Handle<FixedArray> caller = factory->NewFixedArray(2, TENURED);
1025 1047
1026 Handle<JSFunction> callee_throw = 1048 Handle<JSFunction> callee_throw =
1027 CreateThrowTypeErrorFunction(Builtins::kStrictArgumentsCallee); 1049 CreateThrowTypeErrorFunction(Builtins::kStrictArgumentsCallee);
1028 Handle<JSFunction> caller_throw = 1050 Handle<JSFunction> caller_throw =
1029 CreateThrowTypeErrorFunction(Builtins::kStrictArgumentsCaller); 1051 CreateThrowTypeErrorFunction(Builtins::kStrictArgumentsCaller);
1030 1052
1031 // Install the ThrowTypeError functions. 1053 // Install the ThrowTypeError functions.
1032 callee->set(0, *callee_throw); 1054 callee->set(0, *callee_throw);
1033 callee->set(1, *callee_throw); 1055 callee->set(1, *callee_throw);
1034 caller->set(0, *caller_throw); 1056 caller->set(0, *caller_throw);
1035 caller->set(1, *caller_throw); 1057 caller->set(1, *caller_throw);
1036 1058
1037 // Create the descriptor array for the arguments object. 1059 // Create the descriptor array for the arguments object.
1038 Handle<DescriptorArray> descriptors = FACTORY->NewDescriptorArray(3); 1060 Handle<DescriptorArray> descriptors = factory->NewDescriptorArray(3);
1039 { // length 1061 { // length
1040 FieldDescriptor d(*FACTORY->length_symbol(), 0, DONT_ENUM); 1062 FieldDescriptor d(*factory->length_symbol(), 0, DONT_ENUM);
1041 descriptors->Set(0, &d); 1063 descriptors->Set(0, &d);
1042 } 1064 }
1043 { // callee 1065 { // callee
1044 CallbacksDescriptor d(*FACTORY->callee_symbol(), *callee, attributes); 1066 CallbacksDescriptor d(*factory->callee_symbol(), *callee, attributes);
1045 descriptors->Set(1, &d); 1067 descriptors->Set(1, &d);
1046 } 1068 }
1047 { // caller 1069 { // caller
1048 CallbacksDescriptor d(*FACTORY->caller_symbol(), *caller, attributes); 1070 CallbacksDescriptor d(*factory->caller_symbol(), *caller, attributes);
1049 descriptors->Set(2, &d); 1071 descriptors->Set(2, &d);
1050 } 1072 }
1051 descriptors->Sort(); 1073 descriptors->Sort();
1052 1074
1053 // Create the map. Allocate one in-object field for length. 1075 // Create the map. Allocate one in-object field for length.
1054 Handle<Map> map = FACTORY->NewMap(JS_OBJECT_TYPE, 1076 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE,
1055 Heap::kArgumentsObjectSizeStrict); 1077 Heap::kArgumentsObjectSizeStrict);
1056 map->set_instance_descriptors(*descriptors); 1078 map->set_instance_descriptors(*descriptors);
1057 map->set_function_with_prototype(true); 1079 map->set_function_with_prototype(true);
1058 map->set_prototype(global_context()->object_function()->prototype()); 1080 map->set_prototype(global_context()->object_function()->prototype());
1059 map->set_pre_allocated_property_fields(1); 1081 map->set_pre_allocated_property_fields(1);
1060 map->set_inobject_properties(1); 1082 map->set_inobject_properties(1);
1061 1083
1062 // Copy constructor from the non-strict arguments boilerplate. 1084 // Copy constructor from the non-strict arguments boilerplate.
1063 map->set_constructor( 1085 map->set_constructor(
1064 global_context()->arguments_boilerplate()->map()->constructor()); 1086 global_context()->arguments_boilerplate()->map()->constructor());
1065 1087
1066 // Allocate the arguments boilerplate object. 1088 // Allocate the arguments boilerplate object.
1067 Handle<JSObject> result = FACTORY->NewJSObjectFromMap(map); 1089 Handle<JSObject> result = factory->NewJSObjectFromMap(map);
1068 global_context()->set_strict_mode_arguments_boilerplate(*result); 1090 global_context()->set_strict_mode_arguments_boilerplate(*result);
1069 1091
1070 // Add length property only for strict mode boilerplate. 1092 // Add length property only for strict mode boilerplate.
1071 SetLocalPropertyNoThrow(result, FACTORY->length_symbol(), 1093 SetLocalPropertyNoThrow(result, factory->length_symbol(),
1072 FACTORY->undefined_value(), 1094 factory->undefined_value(),
1073 DONT_ENUM); 1095 DONT_ENUM);
1074 1096
1075 #ifdef DEBUG 1097 #ifdef DEBUG
1076 LookupResult lookup; 1098 LookupResult lookup;
1077 result->LocalLookup(HEAP->length_symbol(), &lookup); 1099 result->LocalLookup(heap->length_symbol(), &lookup);
1078 ASSERT(lookup.IsProperty() && (lookup.type() == FIELD)); 1100 ASSERT(lookup.IsProperty() && (lookup.type() == FIELD));
1079 ASSERT(lookup.GetFieldIndex() == Heap::kArgumentsLengthIndex); 1101 ASSERT(lookup.GetFieldIndex() == Heap::kArgumentsLengthIndex);
1080 1102
1081 ASSERT(result->map()->inobject_properties() > Heap::kArgumentsLengthIndex); 1103 ASSERT(result->map()->inobject_properties() > Heap::kArgumentsLengthIndex);
1082 1104
1083 // Check the state of the object. 1105 // Check the state of the object.
1084 ASSERT(result->HasFastProperties()); 1106 ASSERT(result->HasFastProperties());
1085 ASSERT(result->HasFastElements()); 1107 ASSERT(result->HasFastElements());
1086 #endif 1108 #endif
1087 } 1109 }
1088 1110
1089 { // --- context extension 1111 { // --- context extension
1090 // Create a function for the context extension objects. 1112 // Create a function for the context extension objects.
1091 Handle<Code> code = Handle<Code>( 1113 Handle<Code> code = Handle<Code>(
1092 Isolate::Current()->builtins()->builtin(Builtins::kIllegal)); 1114 isolate->builtins()->builtin(Builtins::kIllegal));
1093 Handle<JSFunction> context_extension_fun = 1115 Handle<JSFunction> context_extension_fun =
1094 FACTORY->NewFunction(FACTORY->empty_symbol(), 1116 factory->NewFunction(factory->empty_symbol(),
1095 JS_CONTEXT_EXTENSION_OBJECT_TYPE, 1117 JS_CONTEXT_EXTENSION_OBJECT_TYPE,
1096 JSObject::kHeaderSize, 1118 JSObject::kHeaderSize,
1097 code, 1119 code,
1098 true); 1120 true);
1099 1121
1100 Handle<String> name = FACTORY->LookupAsciiSymbol("context_extension"); 1122 Handle<String> name = factory->LookupAsciiSymbol("context_extension");
1101 context_extension_fun->shared()->set_instance_class_name(*name); 1123 context_extension_fun->shared()->set_instance_class_name(*name);
1102 global_context()->set_context_extension_function(*context_extension_fun); 1124 global_context()->set_context_extension_function(*context_extension_fun);
1103 } 1125 }
1104 1126
1105 1127
1106 { 1128 {
1107 // Setup the call-as-function delegate. 1129 // Setup the call-as-function delegate.
1108 Handle<Code> code = 1130 Handle<Code> code =
1109 Handle<Code>(Isolate::Current()->builtins()->builtin( 1131 Handle<Code>(isolate->builtins()->builtin(
1110 Builtins::kHandleApiCallAsFunction)); 1132 Builtins::kHandleApiCallAsFunction));
1111 Handle<JSFunction> delegate = 1133 Handle<JSFunction> delegate =
1112 FACTORY->NewFunction(FACTORY->empty_symbol(), JS_OBJECT_TYPE, 1134 factory->NewFunction(factory->empty_symbol(), JS_OBJECT_TYPE,
1113 JSObject::kHeaderSize, code, true); 1135 JSObject::kHeaderSize, code, true);
1114 global_context()->set_call_as_function_delegate(*delegate); 1136 global_context()->set_call_as_function_delegate(*delegate);
1115 delegate->shared()->DontAdaptArguments(); 1137 delegate->shared()->DontAdaptArguments();
1116 } 1138 }
1117 1139
1118 { 1140 {
1119 // Setup the call-as-constructor delegate. 1141 // Setup the call-as-constructor delegate.
1120 Handle<Code> code = 1142 Handle<Code> code =
1121 Handle<Code>(Isolate::Current()->builtins()->builtin( 1143 Handle<Code>(isolate->builtins()->builtin(
1122 Builtins::kHandleApiCallAsConstructor)); 1144 Builtins::kHandleApiCallAsConstructor));
1123 Handle<JSFunction> delegate = 1145 Handle<JSFunction> delegate =
1124 FACTORY->NewFunction(FACTORY->empty_symbol(), JS_OBJECT_TYPE, 1146 factory->NewFunction(factory->empty_symbol(), JS_OBJECT_TYPE,
1125 JSObject::kHeaderSize, code, true); 1147 JSObject::kHeaderSize, code, true);
1126 global_context()->set_call_as_constructor_delegate(*delegate); 1148 global_context()->set_call_as_constructor_delegate(*delegate);
1127 delegate->shared()->DontAdaptArguments(); 1149 delegate->shared()->DontAdaptArguments();
1128 } 1150 }
1129 1151
1130 // Initialize the out of memory slot. 1152 // Initialize the out of memory slot.
1131 global_context()->set_out_of_memory(HEAP->false_value()); 1153 global_context()->set_out_of_memory(heap->false_value());
1132 1154
1133 // Initialize the data slot. 1155 // Initialize the data slot.
1134 global_context()->set_data(HEAP->undefined_value()); 1156 global_context()->set_data(heap->undefined_value());
1135 } 1157 }
1136 1158
1137 1159
1138 bool Genesis::CompileBuiltin(int index) { 1160 bool Genesis::CompileBuiltin(int index) {
1139 Vector<const char> name = Natives::GetScriptName(index); 1161 Vector<const char> name = Natives::GetScriptName(index);
1140 Handle<String> source_code = 1162 Handle<String> source_code =
1141 Isolate::Current()->bootstrapper()->NativesSourceLookup(index); 1163 Isolate::Current()->bootstrapper()->NativesSourceLookup(index);
1142 return CompileNative(name, source_code); 1164 return CompileNative(name, source_code);
1143 } 1165 }
1144 1166
(...skipping 18 matching lines...) Expand all
1163 return result; 1185 return result;
1164 } 1186 }
1165 1187
1166 1188
1167 bool Genesis::CompileScriptCached(Vector<const char> name, 1189 bool Genesis::CompileScriptCached(Vector<const char> name,
1168 Handle<String> source, 1190 Handle<String> source,
1169 SourceCodeCache* cache, 1191 SourceCodeCache* cache,
1170 v8::Extension* extension, 1192 v8::Extension* extension,
1171 Handle<Context> top_context, 1193 Handle<Context> top_context,
1172 bool use_runtime_context) { 1194 bool use_runtime_context) {
1195 Factory* factory = Isolate::Current()->factory();
1173 HandleScope scope; 1196 HandleScope scope;
1174 Handle<SharedFunctionInfo> function_info; 1197 Handle<SharedFunctionInfo> function_info;
1175 1198
1176 // If we can't find the function in the cache, we compile a new 1199 // If we can't find the function in the cache, we compile a new
1177 // function and insert it into the cache. 1200 // function and insert it into the cache.
1178 if (cache == NULL || !cache->Lookup(name, &function_info)) { 1201 if (cache == NULL || !cache->Lookup(name, &function_info)) {
1179 ASSERT(source->IsAsciiRepresentation()); 1202 ASSERT(source->IsAsciiRepresentation());
1180 Handle<String> script_name = FACTORY->NewStringFromUtf8(name); 1203 Handle<String> script_name = factory->NewStringFromUtf8(name);
1181 function_info = Compiler::Compile( 1204 function_info = Compiler::Compile(
1182 source, 1205 source,
1183 script_name, 1206 script_name,
1184 0, 1207 0,
1185 0, 1208 0,
1186 extension, 1209 extension,
1187 NULL, 1210 NULL,
1188 Handle<String>::null(), 1211 Handle<String>::null(),
1189 use_runtime_context ? NATIVES_CODE : NOT_NATIVES_CODE); 1212 use_runtime_context ? NATIVES_CODE : NOT_NATIVES_CODE);
1190 if (function_info.is_null()) return false; 1213 if (function_info.is_null()) return false;
1191 if (cache != NULL) cache->Add(name, function_info); 1214 if (cache != NULL) cache->Add(name, function_info);
1192 } 1215 }
1193 1216
1194 // Setup the function context. Conceptually, we should clone the 1217 // Setup the function context. Conceptually, we should clone the
1195 // function before overwriting the context but since we're in a 1218 // function before overwriting the context but since we're in a
1196 // single-threaded environment it is not strictly necessary. 1219 // single-threaded environment it is not strictly necessary.
1197 ASSERT(top_context->IsGlobalContext()); 1220 ASSERT(top_context->IsGlobalContext());
1198 Handle<Context> context = 1221 Handle<Context> context =
1199 Handle<Context>(use_runtime_context 1222 Handle<Context>(use_runtime_context
1200 ? Handle<Context>(top_context->runtime_context()) 1223 ? Handle<Context>(top_context->runtime_context())
1201 : top_context); 1224 : top_context);
1202 Handle<JSFunction> fun = 1225 Handle<JSFunction> fun =
1203 FACTORY->NewFunctionFromSharedFunctionInfo(function_info, context); 1226 factory->NewFunctionFromSharedFunctionInfo(function_info, context);
1204 1227
1205 // Call function using either the runtime object or the global 1228 // Call function using either the runtime object or the global
1206 // object as the receiver. Provide no parameters. 1229 // object as the receiver. Provide no parameters.
1207 Handle<Object> receiver = 1230 Handle<Object> receiver =
1208 Handle<Object>(use_runtime_context 1231 Handle<Object>(use_runtime_context
1209 ? top_context->builtins() 1232 ? top_context->builtins()
1210 : top_context->global()); 1233 : top_context->global());
1211 bool has_pending_exception; 1234 bool has_pending_exception;
1212 Handle<Object> result = 1235 Handle<Object> result =
1213 Execution::Call(fun, receiver, 0, NULL, &has_pending_exception); 1236 Execution::Call(fun, receiver, 0, NULL, &has_pending_exception);
1214 if (has_pending_exception) return false; 1237 if (has_pending_exception) return false;
1215 return true; 1238 return true;
1216 } 1239 }
1217 1240
1218 1241
1219 #define INSTALL_NATIVE(Type, name, var) \ 1242 #define INSTALL_NATIVE(Type, name, var) \
1220 Handle<String> var##_name = FACTORY->LookupAsciiSymbol(name); \ 1243 Handle<String> var##_name = factory->LookupAsciiSymbol(name); \
1221 global_context()->set_##var(Type::cast( \ 1244 global_context()->set_##var(Type::cast( \
1222 global_context()->builtins()->GetPropertyNoExceptionThrown(*var##_name))); 1245 global_context()->builtins()->GetPropertyNoExceptionThrown(*var##_name)));
1223 1246
1224 1247
1225 void Genesis::InstallNativeFunctions() { 1248 void Genesis::InstallNativeFunctions() {
1249 Factory* factory = Isolate::Current()->factory();
1226 HandleScope scope; 1250 HandleScope scope;
1227 INSTALL_NATIVE(JSFunction, "CreateDate", create_date_fun); 1251 INSTALL_NATIVE(JSFunction, "CreateDate", create_date_fun);
1228 INSTALL_NATIVE(JSFunction, "ToNumber", to_number_fun); 1252 INSTALL_NATIVE(JSFunction, "ToNumber", to_number_fun);
1229 INSTALL_NATIVE(JSFunction, "ToString", to_string_fun); 1253 INSTALL_NATIVE(JSFunction, "ToString", to_string_fun);
1230 INSTALL_NATIVE(JSFunction, "ToDetailString", to_detail_string_fun); 1254 INSTALL_NATIVE(JSFunction, "ToDetailString", to_detail_string_fun);
1231 INSTALL_NATIVE(JSFunction, "ToObject", to_object_fun); 1255 INSTALL_NATIVE(JSFunction, "ToObject", to_object_fun);
1232 INSTALL_NATIVE(JSFunction, "ToInteger", to_integer_fun); 1256 INSTALL_NATIVE(JSFunction, "ToInteger", to_integer_fun);
1233 INSTALL_NATIVE(JSFunction, "ToUint32", to_uint32_fun); 1257 INSTALL_NATIVE(JSFunction, "ToUint32", to_uint32_fun);
1234 INSTALL_NATIVE(JSFunction, "ToInt32", to_int32_fun); 1258 INSTALL_NATIVE(JSFunction, "ToInt32", to_int32_fun);
1235 INSTALL_NATIVE(JSFunction, "GlobalEval", global_eval_fun); 1259 INSTALL_NATIVE(JSFunction, "GlobalEval", global_eval_fun);
1236 INSTALL_NATIVE(JSFunction, "Instantiate", instantiate_fun); 1260 INSTALL_NATIVE(JSFunction, "Instantiate", instantiate_fun);
1237 INSTALL_NATIVE(JSFunction, "ConfigureTemplateInstance", 1261 INSTALL_NATIVE(JSFunction, "ConfigureTemplateInstance",
1238 configure_instance_fun); 1262 configure_instance_fun);
1239 INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun); 1263 INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun);
1240 INSTALL_NATIVE(JSObject, "functionCache", function_cache); 1264 INSTALL_NATIVE(JSObject, "functionCache", function_cache);
1241 } 1265 }
1242 1266
1243 #undef INSTALL_NATIVE 1267 #undef INSTALL_NATIVE
1244 1268
1245 1269
1246 bool Genesis::InstallNatives() { 1270 bool Genesis::InstallNatives() {
1247 HandleScope scope; 1271 HandleScope scope;
1248 Isolate* isolate = Isolate::Current(); 1272 Isolate* isolate = Isolate::Current();
1249 Factory* factory = isolate->factory(); 1273 Factory* factory = isolate->factory();
1274 Heap* heap = isolate->heap();
1250 1275
1251 // Create a function for the builtins object. Allocate space for the 1276 // Create a function for the builtins object. Allocate space for the
1252 // JavaScript builtins, a reference to the builtins object 1277 // JavaScript builtins, a reference to the builtins object
1253 // (itself) and a reference to the global_context directly in the object. 1278 // (itself) and a reference to the global_context directly in the object.
1254 Handle<Code> code = Handle<Code>( 1279 Handle<Code> code = Handle<Code>(
1255 isolate->builtins()->builtin(Builtins::kIllegal)); 1280 isolate->builtins()->builtin(Builtins::kIllegal));
1256 Handle<JSFunction> builtins_fun = 1281 Handle<JSFunction> builtins_fun =
1257 factory->NewFunction(factory->empty_symbol(), JS_BUILTINS_OBJECT_TYPE, 1282 factory->NewFunction(factory->empty_symbol(), JS_BUILTINS_OBJECT_TYPE,
1258 JSBuiltinsObject::kSize, code, true); 1283 JSBuiltinsObject::kSize, code, true);
1259 1284
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 factory->LookupAsciiSymbol("eval_from_function_name"), 1430 factory->LookupAsciiSymbol("eval_from_function_name"),
1406 proxy_eval_from_function_name, 1431 proxy_eval_from_function_name,
1407 common_attributes); 1432 common_attributes);
1408 1433
1409 Handle<Map> script_map = Handle<Map>(script_fun->initial_map()); 1434 Handle<Map> script_map = Handle<Map>(script_fun->initial_map());
1410 script_map->set_instance_descriptors(*script_descriptors); 1435 script_map->set_instance_descriptors(*script_descriptors);
1411 1436
1412 // Allocate the empty script. 1437 // Allocate the empty script.
1413 Handle<Script> script = factory->NewScript(factory->empty_string()); 1438 Handle<Script> script = factory->NewScript(factory->empty_string());
1414 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); 1439 script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
1415 HEAP->public_set_empty_script(*script); 1440 heap->public_set_empty_script(*script);
1416 } 1441 }
1417 { 1442 {
1418 // Builtin function for OpaqueReference -- a JSValue-based object, 1443 // Builtin function for OpaqueReference -- a JSValue-based object,
1419 // that keeps its field isolated from JavaScript code. It may store 1444 // that keeps its field isolated from JavaScript code. It may store
1420 // objects, that JavaScript code may not access. 1445 // objects, that JavaScript code may not access.
1421 Handle<JSFunction> opaque_reference_fun = 1446 Handle<JSFunction> opaque_reference_fun =
1422 InstallFunction(builtins, "OpaqueReference", JS_VALUE_TYPE, 1447 InstallFunction(builtins, "OpaqueReference", JS_VALUE_TYPE,
1423 JSValue::kSize, 1448 JSValue::kSize,
1424 isolate->initial_object_prototype(), 1449 isolate->initial_object_prototype(),
1425 Builtins::kIllegal, false); 1450 Builtins::kIllegal, false);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 array_map->instance_descriptors()); 1578 array_map->instance_descriptors());
1554 ASSERT_EQ(1, array_descriptors->number_of_descriptors()); 1579 ASSERT_EQ(1, array_descriptors->number_of_descriptors());
1555 1580
1556 Handle<DescriptorArray> reresult_descriptors = 1581 Handle<DescriptorArray> reresult_descriptors =
1557 factory->NewDescriptorArray(3); 1582 factory->NewDescriptorArray(3);
1558 1583
1559 reresult_descriptors->CopyFrom(0, *array_descriptors, 0); 1584 reresult_descriptors->CopyFrom(0, *array_descriptors, 0);
1560 1585
1561 int enum_index = 0; 1586 int enum_index = 0;
1562 { 1587 {
1563 FieldDescriptor index_field(HEAP->index_symbol(), 1588 FieldDescriptor index_field(heap->index_symbol(),
1564 JSRegExpResult::kIndexIndex, 1589 JSRegExpResult::kIndexIndex,
1565 NONE, 1590 NONE,
1566 enum_index++); 1591 enum_index++);
1567 reresult_descriptors->Set(1, &index_field); 1592 reresult_descriptors->Set(1, &index_field);
1568 } 1593 }
1569 1594
1570 { 1595 {
1571 FieldDescriptor input_field(HEAP->input_symbol(), 1596 FieldDescriptor input_field(heap->input_symbol(),
1572 JSRegExpResult::kInputIndex, 1597 JSRegExpResult::kInputIndex,
1573 NONE, 1598 NONE,
1574 enum_index++); 1599 enum_index++);
1575 reresult_descriptors->Set(2, &input_field); 1600 reresult_descriptors->Set(2, &input_field);
1576 } 1601 }
1577 reresult_descriptors->Sort(); 1602 reresult_descriptors->Sort();
1578 1603
1579 initial_map->set_inobject_properties(2); 1604 initial_map->set_inobject_properties(2);
1580 initial_map->set_pre_allocated_property_fields(2); 1605 initial_map->set_pre_allocated_property_fields(2);
1581 initial_map->set_unused_property_fields(0); 1606 initial_map->set_unused_property_fields(0);
1582 initial_map->set_instance_descriptors(*reresult_descriptors); 1607 initial_map->set_instance_descriptors(*reresult_descriptors);
1583 1608
1584 global_context()->set_regexp_result_map(*initial_map); 1609 global_context()->set_regexp_result_map(*initial_map);
1585 } 1610 }
1586 1611
1587 1612
1588 #ifdef DEBUG 1613 #ifdef DEBUG
1589 builtins->Verify(); 1614 builtins->Verify();
1590 #endif 1615 #endif
1591 1616
1592 return true; 1617 return true;
1593 } 1618 }
1594 1619
1595 1620
1596 static Handle<JSObject> ResolveBuiltinIdHolder( 1621 static Handle<JSObject> ResolveBuiltinIdHolder(
1597 Handle<Context> global_context, 1622 Handle<Context> global_context,
1598 const char* holder_expr) { 1623 const char* holder_expr) {
1624 Factory* factory = Isolate::Current()->factory();
1599 Handle<GlobalObject> global(global_context->global()); 1625 Handle<GlobalObject> global(global_context->global());
1600 const char* period_pos = strchr(holder_expr, '.'); 1626 const char* period_pos = strchr(holder_expr, '.');
1601 if (period_pos == NULL) { 1627 if (period_pos == NULL) {
1602 return Handle<JSObject>::cast( 1628 return Handle<JSObject>::cast(
1603 GetProperty(global, FACTORY->LookupAsciiSymbol(holder_expr))); 1629 GetProperty(global, factory->LookupAsciiSymbol(holder_expr)));
1604 } 1630 }
1605 ASSERT_EQ(".prototype", period_pos); 1631 ASSERT_EQ(".prototype", period_pos);
1606 Vector<const char> property(holder_expr, 1632 Vector<const char> property(holder_expr,
1607 static_cast<int>(period_pos - holder_expr)); 1633 static_cast<int>(period_pos - holder_expr));
1608 Handle<JSFunction> function = Handle<JSFunction>::cast( 1634 Handle<JSFunction> function = Handle<JSFunction>::cast(
1609 GetProperty(global, FACTORY->LookupSymbol(property))); 1635 GetProperty(global, factory->LookupSymbol(property)));
1610 return Handle<JSObject>(JSObject::cast(function->prototype())); 1636 return Handle<JSObject>(JSObject::cast(function->prototype()));
1611 } 1637 }
1612 1638
1613 1639
1614 static void InstallBuiltinFunctionId(Handle<JSObject> holder, 1640 static void InstallBuiltinFunctionId(Handle<JSObject> holder,
1615 const char* function_name, 1641 const char* function_name,
1616 BuiltinFunctionId id) { 1642 BuiltinFunctionId id) {
1617 Handle<String> name = FACTORY->LookupAsciiSymbol(function_name); 1643 Handle<String> name = FACTORY->LookupAsciiSymbol(function_name);
1618 Object* function_object = holder->GetProperty(*name)->ToObjectUnchecked(); 1644 Object* function_object = holder->GetProperty(*name)->ToObjectUnchecked();
1619 Handle<JSFunction> function(JSFunction::cast(function_object)); 1645 Handle<JSFunction> function(JSFunction::cast(function_object));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1690 BootstrapperActive active; 1716 BootstrapperActive active;
1691 SaveContext saved_context(isolate); 1717 SaveContext saved_context(isolate);
1692 isolate->set_context(*global_context); 1718 isolate->set_context(*global_context);
1693 if (!Genesis::InstallExtensions(global_context, extensions)) return false; 1719 if (!Genesis::InstallExtensions(global_context, extensions)) return false;
1694 Genesis::InstallSpecialObjects(global_context); 1720 Genesis::InstallSpecialObjects(global_context);
1695 return true; 1721 return true;
1696 } 1722 }
1697 1723
1698 1724
1699 void Genesis::InstallSpecialObjects(Handle<Context> global_context) { 1725 void Genesis::InstallSpecialObjects(Handle<Context> global_context) {
1726 Factory* factory = Isolate::Current()->factory();
1700 HandleScope scope; 1727 HandleScope scope;
1701 Handle<JSGlobalObject> js_global( 1728 Handle<JSGlobalObject> js_global(
1702 JSGlobalObject::cast(global_context->global())); 1729 JSGlobalObject::cast(global_context->global()));
1703 // Expose the natives in global if a name for it is specified. 1730 // Expose the natives in global if a name for it is specified.
1704 if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) { 1731 if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) {
1705 Handle<String> natives_string = 1732 Handle<String> natives_string =
1706 FACTORY->LookupAsciiSymbol(FLAG_expose_natives_as); 1733 factory->LookupAsciiSymbol(FLAG_expose_natives_as);
1707 SetLocalPropertyNoThrow(js_global, natives_string, 1734 SetLocalPropertyNoThrow(js_global, natives_string,
1708 Handle<JSObject>(js_global->builtins()), DONT_ENUM); 1735 Handle<JSObject>(js_global->builtins()), DONT_ENUM);
1709 } 1736 }
1710 1737
1711 Handle<Object> Error = GetProperty(js_global, "Error"); 1738 Handle<Object> Error = GetProperty(js_global, "Error");
1712 if (Error->IsJSObject()) { 1739 if (Error->IsJSObject()) {
1713 Handle<String> name = FACTORY->LookupAsciiSymbol("stackTraceLimit"); 1740 Handle<String> name = factory->LookupAsciiSymbol("stackTraceLimit");
1714 SetLocalPropertyNoThrow(Handle<JSObject>::cast(Error), 1741 SetLocalPropertyNoThrow(Handle<JSObject>::cast(Error),
1715 name, 1742 name,
1716 Handle<Smi>(Smi::FromInt(FLAG_stack_trace_limit)), 1743 Handle<Smi>(Smi::FromInt(FLAG_stack_trace_limit)),
1717 NONE); 1744 NONE);
1718 } 1745 }
1719 1746
1720 #ifdef ENABLE_DEBUGGER_SUPPORT 1747 #ifdef ENABLE_DEBUGGER_SUPPORT
1721 // Expose the debug global object in global if a name for it is specified. 1748 // Expose the debug global object in global if a name for it is specified.
1722 if (FLAG_expose_debug_as != NULL && strlen(FLAG_expose_debug_as) != 0) { 1749 if (FLAG_expose_debug_as != NULL && strlen(FLAG_expose_debug_as) != 0) {
1723 Debug* debug = Isolate::Current()->debug(); 1750 Debug* debug = Isolate::Current()->debug();
1724 // If loading fails we just bail out without installing the 1751 // If loading fails we just bail out without installing the
1725 // debugger but without tanking the whole context. 1752 // debugger but without tanking the whole context.
1726 if (!debug->Load()) return; 1753 if (!debug->Load()) return;
1727 // Set the security token for the debugger context to the same as 1754 // Set the security token for the debugger context to the same as
1728 // the shell global context to allow calling between these (otherwise 1755 // the shell global context to allow calling between these (otherwise
1729 // exposing debug global object doesn't make much sense). 1756 // exposing debug global object doesn't make much sense).
1730 debug->debug_context()->set_security_token( 1757 debug->debug_context()->set_security_token(
1731 global_context->security_token()); 1758 global_context->security_token());
1732 1759
1733 Handle<String> debug_string = 1760 Handle<String> debug_string =
1734 FACTORY->LookupAsciiSymbol(FLAG_expose_debug_as); 1761 factory->LookupAsciiSymbol(FLAG_expose_debug_as);
1735 Handle<Object> global_proxy(debug->debug_context()->global_proxy()); 1762 Handle<Object> global_proxy(debug->debug_context()->global_proxy());
1736 SetLocalPropertyNoThrow(js_global, debug_string, global_proxy, DONT_ENUM); 1763 SetLocalPropertyNoThrow(js_global, debug_string, global_proxy, DONT_ENUM);
1737 } 1764 }
1738 #endif 1765 #endif
1739 } 1766 }
1740 1767
1741 1768
1742 bool Genesis::InstallExtensions(Handle<Context> global_context, 1769 bool Genesis::InstallExtensions(Handle<Context> global_context,
1743 v8::ExtensionConfiguration* extensions) { 1770 v8::ExtensionConfiguration* extensions) {
1744 // TODO(isolates): Extensions on multiple isolates may take a little more 1771 // TODO(isolates): Extensions on multiple isolates may take a little more
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1805 "v8::Context::New()", "Circular extension dependency"); 1832 "v8::Context::New()", "Circular extension dependency");
1806 return false; 1833 return false;
1807 } 1834 }
1808 ASSERT(current->state() == v8::UNVISITED); 1835 ASSERT(current->state() == v8::UNVISITED);
1809 current->set_state(v8::VISITED); 1836 current->set_state(v8::VISITED);
1810 v8::Extension* extension = current->extension(); 1837 v8::Extension* extension = current->extension();
1811 // Install the extension's dependencies 1838 // Install the extension's dependencies
1812 for (int i = 0; i < extension->dependency_count(); i++) { 1839 for (int i = 0; i < extension->dependency_count(); i++) {
1813 if (!InstallExtension(extension->dependencies()[i])) return false; 1840 if (!InstallExtension(extension->dependencies()[i])) return false;
1814 } 1841 }
1842 Isolate* isolate = Isolate::Current();
1815 Vector<const char> source = CStrVector(extension->source()); 1843 Vector<const char> source = CStrVector(extension->source());
1816 Handle<String> source_code = FACTORY->NewStringFromAscii(source); 1844 Handle<String> source_code = isolate->factory()->NewStringFromAscii(source);
1817 bool result = CompileScriptCached(CStrVector(extension->name()), 1845 bool result = CompileScriptCached(CStrVector(extension->name()),
1818 source_code, 1846 source_code,
1819 Isolate::Current()->bootstrapper()-> 1847 isolate->bootstrapper()->extensions_cache(),
1820 extensions_cache(),
1821 extension, 1848 extension,
1822 Handle<Context>( 1849 Handle<Context>(isolate->context()),
1823 Isolate::Current()->context()),
1824 false); 1850 false);
1825 ASSERT(Isolate::Current()->has_pending_exception() != result); 1851 ASSERT(isolate->has_pending_exception() != result);
1826 if (!result) { 1852 if (!result) {
1827 Isolate::Current()->clear_pending_exception(); 1853 isolate->clear_pending_exception();
1828 } 1854 }
1829 current->set_state(v8::INSTALLED); 1855 current->set_state(v8::INSTALLED);
1830 return result; 1856 return result;
1831 } 1857 }
1832 1858
1833 1859
1834 bool Genesis::InstallJSBuiltins(Handle<JSBuiltinsObject> builtins) { 1860 bool Genesis::InstallJSBuiltins(Handle<JSBuiltinsObject> builtins) {
1835 HandleScope scope; 1861 HandleScope scope;
1836 for (int i = 0; i < Builtins::NumberOfJavaScriptBuiltins(); i++) { 1862 for (int i = 0; i < Builtins::NumberOfJavaScriptBuiltins(); i++) {
1837 Builtins::JavaScript id = static_cast<Builtins::JavaScript>(i); 1863 Builtins::JavaScript id = static_cast<Builtins::JavaScript>(i);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1877 return true; 1903 return true;
1878 } 1904 }
1879 1905
1880 1906
1881 bool Genesis::ConfigureApiObject(Handle<JSObject> object, 1907 bool Genesis::ConfigureApiObject(Handle<JSObject> object,
1882 Handle<ObjectTemplateInfo> object_template) { 1908 Handle<ObjectTemplateInfo> object_template) {
1883 ASSERT(!object_template.is_null()); 1909 ASSERT(!object_template.is_null());
1884 ASSERT(object->IsInstanceOf( 1910 ASSERT(object->IsInstanceOf(
1885 FunctionTemplateInfo::cast(object_template->constructor()))); 1911 FunctionTemplateInfo::cast(object_template->constructor())));
1886 1912
1913 Isolate* isolate = Isolate::Current();
1887 bool pending_exception = false; 1914 bool pending_exception = false;
1888 Handle<JSObject> obj = 1915 Handle<JSObject> obj =
1889 Execution::InstantiateObject(object_template, &pending_exception); 1916 Execution::InstantiateObject(object_template, &pending_exception);
1890 if (pending_exception) { 1917 if (pending_exception) {
1891 ASSERT(Isolate::Current()->has_pending_exception()); 1918 ASSERT(isolate->has_pending_exception());
1892 Isolate::Current()->clear_pending_exception(); 1919 isolate->clear_pending_exception();
1893 return false; 1920 return false;
1894 } 1921 }
1895 TransferObject(obj, object); 1922 TransferObject(obj, object);
1896 return true; 1923 return true;
1897 } 1924 }
1898 1925
1899 1926
1900 void Genesis::TransferNamedProperties(Handle<JSObject> from, 1927 void Genesis::TransferNamedProperties(Handle<JSObject> from,
1901 Handle<JSObject> to) { 1928 Handle<JSObject> to) {
1902 if (from->HasFastProperties()) { 1929 if (from->HasFastProperties()) {
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
2094 return from + sizeof(NestingCounterType); 2121 return from + sizeof(NestingCounterType);
2095 } 2122 }
2096 2123
2097 2124
2098 // Called when the top-level V8 mutex is destroyed. 2125 // Called when the top-level V8 mutex is destroyed.
2099 void Bootstrapper::FreeThreadResources() { 2126 void Bootstrapper::FreeThreadResources() {
2100 ASSERT(!IsActive()); 2127 ASSERT(!IsActive());
2101 } 2128 }
2102 2129
2103 } } // namespace v8::internal 2130 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/atomicops_internals_mips_gcc.h ('k') | src/code-stubs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698