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

Side by Side Diff: src/api.cc

Issue 24920003: Function::Call and Object::CallAsFunction APIs should allow v8::Value as a receiver (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Add CallAsFunction Created 7 years, 2 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 3923 matching lines...) Expand 10 before | Expand all | Expand 10 after
3934 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3934 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3935 ON_BAILOUT(isolate, "v8::Object::IsCallable()", return false); 3935 ON_BAILOUT(isolate, "v8::Object::IsCallable()", return false);
3936 ENTER_V8(isolate); 3936 ENTER_V8(isolate);
3937 i::HandleScope scope(isolate); 3937 i::HandleScope scope(isolate);
3938 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); 3938 i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
3939 if (obj->IsJSFunction()) return true; 3939 if (obj->IsJSFunction()) return true;
3940 return i::Execution::GetFunctionDelegate(isolate, obj)->IsJSFunction(); 3940 return i::Execution::GetFunctionDelegate(isolate, obj)->IsJSFunction();
3941 } 3941 }
3942 3942
3943 3943
3944 Local<v8::Value> Object::CallAsFunction(v8::Handle<v8::Object> recv, 3944 Local<v8::Value> Object::CallAsFunction(v8::Handle<v8::Value> recv,
3945 int argc, 3945 int argc,
3946 v8::Handle<v8::Value> argv[]) { 3946 v8::Handle<v8::Value> argv[]) {
3947 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3947 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3948 ON_BAILOUT(isolate, "v8::Object::CallAsFunction()", 3948 ON_BAILOUT(isolate, "v8::Object::CallAsFunction()",
3949 return Local<v8::Value>()); 3949 return Local<v8::Value>());
3950 LOG_API(isolate, "Object::CallAsFunction"); 3950 LOG_API(isolate, "Object::CallAsFunction");
3951 ENTER_V8(isolate); 3951 ENTER_V8(isolate);
3952 i::Logger::TimerEventScope timer_scope( 3952 i::Logger::TimerEventScope timer_scope(
3953 isolate, i::Logger::TimerEventScope::v8_execute); 3953 isolate, i::Logger::TimerEventScope::v8_execute);
3954 i::HandleScope scope(isolate); 3954 i::HandleScope scope(isolate);
3955 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); 3955 i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
3956 i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); 3956 i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv);
3957 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); 3957 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
3958 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); 3958 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
3959 i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>(); 3959 i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>();
3960 if (obj->IsJSFunction()) { 3960 if (obj->IsJSFunction()) {
3961 fun = i::Handle<i::JSFunction>::cast(obj); 3961 fun = i::Handle<i::JSFunction>::cast(obj);
3962 } else { 3962 } else {
3963 EXCEPTION_PREAMBLE(isolate); 3963 EXCEPTION_PREAMBLE(isolate);
3964 i::Handle<i::Object> delegate = i::Execution::TryGetFunctionDelegate( 3964 i::Handle<i::Object> delegate = i::Execution::TryGetFunctionDelegate(
3965 isolate, obj, &has_pending_exception); 3965 isolate, obj, &has_pending_exception);
3966 EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); 3966 EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
3967 fun = i::Handle<i::JSFunction>::cast(delegate); 3967 fun = i::Handle<i::JSFunction>::cast(delegate);
3968 recv_obj = obj; 3968 recv_obj = obj;
3969 } 3969 }
3970 EXCEPTION_PREAMBLE(isolate); 3970 EXCEPTION_PREAMBLE(isolate);
3971 i::Handle<i::Object> returned = i::Execution::Call( 3971 i::Handle<i::Object> returned = i::Execution::Call(
3972 isolate, fun, recv_obj, argc, args, &has_pending_exception); 3972 isolate, fun, recv_obj, argc, args, &has_pending_exception, true);
3973 EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Value>()); 3973 EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Value>());
3974 return Utils::ToLocal(scope.CloseAndEscape(returned)); 3974 return Utils::ToLocal(scope.CloseAndEscape(returned));
3975 } 3975 }
3976 3976
3977 3977
3978 Local<v8::Value> Object::CallAsConstructor(int argc, 3978 Local<v8::Value> Object::CallAsConstructor(int argc,
3979 v8::Handle<v8::Value> argv[]) { 3979 v8::Handle<v8::Value> argv[]) {
3980 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3980 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3981 ON_BAILOUT(isolate, "v8::Object::CallAsConstructor()", 3981 ON_BAILOUT(isolate, "v8::Object::CallAsConstructor()",
3982 return Local<v8::Object>()); 3982 return Local<v8::Object>());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
4046 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); 4046 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
4047 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); 4047 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
4048 EXCEPTION_PREAMBLE(isolate); 4048 EXCEPTION_PREAMBLE(isolate);
4049 i::Handle<i::Object> returned = 4049 i::Handle<i::Object> returned =
4050 i::Execution::New(function, argc, args, &has_pending_exception); 4050 i::Execution::New(function, argc, args, &has_pending_exception);
4051 EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>()); 4051 EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>());
4052 return scope.Close(Utils::ToLocal(i::Handle<i::JSObject>::cast(returned))); 4052 return scope.Close(Utils::ToLocal(i::Handle<i::JSObject>::cast(returned)));
4053 } 4053 }
4054 4054
4055 4055
4056 Local<v8::Value> Function::Call(v8::Handle<v8::Object> recv, int argc, 4056 Local<v8::Value> Function::Call(v8::Handle<v8::Value> recv, int argc,
4057 v8::Handle<v8::Value> argv[]) { 4057 v8::Handle<v8::Value> argv[]) {
4058 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 4058 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
4059 ON_BAILOUT(isolate, "v8::Function::Call()", return Local<v8::Value>()); 4059 ON_BAILOUT(isolate, "v8::Function::Call()", return Local<v8::Value>());
4060 LOG_API(isolate, "Function::Call"); 4060 LOG_API(isolate, "Function::Call");
4061 ENTER_V8(isolate); 4061 ENTER_V8(isolate);
4062 i::Logger::TimerEventScope timer_scope( 4062 i::Logger::TimerEventScope timer_scope(
4063 isolate, i::Logger::TimerEventScope::v8_execute); 4063 isolate, i::Logger::TimerEventScope::v8_execute);
4064 i::Object* raw_result = NULL; 4064 i::Object* raw_result = NULL;
4065 { 4065 {
4066 i::HandleScope scope(isolate); 4066 i::HandleScope scope(isolate);
4067 i::Handle<i::JSFunction> fun = Utils::OpenHandle(this); 4067 i::Handle<i::JSFunction> fun = Utils::OpenHandle(this);
4068 i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); 4068 i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv);
4069 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); 4069 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
4070 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); 4070 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
4071 EXCEPTION_PREAMBLE(isolate); 4071 EXCEPTION_PREAMBLE(isolate);
4072 i::Handle<i::Object> returned = i::Execution::Call( 4072 i::Handle<i::Object> returned = i::Execution::Call(
4073 isolate, fun, recv_obj, argc, args, &has_pending_exception); 4073 isolate, fun, recv_obj, argc, args, &has_pending_exception, true);
4074 EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Object>()); 4074 EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Object>());
4075 raw_result = *returned; 4075 raw_result = *returned;
4076 } 4076 }
4077 i::Handle<i::Object> result(raw_result, isolate); 4077 i::Handle<i::Object> result(raw_result, isolate);
4078 return Utils::ToLocal(result); 4078 return Utils::ToLocal(result);
4079 } 4079 }
4080 4080
4081 4081
4082 void Function::SetName(v8::Handle<v8::String> name) { 4082 void Function::SetName(v8::Handle<v8::String> name) {
4083 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 4083 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
(...skipping 3496 matching lines...) Expand 10 before | Expand all | Expand 10 after
7580 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7580 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7581 Address callback_address = 7581 Address callback_address =
7582 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7582 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7583 VMState<EXTERNAL> state(isolate); 7583 VMState<EXTERNAL> state(isolate);
7584 ExternalCallbackScope call_scope(isolate, callback_address); 7584 ExternalCallbackScope call_scope(isolate, callback_address);
7585 callback(info); 7585 callback(info);
7586 } 7586 }
7587 7587
7588 7588
7589 } } // namespace v8::internal 7589 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | test/cctest/test-api.cc » ('j') | test/cctest/test-api.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698