If objects/values can be shared throughout a runtime, why do we need to supply a JSContext reference to create them? #1238
-
|
quickjs/docs/docs/developer-guide/intro.md Lines 10 to 21 in ca0d50d This implies I can pass objects around within the same Why then have a signature like this: Wouldn't this make more sense: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
For primitives, yes; or rather, it doesn't matter. For objects, no. For consistency, everything takes a pointer to JSContext, also because otherwise you get inconsistencies like: JSValue JS_NewBool(JSRuntime *rt, bool val);Vs. JSValue JS_ToBool(JSRuntime *ctx, JSValueConst val);The latter needs JSContext because the ToBool operation can invoke JS code. |
Beta Was this translation helpful? Give feedback.
For primitives, yes; or rather, it doesn't matter.
For objects, no.
objectFromAnotherContext instanceof Objectis false because each JSContext has its own copy of the standard global objects like Object, Array, Date, etc.For consistency, everything takes a pointer to JSContext, also because otherwise you get inconsistencies like:
Vs.
The latter needs JSContext because the ToBool operation can invoke JS code.