Hi Zhe.

I'm developing an application which uses webkit's JavaScriptCore and a customized global object (by providing a special class when creating the context). My customized global object provides some built-in properties that can be accessed by javascript code. Now, I want to support a special behavior: allows javascript code to override a built-in property of global object by using variable declaraction statement. For example, assuming the global object has a built-in property, named "foo", a "var foo;" statement shall create a javascript variable, named "foo" and the original built-in "foo" shall be overrid by this new javascript variable. But if there is no "var foo;" statement, the built-in foo shall be able to get and set from javascript code.

Now the problem is, current JavaScriptCore's C API (especially those HasProperty, GetProperty, SetProperty callbacks of a class definition) can't distinguish variable delcaration statement and variable assigment statement. I checked SpiderMonkey's API and found it can distinguish such things by providing a flag when calling ResolveProperty callback.

I'm surprised to hear that SpiderMonkey's property setting API includes a flag distinguishing var declarations from other kinds of property setting. Internet Explorer supports shadowing global properties with var declarations, but Firefox does not. (Perhaps you're thinking of the SpiderMonkey flag to distinguish "x = y" syntax from "this.x = y" syntax, which is slightly different.)

It may not be my place, but I would discourage you from giving var declarations a special behavior, distinct from their behavior on the web. Much of the value of JavaScript derives from the fact that so many programmers understand how it works, due to their experience with the web.

Do you have any idea on this issue? How can I implement such behavior based on current API?

There is no API in JavaScriptCore for distinguishing between "var" and other property setting. I'm not sure how you would implement that.

Geoff
_______________________________________________
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev

Reply via email to