本文整理汇总了C++中Local::GetIsolate方法的典型用法代码示例。如果您正苦于以下问题:C++ Local::GetIsolate方法的具体用法?C++ Local::GetIsolate怎么用?C++ Local::GetIsolate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Local
的用法示例。
在下文中一共展示了Local::GetIsolate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Init
void Server::Init(Local<Context> ctx){
isolate = ctx->GetIsolate();
context.Reset(ctx->GetIsolate(), ctx);
ifstream serverFile("js/samp.js/Server.js", std::ios::in);
if (!serverFile){
sjs::logger::error("Missing required file Server.js");
SAMPJS::Shutdown();
}
std::string serverSource((std::istreambuf_iterator<char>(serverFile)), std::istreambuf_iterator<char>());
SAMPJS::ExecuteCode(ctx, "Server.js", serverSource);
SAMPJS::ExecuteCode(ctx, "$server", "var $server = new Server();");
JS_Object global(ctx->Global());
global.Set("CallNative", Server::JS_CallNative);
JS_Object server(global.getObject("$server"));
JS_Object memory(server.getObject("memory"));
memory.Set("current", Server::JS_CurrentMemory);
memory.Set("peak", Server::JS_PeakMemory);
server.Set("Debug", Utils::JS_Debug);
}
示例2: InitAll
void InitAll(Local<Object> exports) {
//intent::log::Logger::initialize(intent::log::Logger::SeverityLevel::TRACE);
intentjs::SerializableChatbot::Init(exports->GetIsolate());
NODE_SET_METHOD(exports, "createSerializableChatbotFromJsonModel", CreateSerializableChatbotFromJsonModel);
NODE_SET_METHOD(exports, "createSerializableChatbotFromOIML", CreateSerializableChatbotFromOIML);
}
示例3: tryCatch
/* static */
void V8Runtime::bootstrap(Local<Context> context)
{
Isolate* isolate = context->GetIsolate();
EventEmitter::initTemplate(context);
Local<Object> kroll = Object::New(isolate);
krollGlobalObject.Reset(isolate, kroll);
Local<Array> mc = Array::New(isolate);
moduleContexts.Reset(isolate, mc);
KrollBindings::initFunctions(kroll, context);
SetMethod(isolate, kroll, "log", krollLog);
// Move this into the EventEmitter::initTemplate call?
Local<FunctionTemplate> eect = Local<FunctionTemplate>::New(isolate, EventEmitter::constructorTemplate);
{
v8::TryCatch tryCatch(isolate);
Local<Function> eventEmitterConstructor;
MaybeLocal<Function> maybeEventEmitterConstructor = eect->GetFunction(context);
if (!maybeEventEmitterConstructor.ToLocal(&eventEmitterConstructor)) {
titanium::V8Util::fatalException(isolate, tryCatch);
return;
}
kroll->Set(NEW_SYMBOL(isolate, "EventEmitter"), eventEmitterConstructor);
}
kroll->Set(NEW_SYMBOL(isolate, "runtime"), STRING_NEW(isolate, "v8"));
kroll->Set(NEW_SYMBOL(isolate, "DBG"), v8::Boolean::New(isolate, V8Runtime::DBG));
kroll->Set(NEW_SYMBOL(isolate, "moduleContexts"), mc);
LOG_TIMER(TAG, "Executing kroll.js");
TryCatch tryCatch(isolate);
Local<Value> result = V8Util::executeString(isolate, KrollBindings::getMainSource(isolate), STRING_NEW(isolate, "ti:/kroll.js"));
if (tryCatch.HasCaught()) {
V8Util::reportException(isolate, tryCatch, true);
}
if (!result->IsFunction()) {
LOGF(TAG, "kroll.js result is not a function");
V8Util::reportException(isolate, tryCatch, true);
}
// Add a reference to the global object
Local<Object> global = context->Global();
// Expose the global object as a property on itself
// (Allows you to set stuff on `global` from anywhere in JavaScript.)
global->Set(NEW_SYMBOL(isolate, "global"), global);
Local<Function> mainFunction = result.As<Function>();
Local<Value> args[] = { kroll };
mainFunction->Call(context, global, 1, args);
if (tryCatch.HasCaught()) {
V8Util::reportException(isolate, tryCatch, true);
LOGE(TAG, "Caught exception while bootstrapping Kroll");
}
}
示例4:
shared_ptr<Server> Server::GetInstance(Local<Context> context){
sjs::logger::debug("Getting Instance");
Local<Object> self = Local<Object>::Cast(context->Global()->Get(STRING2JS(context->GetIsolate(), "$sampjs")));
Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
void* ptr = wrap->Value();
Server* server = static_cast<Server*>(ptr);
sjs::logger::debug("Casting");
return make_shared<Server>(*server);
}
示例5: Init
void ABPFilterParserWrap::Init(Local<Object> exports) {
Isolate* isolate = exports->GetIsolate();
// Prepare constructor template
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
tpl->SetClassName(String::NewFromUtf8(isolate, "ABPFilterParser"));
tpl->InstanceTemplate()->SetInternalFieldCount(1);
// Prototype
NODE_SET_PROTOTYPE_METHOD(tpl, "parse", ABPFilterParserWrap::Parse);
NODE_SET_PROTOTYPE_METHOD(tpl, "matches", ABPFilterParserWrap::Matches);
NODE_SET_PROTOTYPE_METHOD(tpl, "serialize", ABPFilterParserWrap::Serialize);
NODE_SET_PROTOTYPE_METHOD(tpl, "deserialize",
ABPFilterParserWrap::Deserialize);
NODE_SET_PROTOTYPE_METHOD(tpl, "cleanup", ABPFilterParserWrap::Cleanup);
Local<Object> filterOptions = Object::New(isolate);
filterOptions->Set(String::NewFromUtf8(isolate, "noFilterOption"),
Int32::New(isolate, 0));
filterOptions->Set(String::NewFromUtf8(isolate, "script"),
Int32::New(isolate, 01));
filterOptions->Set(String::NewFromUtf8(isolate, "image"),
Int32::New(isolate, 02));
filterOptions->Set(String::NewFromUtf8(isolate, "stylesheet"),
Int32::New(isolate, 04));
filterOptions->Set(String::NewFromUtf8(isolate, "object"),
Int32::New(isolate, 010));
filterOptions->Set(String::NewFromUtf8(isolate, "xmlHttpRequest"),
Int32::New(isolate, 020));
filterOptions->Set(String::NewFromUtf8(isolate, "objectSubrequest"),
Int32::New(isolate, 040));
filterOptions->Set(String::NewFromUtf8(isolate, "subdocument"),
Int32::New(isolate, 0100));
filterOptions->Set(String::NewFromUtf8(isolate, "document"),
Int32::New(isolate, 0200));
filterOptions->Set(String::NewFromUtf8(isolate, "other"),
Int32::New(isolate, 0400));
filterOptions->Set(String::NewFromUtf8(isolate, "xbl"),
Int32::New(isolate, 01000));
filterOptions->Set(String::NewFromUtf8(isolate, "collapse"),
Int32::New(isolate, 02000));
filterOptions->Set(String::NewFromUtf8(isolate, "doNotTrack"),
Int32::New(isolate, 04000));
filterOptions->Set(String::NewFromUtf8(isolate, "elemHide"),
Int32::New(isolate, 010000));
filterOptions->Set(String::NewFromUtf8(isolate, "thirdParty"),
Int32::New(isolate, 020000));
filterOptions->Set(String::NewFromUtf8(isolate, "notThirdParty"),
Int32::New(isolate, 040000));
constructor.Reset(isolate, tpl->GetFunction());
exports->Set(String::NewFromUtf8(isolate, "ABPFilterParser"),
tpl->GetFunction());
exports->Set(String::NewFromUtf8(isolate, "FilterOptions"), filterOptions);
}
示例6: Initialize
void Bus::Initialize(Local<Object> exports) {
Isolate* isolate = exports->GetIsolate();
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
tpl->InstanceTemplate()->SetInternalFieldCount(1);
tpl->SetClassName(String::NewFromUtf8(isolate, "Bus"));
NODE_SET_PROTOTYPE_METHOD(tpl, "watch", Watch);
constructor.Reset(isolate, tpl->GetFunction());
exports->Set(String::NewFromUtf8(isolate, "Bus"), tpl->GetFunction());
}
示例7: init
void init( Local<Object> exports )
/********************************/
{
uv_mutex_init(&api_mutex);
#if v012
Isolate *isolate = Isolate::GetCurrent();
#else
Isolate *isolate = exports->GetIsolate();
#endif
StmtObject::Init( isolate );
Connection::Init( isolate );
NODE_SET_METHOD( exports, "createConnection", Connection::NewInstance );
}
示例8: InitializeModule
void EModuleHelper::InitializeModule( Local< Object > target )
{
Isolate* isolate = target->GetIsolate( );
HandleScope scope( isolate );
NODE_SET_METHOD( target, "setWriteStreamInitializer", EModuleHelper::SetWriteStreamInitializer );
NODE_SET_METHOD( target, "setReadStreamInitializer", EModuleHelper::SetReadStreamInitializer );
NODE_SET_METHOD( target, "setPromiseInitializer", EModuleHelper::SetPromiseInitializer );
NODE_SET_METHOD( target, "setLogHandler", EModuleHelper::SetLogHandler );
NODE_SET_METHOD( target, "processNextChunk", EModuleHelper::ProcessNextChunk );
NODE_SET_METHOD( target, "requestNextChunk", EModuleHelper::RequestNextChunk );
}
示例9: isolate_scope
Local<Value> SAMPJS::ExecuteCode(Local<Context> context, string name, string code,int offset){
Isolate *isolate = context->GetIsolate();
Locker v8Locker(isolate);
Isolate::Scope isolate_scope(isolate);
HandleScope hs(isolate);
EscapableHandleScope handle_scope(isolate);
Local<Context> ctx = Local<Context>::New(isolate, context);
Context::Scope context_scope(ctx);
auto scriptname = String::NewFromUtf8(isolate, name.c_str());
ScriptOrigin origin(scriptname, Integer::New(isolate,offset));
/* if (strict){
code = "\"use strict\"\r\n" + code;
} */
auto source = String::NewFromUtf8(isolate, code.c_str());
TryCatch try_catch;
auto script = v8::Script::Compile(source, &origin);
if (script.IsEmpty()){
isolate->CancelTerminateExecution();
Utils::PrintException(&try_catch);
}
else {
try_catch.Reset();
Local<Value> result = script->Run();
if (try_catch.HasCaught()){
isolate->CancelTerminateExecution();
Utils::PrintException(&try_catch);
Local<Value> ret;
return ret;
}
return handle_scope.Escape(result);
}
return Local<Value>();
}
示例10: Main
void Main(Local<Object> exports)
{
Isolate *isolate = exports->GetIsolate();
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, constructor);
tpl->InstanceTemplate()->SetInternalFieldCount(1);
NODE_SET_PROTOTYPE_METHOD(tpl, "on", on);
NODE_SET_PROTOTYPE_METHOD(tpl, "send", send);
NODE_SET_PROTOTYPE_METHOD(tpl, "setUserData", setUserData);
NODE_SET_PROTOTYPE_METHOD(tpl, "getUserData", getUserData);
NODE_SET_PROTOTYPE_METHOD(tpl, "getFd", getFd);
exports->Set(String::NewFromUtf8(isolate, "Server"), tpl->GetFunction());
Local<ObjectTemplate> socketTemplate = ObjectTemplate::New(isolate);
socketTemplate->SetInternalFieldCount(2);
persistentSocket.Reset(isolate, socketTemplate->NewInstance());
}
示例11: Init
void MySQL::Init(Local<Context> ctx){
num_conns = 0;
isolate = ctx->GetIsolate();
V8CONTEXT(isolate, ctx);
context.Reset(isolate, ctx);
ifstream mysqlFile("js/samp.js/MySQL.js", std::ios::in);
if (!mysqlFile){
sjs::logger::error("Missing required file MySQL.js");
SAMPJS::Shutdown();
}
std::string mysqlSource((std::istreambuf_iterator<char>(mysqlFile)), std::istreambuf_iterator<char>());
SAMPJS::ExecuteCode(ctx, "MySQL.js", mysqlSource);
ifstream mysqlcFile("js/samp.js/MySQLConnection.js", std::ios::in);
if (!mysqlcFile){
sjs::logger::error("Missing required file MySQLConnection.js");
SAMPJS::Shutdown();
}
std::string mysqlcSource((std::istreambuf_iterator<char>(mysqlcFile)), std::istreambuf_iterator<char>());
SAMPJS::ExecuteCode(ctx, "MySQLConnection.js", mysqlcSource);
SAMPJS::ExecuteCode(ctx, "$mysql", "var $mysql = new MySQL();");
JS_Object global(ctx->Global());
JS_Object mysql(global.getObject("$mysql"));
auto mysql_tmpl = ObjectTemplate::New(isolate);
mysql_tmpl->SetInternalFieldCount(1);
auto mysqli = mysql_tmpl->NewInstance();
mysqli->SetInternalField(0, External::New(isolate, this));
JS_Object mysqlo(mysqli);
mysqlo.Set("createConnection", JS_New);
mysqlo.Set("escape", JS_Escape);
mysql.Set("internal", mysqlo.get());
}
示例12: tryCatch
/* static */
void V8Runtime::bootstrap(Local<Context> context)
{
Isolate* isolate = context->GetIsolate();
EventEmitter::initTemplate(context);
Local<Object> global = Object::New(isolate);
krollGlobalObject.Reset(isolate, global);
Local<Array> mc = Array::New(isolate);
moduleContexts.Reset(isolate, mc);
KrollBindings::initFunctions(global, context);
SetMethod(isolate, global, "log", krollLog);
// Move this into the EventEmitter::initTemplate call?
Local<FunctionTemplate> eect = Local<FunctionTemplate>::New(isolate, EventEmitter::constructorTemplate);
global->Set(NEW_SYMBOL(isolate, "EventEmitter"), eect->GetFunction());
global->Set(NEW_SYMBOL(isolate, "runtime"), STRING_NEW(isolate, "v8"));
global->Set(NEW_SYMBOL(isolate, "DBG"), v8::Boolean::New(isolate, V8Runtime::DBG));
global->Set(NEW_SYMBOL(isolate, "moduleContexts"), mc);
LOG_TIMER(TAG, "Executing kroll.js");
TryCatch tryCatch(isolate);
Local<Value> result = V8Util::executeString(isolate, KrollBindings::getMainSource(isolate), STRING_NEW(isolate, "ti:/kroll.js"));
if (tryCatch.HasCaught()) {
V8Util::reportException(isolate, tryCatch, true);
}
if (!result->IsFunction()) {
LOGF(TAG, "kroll.js result is not a function");
V8Util::reportException(isolate, tryCatch, true);
}
Local<Function> mainFunction = result.As<Function>();
Local<Value> args[] = { global };
mainFunction->Call(context, context->Global(), 1, args);
if (tryCatch.HasCaught()) {
V8Util::reportException(isolate, tryCatch, true);
LOGE(TAG, "Caught exception while bootstrapping Kroll");
}
}
示例13: Init
void IMessageDlg::Init(Local<Object> exports) {
Isolate* isolate = exports->GetIsolate();
// Prepare constructor template
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
tpl->SetClassName(String::NewFromUtf8(isolate, "IMessageDlg"));
tpl->InstanceTemplate()->SetInternalFieldCount(1);
// Prototype
NODE_SET_PROTOTYPE_METHOD(tpl, "init", _init);
NODE_SET_PROTOTYPE_METHOD(tpl, "popup", _popup);
NODE_SET_PROTOTYPE_METHOD(tpl, "getValue", _getValue);
NODE_SET_PROTOTYPE_METHOD(tpl, "destroy", _destroy);
NODE_SET_METHOD(tpl, "extend", extend);
constructor.Reset(isolate, tpl->GetFunction());
exports->Set(String::NewFromUtf8(isolate, "IMessageDlg"),tpl->GetFunction());
}
示例14: Init
void IdPool::Init(Local<Object> exports)
{
Isolate* isolate = exports->GetIsolate();
// Prepare constructor template
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
tpl->SetClassName(String::NewFromUtf8(isolate, "IdPool"));
tpl->InstanceTemplate()->SetInternalFieldCount(4);
// Prototype
NODE_SET_PROTOTYPE_METHOD(tpl, "reserve", reserve);
NODE_SET_PROTOTYPE_METHOD(tpl, "release", release);
NODE_SET_PROTOTYPE_METHOD(tpl, "clear", clear);
NODE_SET_PROTOTYPE_METHOD(tpl, "has", has);
NODE_SET_PROTOTYPE_METHOD(tpl, "size", size);
NODE_SET_PROTOTYPE_METHOD(tpl, "length", length);
constructor.Reset(isolate, tpl->GetFunction());
exports->Set(String::NewFromUtf8(isolate, "IdPool"), tpl->GetFunction());
}
示例15: Initialize
void APIModule::Initialize(Local<Object> target, Local<Context> context)
{
Isolate* isolate = context->GetIsolate();
HandleScope scope(isolate);
Local<FunctionTemplate> constructor = FunctionTemplate::New(isolate);
constructor->SetClassName(NEW_SYMBOL(isolate, "API"));
constructorTemplate.Reset(isolate, constructor);
// Hook methods to the API prototype, notice these aren't hooked to API
// itself, instead we return a singleton of an API instance and export it
// as Ti.API
// Not sure why we then hook apiName as instance proprty, since
// the difference is made moot by the singleton!
SetProtoMethod(isolate, constructor, "debug", logDebug);
SetProtoMethod(isolate, constructor, "info", logInfo);
SetProtoMethod(isolate, constructor, "warn", logWarn);
SetProtoMethod(isolate, constructor, "error", logError);
SetProtoMethod(isolate, constructor, "trace", logTrace);
SetProtoMethod(isolate, constructor, "notice", logNotice);
SetProtoMethod(isolate, constructor, "critical", logCritical);
SetProtoMethod(isolate, constructor, "fatal", logFatal);
SetProtoMethod(isolate, constructor, "log", log);
SetProtoMethod(isolate, constructor, "getApiName", APIModule::getApiName);
// Add an "apiName" property to instances, which delegates to APIModule::getter_apiName
// TODO Use a constant here?
Local<ObjectTemplate> instanceTemplate = constructor->InstanceTemplate();
instanceTemplate->SetAccessor(NEW_SYMBOL(isolate, "apiName"), APIModule::getter_apiName);
// Expose a method for terminating the application for the debugger.
// Debugger will send an evaluation request calling this method
// when it wants the application to terminate immediately.
if (V8Runtime::debuggerEnabled) {
SetProtoMethod(isolate, constructor, "terminate", terminate);
SetProtoMethod(isolate, constructor, "debugBreak", debugBreak);
}
// Make API extend from KrollModule
constructor->Inherit(KrollModule::getProxyTemplate(isolate));
// export an instance of API as "API" (basically make a static singleton)
target->Set(NEW_SYMBOL(isolate, "API"), constructor->GetFunction(context).ToLocalChecked()->NewInstance(context).ToLocalChecked());
}