Bug 93488
Summary: | [V8] IDL static attributes doesn't work in V8 | ||
---|---|---|---|
Product: | WebKit | Reporter: | Kentaro Hara <haraken> |
Component: | WebCore JavaScript | Assignee: | Kentaro Hara <haraken> |
Status: | RESOLVED INVALID | ||
Severity: | Normal | CC: | abarth, arv, jaffathecake, jochen, jonlee, mike |
Priority: | P2 | ||
Version: | 528+ (Nightly build) | ||
Hardware: | Unspecified | ||
OS: | Unspecified |
Kentaro Hara
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 | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Kentaro Hara
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
(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
(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
(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
*** Bug 108011 has been marked as a duplicate of this bug. ***
jochen
*** Bug 108198 has been marked as a duplicate of this bug. ***
Brian Burg
Closing some V8-related work items.