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

Side by Side Diff: src/runtime.cc

Issue 7623011: Implement function proxies (except for their use as constructors). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed second round of comments. Created 9 years, 3 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/runtime.h ('k') | src/runtime.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSProxy) { 605 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSProxy) {
606 ASSERT(args.length() == 2); 606 ASSERT(args.length() == 2);
607 Object* handler = args[0]; 607 Object* handler = args[0];
608 Object* prototype = args[1]; 608 Object* prototype = args[1];
609 Object* used_prototype = 609 Object* used_prototype =
610 prototype->IsJSReceiver() ? prototype : isolate->heap()->null_value(); 610 prototype->IsJSReceiver() ? prototype : isolate->heap()->null_value();
611 return isolate->heap()->AllocateJSProxy(handler, used_prototype); 611 return isolate->heap()->AllocateJSProxy(handler, used_prototype);
612 } 612 }
613 613
614 614
615 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSFunctionProxy) {
616 ASSERT(args.length() == 4);
617 Object* handler = args[0];
618 Object* call_trap = args[1];
619 Object* construct_trap = args[2];
620 Object* prototype = args[3];
621 Object* used_prototype =
622 prototype->IsJSReceiver() ? prototype : isolate->heap()->null_value();
623 return isolate->heap()->AllocateJSFunctionProxy(
624 handler, call_trap, construct_trap, used_prototype);
625 }
626
627
615 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsJSProxy) { 628 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsJSProxy) {
616 ASSERT(args.length() == 1); 629 ASSERT(args.length() == 1);
617 Object* obj = args[0]; 630 Object* obj = args[0];
618 return isolate->heap()->ToBoolean(obj->IsJSProxy()); 631 return isolate->heap()->ToBoolean(obj->IsJSProxy());
619 } 632 }
620 633
621 634
635 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsJSFunctionProxy) {
636 ASSERT(args.length() == 1);
637 Object* obj = args[0];
638 return isolate->heap()->ToBoolean(obj->IsJSFunctionProxy());
639 }
640
641
622 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetHandler) { 642 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetHandler) {
623 ASSERT(args.length() == 1); 643 ASSERT(args.length() == 1);
624 CONVERT_CHECKED(JSProxy, proxy, args[0]); 644 CONVERT_CHECKED(JSProxy, proxy, args[0]);
625 return proxy->handler(); 645 return proxy->handler();
626 } 646 }
627 647
628 648
649 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetCallTrap) {
650 ASSERT(args.length() == 1);
651 CONVERT_CHECKED(JSFunctionProxy, proxy, args[0]);
652 return proxy->call_trap();
653 }
654
655
656 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetConstructTrap) {
657 ASSERT(args.length() == 1);
658 CONVERT_CHECKED(JSFunctionProxy, proxy, args[0]);
659 return proxy->construct_trap();
660 }
661
662
629 RUNTIME_FUNCTION(MaybeObject*, Runtime_Fix) { 663 RUNTIME_FUNCTION(MaybeObject*, Runtime_Fix) {
630 ASSERT(args.length() == 1); 664 ASSERT(args.length() == 1);
631 CONVERT_CHECKED(JSProxy, proxy, args[0]); 665 CONVERT_CHECKED(JSProxy, proxy, args[0]);
632 proxy->Fix(); 666 proxy->Fix();
633 return isolate->heap()->undefined_value(); 667 return isolate->heap()->undefined_value();
634 } 668 }
635 669
636 670
637 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakMapInitialize) { 671 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakMapInitialize) {
638 HandleScope scope(isolate); 672 HandleScope scope(isolate);
(...skipping 4214 matching lines...) Expand 10 before | Expand all | Expand 10 after
4853 return isolate->heap()->boolean_symbol(); 4887 return isolate->heap()->boolean_symbol();
4854 } 4888 }
4855 if (heap_obj->IsNull()) { 4889 if (heap_obj->IsNull()) {
4856 return FLAG_harmony_typeof 4890 return FLAG_harmony_typeof
4857 ? isolate->heap()->null_symbol() 4891 ? isolate->heap()->null_symbol()
4858 : isolate->heap()->object_symbol(); 4892 : isolate->heap()->object_symbol();
4859 } 4893 }
4860 ASSERT(heap_obj->IsUndefined()); 4894 ASSERT(heap_obj->IsUndefined());
4861 return isolate->heap()->undefined_symbol(); 4895 return isolate->heap()->undefined_symbol();
4862 case JS_FUNCTION_TYPE: 4896 case JS_FUNCTION_TYPE:
4897 case JS_FUNCTION_PROXY_TYPE:
4863 return isolate->heap()->function_symbol(); 4898 return isolate->heap()->function_symbol();
4864 default: 4899 default:
4865 // For any kind of object not handled above, the spec rule for 4900 // For any kind of object not handled above, the spec rule for
4866 // host objects gives that it is okay to return "object" 4901 // host objects gives that it is okay to return "object"
4867 return isolate->heap()->object_symbol(); 4902 return isolate->heap()->object_symbol();
4868 } 4903 }
4869 } 4904 }
4870 4905
4871 4906
4872 static bool AreDigits(const char*s, int from, int to) { 4907 static bool AreDigits(const char*s, int from, int to) {
(...skipping 3332 matching lines...) Expand 10 before | Expand all | Expand 10 after
8205 return Smi::FromInt(ast_id); 8240 return Smi::FromInt(ast_id);
8206 } else { 8241 } else {
8207 if (function->IsMarkedForLazyRecompilation()) { 8242 if (function->IsMarkedForLazyRecompilation()) {
8208 function->ReplaceCode(function->shared()->code()); 8243 function->ReplaceCode(function->shared()->code());
8209 } 8244 }
8210 return Smi::FromInt(-1); 8245 return Smi::FromInt(-1);
8211 } 8246 }
8212 } 8247 }
8213 8248
8214 8249
8250 RUNTIME_FUNCTION(MaybeObject*, Runtime_Apply) {
8251 HandleScope scope(isolate);
8252 ASSERT(args.length() == 5);
8253 CONVERT_CHECKED(JSReceiver, fun, args[0]);
8254 Object* receiver = args[1];
8255 CONVERT_CHECKED(JSObject, arguments, args[2]);
8256 CONVERT_CHECKED(Smi, shift, args[3]);
8257 CONVERT_CHECKED(Smi, arity, args[4]);
8258
8259 int offset = shift->value();
8260 int argc = arity->value();
8261 ASSERT(offset >= 0);
8262 ASSERT(argc >= 0);
8263
8264 // If there are too many arguments, allocate argv via malloc.
8265 const int argv_small_size = 10;
8266 Handle<Object> argv_small_buffer[argv_small_size];
8267 SmartPointer<Handle<Object> > argv_large_buffer;
8268 Handle<Object>* argv = argv_small_buffer;
8269 if (argc > argv_small_size) {
8270 argv = new Handle<Object>[argc];
8271 if (argv == NULL) return isolate->StackOverflow();
8272 argv_large_buffer = SmartPointer<Handle<Object> >(argv);
8273 }
8274
8275 for (int i = 0; i < argc; ++i) {
8276 MaybeObject* maybe = arguments->GetElement(offset + i);
8277 Object* object;
8278 if (!maybe->To<Object>(&object)) return maybe;
8279 argv[i] = Handle<Object>(object);
8280 }
8281
8282 bool threw = false;
8283 Handle<JSReceiver> hfun(fun);
8284 Handle<Object> hreceiver(receiver);
8285 Handle<Object> result = Execution::Call(
8286 hfun, hreceiver, argc, reinterpret_cast<Object***>(argv), &threw, true);
8287
8288 if (threw) return Failure::Exception();
8289 return *result;
8290 }
8291
8292
8215 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetFunctionDelegate) { 8293 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetFunctionDelegate) {
8216 HandleScope scope(isolate); 8294 HandleScope scope(isolate);
8217 ASSERT(args.length() == 1); 8295 ASSERT(args.length() == 1);
8218 RUNTIME_ASSERT(!args[0]->IsJSFunction()); 8296 RUNTIME_ASSERT(!args[0]->IsJSFunction());
8219 return *Execution::GetFunctionDelegate(args.at<Object>(0)); 8297 return *Execution::GetFunctionDelegate(args.at<Object>(0));
8220 } 8298 }
8221 8299
8222 8300
8223 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetConstructorDelegate) { 8301 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetConstructorDelegate) {
8224 HandleScope scope(isolate); 8302 HandleScope scope(isolate);
(...skipping 4614 matching lines...) Expand 10 before | Expand all | Expand 10 after
12839 } else { 12917 } else {
12840 // Handle last resort GC and make sure to allow future allocations 12918 // Handle last resort GC and make sure to allow future allocations
12841 // to grow the heap without causing GCs (if possible). 12919 // to grow the heap without causing GCs (if possible).
12842 isolate->counters()->gc_last_resort_from_js()->Increment(); 12920 isolate->counters()->gc_last_resort_from_js()->Increment();
12843 isolate->heap()->CollectAllGarbage(false); 12921 isolate->heap()->CollectAllGarbage(false);
12844 } 12922 }
12845 } 12923 }
12846 12924
12847 12925
12848 } } // namespace v8::internal 12926 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | src/runtime.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698