Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

22 views
Skip to first unread message

msami

unread,
Aug 20, 2019, 8:18:18 AM8/20/19
to

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





Jason Orendorff

unread,
Aug 20, 2019, 9:23:37 AM8/20/19
to msami, dev-tech-...@lists.mozilla.org
On Tue, Aug 20, 2019 at 7:20 AM msami <muhamma...@gmail.com> 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

msami

unread,
Aug 21, 2019, 4:48:16 AM8/21/19
to
> 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.

msami

unread,
Aug 21, 2019, 9:36:28 AM8/21/19
to
is there is a way to print JSObject

Jason Orendorff

unread,
Aug 21, 2019, 4:04:55 PM8/21/19
to msami, dev-tech-...@lists.mozilla.org
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 <muhamma...@gmail.com> wrote:

> is there is a way to print JSObject
> _______________________________________________
> dev-tech-js-engine mailing list
> dev-tech-...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-tech-js-engine
>
0 new messages