Bug 93488 - [V8] IDL static attributes doesn't work in V8
Summary: [V8] IDL static attributes doesn't work in V8
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Kentaro Hara
URL:
Keywords:
: 108011 108198 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-08-08 08:38 PDT by Kentaro Hara
Modified: 2014-12-16 00:48 PST (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kentaro Hara 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
Comment 1 Kentaro Hara 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()?
Comment 2 Kentaro Hara 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?
Comment 3 Erik Arvidsson 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.
Comment 4 Kentaro Hara 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
Comment 5 jochen 2013-01-26 12:55:55 PST
*** Bug 108011 has been marked as a duplicate of this bug. ***
Comment 6 jochen 2013-02-02 00:46:33 PST
*** Bug 108198 has been marked as a duplicate of this bug. ***
Comment 7 Brian Burg 2014-12-16 00:48:05 PST
Closing some V8-related work items.