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

Side by Side Diff: src/runtime.cc

Issue 1722003: Added ability to remove prototype from function. In this case, [[Construct]] ... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Fixes according to Erik's comments Created 10 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
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 NoHandleAllocation ha; 1443 NoHandleAllocation ha;
1444 ASSERT(args.length() == 2); 1444 ASSERT(args.length() == 2);
1445 1445
1446 CONVERT_CHECKED(JSFunction, f, args[0]); 1446 CONVERT_CHECKED(JSFunction, f, args[0]);
1447 CONVERT_CHECKED(String, name, args[1]); 1447 CONVERT_CHECKED(String, name, args[1]);
1448 f->shared()->set_name(name); 1448 f->shared()->set_name(name);
1449 return Heap::undefined_value(); 1449 return Heap::undefined_value();
1450 } 1450 }
1451 1451
1452 1452
1453 static Object* Runtime_FunctionRemovePrototype(Arguments args) {
1454 NoHandleAllocation ha;
1455 ASSERT(args.length() == 1);
1456
1457 CONVERT_CHECKED(JSFunction, f, args[0]);
1458 Object* obj = f->RemovePrototype();
1459 if (obj->IsFailure()) return obj;
1460
1461 return Heap::undefined_value();
1462 }
1463
1464
1453 static Object* Runtime_FunctionGetScript(Arguments args) { 1465 static Object* Runtime_FunctionGetScript(Arguments args) {
1454 HandleScope scope; 1466 HandleScope scope;
1455 ASSERT(args.length() == 1); 1467 ASSERT(args.length() == 1);
1456 1468
1457 CONVERT_CHECKED(JSFunction, fun, args[0]); 1469 CONVERT_CHECKED(JSFunction, fun, args[0]);
1458 Handle<Object> script = Handle<Object>(fun->shared()->script()); 1470 Handle<Object> script = Handle<Object>(fun->shared()->script());
1459 if (!script->IsScript()) return Heap::undefined_value(); 1471 if (!script->IsScript()) return Heap::undefined_value();
1460 1472
1461 return *GetScriptWrapper(Handle<Script>::cast(script)); 1473 return *GetScriptWrapper(Handle<Script>::cast(script));
1462 } 1474 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 fun->shared()->set_length(length->value()); 1528 fun->shared()->set_length(length->value());
1517 return length; 1529 return length;
1518 } 1530 }
1519 1531
1520 1532
1521 static Object* Runtime_FunctionSetPrototype(Arguments args) { 1533 static Object* Runtime_FunctionSetPrototype(Arguments args) {
1522 NoHandleAllocation ha; 1534 NoHandleAllocation ha;
1523 ASSERT(args.length() == 2); 1535 ASSERT(args.length() == 2);
1524 1536
1525 CONVERT_CHECKED(JSFunction, fun, args[0]); 1537 CONVERT_CHECKED(JSFunction, fun, args[0]);
1538 ASSERT(fun->should_have_prototype());
1526 Object* obj = Accessors::FunctionSetPrototype(fun, args[1], NULL); 1539 Object* obj = Accessors::FunctionSetPrototype(fun, args[1], NULL);
1527 if (obj->IsFailure()) return obj; 1540 if (obj->IsFailure()) return obj;
1528 return args[0]; // return TOS 1541 return args[0]; // return TOS
1529 } 1542 }
1530 1543
1531 1544
1532 static Object* Runtime_FunctionIsAPIFunction(Arguments args) { 1545 static Object* Runtime_FunctionIsAPIFunction(Arguments args) {
1533 NoHandleAllocation ha; 1546 NoHandleAllocation ha;
1534 ASSERT(args.length() == 1); 1547 ASSERT(args.length() == 1);
1535 1548
(...skipping 4997 matching lines...) Expand 10 before | Expand all | Expand 10 after
6533 6546
6534 // If the constructor isn't a proper function we throw a type error. 6547 // If the constructor isn't a proper function we throw a type error.
6535 if (!constructor->IsJSFunction()) { 6548 if (!constructor->IsJSFunction()) {
6536 Vector< Handle<Object> > arguments = HandleVector(&constructor, 1); 6549 Vector< Handle<Object> > arguments = HandleVector(&constructor, 1);
6537 Handle<Object> type_error = 6550 Handle<Object> type_error =
6538 Factory::NewTypeError("not_constructor", arguments); 6551 Factory::NewTypeError("not_constructor", arguments);
6539 return Top::Throw(*type_error); 6552 return Top::Throw(*type_error);
6540 } 6553 }
6541 6554
6542 Handle<JSFunction> function = Handle<JSFunction>::cast(constructor); 6555 Handle<JSFunction> function = Handle<JSFunction>::cast(constructor);
6556
6557 // If function should not have prototype, construction is not allowed. In this
6558 // case generated code bailouts here, since function has no initial_map.
6559 if (!function->should_have_prototype()) {
6560 Vector< Handle<Object> > arguments = HandleVector(&constructor, 1);
6561 Handle<Object> type_error =
6562 Factory::NewTypeError("not_constructor", arguments);
6563 return Top::Throw(*type_error);
6564 }
6565
6543 #ifdef ENABLE_DEBUGGER_SUPPORT 6566 #ifdef ENABLE_DEBUGGER_SUPPORT
6544 // Handle stepping into constructors if step into is active. 6567 // Handle stepping into constructors if step into is active.
6545 if (Debug::StepInActive()) { 6568 if (Debug::StepInActive()) {
6546 Debug::HandleStepIn(function, Handle<Object>::null(), 0, true); 6569 Debug::HandleStepIn(function, Handle<Object>::null(), 0, true);
6547 } 6570 }
6548 #endif 6571 #endif
6549 6572
6550 if (function->has_initial_map()) { 6573 if (function->has_initial_map()) {
6551 if (function->initial_map()->instance_type() == JS_FUNCTION_TYPE) { 6574 if (function->initial_map()->instance_type() == JS_FUNCTION_TYPE) {
6552 // The 'Function' function ignores the receiver object when 6575 // The 'Function' function ignores the receiver object when
(...skipping 3648 matching lines...) Expand 10 before | Expand all | Expand 10 after
10201 } else { 10224 } else {
10202 // Handle last resort GC and make sure to allow future allocations 10225 // Handle last resort GC and make sure to allow future allocations
10203 // to grow the heap without causing GCs (if possible). 10226 // to grow the heap without causing GCs (if possible).
10204 Counters::gc_last_resort_from_js.Increment(); 10227 Counters::gc_last_resort_from_js.Increment();
10205 Heap::CollectAllGarbage(false); 10228 Heap::CollectAllGarbage(false);
10206 } 10229 }
10207 } 10230 }
10208 10231
10209 10232
10210 } } // namespace v8::internal 10233 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698