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

Side by Side Diff: src/bootstrapper.cc

Issue 6815029: Merge (7180:7265] from bleeding_edge to the experimental/gc branch.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
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/assembler.cc ('k') | src/builtins.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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 // triggered during environment creation there may be weak handle 200 // triggered during environment creation there may be weak handle
201 // processing callbacks which may create new environments. 201 // processing callbacks which may create new environments.
202 Genesis* previous_; 202 Genesis* previous_;
203 203
204 Handle<Context> global_context() { return global_context_; } 204 Handle<Context> global_context() { return global_context_; }
205 205
206 // Creates some basic objects. Used for creating a context from scratch. 206 // Creates some basic objects. Used for creating a context from scratch.
207 void CreateRoots(); 207 void CreateRoots();
208 // Creates the empty function. Used for creating a context from scratch. 208 // Creates the empty function. Used for creating a context from scratch.
209 Handle<JSFunction> CreateEmptyFunction(); 209 Handle<JSFunction> CreateEmptyFunction();
210 // Creates the ThrowTypeError function. ECMA 5th Ed. 13.2.3
211 Handle<JSFunction> CreateThrowTypeErrorFunction(Builtins::Name builtin);
212
213 void CreateStrictModeFunctionMaps(Handle<JSFunction> empty);
210 // Creates the global objects using the global and the template passed in 214 // Creates the global objects using the global and the template passed in
211 // through the API. We call this regardless of whether we are building a 215 // through the API. We call this regardless of whether we are building a
212 // context from scratch or using a deserialized one from the partial snapshot 216 // context from scratch or using a deserialized one from the partial snapshot
213 // but in the latter case we don't use the objects it produces directly, as 217 // but in the latter case we don't use the objects it produces directly, as
214 // we have to used the deserialized ones that are linked together with the 218 // we have to used the deserialized ones that are linked together with the
215 // rest of the context snapshot. 219 // rest of the context snapshot.
216 Handle<JSGlobalProxy> CreateNewGlobals( 220 Handle<JSGlobalProxy> CreateNewGlobals(
217 v8::Handle<v8::ObjectTemplate> global_template, 221 v8::Handle<v8::ObjectTemplate> global_template,
218 Handle<Object> global_object, 222 Handle<Object> global_object,
219 Handle<GlobalObject>* global_proxy_out); 223 Handle<GlobalObject>* global_proxy_out);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 // 'from'. 257 // 'from'.
254 void TransferObject(Handle<JSObject> from, Handle<JSObject> to); 258 void TransferObject(Handle<JSObject> from, Handle<JSObject> to);
255 void TransferNamedProperties(Handle<JSObject> from, Handle<JSObject> to); 259 void TransferNamedProperties(Handle<JSObject> from, Handle<JSObject> to);
256 void TransferIndexedProperties(Handle<JSObject> from, Handle<JSObject> to); 260 void TransferIndexedProperties(Handle<JSObject> from, Handle<JSObject> to);
257 261
258 enum PrototypePropertyMode { 262 enum PrototypePropertyMode {
259 DONT_ADD_PROTOTYPE, 263 DONT_ADD_PROTOTYPE,
260 ADD_READONLY_PROTOTYPE, 264 ADD_READONLY_PROTOTYPE,
261 ADD_WRITEABLE_PROTOTYPE 265 ADD_WRITEABLE_PROTOTYPE
262 }; 266 };
267
268 Handle<Map> CreateFunctionMap(PrototypePropertyMode prototype_mode);
269
263 Handle<DescriptorArray> ComputeFunctionInstanceDescriptor( 270 Handle<DescriptorArray> ComputeFunctionInstanceDescriptor(
264 PrototypePropertyMode prototypeMode); 271 PrototypePropertyMode prototypeMode);
265 void MakeFunctionInstancePrototypeWritable(); 272 void MakeFunctionInstancePrototypeWritable();
266 273
274 Handle<Map> CreateStrictModeFunctionMap(
275 PrototypePropertyMode prototype_mode,
276 Handle<JSFunction> empty_function,
277 Handle<FixedArray> arguments_callbacks,
278 Handle<FixedArray> caller_callbacks);
279
280 Handle<DescriptorArray> ComputeStrictFunctionInstanceDescriptor(
281 PrototypePropertyMode propertyMode,
282 Handle<FixedArray> arguments,
283 Handle<FixedArray> caller);
284
267 static bool CompileBuiltin(int index); 285 static bool CompileBuiltin(int index);
268 static bool CompileNative(Vector<const char> name, Handle<String> source); 286 static bool CompileNative(Vector<const char> name, Handle<String> source);
269 static bool CompileScriptCached(Vector<const char> name, 287 static bool CompileScriptCached(Vector<const char> name,
270 Handle<String> source, 288 Handle<String> source,
271 SourceCodeCache* cache, 289 SourceCodeCache* cache,
272 v8::Extension* extension, 290 v8::Extension* extension,
273 Handle<Context> top_context, 291 Handle<Context> top_context,
274 bool use_runtime_context); 292 bool use_runtime_context);
275 293
276 Handle<Context> result_; 294 Handle<Context> result_;
277 Handle<JSFunction> empty_function_; 295
296 // Function instance maps. Function literal maps are created initially with
297 // a read only prototype for the processing of JS builtins. Later the function
298 // instance maps are replaced in order to make prototype writable.
299 // These are the final, writable prototype, maps.
300 Handle<Map> function_instance_map_writable_prototype_;
301 Handle<Map> strict_mode_function_instance_map_writable_prototype_;
302
278 BootstrapperActive active_; 303 BootstrapperActive active_;
279 friend class Bootstrapper; 304 friend class Bootstrapper;
280 }; 305 };
281 306
282 307
283 void Bootstrapper::Iterate(ObjectVisitor* v) { 308 void Bootstrapper::Iterate(ObjectVisitor* v) {
284 extensions_cache.Iterate(v); 309 extensions_cache.Iterate(v);
285 v->Synchronize("Extensions"); 310 v->Synchronize("Extensions");
286 } 311 }
287 312
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 SetLocalPropertyNoThrow(target, symbol, function, DONT_ENUM); 377 SetLocalPropertyNoThrow(target, symbol, function, DONT_ENUM);
353 if (is_ecma_native) { 378 if (is_ecma_native) {
354 function->shared()->set_instance_class_name(*symbol); 379 function->shared()->set_instance_class_name(*symbol);
355 } 380 }
356 return function; 381 return function;
357 } 382 }
358 383
359 384
360 Handle<DescriptorArray> Genesis::ComputeFunctionInstanceDescriptor( 385 Handle<DescriptorArray> Genesis::ComputeFunctionInstanceDescriptor(
361 PrototypePropertyMode prototypeMode) { 386 PrototypePropertyMode prototypeMode) {
362 Handle<DescriptorArray> result = Factory::empty_descriptor_array(); 387 Handle<DescriptorArray> descriptors =
363 388 Factory::NewDescriptorArray(prototypeMode == DONT_ADD_PROTOTYPE ? 4 : 5);
364 if (prototypeMode != DONT_ADD_PROTOTYPE) {
365 PropertyAttributes attributes = static_cast<PropertyAttributes>(
366 DONT_ENUM |
367 DONT_DELETE |
368 (prototypeMode == ADD_READONLY_PROTOTYPE ? READ_ONLY : 0));
369 result =
370 Factory::CopyAppendProxyDescriptor(
371 result,
372 Factory::prototype_symbol(),
373 Factory::NewProxy(&Accessors::FunctionPrototype),
374 attributes);
375 }
376
377 PropertyAttributes attributes = 389 PropertyAttributes attributes =
378 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); 390 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
379 // Add length.
380 result =
381 Factory::CopyAppendProxyDescriptor(
382 result,
383 Factory::length_symbol(),
384 Factory::NewProxy(&Accessors::FunctionLength),
385 attributes);
386 391
387 // Add name. 392 { // Add length.
388 result = 393 Handle<Proxy> proxy = Factory::NewProxy(&Accessors::FunctionLength);
389 Factory::CopyAppendProxyDescriptor( 394 CallbacksDescriptor d(*Factory::length_symbol(), *proxy, attributes);
390 result, 395 descriptors->Set(0, &d);
391 Factory::name_symbol(), 396 }
392 Factory::NewProxy(&Accessors::FunctionName), 397 { // Add name.
393 attributes); 398 Handle<Proxy> proxy = Factory::NewProxy(&Accessors::FunctionName);
399 CallbacksDescriptor d(*Factory::name_symbol(), *proxy, attributes);
400 descriptors->Set(1, &d);
401 }
402 { // Add arguments.
403 Handle<Proxy> proxy = Factory::NewProxy(&Accessors::FunctionArguments);
404 CallbacksDescriptor d(*Factory::arguments_symbol(), *proxy, attributes);
405 descriptors->Set(2, &d);
406 }
407 { // Add caller.
408 Handle<Proxy> proxy = Factory::NewProxy(&Accessors::FunctionCaller);
409 CallbacksDescriptor d(*Factory::caller_symbol(), *proxy, attributes);
410 descriptors->Set(3, &d);
411 }
412 if (prototypeMode != DONT_ADD_PROTOTYPE) {
413 // Add prototype.
414 if (prototypeMode == ADD_WRITEABLE_PROTOTYPE) {
415 attributes = static_cast<PropertyAttributes>(attributes & ~READ_ONLY);
416 }
417 Handle<Proxy> proxy = Factory::NewProxy(&Accessors::FunctionPrototype);
418 CallbacksDescriptor d(*Factory::prototype_symbol(), *proxy, attributes);
419 descriptors->Set(4, &d);
420 }
421 descriptors->Sort();
422 return descriptors;
423 }
394 424
395 // Add arguments.
396 result =
397 Factory::CopyAppendProxyDescriptor(
398 result,
399 Factory::arguments_symbol(),
400 Factory::NewProxy(&Accessors::FunctionArguments),
401 attributes);
402 425
403 // Add caller. 426 Handle<Map> Genesis::CreateFunctionMap(PrototypePropertyMode prototype_mode) {
404 result = 427 Handle<Map> map = Factory::NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
405 Factory::CopyAppendProxyDescriptor( 428 Handle<DescriptorArray> descriptors =
406 result, 429 ComputeFunctionInstanceDescriptor(prototype_mode);
407 Factory::caller_symbol(), 430 map->set_instance_descriptors(*descriptors);
408 Factory::NewProxy(&Accessors::FunctionCaller), 431 map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE);
409 attributes); 432 return map;
410
411 return result;
412 } 433 }
413 434
414 435
415 Handle<JSFunction> Genesis::CreateEmptyFunction() { 436 Handle<JSFunction> Genesis::CreateEmptyFunction() {
416 // Allocate the map for function instances. 437 // Allocate the map for function instances. Maps are allocated first and their
417 Handle<Map> fm = Factory::NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); 438 // prototypes patched later, once empty function is created.
418 global_context()->set_function_instance_map(*fm); 439
419 // Please note that the prototype property for function instances must be 440 // Please note that the prototype property for function instances must be
420 // writable. 441 // writable.
421 Handle<DescriptorArray> function_map_descriptors = 442 global_context()->set_function_instance_map(
422 ComputeFunctionInstanceDescriptor(ADD_WRITEABLE_PROTOTYPE); 443 *CreateFunctionMap(ADD_WRITEABLE_PROTOTYPE));
423 fm->set_instance_descriptors(*function_map_descriptors);
424 fm->set_function_with_prototype(true);
425 444
426 // Functions with this map will not have a 'prototype' property, and 445 // Functions with this map will not have a 'prototype' property, and
427 // can not be used as constructors. 446 // can not be used as constructors.
428 Handle<Map> function_without_prototype_map =
429 Factory::NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
430 global_context()->set_function_without_prototype_map( 447 global_context()->set_function_without_prototype_map(
431 *function_without_prototype_map); 448 *CreateFunctionMap(DONT_ADD_PROTOTYPE));
432 Handle<DescriptorArray> function_without_prototype_map_descriptors =
433 ComputeFunctionInstanceDescriptor(DONT_ADD_PROTOTYPE);
434 function_without_prototype_map->set_instance_descriptors(
435 *function_without_prototype_map_descriptors);
436 function_without_prototype_map->set_function_with_prototype(false);
437 449
438 // Allocate the function map first and then patch the prototype later 450 // Allocate the function map. This map is temporary, used only for processing
439 fm = Factory::NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); 451 // of builtins.
440 global_context()->set_function_map(*fm); 452 // Later the map is replaced with writable prototype map, allocated below.
441 function_map_descriptors = 453 global_context()->set_function_map(
442 ComputeFunctionInstanceDescriptor(ADD_READONLY_PROTOTYPE); 454 *CreateFunctionMap(ADD_READONLY_PROTOTYPE));
443 fm->set_instance_descriptors(*function_map_descriptors); 455
444 fm->set_function_with_prototype(true); 456 // The final map for functions. Writeable prototype.
457 // This map is installed in MakeFunctionInstancePrototypeWritable.
458 function_instance_map_writable_prototype_ =
459 CreateFunctionMap(ADD_WRITEABLE_PROTOTYPE);
445 460
446 Handle<String> object_name = Handle<String>(Heap::Object_symbol()); 461 Handle<String> object_name = Handle<String>(Heap::Object_symbol());
447 462
448 { // --- O b j e c t --- 463 { // --- O b j e c t ---
449 Handle<JSFunction> object_fun = 464 Handle<JSFunction> object_fun =
450 Factory::NewFunction(object_name, Factory::null_value()); 465 Factory::NewFunction(object_name, Factory::null_value());
451 Handle<Map> object_function_map = 466 Handle<Map> object_function_map =
452 Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 467 Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
453 object_fun->set_initial_map(*object_function_map); 468 object_fun->set_initial_map(*object_function_map);
454 object_function_map->set_constructor(*object_fun); 469 object_function_map->set_constructor(*object_fun);
455 470
456 global_context()->set_object_function(*object_fun); 471 global_context()->set_object_function(*object_fun);
457 472
458 // Allocate a new prototype for the object function. 473 // Allocate a new prototype for the object function.
459 Handle<JSObject> prototype = Factory::NewJSObject(Top::object_function(), 474 Handle<JSObject> prototype = Factory::NewJSObject(Top::object_function(),
460 TENURED); 475 TENURED);
461 476
462 global_context()->set_initial_object_prototype(*prototype); 477 global_context()->set_initial_object_prototype(*prototype);
463 SetPrototype(object_fun, prototype); 478 SetPrototype(object_fun, prototype);
464 object_function_map-> 479 object_function_map->
465 set_instance_descriptors(Heap::empty_descriptor_array()); 480 set_instance_descriptors(Heap::empty_descriptor_array());
466 } 481 }
467 482
468 // Allocate the empty function as the prototype for function ECMAScript 483 // Allocate the empty function as the prototype for function ECMAScript
469 // 262 15.3.4. 484 // 262 15.3.4.
470 Handle<String> symbol = Factory::LookupAsciiSymbol("Empty"); 485 Handle<String> symbol = Factory::LookupAsciiSymbol("Empty");
471 Handle<JSFunction> empty_function = 486 Handle<JSFunction> empty_function =
472 Factory::NewFunctionWithoutPrototype(symbol); 487 Factory::NewFunctionWithoutPrototype(symbol, kNonStrictMode);
473 488
474 // --- E m p t y --- 489 // --- E m p t y ---
475 Handle<Code> code = 490 Handle<Code> code =
476 Handle<Code>(Builtins::builtin(Builtins::EmptyFunction)); 491 Handle<Code>(Builtins::builtin(Builtins::EmptyFunction));
477 empty_function->set_code(*code); 492 empty_function->set_code(*code);
478 empty_function->shared()->set_code(*code); 493 empty_function->shared()->set_code(*code);
479 Handle<String> source = Factory::NewStringFromAscii(CStrVector("() {}")); 494 Handle<String> source = Factory::NewStringFromAscii(CStrVector("() {}"));
480 Handle<Script> script = Factory::NewScript(source); 495 Handle<Script> script = Factory::NewScript(source);
481 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); 496 script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
482 empty_function->shared()->set_script(*script); 497 empty_function->shared()->set_script(*script);
483 empty_function->shared()->set_start_position(0); 498 empty_function->shared()->set_start_position(0);
484 empty_function->shared()->set_end_position(source->length()); 499 empty_function->shared()->set_end_position(source->length());
485 empty_function->shared()->DontAdaptArguments(); 500 empty_function->shared()->DontAdaptArguments();
501
502 // Set prototypes for the function maps.
486 global_context()->function_map()->set_prototype(*empty_function); 503 global_context()->function_map()->set_prototype(*empty_function);
487 global_context()->function_instance_map()->set_prototype(*empty_function); 504 global_context()->function_instance_map()->set_prototype(*empty_function);
488 global_context()->function_without_prototype_map()-> 505 global_context()->function_without_prototype_map()->
489 set_prototype(*empty_function); 506 set_prototype(*empty_function);
507 function_instance_map_writable_prototype_->set_prototype(*empty_function);
490 508
491 // Allocate the function map first and then patch the prototype later 509 // Allocate the function map first and then patch the prototype later
510 Handle<Map> function_without_prototype_map(
511 global_context()->function_without_prototype_map());
492 Handle<Map> empty_fm = Factory::CopyMapDropDescriptors( 512 Handle<Map> empty_fm = Factory::CopyMapDropDescriptors(
493 function_without_prototype_map); 513 function_without_prototype_map);
494 empty_fm->set_instance_descriptors( 514 empty_fm->set_instance_descriptors(
495 *function_without_prototype_map_descriptors); 515 function_without_prototype_map->instance_descriptors());
496 empty_fm->set_prototype(global_context()->object_function()->prototype()); 516 empty_fm->set_prototype(global_context()->object_function()->prototype());
497 empty_function->set_map(*empty_fm); 517 empty_function->set_map(*empty_fm);
498 return empty_function; 518 return empty_function;
499 } 519 }
500 520
501 521
522 Handle<DescriptorArray> Genesis::ComputeStrictFunctionInstanceDescriptor(
523 PrototypePropertyMode prototypeMode,
524 Handle<FixedArray> arguments,
525 Handle<FixedArray> caller) {
526 Handle<DescriptorArray> descriptors =
527 Factory::NewDescriptorArray(prototypeMode == DONT_ADD_PROTOTYPE ? 4 : 5);
528 PropertyAttributes attributes = static_cast<PropertyAttributes>(
529 DONT_ENUM | DONT_DELETE | READ_ONLY);
530
531 { // length
532 Handle<Proxy> proxy = Factory::NewProxy(&Accessors::FunctionLength);
533 CallbacksDescriptor d(*Factory::length_symbol(), *proxy, attributes);
534 descriptors->Set(0, &d);
535 }
536 { // name
537 Handle<Proxy> proxy = Factory::NewProxy(&Accessors::FunctionName);
538 CallbacksDescriptor d(*Factory::name_symbol(), *proxy, attributes);
539 descriptors->Set(1, &d);
540 }
541 { // arguments
542 CallbacksDescriptor d(*Factory::arguments_symbol(), *arguments, attributes);
543 descriptors->Set(2, &d);
544 }
545 { // caller
546 CallbacksDescriptor d(*Factory::caller_symbol(), *caller, attributes);
547 descriptors->Set(3, &d);
548 }
549
550 // prototype
551 if (prototypeMode != DONT_ADD_PROTOTYPE) {
552 if (prototypeMode == ADD_WRITEABLE_PROTOTYPE) {
553 attributes = static_cast<PropertyAttributes>(attributes & ~READ_ONLY);
554 }
555 Handle<Proxy> proxy = Factory::NewProxy(&Accessors::FunctionPrototype);
556 CallbacksDescriptor d(*Factory::prototype_symbol(), *proxy, attributes);
557 descriptors->Set(4, &d);
558 }
559
560 descriptors->Sort();
561 return descriptors;
562 }
563
564
565 // ECMAScript 5th Edition, 13.2.3
566 Handle<JSFunction> Genesis::CreateThrowTypeErrorFunction(
567 Builtins::Name builtin) {
568 Handle<String> name = Factory::LookupAsciiSymbol("ThrowTypeError");
569 Handle<JSFunction> throw_type_error =
570 Factory::NewFunctionWithoutPrototype(name, kStrictMode);
571 Handle<Code> code = Handle<Code>(Builtins::builtin(builtin));
572
573 throw_type_error->set_map(global_context()->strict_mode_function_map());
574 throw_type_error->set_code(*code);
575 throw_type_error->shared()->set_code(*code);
576 throw_type_error->shared()->DontAdaptArguments();
577
578 PreventExtensions(throw_type_error);
579
580 return throw_type_error;
581 }
582
583
584 Handle<Map> Genesis::CreateStrictModeFunctionMap(
585 PrototypePropertyMode prototype_mode,
586 Handle<JSFunction> empty_function,
587 Handle<FixedArray> arguments_callbacks,
588 Handle<FixedArray> caller_callbacks) {
589 Handle<Map> map = Factory::NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
590 Handle<DescriptorArray> descriptors =
591 ComputeStrictFunctionInstanceDescriptor(prototype_mode,
592 arguments_callbacks,
593 caller_callbacks);
594 map->set_instance_descriptors(*descriptors);
595 map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE);
596 map->set_prototype(*empty_function);
597 return map;
598 }
599
600
601 void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) {
602 // Create the callbacks arrays for ThrowTypeError functions.
603 // The get/set callacks are filled in after the maps are created below.
604 Handle<FixedArray> arguments = Factory::NewFixedArray(2, TENURED);
605 Handle<FixedArray> caller = Factory::NewFixedArray(2, TENURED);
606
607 // Allocate map for the strict mode function instances.
608 global_context()->set_strict_mode_function_instance_map(
609 *CreateStrictModeFunctionMap(
610 ADD_WRITEABLE_PROTOTYPE, empty, arguments, caller));
611
612 // Allocate map for the prototype-less strict mode instances.
613 global_context()->set_strict_mode_function_without_prototype_map(
614 *CreateStrictModeFunctionMap(
615 DONT_ADD_PROTOTYPE, empty, arguments, caller));
616
617 // Allocate map for the strict mode functions. This map is temporary, used
618 // only for processing of builtins.
619 // Later the map is replaced with writable prototype map, allocated below.
620 global_context()->set_strict_mode_function_map(
621 *CreateStrictModeFunctionMap(
622 ADD_READONLY_PROTOTYPE, empty, arguments, caller));
623
624 // The final map for the strict mode functions. Writeable prototype.
625 // This map is installed in MakeFunctionInstancePrototypeWritable.
626 strict_mode_function_instance_map_writable_prototype_ =
627 CreateStrictModeFunctionMap(
628 ADD_WRITEABLE_PROTOTYPE, empty, arguments, caller);
629
630 // Create the ThrowTypeError function instances.
631 Handle<JSFunction> arguments_throw =
632 CreateThrowTypeErrorFunction(Builtins::StrictFunctionArguments);
633 Handle<JSFunction> caller_throw =
634 CreateThrowTypeErrorFunction(Builtins::StrictFunctionCaller);
635
636 // Complete the callback fixed arrays.
637 arguments->set(0, *arguments_throw);
638 arguments->set(1, *arguments_throw);
639 caller->set(0, *caller_throw);
640 caller->set(1, *caller_throw);
641 }
642
643
502 static void AddToWeakGlobalContextList(Context* context) { 644 static void AddToWeakGlobalContextList(Context* context) {
503 ASSERT(context->IsGlobalContext()); 645 ASSERT(context->IsGlobalContext());
504 #ifdef DEBUG 646 #ifdef DEBUG
505 { // NOLINT 647 { // NOLINT
506 ASSERT(context->get(Context::NEXT_CONTEXT_LINK)->IsUndefined()); 648 ASSERT(context->get(Context::NEXT_CONTEXT_LINK)->IsUndefined());
507 // Check that context is not in the list yet. 649 // Check that context is not in the list yet.
508 for (Object* current = Heap::global_contexts_list(); 650 for (Object* current = Heap::global_contexts_list();
509 !current->IsUndefined(); 651 !current->IsUndefined();
510 current = Context::cast(current)->get(Context::NEXT_CONTEXT_LINK)) { 652 current = Context::cast(current)->get(Context::NEXT_CONTEXT_LINK)) {
511 ASSERT(current != context); 653 ASSERT(current != context);
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 JSObject::kHeaderSize, 1014 JSObject::kHeaderSize,
873 prototype, 1015 prototype,
874 code, 1016 code,
875 false); 1017 false);
876 ASSERT(!function->has_initial_map()); 1018 ASSERT(!function->has_initial_map());
877 function->shared()->set_instance_class_name(*symbol); 1019 function->shared()->set_instance_class_name(*symbol);
878 function->shared()->set_expected_nof_properties(2); 1020 function->shared()->set_expected_nof_properties(2);
879 Handle<JSObject> result = Factory::NewJSObject(function); 1021 Handle<JSObject> result = Factory::NewJSObject(function);
880 1022
881 global_context()->set_arguments_boilerplate(*result); 1023 global_context()->set_arguments_boilerplate(*result);
882 // Note: callee must be added as the first property and 1024 // Note: length must be added as the first property and
883 // length must be added as the second property. 1025 // callee must be added as the second property.
1026 SetLocalPropertyNoThrow(result, Factory::length_symbol(),
1027 Factory::undefined_value(),
1028 DONT_ENUM);
884 SetLocalPropertyNoThrow(result, Factory::callee_symbol(), 1029 SetLocalPropertyNoThrow(result, Factory::callee_symbol(),
885 Factory::undefined_value(), 1030 Factory::undefined_value(),
886 DONT_ENUM); 1031 DONT_ENUM);
887 SetLocalPropertyNoThrow(result, Factory::length_symbol(),
888 Factory::undefined_value(),
889 DONT_ENUM);
890 1032
891 #ifdef DEBUG 1033 #ifdef DEBUG
892 LookupResult lookup; 1034 LookupResult lookup;
893 result->LocalLookup(Heap::callee_symbol(), &lookup); 1035 result->LocalLookup(Heap::callee_symbol(), &lookup);
894 ASSERT(lookup.IsProperty() && (lookup.type() == FIELD)); 1036 ASSERT(lookup.IsProperty() && (lookup.type() == FIELD));
895 ASSERT(lookup.GetFieldIndex() == Heap::arguments_callee_index); 1037 ASSERT(lookup.GetFieldIndex() == Heap::kArgumentsCalleeIndex);
896 1038
897 result->LocalLookup(Heap::length_symbol(), &lookup); 1039 result->LocalLookup(Heap::length_symbol(), &lookup);
898 ASSERT(lookup.IsProperty() && (lookup.type() == FIELD)); 1040 ASSERT(lookup.IsProperty() && (lookup.type() == FIELD));
899 ASSERT(lookup.GetFieldIndex() == Heap::arguments_length_index); 1041 ASSERT(lookup.GetFieldIndex() == Heap::kArgumentsLengthIndex);
900 1042
901 ASSERT(result->map()->inobject_properties() > Heap::arguments_callee_index); 1043 ASSERT(result->map()->inobject_properties() > Heap::kArgumentsCalleeIndex);
902 ASSERT(result->map()->inobject_properties() > Heap::arguments_length_index); 1044 ASSERT(result->map()->inobject_properties() > Heap::kArgumentsLengthIndex);
903 1045
904 // Check the state of the object. 1046 // Check the state of the object.
905 ASSERT(result->HasFastProperties()); 1047 ASSERT(result->HasFastProperties());
906 ASSERT(result->HasFastElements()); 1048 ASSERT(result->HasFastElements());
907 #endif 1049 #endif
908 } 1050 }
909 1051
1052 { // --- strict mode arguments boilerplate
1053 const PropertyAttributes attributes =
1054 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
1055
1056 // Create the ThrowTypeError functions.
1057 Handle<FixedArray> callee = Factory::NewFixedArray(2, TENURED);
1058 Handle<FixedArray> caller = Factory::NewFixedArray(2, TENURED);
1059
1060 Handle<JSFunction> callee_throw =
1061 CreateThrowTypeErrorFunction(Builtins::StrictArgumentsCallee);
1062 Handle<JSFunction> caller_throw =
1063 CreateThrowTypeErrorFunction(Builtins::StrictArgumentsCaller);
1064
1065 // Install the ThrowTypeError functions.
1066 callee->set(0, *callee_throw);
1067 callee->set(1, *callee_throw);
1068 caller->set(0, *caller_throw);
1069 caller->set(1, *caller_throw);
1070
1071 // Create the descriptor array for the arguments object.
1072 Handle<DescriptorArray> descriptors = Factory::NewDescriptorArray(3);
1073 { // length
1074 FieldDescriptor d(*Factory::length_symbol(), 0, DONT_ENUM);
1075 descriptors->Set(0, &d);
1076 }
1077 { // callee
1078 CallbacksDescriptor d(*Factory::callee_symbol(), *callee, attributes);
1079 descriptors->Set(1, &d);
1080 }
1081 { // caller
1082 CallbacksDescriptor d(*Factory::caller_symbol(), *caller, attributes);
1083 descriptors->Set(2, &d);
1084 }
1085 descriptors->Sort();
1086
1087 // Create the map. Allocate one in-object field for length.
1088 Handle<Map> map = Factory::NewMap(JS_OBJECT_TYPE,
1089 Heap::kArgumentsObjectSizeStrict);
1090 map->set_instance_descriptors(*descriptors);
1091 map->set_function_with_prototype(true);
1092 map->set_prototype(global_context()->object_function()->prototype());
1093 map->set_pre_allocated_property_fields(1);
1094 map->set_inobject_properties(1);
1095
1096 // Copy constructor from the non-strict arguments boilerplate.
1097 map->set_constructor(
1098 global_context()->arguments_boilerplate()->map()->constructor());
1099
1100 // Allocate the arguments boilerplate object.
1101 Handle<JSObject> result = Factory::NewJSObjectFromMap(map);
1102 global_context()->set_strict_mode_arguments_boilerplate(*result);
1103
1104 // Add length property only for strict mode boilerplate.
1105 SetLocalPropertyNoThrow(result, Factory::length_symbol(),
1106 Factory::undefined_value(),
1107 DONT_ENUM);
1108
1109 #ifdef DEBUG
1110 LookupResult lookup;
1111 result->LocalLookup(Heap::length_symbol(), &lookup);
1112 ASSERT(lookup.IsProperty() && (lookup.type() == FIELD));
1113 ASSERT(lookup.GetFieldIndex() == Heap::kArgumentsLengthIndex);
1114
1115 ASSERT(result->map()->inobject_properties() > Heap::kArgumentsLengthIndex);
1116
1117 // Check the state of the object.
1118 ASSERT(result->HasFastProperties());
1119 ASSERT(result->HasFastElements());
1120 #endif
1121 }
1122
910 { // --- context extension 1123 { // --- context extension
911 // Create a function for the context extension objects. 1124 // Create a function for the context extension objects.
912 Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::Illegal)); 1125 Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::Illegal));
913 Handle<JSFunction> context_extension_fun = 1126 Handle<JSFunction> context_extension_fun =
914 Factory::NewFunction(Factory::empty_symbol(), 1127 Factory::NewFunction(Factory::empty_symbol(),
915 JS_CONTEXT_EXTENSION_OBJECT_TYPE, 1128 JS_CONTEXT_EXTENSION_OBJECT_TYPE,
916 JSObject::kHeaderSize, 1129 JSObject::kHeaderSize,
917 code, 1130 code,
918 true); 1131 true);
919 1132
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after
1802 2015
1803 // Transfer the prototype (new map is needed). 2016 // Transfer the prototype (new map is needed).
1804 Handle<Map> old_to_map = Handle<Map>(to->map()); 2017 Handle<Map> old_to_map = Handle<Map>(to->map());
1805 Handle<Map> new_to_map = Factory::CopyMapDropTransitions(old_to_map); 2018 Handle<Map> new_to_map = Factory::CopyMapDropTransitions(old_to_map);
1806 new_to_map->set_prototype(from->map()->prototype()); 2019 new_to_map->set_prototype(from->map()->prototype());
1807 to->set_map(*new_to_map); 2020 to->set_map(*new_to_map);
1808 } 2021 }
1809 2022
1810 2023
1811 void Genesis::MakeFunctionInstancePrototypeWritable() { 2024 void Genesis::MakeFunctionInstancePrototypeWritable() {
1812 // Make a new function map so all future functions 2025 // The maps with writable prototype are created in CreateEmptyFunction
1813 // will have settable and enumerable prototype properties. 2026 // and CreateStrictModeFunctionMaps respectively. Initially the maps are
1814 HandleScope scope; 2027 // created with read-only prototype for JS builtins processing.
2028 ASSERT(!function_instance_map_writable_prototype_.is_null());
2029 ASSERT(!strict_mode_function_instance_map_writable_prototype_.is_null());
1815 2030
1816 Handle<DescriptorArray> function_map_descriptors = 2031 // Replace function instance maps to make prototype writable.
1817 ComputeFunctionInstanceDescriptor(ADD_WRITEABLE_PROTOTYPE); 2032 global_context()->set_function_map(
1818 Handle<Map> fm = Factory::CopyMapDropDescriptors(Top::function_map()); 2033 *function_instance_map_writable_prototype_);
1819 fm->set_instance_descriptors(*function_map_descriptors); 2034 global_context()->set_strict_mode_function_map(
1820 fm->set_function_with_prototype(true); 2035 *strict_mode_function_instance_map_writable_prototype_);
1821 Top::context()->global_context()->set_function_map(*fm);
1822 } 2036 }
1823 2037
1824 2038
1825 Genesis::Genesis(Handle<Object> global_object, 2039 Genesis::Genesis(Handle<Object> global_object,
1826 v8::Handle<v8::ObjectTemplate> global_template, 2040 v8::Handle<v8::ObjectTemplate> global_template,
1827 v8::ExtensionConfiguration* extensions) { 2041 v8::ExtensionConfiguration* extensions) {
1828 result_ = Handle<Context>::null(); 2042 result_ = Handle<Context>::null();
1829 // If V8 isn't running and cannot be initialized, just return. 2043 // If V8 isn't running and cannot be initialized, just return.
1830 if (!V8::IsRunning() && !V8::Initialize(NULL)) return; 2044 if (!V8::IsRunning() && !V8::Initialize(NULL)) return;
1831 2045
1832 // Before creating the roots we must save the context and restore it 2046 // Before creating the roots we must save the context and restore it
1833 // on all function exits. 2047 // on all function exits.
1834 HandleScope scope; 2048 HandleScope scope;
1835 SaveContext saved_context; 2049 SaveContext saved_context;
1836 2050
1837 Handle<Context> new_context = Snapshot::NewContextFromSnapshot(); 2051 Handle<Context> new_context = Snapshot::NewContextFromSnapshot();
1838 if (!new_context.is_null()) { 2052 if (!new_context.is_null()) {
1839 global_context_ = 2053 global_context_ =
1840 Handle<Context>::cast(GlobalHandles::Create(*new_context)); 2054 Handle<Context>::cast(GlobalHandles::Create(*new_context));
1841 AddToWeakGlobalContextList(*global_context_); 2055 AddToWeakGlobalContextList(*global_context_);
1842 Top::set_context(*global_context_); 2056 Top::set_context(*global_context_);
1843 i::Counters::contexts_created_by_snapshot.Increment(); 2057 i::Counters::contexts_created_by_snapshot.Increment();
1844 JSFunction* empty_function =
1845 JSFunction::cast(global_context_->function_map()->prototype());
1846 empty_function_ = Handle<JSFunction>(empty_function);
1847 Handle<GlobalObject> inner_global; 2058 Handle<GlobalObject> inner_global;
1848 Handle<JSGlobalProxy> global_proxy = 2059 Handle<JSGlobalProxy> global_proxy =
1849 CreateNewGlobals(global_template, 2060 CreateNewGlobals(global_template,
1850 global_object, 2061 global_object,
1851 &inner_global); 2062 &inner_global);
1852 2063
1853 HookUpGlobalProxy(inner_global, global_proxy); 2064 HookUpGlobalProxy(inner_global, global_proxy);
1854 HookUpInnerGlobal(inner_global); 2065 HookUpInnerGlobal(inner_global);
1855 2066
1856 if (!ConfigureGlobalObjects(global_template)) return; 2067 if (!ConfigureGlobalObjects(global_template)) return;
1857 } else { 2068 } else {
1858 // We get here if there was no context snapshot. 2069 // We get here if there was no context snapshot.
1859 CreateRoots(); 2070 CreateRoots();
1860 Handle<JSFunction> empty_function = CreateEmptyFunction(); 2071 Handle<JSFunction> empty_function = CreateEmptyFunction();
2072 CreateStrictModeFunctionMaps(empty_function);
1861 Handle<GlobalObject> inner_global; 2073 Handle<GlobalObject> inner_global;
1862 Handle<JSGlobalProxy> global_proxy = 2074 Handle<JSGlobalProxy> global_proxy =
1863 CreateNewGlobals(global_template, global_object, &inner_global); 2075 CreateNewGlobals(global_template, global_object, &inner_global);
1864 HookUpGlobalProxy(inner_global, global_proxy); 2076 HookUpGlobalProxy(inner_global, global_proxy);
1865 InitializeGlobal(inner_global, empty_function); 2077 InitializeGlobal(inner_global, empty_function);
1866 InstallJSFunctionResultCaches(); 2078 InstallJSFunctionResultCaches();
1867 InitializeNormalizedMapCaches(); 2079 InitializeNormalizedMapCaches();
1868 if (!InstallNatives()) return; 2080 if (!InstallNatives()) return;
1869 2081
1870 MakeFunctionInstancePrototypeWritable(); 2082 MakeFunctionInstancePrototypeWritable();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1917 } 2129 }
1918 2130
1919 2131
1920 // Restore statics that are thread local. 2132 // Restore statics that are thread local.
1921 char* BootstrapperActive::RestoreState(char* from) { 2133 char* BootstrapperActive::RestoreState(char* from) {
1922 nesting_ = *reinterpret_cast<int*>(from); 2134 nesting_ = *reinterpret_cast<int*>(from);
1923 return from + sizeof(nesting_); 2135 return from + sizeof(nesting_);
1924 } 2136 }
1925 2137
1926 } } // namespace v8::internal 2138 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/assembler.cc ('k') | src/builtins.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698