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

Side by Side Diff: src/bootstrapper.cc

Issue 1769013: Make Empty function to have no prototype and use it as __proto__ for all func... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years, 7 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 | « no previous file | test/mjsunit/unusual-constructor.js » ('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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 global_context()->set_function_instance_map(*fm); 411 global_context()->set_function_instance_map(*fm);
412 // Please note that the prototype property for function instances must be 412 // Please note that the prototype property for function instances must be
413 // writable. 413 // writable.
414 Handle<DescriptorArray> function_map_descriptors = 414 Handle<DescriptorArray> function_map_descriptors =
415 ComputeFunctionInstanceDescriptor(ADD_WRITEABLE_PROTOTYPE); 415 ComputeFunctionInstanceDescriptor(ADD_WRITEABLE_PROTOTYPE);
416 fm->set_instance_descriptors(*function_map_descriptors); 416 fm->set_instance_descriptors(*function_map_descriptors);
417 fm->set_function_with_prototype(true); 417 fm->set_function_with_prototype(true);
418 418
419 // Functions with this map will not have a 'prototype' property, and 419 // Functions with this map will not have a 'prototype' property, and
420 // can not be used as constructors. 420 // can not be used as constructors.
421 fm = Factory::NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); 421 Handle<Map> function_without_prototype_map =
422 global_context()->set_function_without_prototype_map(*fm); 422 Factory::NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
423 function_map_descriptors = 423 global_context()->set_function_without_prototype_map(
424 *function_without_prototype_map);
425 Handle<DescriptorArray> function_without_prototype_map_descriptors =
424 ComputeFunctionInstanceDescriptor(DONT_ADD_PROTOTYPE); 426 ComputeFunctionInstanceDescriptor(DONT_ADD_PROTOTYPE);
425 fm->set_instance_descriptors(*function_map_descriptors); 427 function_without_prototype_map->set_instance_descriptors(
426 fm->set_function_with_prototype(false); 428 *function_without_prototype_map_descriptors);
429 function_without_prototype_map->set_function_with_prototype(false);
427 430
428 // Allocate the function map first and then patch the prototype later 431 // Allocate the function map first and then patch the prototype later
429 fm = Factory::NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); 432 fm = Factory::NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
430 global_context()->set_function_map(*fm); 433 global_context()->set_function_map(*fm);
431 function_map_descriptors = 434 function_map_descriptors =
432 ComputeFunctionInstanceDescriptor(ADD_READONLY_PROTOTYPE); 435 ComputeFunctionInstanceDescriptor(ADD_READONLY_PROTOTYPE);
433 fm->set_instance_descriptors(*function_map_descriptors); 436 fm->set_instance_descriptors(*function_map_descriptors);
434 fm->set_function_with_prototype(true); 437 fm->set_function_with_prototype(true);
435 438
436 Handle<String> object_name = Handle<String>(Heap::Object_symbol()); 439 Handle<String> object_name = Handle<String>(Heap::Object_symbol());
(...skipping 15 matching lines...) Expand all
452 global_context()->set_initial_object_prototype(*prototype); 455 global_context()->set_initial_object_prototype(*prototype);
453 SetPrototype(object_fun, prototype); 456 SetPrototype(object_fun, prototype);
454 object_function_map-> 457 object_function_map->
455 set_instance_descriptors(Heap::empty_descriptor_array()); 458 set_instance_descriptors(Heap::empty_descriptor_array());
456 } 459 }
457 460
458 // Allocate the empty function as the prototype for function ECMAScript 461 // Allocate the empty function as the prototype for function ECMAScript
459 // 262 15.3.4. 462 // 262 15.3.4.
460 Handle<String> symbol = Factory::LookupAsciiSymbol("Empty"); 463 Handle<String> symbol = Factory::LookupAsciiSymbol("Empty");
461 Handle<JSFunction> empty_function = 464 Handle<JSFunction> empty_function =
462 Factory::NewFunction(symbol, Factory::null_value()); 465 Factory::NewFunctionWithoutPrototype(symbol);
463 466
464 // --- E m p t y --- 467 // --- E m p t y ---
465 Handle<Code> code = 468 Handle<Code> code =
466 Handle<Code>(Builtins::builtin(Builtins::EmptyFunction)); 469 Handle<Code>(Builtins::builtin(Builtins::EmptyFunction));
467 empty_function->set_code(*code); 470 empty_function->set_code(*code);
468 Handle<String> source = Factory::NewStringFromAscii(CStrVector("() {}")); 471 Handle<String> source = Factory::NewStringFromAscii(CStrVector("() {}"));
469 Handle<Script> script = Factory::NewScript(source); 472 Handle<Script> script = Factory::NewScript(source);
470 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); 473 script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
471 empty_function->shared()->set_script(*script); 474 empty_function->shared()->set_script(*script);
472 empty_function->shared()->set_start_position(0); 475 empty_function->shared()->set_start_position(0);
473 empty_function->shared()->set_end_position(source->length()); 476 empty_function->shared()->set_end_position(source->length());
474 empty_function->shared()->DontAdaptArguments(); 477 empty_function->shared()->DontAdaptArguments();
475 global_context()->function_map()->set_prototype(*empty_function); 478 global_context()->function_map()->set_prototype(*empty_function);
476 global_context()->function_instance_map()->set_prototype(*empty_function); 479 global_context()->function_instance_map()->set_prototype(*empty_function);
477 480 global_context()->function_without_prototype_map()->
478 // Allocate a distinct prototype for the function map for functions without 481 set_prototype(*empty_function);
479 // prototype, so it will not add 'prototype' property in the proto chain.
480 global_context()->function_without_prototype_map()->set_prototype(
481 *Factory::NewJSObject(Top::object_function(), TENURED));
482 482
483 // Allocate the function map first and then patch the prototype later 483 // Allocate the function map first and then patch the prototype later
484 Handle<Map> empty_fm = Factory::CopyMapDropDescriptors(fm); 484 Handle<Map> empty_fm = Factory::CopyMapDropDescriptors(
485 empty_fm->set_instance_descriptors(*function_map_descriptors); 485 function_without_prototype_map);
486 empty_fm->set_instance_descriptors(
487 *function_without_prototype_map_descriptors);
486 empty_fm->set_prototype(global_context()->object_function()->prototype()); 488 empty_fm->set_prototype(global_context()->object_function()->prototype());
487 empty_function->set_map(*empty_fm); 489 empty_function->set_map(*empty_fm);
488 return empty_function; 490 return empty_function;
489 } 491 }
490 492
491 493
492 void Genesis::CreateRoots() { 494 void Genesis::CreateRoots() {
493 // Allocate the global context FixedArray first and then patch the 495 // Allocate the global context FixedArray first and then patch the
494 // closure and extension object later (we need the empty function 496 // closure and extension object later (we need the empty function
495 // and the global object, but in order to create those, we need the 497 // and the global object, but in order to create those, we need the
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 // only work if it appears to be compiled. 1253 // only work if it appears to be compiled.
1252 call->shared()->DontAdaptArguments(); 1254 call->shared()->DontAdaptArguments();
1253 ASSERT(call->is_compiled()); 1255 ASSERT(call->is_compiled());
1254 1256
1255 // Set the expected parameters for apply to 2; required by builtin. 1257 // Set the expected parameters for apply to 2; required by builtin.
1256 apply->shared()->set_formal_parameter_count(2); 1258 apply->shared()->set_formal_parameter_count(2);
1257 1259
1258 // Set the lengths for the functions to satisfy ECMA-262. 1260 // Set the lengths for the functions to satisfy ECMA-262.
1259 call->shared()->set_length(1); 1261 call->shared()->set_length(1);
1260 apply->shared()->set_length(2); 1262 apply->shared()->set_length(2);
1261
1262 // Install the call, apply, toString and constructor properties
1263 // for the functions without prototype.
1264 Handle<JSObject> wp_proto = Handle<JSObject>(
1265 JSObject::cast(Top::function_without_prototype_map()->prototype()));
1266
1267 Handle<String> call_symbol = Factory::LookupAsciiSymbol("call");
1268 SetProperty(wp_proto, call_symbol, call, DONT_ENUM);
1269
1270 Handle<String> apply_symbol = Factory::LookupAsciiSymbol("apply");
1271 SetProperty(wp_proto, apply_symbol, apply, DONT_ENUM);
1272
1273 Handle<Object> to_string = GetProperty(proto, "toString");
1274 Handle<String> to_string_symbol = Factory::LookupAsciiSymbol("toString");
1275 SetProperty(wp_proto, to_string_symbol, to_string, DONT_ENUM);
1276
1277 SetProperty(wp_proto, Factory::constructor_symbol(), function, DONT_ENUM);
1278 } 1263 }
1279 1264
1280 // Create a constructor for RegExp results (a variant of Array that 1265 // Create a constructor for RegExp results (a variant of Array that
1281 // predefines the two properties index and match). 1266 // predefines the two properties index and match).
1282 { 1267 {
1283 // RegExpResult initial map. 1268 // RegExpResult initial map.
1284 1269
1285 // Find global.Array.prototype to inherit from. 1270 // Find global.Array.prototype to inherit from.
1286 Handle<JSFunction> array_constructor(global_context()->array_function()); 1271 Handle<JSFunction> array_constructor(global_context()->array_function());
1287 Handle<JSObject> array_prototype( 1272 Handle<JSObject> array_prototype(
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
1796 } 1781 }
1797 1782
1798 1783
1799 // Restore statics that are thread local. 1784 // Restore statics that are thread local.
1800 char* BootstrapperActive::RestoreState(char* from) { 1785 char* BootstrapperActive::RestoreState(char* from) {
1801 nesting_ = *reinterpret_cast<int*>(from); 1786 nesting_ = *reinterpret_cast<int*>(from);
1802 return from + sizeof(nesting_); 1787 return from + sizeof(nesting_);
1803 } 1788 }
1804 1789
1805 } } // namespace v8::internal 1790 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/unusual-constructor.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698