Bug 93488 - [V8] IDL static attributes doesn't work in V8
: [V8] IDL static attributes doesn't work in V8
Status: NEW
: WebKit
WebCore JavaScript
: 528+ (Nightly build)
: Unspecified Unspecified
: P2 Normal
Assigned To:
:
:
:
:
  Show dependency treegraph
 
Reported: 2012-08-08 08:38 PST by
Modified: 2013-02-02 00:46 PST (History)


Attachments


Note

You need to log in before you can comment on or make changes to this bug.


Description From 2012-08-08 08:38:53 PST
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
------- Comment #1 From 2012-08-09 05:09:41 PST -------
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()?
------- Comment #2 From 2012-08-09 18:20:26 PST -------
(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?
------- Comment #3 From 2012-08-09 18:47:47 PST -------
(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.
------- Comment #4 From 2012-08-09 19:02:40 PST -------
(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
------- Comment #5 From 2013-01-26 12:55:55 PST -------
*** Bug 108011 has been marked as a duplicate of this bug. ***
------- Comment #6 From 2013-02-02 00:46:33 PST -------
*** Bug 108198 has been marked as a duplicate of this bug. ***