| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 } | 479 } |
| 480 | 480 |
| 481 | 481 |
| 482 Handle<JSFunction> Factory::NewFunction(Handle<String> name, | 482 Handle<JSFunction> Factory::NewFunction(Handle<String> name, |
| 483 InstanceType type, | 483 InstanceType type, |
| 484 int instance_size, | 484 int instance_size, |
| 485 Handle<Code> code, | 485 Handle<Code> code, |
| 486 bool force_initial_map) { | 486 bool force_initial_map) { |
| 487 // Allocate the function | 487 // Allocate the function |
| 488 Handle<JSFunction> function = NewFunction(name, the_hole_value()); | 488 Handle<JSFunction> function = NewFunction(name, the_hole_value()); |
| 489 |
| 490 // Setup the code pointer in both the shared function info and in |
| 491 // the function itself. |
| 492 function->shared()->set_code(*code); |
| 489 function->set_code(*code); | 493 function->set_code(*code); |
| 490 | 494 |
| 491 if (force_initial_map || | 495 if (force_initial_map || |
| 492 type != JS_OBJECT_TYPE || | 496 type != JS_OBJECT_TYPE || |
| 493 instance_size != JSObject::kHeaderSize) { | 497 instance_size != JSObject::kHeaderSize) { |
| 494 Handle<Map> initial_map = NewMap(type, instance_size); | 498 Handle<Map> initial_map = NewMap(type, instance_size); |
| 495 Handle<JSObject> prototype = NewFunctionPrototype(function); | 499 Handle<JSObject> prototype = NewFunctionPrototype(function); |
| 496 initial_map->set_prototype(*prototype); | 500 initial_map->set_prototype(*prototype); |
| 497 function->set_initial_map(*initial_map); | 501 function->set_initial_map(*initial_map); |
| 498 initial_map->set_constructor(*function); | 502 initial_map->set_constructor(*function); |
| 499 } else { | 503 } else { |
| 500 ASSERT(!function->has_initial_map()); | 504 ASSERT(!function->has_initial_map()); |
| 501 ASSERT(!function->has_prototype()); | 505 ASSERT(!function->has_prototype()); |
| 502 } | 506 } |
| 503 | 507 |
| 504 return function; | 508 return function; |
| 505 } | 509 } |
| 506 | 510 |
| 507 | 511 |
| 508 Handle<JSFunction> Factory::NewFunctionWithPrototype(Handle<String> name, | 512 Handle<JSFunction> Factory::NewFunctionWithPrototype(Handle<String> name, |
| 509 InstanceType type, | 513 InstanceType type, |
| 510 int instance_size, | 514 int instance_size, |
| 511 Handle<JSObject> prototype, | 515 Handle<JSObject> prototype, |
| 512 Handle<Code> code, | 516 Handle<Code> code, |
| 513 bool force_initial_map) { | 517 bool force_initial_map) { |
| 514 // Allocate the function | 518 // Allocate the function. |
| 515 Handle<JSFunction> function = NewFunction(name, prototype); | 519 Handle<JSFunction> function = NewFunction(name, prototype); |
| 516 | 520 |
| 521 // Setup the code pointer in both the shared function info and in |
| 522 // the function itself. |
| 523 function->shared()->set_code(*code); |
| 517 function->set_code(*code); | 524 function->set_code(*code); |
| 518 | 525 |
| 519 if (force_initial_map || | 526 if (force_initial_map || |
| 520 type != JS_OBJECT_TYPE || | 527 type != JS_OBJECT_TYPE || |
| 521 instance_size != JSObject::kHeaderSize) { | 528 instance_size != JSObject::kHeaderSize) { |
| 522 Handle<Map> initial_map = NewMap(type, instance_size); | 529 Handle<Map> initial_map = NewMap(type, instance_size); |
| 523 function->set_initial_map(*initial_map); | 530 function->set_initial_map(*initial_map); |
| 524 initial_map->set_constructor(*function); | 531 initial_map->set_constructor(*function); |
| 525 } | 532 } |
| 526 | 533 |
| 527 // Set function.prototype and give the prototype a constructor | 534 // Set function.prototype and give the prototype a constructor |
| 528 // property that refers to the function. | 535 // property that refers to the function. |
| 529 SetPrototypeProperty(function, prototype); | 536 SetPrototypeProperty(function, prototype); |
| 530 SetProperty(prototype, Factory::constructor_symbol(), function, DONT_ENUM); | 537 SetProperty(prototype, Factory::constructor_symbol(), function, DONT_ENUM); |
| 531 return function; | 538 return function; |
| 532 } | 539 } |
| 533 | 540 |
| 534 | 541 |
| 535 Handle<JSFunction> Factory::NewFunctionWithoutPrototype(Handle<String> name, | 542 Handle<JSFunction> Factory::NewFunctionWithoutPrototype(Handle<String> name, |
| 536 Handle<Code> code) { | 543 Handle<Code> code) { |
| 537 Handle<JSFunction> function = NewFunctionWithoutPrototype(name); | 544 Handle<JSFunction> function = NewFunctionWithoutPrototype(name); |
| 545 function->shared()->set_code(*code); |
| 538 function->set_code(*code); | 546 function->set_code(*code); |
| 539 ASSERT(!function->has_initial_map()); | 547 ASSERT(!function->has_initial_map()); |
| 540 ASSERT(!function->has_prototype()); | 548 ASSERT(!function->has_prototype()); |
| 541 return function; | 549 return function; |
| 542 } | 550 } |
| 543 | 551 |
| 544 | 552 |
| 545 Handle<Code> Factory::NewCode(const CodeDesc& desc, | 553 Handle<Code> Factory::NewCode(const CodeDesc& desc, |
| 546 Code::Flags flags, | 554 Code::Flags flags, |
| 547 Handle<Object> self_ref) { | 555 Handle<Object> self_ref) { |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 Execution::ConfigureInstance(instance, | 1002 Execution::ConfigureInstance(instance, |
| 995 instance_template, | 1003 instance_template, |
| 996 pending_exception); | 1004 pending_exception); |
| 997 } else { | 1005 } else { |
| 998 *pending_exception = false; | 1006 *pending_exception = false; |
| 999 } | 1007 } |
| 1000 } | 1008 } |
| 1001 | 1009 |
| 1002 | 1010 |
| 1003 } } // namespace v8::internal | 1011 } } // namespace v8::internal |
| OLD | NEW |