RESOLVED INVALID 93488
[V8] IDL static attributes doesn't work in V8
https://bugs.webkit.org/show_bug.cgi?id=93488
Summary [V8] IDL static attributes doesn't work in V8
Kentaro Hara
Reported 2012-08-08 08:38:53 PDT
The implementation of IDL static attributes in CodeGeneratorV8.pm is wrong. Assume the following IDL: interface Notification { static attribute permission; }; Expected behavior: var n = new Notification("title"); n.permission; // TypeError Notification.permission; // "default" Actual behavior: var n = new Notification("title"); n.permission; // "default" Notification.permission; // TypeError
Attachments
Kentaro Hara
Comment 1 2012-08-09 05:09:41 PDT
abarth: I want to implement static attributes in V8. In my understanding, something like the following code should be generated: // Notification.idl interface Notification { static void requestPermission(); // Static method. This is already implemented. static attribute permission; // Static attribute. I want to implement this. }; // V8Notification.cpp static v8::Persistent<v8::FunctionTemplate> ConfigureV8NotificationTemplate(v8::Persistent<v8::FunctionTemplate> desc) { ...; // [A] The code the current CodeGenerator generates for static method. This code works fine. desc->Set(v8::String::New("requestPermission"), v8::FunctionTemplate::New(V8Notification::requestPermissionCallback, v8Undefined(), v8::Local<v8::Signature>())); ...; // [B] The code I want to generate for static attribute. desc->SetAccessor(v8::String::New("permission"), NotificationV8Internal::permissionAttrGetter, 0, v8::External::Wrap(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); ...; } However, [B] cannot be compiled because desc (i.e. FunctionTemplate) does not have SetAccessor(). In V8, SetAccessor() is defined on Object and ObjectTemplate only. I guess that static attributes should be defined on FunctionTemplate, which implies that we cannot implement static attributes unless V8 implements FunctionTemplate::SetAccessor(). Is my understanding correct? Would there be any way to implement static attributes without FunctionTemplate::SetAccessor()?
Kentaro Hara
Comment 2 2012-08-09 18:20:26 PDT
(In reply to comment #1) > Is my understanding correct? Would there be any way to implement static attributes without FunctionTemplate::SetAccessor()? arv: would you have any idea about this?
Erik Arvidsson
Comment 3 2012-08-09 18:47:47 PDT
(In reply to comment #2) > (In reply to comment #1) > > Is my understanding correct? Would there be any way to implement static attributes without FunctionTemplate::SetAccessor()? > > arv: would you have any idea about this? I think the right way to do this is to make FunctionTemplate extend ObjectTemplate in the V8 API since Functions are just callable objects. To work around this we could add the accessor when we create the real function object but that seems a bit strange. I've always found that the FunctionTemplate and ObjectTemplate does not match ES semantics very well and they lead to us having to do things in a backwards way.
Kentaro Hara
Comment 4 2012-08-09 19:02:40 PDT
(In reply to comment #3) > I think the right way to do this is to make FunctionTemplate extend ObjectTemplate in the V8 API since Functions are just callable objects. Sounds reasonable. I filed a bug to V8: http://code.google.com/p/v8/issues/detail?id=2281
jochen
Comment 5 2013-01-26 12:55:55 PST
*** Bug 108011 has been marked as a duplicate of this bug. ***
jochen
Comment 6 2013-02-02 00:46:33 PST
*** Bug 108198 has been marked as a duplicate of this bug. ***
Brian Burg
Comment 7 2014-12-16 00:48:05 PST
Closing some V8-related work items.
Note You need to log in before you can comment on or make changes to this bug.