Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Simple JavaScritip with function call
- const char* sinpelTest = "i = 2 + 3;nz = 5 + i;nfunction TestAdd(){return CppVal(z+2);}n TestAdd();";
- test = sinpelTest;
- // Check the Java Script
- if (JS_BufferIsCompilableUnit(
- cx, p_global,
- sinpelTest, strlen(sinpelTest)))
- {
- CompileOptions opts(cx);
- JS::RootedValue rval(cx);
- bool ok;
- ok = false;
- // run the java script and call the cpp function
- ok = Evaluate(cx, opts, sinpelTest, strlen(sinpelTest), &rval);
- }
- // Create the Function Pointer
- bool CreateOperation(JS::MutableHandleFunction fp, JSContext* context,JS::RootedObject& hObj,std::string name, uint32_t parmCount, uint32_t parmAttribute)
- {
- // JS::MutableHandleFunction should handle the GC issues
- JSFunction* ret = JS_DefineFunction(context, hObj,
- name.c_str(), JSTriesOperationHandler,
- parmCount, parmAttribute);
- if (ret != nullptr )
- {
- fp.set(ret);
- }
- return ret != NULL;
- }
- // calling CreateOperation
- JS::RootedFunction fp (cx);
- CreateOperation(&fp,cx,p_global,std::string("CppVal"), 1);
- // Simple JavaScritip with function call
- const char* sinpelTest = "i = 2 + 3;nz = 5 + i;nfunction TestAdd(){return CppVal(z+2);}n TestAdd();";
- test = sinpelTest;
- if (JS_BufferIsCompilableUnit(
- cx, p_global,
- sinpelTest, strlen(sinpelTest)))
- {
- CompileOptions opts(cx);
- JS::RootedValue rval(cx);
- bool ok;
- ok = false;
- // SEG Fault Why this happend?
- ok = Evaluate(cx, opts, sinpelTest, strlen(sinpelTest), &rval);
- }
Add Comment
Please, Sign In to add comment