Problem with JS_CallFunctionName

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

Problem with JS_CallFunctionName

Török Zoltán
Hello,

Somehow I can't execute a function defined in JavaScript from C++.

I do this: (the context, the global object and the runtime initialized
properly)

--------------------------------------------------------
JS_ClearPendingException(m_js_ctx);

JSScript* l_script = JS_CompileScript(m_js_ctx, m_js_global, l_buffer,
strlen(l_buffer), NULL, 1);
if (l_script) {
  jsval retval;

  //
  // this cause an error: TypeError: undefined is not a function
  //
  if (!JS_CallFunctionName(m_js_ctx, m_js_global, "BDSGetObject", 0,
NULL, &retval))
    goto jsout;

  // ...
}
jsout:
  // ...

--------------------------------------------------------
The JavaScript looks like this:

function BDSGetObject()
{
  return "result";
}
_______________________________________________
mozilla-jseng mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-jseng
Reply | Threaded
Open this post in threaded view
|

Re: Problem with JS_CallFunctionName

Brian Dupras
> Somehow I can't execute a function defined in JavaScript ...

I'm new to SM, but what I found is that after compiling the script, I
have to execute it, even though it's only defining a function and has
no top-level statements.  I assume this is because functions are simply
objects, and compiling doesn't imply that objects get created.  So, ...

JS_CompileScrips(...)

JS_ExecuteScript(...)

JS_CallFunctionName(...)

As a new user, it'd be good for me to get confirmation that this is the
Right Way (tm) to do things.

_______________________________________________
mozilla-jseng mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-jseng
Reply | Threaded
Open this post in threaded view
|

Re: Problem with JS_CallFunctionName

torokze
Brian you are right.
Thanks

_______________________________________________
mozilla-jseng mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-jseng