[webkit-dev] nested scopes

Henrique Bastos henrique at bastos.net
Wed Feb 25 04:47:01 PST 2009


On 24/02/2009, at 14:33, Darin Adler wrote:

> On Feb 24, 2009, at 5:18 AM, Raj Kiran Talusani wrote:
>
>> I am developing a wrapper API on top of JavaScriptCore for  
>> integration with my application.
>>
>> Here is an overview of my API.
>>
>> In my application scripts are executed and variables are defined in  
>> different scopes. This example shows the functionality needed.
>>
>> js_init(); - initialize
>> js_set_var("abc","2"); - set abc=2 in global scope
>> js_push_scope(); - create a new scope
>> js_set_var("abc","4"); - set abc=4 in new scope
>> js_print_var("abc"); - should print 4 as we are in new scope
>> js_pop_scope(); - pop most recent scope. i,e. the new scope
>> js_print_var("abc"); - Now it should print 2 because we are back to  
>> global scope.
>>
>> My question is what should i be doing in js_push_scope and  
>> js_pop_scope so that a new JavaScript scope is created and destroyed.
>
> If you are wrapping JavaScriptCore you should use the public API,  
> not the internals. The public API is in headers like JSBase.h,  
> JSValueRef.h, JSObjectRef.h, and JSClassRef.h. However, the public  
> API doesn't have any concept of explicitly creating scopes; instead  
> scopes are created by the engine automatically for the various  
> language constructs that require them. An explicit way to create a  
> scope doesn't seem to be necessary API for use of the engine, and  
> there are other reasons not to add it — different scopes have  
> different semantics in the language. I'm assuming this requirement  
> is baggage from whatever engine previously implemented this  
> js_push_scope API.

I don't know much about your project. Assuming that you need a general  
purpose scripting language, this can be done easily with Lua. http://www.lua.org/manual/5.1/manual.html#lua_State

Regards,
--
Henrique Bastos
henrique at bastos.net
http://henriquebastos.net
+55 21 9618-6180


More information about the webkit-dev mailing list