0

I saw example code on spider monkey site , JS_EvaluateScript always refer to global scope object , If I would like to create scope object which the parent is global scope , this will work ?

JS_EvaluateScript (cx , scope_obj, ... ) 

scope_1 ----has -- global object as parent
scope_2 ----has -- global object as parent as well

When I run

  JS_EvaluateScript(cx , scope_1 , "var scope1var = 'hello'"....)

it's fine...

And Then I run

  JS_EvaluateScript(cx , scope_2 , "scope1var +' world'"....)

it should has error because scope_2 doesn't have variable of scope_1.

but the result return as " hello world"

Please advise if I miss anything , sir

============================

Or could you please tell me how to implement when code is entering new scope ? Thank you.

Denny
  • 449
  • 4
  • 17

1 Answers1

0

As I found script with "var" snytax , the JS_EvaluateScript function will execute with global scope only

JS_EvaluateScript(cx , scope_1 , "var scope1var = 'hello'"....)

it declare variable as global scope / or just like run define Property of global scope with JSPROP_PERMANENT flag (so you can not run script "delete scope1var" )

JS_DefineProperty(cx,globalScop,...,JSPROP_PERMANENT)

Denny
  • 449
  • 4
  • 17