Add ObjectTemplate::New() taking FunctionTemplate.
I know the bug has been closed but this seems like a simple addition that may be useful in other ways as well. BUG=v8:2180 LOG=N Review URL: https://codereview.chromium.org/1128553002 Cr-Commit-Position: refs/heads/master@{#28261}
This commit is contained in:
parent
7798548a8f
commit
6618793e87
@ -4274,7 +4274,9 @@ struct IndexedPropertyHandlerConfiguration {
|
||||
class V8_EXPORT ObjectTemplate : public Template {
|
||||
public:
|
||||
/** Creates an ObjectTemplate. */
|
||||
static Local<ObjectTemplate> New(Isolate* isolate);
|
||||
static Local<ObjectTemplate> New(
|
||||
Isolate* isolate,
|
||||
Handle<FunctionTemplate> constructor = Handle<FunctionTemplate>());
|
||||
static V8_DEPRECATE_SOON("Use isolate version", Local<ObjectTemplate> New());
|
||||
|
||||
/** Creates a new instance of this template.*/
|
||||
|
@ -1198,8 +1198,9 @@ void FunctionTemplate::RemovePrototype() {
|
||||
// --- O b j e c t T e m p l a t e ---
|
||||
|
||||
|
||||
Local<ObjectTemplate> ObjectTemplate::New(Isolate* isolate) {
|
||||
return New(reinterpret_cast<i::Isolate*>(isolate), Local<FunctionTemplate>());
|
||||
Local<ObjectTemplate> ObjectTemplate::New(
|
||||
Isolate* isolate, v8::Handle<FunctionTemplate> constructor) {
|
||||
return New(reinterpret_cast<i::Isolate*>(isolate), constructor);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1782,17 +1782,22 @@ THREADED_TEST(GlobalPrototype) {
|
||||
THREADED_TEST(ObjectTemplate) {
|
||||
v8::Isolate* isolate = CcTest::isolate();
|
||||
v8::HandleScope scope(isolate);
|
||||
Local<ObjectTemplate> templ1 = ObjectTemplate::New(isolate);
|
||||
Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate);
|
||||
v8::Local<v8::String> class_name =
|
||||
v8::String::NewFromUtf8(isolate, "the_class_name");
|
||||
fun->SetClassName(class_name);
|
||||
Local<ObjectTemplate> templ1 = ObjectTemplate::New(isolate, fun);
|
||||
templ1->Set(isolate, "x", v8_num(10));
|
||||
templ1->Set(isolate, "y", v8_num(13));
|
||||
LocalContext env;
|
||||
Local<v8::Object> instance1 = templ1->NewInstance();
|
||||
CHECK(class_name->StrictEquals(instance1->GetConstructorName()));
|
||||
env->Global()->Set(v8_str("p"), instance1);
|
||||
CHECK(v8_compile("(p.x == 10)")->Run()->BooleanValue());
|
||||
CHECK(v8_compile("(p.y == 13)")->Run()->BooleanValue());
|
||||
Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate);
|
||||
fun->PrototypeTemplate()->Set(isolate, "nirk", v8_num(123));
|
||||
Local<ObjectTemplate> templ2 = fun->InstanceTemplate();
|
||||
Local<v8::FunctionTemplate> fun2 = v8::FunctionTemplate::New(isolate);
|
||||
fun2->PrototypeTemplate()->Set(isolate, "nirk", v8_num(123));
|
||||
Local<ObjectTemplate> templ2 = fun2->InstanceTemplate();
|
||||
templ2->Set(isolate, "a", v8_num(12));
|
||||
templ2->Set(isolate, "b", templ1);
|
||||
Local<v8::Object> instance2 = templ2->NewInstance();
|
||||
|
Loading…
Reference in New Issue
Block a user