本文整理汇总了C++中Local::IsEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ Local::IsEmpty方法的具体用法?C++ Local::IsEmpty怎么用?C++ Local::IsEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Local
的用法示例。
在下文中一共展示了Local::IsEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: origin
ScriptValuePtr V8Engine::runScript(std::string script, std::string identifier)
{
HandleScope handleScope;
TryCatch tc;
Local<String> source = String::New(script.c_str());
// Build data
ScriptOrigin origin(String::New(identifier.c_str()));
// Compile the source code.
Local<Script> code = Script::Compile(source, &origin);
if (code.IsEmpty())
handleException(tc);
// Run the script to get the result.
Local<Value> result = code->Run();
if (result.IsEmpty())
handleException(tc);
return ScriptValuePtr( new V8Value(this, result) );
}
示例2: InvokeProperty
jsvalue JsContext::InvokeProperty(Persistent<Object>* obj, const uint16_t* name, jsvalue args)
{
jsvalue v;
Locker locker(isolate_);
Isolate::Scope isolate_scope(isolate_);
(*context_)->Enter();
HandleScope scope;
TryCatch trycatch;
Local<Value> prop = (*obj)->Get(String::New(name));
if (prop.IsEmpty() || !prop->IsFunction()) {
v = engine_->StringFromV8(String::New("property not found or isn't a function"));
v.type = JSVALUE_TYPE_STRING_ERROR;
}
else {
std::vector<Local<Value> > argv(args.length);
engine_->ArrayToV8Args(args, id_, &argv[0]);
// TODO: Check ArrayToV8Args return value (but right now can't fail, right?)
Local<Function> func = Local<Function>::Cast(prop);
Local<Value> value = func->Call(*obj, args.length, &argv[0]);
if (!value.IsEmpty()) {
v = engine_->AnyFromV8(value);
}
else {
v = engine_->ErrorFromV8(trycatch);
}
}
(*context_)->Exit();
return v;
}
示例3: handle_scope
char *JSMain::GetStackInfo(Isolate *isolate, int *lineNumber)
{
HandleScope handle_scope(isolate);
const char *file = __FILE__; /* Use current filename if we can't find the correct from JS stack */
int line = __LINE__; /* Use current line number if we can't find the correct from JS stack */
char *ret = NULL;
/* Try to get the current stack trace (script file) */
Local<StackTrace> stFile = StackTrace::CurrentStackTrace(isolate, 1, StackTrace::kScriptName);
if (!stFile.IsEmpty()) {
Local<StackFrame> sf = stFile->GetFrame(0);
if (!sf.IsEmpty()) {
Local<String> fn = sf->GetScriptName();
if (!fn.IsEmpty()) {
String::Utf8Value str(fn);
if (*str) {
js_strdup(ret, *str); // We must dup here
}
}
}
}
/* dup current filename if we got nothing from stack */
if (ret == NULL) {
js_strdup(ret, file);
}
/* Try to get the current stack trace (line number) */
if (lineNumber) {
*lineNumber = 0;
Local<StackTrace> stLine = StackTrace::CurrentStackTrace(isolate, 1, StackTrace::kLineNumber);
if (!stLine.IsEmpty()) {
Local<StackFrame> sf = stLine->GetFrame(0);
if (!sf.IsEmpty()) {
*lineNumber = sf->GetLineNumber();
}
}
/* Use current file number if we got nothing from stack */
if (*lineNumber == 0) {
*lineNumber = line;
}
}
/* Return dup'ed value - this must be freed by the calling function */
return ret;
}
示例4: Init
void Module::Init(Isolate *isolate)
{
JEnv env;
MODULE_CLASS = env.FindClass("com/tns/Module");
assert(MODULE_CLASS != nullptr);
RESOLVE_PATH_METHOD_ID = env.GetStaticMethodID(MODULE_CLASS, "resolvePath", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;");
assert(RESOLVE_PATH_METHOD_ID != nullptr);
string requireFactoryScript =
"(function () { "
" function require_factory(requireInternal, dirName) { "
" return function require(modulePath) { "
" if(global.__requireOverride) { "
" var result = global.__requireOverride(modulePath, dirName); "
" if(result) { "
" return result; "
" } "
" } "
" return requireInternal(modulePath, dirName); "
" } "
" } "
" return require_factory; "
"})()";
auto source = ConvertToV8String(requireFactoryScript);
auto context = isolate->GetCurrentContext();
Local<Script> script;
auto maybeScript = Script::Compile(context, source).ToLocal(&script);
assert(!script.IsEmpty());
Local<Value> result;
auto maybeResult = script->Run(context).ToLocal(&result);
assert(!result.IsEmpty() && result->IsFunction());
auto requireFactoryFunction = result.As<Function>();
auto cache = GetCache(isolate);
cache->RequireFactoryFunction = new Persistent<Function>(isolate, requireFactoryFunction);
auto requireFuncTemplate = FunctionTemplate::New(isolate, RequireCallback);
auto requireFunc = requireFuncTemplate->GetFunction();
cache->RequireFunction = new Persistent<Function>(isolate, requireFunc);
auto global = isolate->GetCurrentContext()->Global();
auto globalRequire = GetRequireFunction(isolate, Constants::APP_ROOT_FOLDER_PATH);
global->Set(ConvertToV8String("require"), globalRequire);
}
示例5:
void
test_HandleScope() {
HandleScope outer;
Local<Value> v;
{
HandleScope inner;
v = inner.Close(String::New("hey"));
}
do_check_true(!v.IsEmpty());
Local<String> s = v->ToString();
do_check_true(!s.IsEmpty());
do_check_true(s->Equals(v));
}
示例6: RunScript
jobject NativePlatform::RunScript(JNIEnv *_env, jobject obj, jstring scriptFile)
{
JEnv env(_env);
jobject res = nullptr;
auto isolate = g_isolate;
Isolate::Scope isolate_scope(isolate);
HandleScope handleScope(isolate);
auto context = isolate->GetCurrentContext();
auto filename = ArgConverter::jstringToString(scriptFile);
auto src = File::ReadText(filename);
auto source = ConvertToV8String(src);
TryCatch tc;
Local<Script> script;
ScriptOrigin origin(ConvertToV8String(filename));
auto maybeScript = Script::Compile(context, source, &origin).ToLocal(&script);
if(tc.HasCaught()) {
throw NativeScriptException(tc, "Script " + filename + " contains compilation errors!");
}
if (!script.IsEmpty())
{
Local<Value> result;
auto maybeResult = script->Run(context).ToLocal(&result);
if(tc.HasCaught()) {
throw NativeScriptException(tc, "Error running script " + filename);
}
if (!result.IsEmpty())
{
res = ConvertJsValueToJavaObject(env, result, static_cast<int>(Type::Null));
}
else
{
DEBUG_WRITE(">>runScript maybeResult is empty");
}
}
else
{
DEBUG_WRITE(">>runScript maybeScript is empty");
}
return res;
}
示例7: if
/* called by the Java environment for objects that have been finalized */
void Conv::releaseV8Handle(JNIEnv *jniEnv, Persistent<Object> val, int type) {
HandleScope scope;
Handle<String> sHiddenKey;
Interface *interface = 0;
ArrayType *arr = 0;
if(type == -1) {
sHiddenKey = sObjectHiddenKey;
} else if(isArray(type)) {
arrayConv->GetRefsForComponentType(jniEnv, getComponentType(type), &arr);
sHiddenKey = arr->getHiddenKey();
} else if(isInterface(type)) {
interface = env->getInterface(getClassId(type));
sHiddenKey = interface->getHiddenKey();
}
//LOGV("releaseV8Handle; interface = %p; getting hidden value; sHiddenKey = %p\n", interface, sHiddenKey);
if(!sHiddenKey.IsEmpty()) {
Local<Value> hiddenVal = val->GetHiddenValue(sHiddenKey);
if(!hiddenVal.IsEmpty() && !hiddenVal->IsUndefined()) {
jobject extRef = (jobject)External::Unwrap(hiddenVal);
Conv::deleteGlobalRef(jniEnv, extRef);
val->DeleteHiddenValue(sHiddenKey);
if(interface) {
while((interface = interface->getParent())) {
val->DeleteHiddenValue(interface->getHiddenKey());
}
}
}
}
val.Dispose();
}
示例8: UnwrapObject
int Conv::UnwrapObject(JNIEnv *jniEnv, Handle<Object> val, Handle<String> key, jobject *jVal) {
int result = ErrorNotfound;
//LOGV("UnwrapObject; getting hidden value; key = %p\n", key);
Local<Value> hiddenVal = val->GetHiddenValue(key);
if(!hiddenVal.IsEmpty() && !hiddenVal->IsUndefined()) {
jobject extRef = (jobject)External::Unwrap(hiddenVal);
if(jniEnv->GetObjectRefType(extRef) == JNIWeakGlobalRefType) {
jobject localRef = jniEnv->NewLocalRef(extRef);
if(localRef == 0) {
/* the Java object died */
jniEnv->DeleteWeakGlobalRef(extRef);
val->DeleteHiddenValue(key);
} else {
/* the java object is alive */
*jVal = localRef;
result = OK;
}
} else {
/* the object is strongly referenced */
*jVal = extRef;
result = OK;
}
}
return result;
}
示例9: Exception
void *ScriptObject::extractHolder(const Arguments &args)
{
HandleScope handleScope;
// Extract first internal field from Argument's holder object
Local<Object> holderObject = args.Holder();
if (holderObject->InternalFieldCount() < 1)
throw bit::Exception("No internal fields found in holder object");
Local<Value> holderValue = holderObject->GetInternalField(0);
if (holderValue.IsEmpty())
throw bit::Exception("Internal field could not be extracted from object");
if (!holderValue->IsExternal())
throw bit::Exception("The first field of holder object is not an ExternalObject");
// Extract void pointer
void *holderPointer = External::Unwrap(holderValue);
if (holderPointer == NULL)
throw bit::Exception("Extracted pointer is null");
return holderPointer;
}
示例10: TryConvertToJavaLong
bool ArgConverter::TryConvertToJavaLong(const Local<Value>& value, jlong& javaLong)
{
bool success = false;
if (!value.IsEmpty())
{
if (value->IsNumber() || value->IsNumberObject())
{
javaLong = (jlong)value->IntegerValue();
success = true;
}
else if (value->IsObject())
{
auto obj = Local<Object>::Cast(value);
auto isJavaLongValue = obj->GetHiddenValue(V8StringConstants::GetJavaLong());
if (!isJavaLongValue.IsEmpty() && isJavaLongValue->BooleanValue())
{
javaLong = (jlong)ConvertToJavaLong(value);
success = true;
}
}
}
return success;
}
示例11: handle_scope
// プロパティ取得共通処理
tjs_error
TJSInstance::getProp(Isolate *isolate, Local<Object> &obj, const tjs_char *membername, tTJSVariant *result)
{
if (!membername) {
return TJS_E_NOTIMPL;
}
HandleScope handle_scope(isolate);
Context::Scope context_scope(getContext());
TryCatch try_catch;
Local<Value> ret = obj->Get(String::NewFromTwoByte(isolate, membername));
if (ret.IsEmpty()) {
return TJS_E_MEMBERNOTFOUND;
} else {
if (result) {
if (ret->IsFunction()) {
*result = toVariant(isolate, ret->ToObject(), obj);
} else {
*result = toVariant(isolate, ret);
}
}
}
return TJS_S_OK;
}
示例12: Set_DialogState_height
static void Set_DialogState_height(Local<String> property, Local<Value> value, const AccessorInfo& info)
{
HandleScope scope;
Local<Object> self = info.Holder();
Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
if (wrap.IsEmpty())
return;
DialogState *tmp = (DialogState *) wrap->Value();
if (tmp == NULL)
return;
if (!value.IsEmpty() && value->IsNumber())
tmp->setHeight(value->Int32Value());
}
示例13: thread
static gboolean
gum_script_process_thread_match (const GumThreadDetails * details,
gpointer user_data)
{
GumScriptMatchContext * ctx =
static_cast<GumScriptMatchContext *> (user_data);
GumScriptCore * core = ctx->self->core;
Isolate * isolate = ctx->isolate;
if (gum_script_is_ignoring (details->id))
return TRUE;
Local<Object> thread (Object::New (isolate));
_gum_script_set (thread, "id", Number::New (isolate, details->id), core);
_gum_script_set (thread, "state", String::NewFromOneByte (isolate,
reinterpret_cast<const uint8_t *> (gum_script_thread_state_to_string (
details->state))),
core);
_gum_script_set (thread, "context", _gum_script_cpu_context_new (
&details->cpu_context, ctx->self->core), core);
Handle<Value> argv[] = { thread };
Local<Value> result = ctx->on_match->Call (ctx->receiver, 1, argv);
gboolean proceed = TRUE;
if (!result.IsEmpty () && result->IsString ())
{
String::Utf8Value str (result);
proceed = (strcmp (*str, "stop") != 0);
}
return proceed;
}
示例14: ExecuteReturnString
stdext::ustring JavaScriptContext::ExecuteReturnString(const stdext::ustring & source, const stdext::ustring & name, stdext::ustring & error)
{
stdext::ustring resultString;
error = wstringToUstring(L"");
Locker locker(m_isolate);
Isolate::Scope isolate_scope(m_isolate);
{
Context::Scope contextScope(*m_ctx);
HandleScope scope;
Local<String> scriptSource = String::New(reinterpret_cast<const uint16_t *>(source.c_str()));
Local<String> scriptName = String::New(reinterpret_cast<const uint16_t *>(name.c_str()));
Local<Script> script = Script::New(scriptSource, scriptName);
Local<Value> result;
{
TryCatch tryCatch;
result = script->Run();
if (!result.IsEmpty())
{
String::Value value(result);
resultString.append(reinterpret_cast<const char16_t *>(*value));
}
if (tryCatch.HasCaught())
{
error.append(wstringToUstring(L"Error running script: "));
error.append(name);
error.append(wstringToUstring(L" - "));
String::Value stackTrace(tryCatch.StackTrace());
error.append(reinterpret_cast<const char16_t*>(*stackTrace));
}
}
}
return resultString;
}
示例15: it
int V8Scope::invoke( ScriptingFunction func , const BSONObj& argsObject, int timeoutMs , bool ignoreReturn ){
Handle<Value> funcValue = _funcs[func-1];
TryCatch try_catch;
int nargs = argsObject.nFields();
auto_ptr< Handle<Value> > args;
if ( nargs ){
args.reset( new Handle<Value>[nargs] );
BSONObjIterator it( argsObject );
for ( int i=0; i<nargs; i++ ){
BSONElement next = it.next();
args.get()[i] = mongoToV8Element( next );
}
}
Local<Value> result = ((v8::Function*)(*funcValue))->Call( _this , nargs , args.get() );
if ( result.IsEmpty() ){
stringstream ss;
ss << "error in invoke: " << toSTLString( &try_catch );
_error = ss.str();
log() << _error << endl;
return 1;
}
if ( ! ignoreReturn ){
_global->Set( v8::String::New( "return" ) , result );
}
return 0;
}