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

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: 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
« no previous file with comments | « include/v8.h ('k') | test/cctest/test-api.cc » ('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 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 3918 matching lines...) Expand 10 before | Expand all | Expand 10 after
3929 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3929 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3930 ON_BAILOUT(isolate, "v8::Object::IsCallable()", return false); 3930 ON_BAILOUT(isolate, "v8::Object::IsCallable()", return false);
3931 ENTER_V8(isolate); 3931 ENTER_V8(isolate);
3932 i::HandleScope scope(isolate); 3932 i::HandleScope scope(isolate);
3933 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); 3933 i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
3934 if (obj->IsJSFunction()) return true; 3934 if (obj->IsJSFunction()) return true;
3935 return i::Execution::GetFunctionDelegate(isolate, obj)->IsJSFunction(); 3935 return i::Execution::GetFunctionDelegate(isolate, obj)->IsJSFunction();
3936 } 3936 }
3937 3937
3938 3938
3939 Local<v8::Value> Object::CallAsFunction(v8::Handle<v8::Object> recv, 3939 Local<v8::Value> Object::CallAsFunction(v8::Handle<v8::Value> recv,
3940 int argc, 3940 int argc,
3941 v8::Handle<v8::Value> argv[]) { 3941 v8::Handle<v8::Value> argv[]) {
3942 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3942 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3943 ON_BAILOUT(isolate, "v8::Object::CallAsFunction()", 3943 ON_BAILOUT(isolate, "v8::Object::CallAsFunction()",
3944 return Local<v8::Value>()); 3944 return Local<v8::Value>());
3945 LOG_API(isolate, "Object::CallAsFunction"); 3945 LOG_API(isolate, "Object::CallAsFunction");
3946 ENTER_V8(isolate); 3946 ENTER_V8(isolate);
3947 i::Logger::TimerEventScope timer_scope( 3947 i::Logger::TimerEventScope timer_scope(
3948 isolate, i::Logger::TimerEventScope::v8_execute); 3948 isolate, i::Logger::TimerEventScope::v8_execute);
3949 i::HandleScope scope(isolate); 3949 i::HandleScope scope(isolate);
3950 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); 3950 i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
3951 i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); 3951 i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv);
3952 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); 3952 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
3953 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); 3953 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
3954 i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>(); 3954 i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>();
3955 if (obj->IsJSFunction()) { 3955 if (obj->IsJSFunction()) {
3956 fun = i::Handle<i::JSFunction>::cast(obj); 3956 fun = i::Handle<i::JSFunction>::cast(obj);
3957 } else { 3957 } else {
3958 EXCEPTION_PREAMBLE(isolate); 3958 EXCEPTION_PREAMBLE(isolate);
3959 i::Handle<i::Object> delegate = i::Execution::TryGetFunctionDelegate( 3959 i::Handle<i::Object> delegate = i::Execution::TryGetFunctionDelegate(
3960 isolate, obj, &has_pending_exception); 3960 isolate, obj, &has_pending_exception);
3961 EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); 3961 EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
3962 fun = i::Handle<i::JSFunction>::cast(delegate); 3962 fun = i::Handle<i::JSFunction>::cast(delegate);
3963 recv_obj = obj; 3963 recv_obj = obj;
3964 } 3964 }
3965 EXCEPTION_PREAMBLE(isolate); 3965 EXCEPTION_PREAMBLE(isolate);
3966 i::Handle<i::Object> returned = i::Execution::Call( 3966 i::Handle<i::Object> returned = i::Execution::Call(
3967 isolate, fun, recv_obj, argc, args, &has_pending_exception); 3967 isolate, fun, recv_obj, argc, args, &has_pending_exception, true);
3968 EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Value>()); 3968 EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Value>());
3969 return Utils::ToLocal(scope.CloseAndEscape(returned)); 3969 return Utils::ToLocal(scope.CloseAndEscape(returned));
3970 } 3970 }
3971 3971
3972 3972
3973 Local<v8::Value> Object::CallAsConstructor(int argc, 3973 Local<v8::Value> Object::CallAsConstructor(int argc,
3974 v8::Handle<v8::Value> argv[]) { 3974 v8::Handle<v8::Value> argv[]) {
3975 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3975 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3976 ON_BAILOUT(isolate, "v8::Object::CallAsConstructor()", 3976 ON_BAILOUT(isolate, "v8::Object::CallAsConstructor()",
3977 return Local<v8::Object>()); 3977 return Local<v8::Object>());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
4041 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); 4041 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
4042 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); 4042 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
4043 EXCEPTION_PREAMBLE(isolate); 4043 EXCEPTION_PREAMBLE(isolate);
4044 i::Handle<i::Object> returned = 4044 i::Handle<i::Object> returned =
4045 i::Execution::New(function, argc, args, &has_pending_exception); 4045 i::Execution::New(function, argc, args, &has_pending_exception);
4046 EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>()); 4046 EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>());
4047 return scope.Close(Utils::ToLocal(i::Handle<i::JSObject>::cast(returned))); 4047 return scope.Close(Utils::ToLocal(i::Handle<i::JSObject>::cast(returned)));
4048 } 4048 }
4049 4049
4050 4050
4051 Local<v8::Value> Function::Call(v8::Handle<v8::Object> recv, int argc, 4051 Local<v8::Value> Function::Call(v8::Handle<v8::Value> recv, int argc,
4052 v8::Handle<v8::Value> argv[]) { 4052 v8::Handle<v8::Value> argv[]) {
4053 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 4053 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
4054 ON_BAILOUT(isolate, "v8::Function::Call()", return Local<v8::Value>()); 4054 ON_BAILOUT(isolate, "v8::Function::Call()", return Local<v8::Value>());
4055 LOG_API(isolate, "Function::Call"); 4055 LOG_API(isolate, "Function::Call");
4056 ENTER_V8(isolate); 4056 ENTER_V8(isolate);
4057 i::Logger::TimerEventScope timer_scope( 4057 i::Logger::TimerEventScope timer_scope(
4058 isolate, i::Logger::TimerEventScope::v8_execute); 4058 isolate, i::Logger::TimerEventScope::v8_execute);
4059 i::Object* raw_result = NULL; 4059 i::Object* raw_result = NULL;
4060 { 4060 {
4061 i::HandleScope scope(isolate); 4061 i::HandleScope scope(isolate);
4062 i::Handle<i::JSFunction> fun = Utils::OpenHandle(this); 4062 i::Handle<i::JSFunction> fun = Utils::OpenHandle(this);
4063 i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); 4063 i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv);
4064 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); 4064 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
4065 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); 4065 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
4066 EXCEPTION_PREAMBLE(isolate); 4066 EXCEPTION_PREAMBLE(isolate);
4067 i::Handle<i::Object> returned = i::Execution::Call( 4067 i::Handle<i::Object> returned = i::Execution::Call(
4068 isolate, fun, recv_obj, argc, args, &has_pending_exception); 4068 isolate, fun, recv_obj, argc, args, &has_pending_exception, true);
4069 EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Object>()); 4069 EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Object>());
4070 raw_result = *returned; 4070 raw_result = *returned;
4071 } 4071 }
4072 i::Handle<i::Object> result(raw_result, isolate); 4072 i::Handle<i::Object> result(raw_result, isolate);
4073 return Utils::ToLocal(result); 4073 return Utils::ToLocal(result);
4074 } 4074 }
4075 4075
4076 4076
4077 void Function::SetName(v8::Handle<v8::String> name) { 4077 void Function::SetName(v8::Handle<v8::String> name) {
4078 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 4078 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
(...skipping 3487 matching lines...) Expand 10 before | Expand all | Expand 10 after
7566 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7566 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7567 Address callback_address = 7567 Address callback_address =
7568 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7568 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7569 VMState<EXTERNAL> state(isolate); 7569 VMState<EXTERNAL> state(isolate);
7570 ExternalCallbackScope call_scope(isolate, callback_address); 7570 ExternalCallbackScope call_scope(isolate, callback_address);
7571 callback(info); 7571 callback(info);
7572 } 7572 }
7573 7573
7574 7574
7575 } } // namespace v8::internal 7575 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698