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

Unified Diff: src/api.cc

Issue 6902108: Implement CallAsConstructor method for Object in the API (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add exception handling and some new test cases Created 9 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 side-by-side diff with in-line comments
Download patch
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index c72857da644eedb55f4ce93002f73ef7e20b29bf..9b02b20a1d806b9f8e3c196242dab3abb3458c29 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -3286,6 +3286,38 @@ Local<v8::Value> Object::CallAsFunction(v8::Handle<v8::Object> recv, int argc,
}
+Local<v8::Object> Object::CallAsConstructor(
+ int argc,
+ v8::Handle<v8::Value> argv[]) const {
+ i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
+ ON_BAILOUT(isolate, "v8::Object::CallAsConstructor()",
+ return Local<v8::Object>());
+ LOG_API(isolate, "Object::CallAsConstructor");
+ ENTER_V8(isolate);
+ HandleScope scope;
Mads Ager (chromium) 2011/05/05 09:03:33 Use the isolate here.
+ i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
+ STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
+ i::Object*** args = reinterpret_cast<i::Object***>(argv);
+ i::Handle<i::Object> returned;
+ i::Handle<i::JSFunction> fun;
+ EXCEPTION_PREAMBLE(isolate);
+ if (obj->IsJSFunction()) {
+ fun = i::Handle<i::JSFunction>::cast(obj);
+ returned = i::Execution::New(fun, argc, args, &has_pending_exception);
+ EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>());
+ } else {
+ i::Handle<i::Object> delegate =
+ i::Execution::TryGetConstructorDelegate(obj, &has_pending_exception);
+ EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>());
+ fun = i::Handle<i::JSFunction>::cast(delegate);
+ returned =
+ i::Execution::Call(fun, obj, argc, args, &has_pending_exception);
+ EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>());
+ }
+ return scope.Close(Utils::ToLocal(i::Handle<i::JSObject>::cast(returned)));
Mads Ager (chromium) 2011/05/05 09:03:33 Let's remove the cast to JSObject here. The functi
+}
+
+
Local<v8::Object> Function::NewInstance() const {
return NewInstance(0, NULL);
}

Powered by Google App Engine
This is Rietveld 408576698