How to defineObject with name, proto and parent (spidermonkey 60)

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to defineObject with name, proto and parent (spidermonkey 60)

msami

JSObject * JS_New(JSContext *cx, JS::HandleObject ctor, const JS::HandleValueArray& args);
#just like new object();


JSObject *
JS_DefineObject(JSContext *cx, JS::HandleObject obj, const char *name,
                const JSClass *clasp = nullptr, unsigned attrs = 0);
#can access by evaluate but no properties

JS_NewObjectWithGivenProto

# can't access by evaluate


I want to define JSObject* on context and access it as if I evaluated script like that var object1={ x:1,y:5};

any help or readings will be most appreciated

Thanks on advance




 
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine
Reply | Threaded
Open this post in threaded view
|

Re: How to defineObject with name, proto and parent (spidermonkey 60)

Jason Orendorff-2
On Tue, Aug 20, 2019 at 7:20 AM msami <[hidden email]> wrote:

> I want to define JSObject* on context and access it as if I evaluated
> script like that var object1={ x:1,y:5};
>

Create the object with JS_NewObject(cx, null), store it in a local
JS::RootedObject variable, define each property on it, then define a
property named "object1" on the global.

I don't know a more convenient way.

-j
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine
Reply | Threaded
Open this post in threaded view
|

Re: How to defineObject with name, proto and parent (spidermonkey 60)

msami
> Create the object with JS_NewObject(cx, null), store it in a local
> JS::RootedObject variable, define each property on it, then define a
> property named "object1" on the global.
>
> I don't know a more convenient way.
>
> -j

Thanks, sir that worked perfectly.
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine
Reply | Threaded
Open this post in threaded view
|

Re: How to defineObject with name, proto and parent (spidermonkey 60)

msami
In reply to this post by msami
is there is a way to print JSObject
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine
Reply | Threaded
Open this post in threaded view
|

Re: How to defineObject with name, proto and parent (spidermonkey 60)

Jason Orendorff-2
Here's what the repl does:
https://searchfox.org/mozilla-central/rev/03853a6e87c4a9405fce1de49e5d03b9e7a7a274/js/src/shell/js.cpp#1298-1308

-j

On Wed, Aug 21, 2019 at 8:40 AM msami <[hidden email]> wrote:

> is there is a way to print JSObject
> _______________________________________________
> dev-tech-js-engine mailing list
> [hidden email]
> https://lists.mozilla.org/listinfo/dev-tech-js-engine
>
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine