本文整理汇总了C++中JS_NewRuntime函数的典型用法代码示例。如果您正苦于以下问题:C++ JS_NewRuntime函数的具体用法?C++ JS_NewRuntime怎么用?C++ JS_NewRuntime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JS_NewRuntime函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createRuntime
virtual JSRuntime * createRuntime() {
JSRuntime *rt = JS_NewRuntime(768 * 1024, JS_USE_HELPER_THREADS);
if (!rt)
return nullptr;
setNativeStackQuota(rt);
return rt;
}
示例2: INDENT_LOG
void TraceMonkeyEngine::init()
{
Logging::log(Logging::DEBUG, "TraceMonkeyEngine::init\r\n");
INDENT_LOG(Logging::DEBUG);
assert(runtime == NULL);
runtime = JS_NewRuntime(8L * 1024L * 1024L); // Force GC after X MB.
if (runtime == NULL)
{
Logging::log(Logging::ERROR, "Cannot create TraceMonkey runtime\r\n");
assert(0);
}
/* Create a context. */
context = JS_NewContext(runtime, 8192);
if (context == NULL)
{
Logging::log(Logging::ERROR, "Cannot create TraceMonkey runtime\r\n");
assert(0);
}
JS_SetOptions(context, JSOPTION_VAROBJFIX);
JS_SetVersion(context, JSVERSION_ECMA_3);
JS_SetErrorReporter(context, reportError);
// Create the global object. Store it locally for a while until it is usable by others
JSObject* _global = JS_NewObject(context, &global_class, NULL, NULL);
if (_global == NULL)
{
Logging::log(Logging::ERROR, "Cannot create TraceMonkey runtime\r\n");
assert(0);
}
/* Populate the global object with the standard globals,
like Object and Array. */
if (!JS_InitStandardClasses(context, _global))
{
Logging::log(Logging::ERROR, "Cannot create TraceMonkey runtime\r\n");
assert(0);
}
// Create our internal wrappers
globalValue = ScriptValuePtr(new TraceMonkeyValue( this, true, OBJECT_TO_JSVAL(_global) ));
global = _global; // Now that globalValue is set, it is usable by others, so reveal it
// JITting
// JS_ToggleOptions(context, JSOPTION_JIT); // Might be buggy, wait for 1.8 to release
// JS_MaybeGC - call during idle time in the main loop? Or other method?
// Use JS_SetContextPrivate and JS_GetContextPrivate to associate application-specific data with a context.
// - Useful for security checks, once we have a context for the system and sandboxed contexts
// for user scripts
// Debugging features
JS_SetGCZeal(context, 2); // XXX This is 'extremely high' - make a parameter, see MDC docs
}
示例3: JS_NewRuntime
JSInterpreter::JSInterpreter() {
/* Create a JS runtime. You always need at least one runtime per process. */
rt = JS_NewRuntime(8 * 1024 * 1024);
if (rt == NULL)
throw * new std::runtime_error("Can't create JS runtime.");
/*
* Create a context. You always need a context per thread.
* Note that this program is not multi-threaded.
*/
cx = JS_NewContext(rt, 8192);
if (cx == NULL)
throw * new std::runtime_error("Can't create js context.");
JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT);
JS_SetVersion(cx, JSVERSION_LATEST);
JS_SetErrorReporter(cx, reportError);
/*
* Create the global object in a new compartment.
* You always need a global object per context.
*/
global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL);
if (global == NULL)
throw * new std::runtime_error("Can't create global object.");
/*
* Populate the global object with the standard JavaScript
* function and object classes, such as Object, Array, Date.
*/
if (!JS_InitStandardClasses(cx, global))
throw * new std::runtime_error("Can't initialise standard classes.");
}
示例4: round_js_sm_engine_init
bool round_js_sm_engine_init(RoundJavaScriptEngine* engine)
{
if (!engine)
return NULL;
JS_SetCStringsAreUTF8();
engine->cx = NULL;
engine->rt = NULL;
engine->obj = NULL;
engine->rt = JS_NewRuntime(8L * 1024L * 1024L);
if (!engine->rt)
return false;
engine->cx = JS_NewContext(engine->rt, 8192);
if (!engine->cx)
return false;
JS_SetErrorReporter(engine->cx, RoundJSReportError);
// Obsolete since JSAPI 16
engine->obj = JS_NewCompartmentAndGlobalObject(engine->cx, &RoundJSGlobalClass, NULL);
if (!engine->obj)
return false;
JS_InitStandardClasses(engine->cx, engine->obj);
JS_DefineFunctions(engine->cx, engine->obj, JS_SM_FUNCTIONS);
return true;
}
示例5: js_init
static int
js_init(void)
{
JSContext *cx;
JS_SetCStringsAreUTF8();
runtime = JS_NewRuntime(0x1000000);
cx = js_newctx(err_reporter);
JS_BeginRequest(cx);
showtimeobj = JS_NewObject(cx, &showtime_class, NULL, NULL);
JS_DefineFunctions(cx, showtimeobj, showtime_functions);
JSFunction *fn = JS_DefineFunction(cx, showtimeobj, "RichText",
js_RichText, 1, 0);
RichText = JS_GetFunctionObject(fn);
JS_AddNamedRoot(cx, &showtimeobj, "showtime");
JS_EndRequest(cx);
JS_DestroyContext(cx);
return 0;
}
示例6: main
int main(int argc, const char *argv[]) {
/* Initialize the JS engine -- new/required as of SpiderMonkey 31. */
/*if (!JS_Init())
return 1;*/
/* Create a JS runtime. */
JSRuntime *rt = JS_NewRuntime(8L * 1024L * 1024L, JS_NO_HELPER_THREADS);
if (!rt)
return 1;
/* Create a context. */
JSContext *cx = JS_NewContext(rt, 8192);
if (!cx)
return 1;
JS_SetOptions(cx, JSOPTION_VAROBJFIX);
JS_SetErrorReporter(cx, reportError);
int status = run(cx);
JS_DestroyContext(cx);
JS_DestroyRuntime(rt);
/* Shut down the JS engine. */
JS_ShutDown();
return status;
}
示例7: ejs_alloc
spidermonkey_vm *sm_initialize(long thread_stack, long heap_size) {
spidermonkey_vm *vm = ejs_alloc(sizeof(spidermonkey_vm));
spidermonkey_state *state = ejs_alloc(sizeof(spidermonkey_state));
state->branch_count = 0;
state->error = NULL;
state->terminate = 0;
int gc_size = (int) heap_size * 0.25;
vm->runtime = JS_NewRuntime(MAX_GC_SIZE);
JS_SetGCParameter(vm->runtime, JSGC_MAX_BYTES, heap_size);
JS_SetGCParameter(vm->runtime, JSGC_MAX_MALLOC_BYTES, gc_size);
vm->context = JS_NewContext(vm->runtime, 8192);
JS_SetScriptStackQuota(vm->context, thread_stack);
begin_request(vm);
JS_SetOptions(vm->context, JSOPTION_VAROBJFIX);
JS_SetOptions(vm->context, JSOPTION_STRICT);
JS_SetOptions(vm->context, JSOPTION_COMPILE_N_GO);
JS_SetOptions(vm->context, JSVERSION_LATEST);
vm->global = JS_NewCompartmentAndGlobalObject(vm->context, &global_class, NULL);
JS_InitStandardClasses(vm->context, vm->global);
JS_SetErrorReporter(vm->context, on_error);
JS_SetOperationCallback(vm->context, on_branch);
JS_SetContextPrivate(vm->context, state);
JSNative funptr = (JSNative) &js_log;
JS_DefineFunction(vm->context, JS_GetGlobalObject(vm->context), "ejsLog", funptr,
0, 0);
end_request(vm);
return vm;
}
示例8: Runtime_new
PyObject*
Runtime_new(PyTypeObject* type, PyObject* args, PyObject* kwargs)
{
Runtime* self = NULL;
unsigned int stacksize = 0x2000000; // 32 MiB heap size.
if (!PyArg_ParseTuple(args, "|I", &stacksize)) goto error;
#ifdef SPIDERMONKEY_31
if (!JS_Init())
{
PyErr_SetString(JSError, "Failed to initilaize JS engine");
goto error;
}
#endif
self = (Runtime*) type->tp_alloc(type, 0);
if(self == NULL) goto error;
self->rt = JS_NewRuntime(stacksize, JS_NO_HELPER_THREADS);
if(self->rt == NULL)
{
PyErr_SetString(JSError, "Failed to allocate new JSRuntime.");
goto error;
}
goto success;
error:
Py_XDECREF(self);
self = NULL;
success:
return (PyObject*) self;
}
示例9: js_init
static int
js_init(void)
{
JSContext *cx;
jsval val;
JS_SetCStringsAreUTF8();
runtime = JS_NewRuntime(0x1000000);
cx = js_newctx(err_reporter);
JS_BeginRequest(cx);
showtimeobj = JS_NewObject(cx, &showtime_class, NULL, NULL);
JS_DefineFunctions(cx, showtimeobj, showtime_functions);
val = INT_TO_JSVAL(showtime_get_version_int());
JS_SetProperty(cx, showtimeobj, "currentVersionInt", &val);
val = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, htsversion));
JS_SetProperty(cx, showtimeobj, "currentVersionString", &val);
JSFunction *fn = JS_DefineFunction(cx, showtimeobj, "RichText",
js_RichText, 1, 0);
RichText = JS_GetFunctionObject(fn);
JS_AddNamedRoot(cx, &showtimeobj, "showtime");
JS_EndRequest(cx);
JS_DestroyContext(cx);
return 0;
}
示例10: theMain
int theMain(int argc, char **argv){
obj.screenLog = TEMP_EN_LOG; //initially disable logging to screen.
//Define the quit handler;
signal(SIGTERM,exitHandle);
initSDL();
//JS_Init(); //SETUP SPIDERMONKEY -> NEW VERSION!!
if(!(runtime = JS_NewRuntime(8L *1024*1024L * 8,JS_USE_HELPER_THREADS /*JS_NO_HELPER_THREADS*/ ))){
fprint(stderr,"Could not setup runtime\n");
exit(EXIT_FAILURE);
}
init_video_libraries(&argc,&argv);
while(1){
char *appPath = NULL;
appPath = launchApp(MENU_SCRIPT,1);
if(appPath == NULL)
continue;
loadApp(appPath);
}
return EXIT_SUCCESS;
}
示例11: main
int
main (int argc, char *argv[])
{
JSRuntime *rt;
JSObject *glob;
int number_failed;
Suite *s;
SRunner *sr;
g_type_init ();
rt = JS_NewRuntime(0x100000);
cx = JS_NewContext(rt, 0x1000);
/* create the global object here */
glob = JS_NewObject(cx, NULL, NULL, NULL);
JS_InitStandardClasses(cx, glob);
s = gom_value_suite ();
sr = srunner_create (s);
srunner_run_all (sr, CK_NORMAL);
number_failed = srunner_ntests_failed (sr);
srunner_free (sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
示例12: main
int main(int argc, const char *argv[]) {
/* JS variables. */
JSRuntime *rt;
JSContext *cx;
JSObject *global;
/* Create a JS runtime. */
rt = JS_NewRuntime(8L * 1024L * 1024L,JS_NO_HELPER_THREADS);
if (rt == NULL)
return 1;
/* Create a context. */
cx = JS_NewContext(rt, 8192);
if (cx == NULL)
return 1;
JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_METHODJIT);
JS_SetVersion(cx, JSVERSION_LATEST);
JS_SetErrorReporter(cx, reportError);
/* Create the global object in a new compartment. */
global = JS_NewGlobalObject(cx, &global_class, NULL);
if (global == NULL)
return 1;
/* Populate the global object with the standard globals, like Object and Array. */
if (!JS_InitStandardClasses(cx, global))
return 1;
/* Your application code here. This may include JSAPI calls
* to create your own custom JavaScript objects and to run scripts.
*
* The following example code creates a literal JavaScript script,
* evaluates it, and prints the result to stdout.
*
* Errors are conventionally saved in a JSBool variable named ok.
*/
JS_DefineFunction(cx,global,"print",&js_print,0,0);
// execJsFile(cx,"t.js");
// testObj(cx);
beforeTest(cx);
execJsFile(cx,"t4.js");
test(cx);
/* End of your application code */
/* Clean things up and shut down SpiderMonkey. */
JS_DestroyContext(cx);
JS_DestroyRuntime(rt);
JS_ShutDown();
return 0;
}
示例13: createRuntime
virtual JSRuntime * createRuntime() override
{
JSRuntime* rt = JS_NewRuntime(0);
if (!rt)
return nullptr;
JS_SetGCParameter(rt, JSGC_MAX_BYTES, (uint32_t)-1);
setNativeStackQuota(rt);
return rt;
}
示例14: JS_NewRuntime
bool Engine::init()
{
m_runtime = JS_NewRuntime(8L*1024L*1024L);
if ( m_runtime==NULL ) {
return false;
}
return true;
}
示例15: qq_js_init
qq_js_t* qq_js_init()
{
qq_js_t* h =(qq_js_t*) s_malloc0(sizeof(*h));
h->runtime = JS_NewRuntime(8L*1024L*1024L);
h->context = JS_NewContext(h->runtime, 8*1024);
JS_SetOptions(h->context, JSOPTION_VAROBJFIX);
JS_SetErrorReporter(h->context, report_error);
h->global = JS_NewCompartmentAndGlobalObject(h->context, &global_class, NULL);
JS_InitStandardClasses(h->context, h->global);
return h;
}