daily pastebin goal
24%
SHARE
TWEET

Untitled

a guest Feb 18th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Simple JavaScritip with function call
  2.     const char* sinpelTest = "i = 2 + 3;nz = 5 + i;nfunction TestAdd(){return CppVal(z+2);}n TestAdd();";
  3.     test = sinpelTest;
  4.  
  5.     // Check the Java Script
  6.     if (JS_BufferIsCompilableUnit(
  7.                 cx, p_global,
  8.                 sinpelTest, strlen(sinpelTest)))
  9.     {
  10.  
  11.         CompileOptions opts(cx);
  12.  
  13.         JS::RootedValue rval(cx);
  14.         bool ok;
  15.         ok = false;
  16.         // run the java script and call the cpp function
  17.         ok = Evaluate(cx, opts, sinpelTest, strlen(sinpelTest), &rval);
  18.     }
  19.    
  20. // Create the Function Pointer
  21. bool CreateOperation(JS::MutableHandleFunction fp, JSContext* context,JS::RootedObject& hObj,std::string name, uint32_t parmCount, uint32_t parmAttribute)
  22. {
  23.     // JS::MutableHandleFunction should handle the GC issues
  24.     JSFunction* ret = JS_DefineFunction(context, hObj,
  25.                                   name.c_str(), JSTriesOperationHandler,  
  26.                                   parmCount, parmAttribute);
  27.     if (ret != nullptr )
  28.     {
  29.         fp.set(ret);
  30.     }
  31.  
  32.     return ret != NULL;
  33. }
  34.  
  35.    // calling CreateOperation
  36.     JS::RootedFunction fp (cx);
  37.     CreateOperation(&fp,cx,p_global,std::string("CppVal"), 1);
  38.  
  39.      // Simple JavaScritip with function call
  40.     const char* sinpelTest = "i = 2 + 3;nz = 5 + i;nfunction TestAdd(){return CppVal(z+2);}n TestAdd();";
  41.     test = sinpelTest;
  42.     if (JS_BufferIsCompilableUnit(
  43.                 cx, p_global,
  44.                 sinpelTest, strlen(sinpelTest)))
  45.     {
  46.  
  47.         CompileOptions opts(cx);
  48.  
  49.         JS::RootedValue rval(cx);
  50.  
  51.         bool ok;
  52.         ok = false;
  53.         // SEG Fault Why this happend?
  54.         ok = Evaluate(cx, opts, sinpelTest, strlen(sinpelTest), &rval);
  55.  
  56.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top