//*,{ // "type":"function", // "name":"setConfig(callback,[filename])", // "text":"读取或设置配置文件,配置文件是一个 Json 格式的文本文件,可以是 utf-8 获取 ansi 编码。", // "param":[ // { // "type":"function", // "name":"callback(cfg)", // "text":"setConfig 函数如果成功,会触发这个回调函数,cfg 是一个对象,它的属性就是配置内容,对这个对象的任何更改最后都会作为 Json 格式保存到配置文件。" // }, // { // "type":"string", // "name":"[filename]", // "text":"配置文件名,缺省是和脚本同路径同名的一个后缀为“.json”的文本文件,如果指定了文件名,则读取和保存对应的文件。" // } // ], // "return":{ // "type":"boolean", // "text":"如果成功打开了配置文件,函数返回 true,否则返回 undefined。" // } //}//* Handle<Value> setConfig(const Arguments& args){ HandleScope stack; while(true){ if(args.Length()<1) break; if(!args[0]->IsFunction()) break; cs::String file; if(args.Length()>1) GetString(args[1],file); cs::Config cfg(file); cs::Json* json = cfg.Lock(); if(!json) break; json->ToString(file,false); Handle<Object> glb = GetGlobal(); Handle<Object> JSON = glb->Get(NEW_STR(JSON))->ToObject(); Handle<Function> parse = Handle<Function>::Cast(JSON->Get(NEW_STR(parse))); Handle<Function> stringify = Handle<Function>::Cast(JSON->Get(NEW_STR(stringify))); Handle<Function> callback = Handle<Function>::Cast(args[0]); Handle<Value> argv[3]; argv[0] = NEW_WSTR(file.Handle()); Handle<Value> v = parse->Call(JSON,1,argv); if(v.IsEmpty()||!v->IsObject()) v = Object::New(); argv[0] = v; CallFunc(glb,callback,1,argv); v = stringify->Call(JSON,1,argv); GetString(v,file); json->Parse(file); return True(); } return Undefined(); }
HandleProxy* V8EngineProxy::Call(HandleProxy *subject, const uint16_t *functionName, HandleProxy *_this, uint16_t argCount, HandleProxy** args) { if (_this == nullptr) _this = subject; // (assume the subject is also "this" if not given) auto hThis = _this->Handle(); if (hThis.IsEmpty() || !hThis->IsObject()) throw exception("Call: The target instance handle ('this') does not represent an object."); auto hSubject = subject->Handle(); Handle<Function> hFunc; if (functionName != nullptr) // (if no name is given, assume the subject IS a function object, otherwise get the property as a function) { if (hSubject.IsEmpty() || !hSubject->IsObject()) throw exception("Call: The subject handle does not represent an object."); auto hProp = hSubject.As<Object>()->Get(NewUString(functionName)); if (hProp.IsEmpty() || !hProp->IsFunction()) throw exception("Call: The specified property does not represent a function."); hFunc = hProp.As<Function>(); } else if (hSubject.IsEmpty() || !hSubject->IsFunction()) throw exception("Call: The subject handle does not represent a function."); else hFunc = hSubject.As<Function>(); TryCatch __tryCatch; Handle<Value> result; if (argCount > 0) { Handle<Value>* _args = new Handle<Value>[argCount]; for (auto i = 0; i < argCount; i++) _args[i] = args[i]->Handle(); result = hFunc->Call(hThis.As<Object>(), argCount, _args); delete[] _args; } else result = hFunc->Call(hThis.As<Object>(), 0, nullptr); HandleProxy *returnVal; if (__tryCatch.HasCaught()) { returnVal = GetHandleProxy(GetErrorMessage(__tryCatch)); returnVal->_Type = JSV_ExecutionError; } else returnVal = result.IsEmpty() ? nullptr : GetHandleProxy(result); return returnVal; }
JNIEXPORT jboolean JNICALL Java_org_appcelerator_kroll_runtime_v8_V8Object_nativeFireEvent (JNIEnv *env, jobject jEmitter, jlong ptr, jstring event, jobject data) { ENTER_V8(V8Runtime::globalContext); JNIScope jniScope(env); Handle<Value> jsEvent = TypeConverter::javaStringToJsString(event); #ifdef TI_DEBUG String::Utf8Value eventName(jsEvent); LOGV(TAG, "firing event \"%s\"", *eventName); #endif Handle<Object> emitter; if (ptr != 0) { emitter = Persistent<Object>((Object *) ptr); } else { emitter = TypeConverter::javaObjectToJsValue(jEmitter)->ToObject(); } Handle<Value> fireEventValue = emitter->Get(EventEmitter::emitSymbol); if (!fireEventValue->IsFunction()) { return JNI_FALSE; } Handle<Function> fireEvent = Handle<Function>::Cast(fireEventValue->ToObject()); Handle<Value> jsData = TypeConverter::javaObjectToJsValue(data); Handle<Value> result; TryCatch tryCatch; if (jsData->IsNull()) { Handle<Value> args[] = { jsEvent }; result = fireEvent->Call(emitter, 1, args); } else { Handle<Value> args[] = { jsEvent, jsData }; result = fireEvent->Call(emitter, 2, args); } if (tryCatch.HasCaught()) { V8Util::openJSErrorDialog(tryCatch); V8Util::reportException(tryCatch); } else if (result->IsTrue()) { return JNI_TRUE; } return JNI_FALSE; }
bool isMatchCandidate(ConstElementPtr e) { Context::Scope context_scope(_script->getContext()); HandleScope handleScope; Persistent<Object> plugin = getPlugin(); Handle<String> isMatchCandidateStr = String::New("isMatchCandidate"); if (plugin->Has(isMatchCandidateStr) == false) { throw HootException("Error finding 'isMatchCandidate' function."); } Handle<v8::Value> value = plugin->Get(isMatchCandidateStr); if (value->IsFunction() == false) { throw HootException("isMatchCandidate is not a function."); } Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(value); Handle<Value> jsArgs[2]; int argc = 0; jsArgs[argc++] = OsmMapJs::create(_map); jsArgs[argc++] = ElementJs::New(e); Handle<Value> f = func->Call(plugin, argc, jsArgs); return f->BooleanValue(); }
static void DNSSD_API OnServiceRegistered(DNSServiceRef sdRef, DNSServiceFlags flags, DNSServiceErrorType errorCode, const char * name, const char * serviceType, const char * domain, void * context) { if ( ! context) return; HandleScope scope; ServiceRef * serviceRef = static_cast<ServiceRef*>(context); Handle<Function> callback = serviceRef->GetCallback(); Handle<Object> this_ = serviceRef->GetThis(); if ( ! callback.IsEmpty() && ! this_.IsEmpty()) { const size_t argc(7); Local<Value> args[argc]; args[0] = Local<Object>::New(serviceRef->handle_); args[1] = Integer::New(flags); args[2] = Integer::New(errorCode); args[3] = stringOrUndefined(name); args[4] = stringOrUndefined(serviceType); args[5] = stringOrUndefined(domain); if (serviceRef->GetContext().IsEmpty()) { args[6] = Local<Value>::New(Undefined()); } else { args[6] = Local<Value>::New(serviceRef->GetContext()); } callback->Call(this_, argc, args); } }
void TargetCallback(Isolate* isolate, Persistent<Object>* target, WeakRef* arg) { HandleScope scope; if(!arg->target.IsNearDeath()) { return; } Local<Object> fnthis = Local<Object>::New(Isolate::GetCurrent(), arg->target); Handle<Value> argv[1]; argv[0] = fnthis; // invoke any listening callbacks Local<Array> callbacks = Local<Array>::New(Isolate::GetCurrent(), arg->callbacks); uint32_t len = callbacks->Length(); for (uint32_t i = 0; i < len; i++) { Handle<Function> cb = Handle<Function>::Cast(callbacks->Get(i)); TryCatch try_catch; cb->Call(fnthis, 1, argv); if (try_catch.HasCaught()) { ThrowException(String::New("TargetCallback")); } } arg->target.Dispose(); arg->target.Clear(); arg->callbacks.Dispose(); arg->callbacks.Clear(); }
void operator()() { Locker l; HandleScope handle_scope; Handle< Context > context; Handle< v8::Function > fun; auto_ptr< V8Scope > scope; if ( config_.newScope_ ) { scope.reset( dynamic_cast< V8Scope * >( globalScriptEngine->newScope() ) ); context = scope->context(); // A v8::Function tracks the context in which it was created, so we have to // create a new function in the new context. Context::Scope baseScope( baseContext_ ); string fCode = toSTLString( config_.f_->ToString() ); Context::Scope context_scope( context ); fun = scope->__createFunction( fCode.c_str() ); } else { context = baseContext_; Context::Scope context_scope( context ); fun = config_.f_; } Context::Scope context_scope( context ); boost::scoped_array< Local< Value > > argv( new Local< Value >[ config_.args_.size() ] ); for( unsigned int i = 0; i < config_.args_.size(); ++i ) argv[ i ] = Local< Value >::New( config_.args_[ i ] ); TryCatch try_catch; Handle< Value > ret = fun->Call( context->Global(), config_.args_.size(), argv.get() ); if ( ret.IsEmpty() ) { string e = toSTLString( &try_catch ); log() << "js thread raised exception: " << e << endl; // v8 probably does something sane if ret is empty, but not going to assume that for now ret = v8::Undefined(); } config_.returnData_ = Persistent< Value >::New( ret ); }
/* static */ void V8Runtime::bootstrap(Local<Object> global) { EventEmitter::Initialize(); krollGlobalObject = Persistent<Object>::New(Object::New()); DEFINE_METHOD(krollGlobalObject, "log", krollLog); DEFINE_METHOD(krollGlobalObject, "binding", KrollBindings::getBinding); DEFINE_TEMPLATE(krollGlobalObject, "EventEmitter", EventEmitter::constructorTemplate); krollGlobalObject->Set(String::NewSymbol("runtime"), String::New("v8")); LOG_TIMER(TAG, "Executing kroll.js"); TryCatch tryCatch; Handle<Value> result = V8Util::executeString(KrollBindings::getMainSource(), String::New("kroll.js")); if (tryCatch.HasCaught()) { V8Util::reportException(tryCatch, true); } if (!result->IsFunction()) { LOGF(TAG, "kroll.js result is not a function"); V8Util::reportException(tryCatch, true); } Handle<Function> mainFunction = Handle<Function>::Cast(result); Local<Value> args[] = { Local<Value>::New(krollGlobalObject) }; mainFunction->Call(global, 1, args); if (tryCatch.HasCaught()) { V8Util::reportException(tryCatch, true); LOGE(TAG, "Caught exception while bootstrapping Kroll"); } }
Handle<Value> ScriptMatch::_callGetMatchFeatureDetails(const ConstOsmMapPtr& map) const { Isolate* current = v8::Isolate::GetCurrent(); EscapableHandleScope handleScope(current); Context::Scope context_scope(_script->getContext(current)); Handle<Object> plugin = Handle<Object>::Cast( _script->getContext(current)->Global()->Get(String::NewFromUtf8(current, "plugin"))); Handle<Value> value = plugin->Get(String::NewFromUtf8(current, "getMatchFeatureDetails")); Handle<Function> func = Handle<Function>::Cast(value); Handle<Value> jsArgs[3]; if (func.IsEmpty() || func->IsFunction() == false) { throw IllegalArgumentException("getMatchFeatureDetails must be a valid function."); } Handle<Object> mapObj = OsmMapJs::create(map); int argc = 0; jsArgs[argc++] = mapObj; jsArgs[argc++] = ElementJs::New(map->getElement(_eid1)); jsArgs[argc++] = ElementJs::New(map->getElement(_eid2)); TryCatch trycatch; Handle<Value> result = func->Call(plugin, argc, jsArgs); HootExceptionJs::checkV8Exception(result, trycatch); return handleScope.Escape(result); }
IOBasicTypes::LongBufferSizeType ObjectByteWriterWithPosition::Write(const IOBasicTypes::Byte* inBuffer,IOBasicTypes::LongBufferSizeType inBufferSize) { HandleScope handle; Handle<Object> anArray = Array::New((int)inBufferSize); for(int i=0;i<(int)inBufferSize;++i) anArray->Set(Number::New(i),Number::New(inBuffer[i])); Handle<Value> value = mObject->Get(String::New("write")); if(value->IsUndefined() || !value->IsFunction()) { ThrowException(Exception::TypeError(String::New("write is not a function, it should be you know..."))); return 0; } Handle<Function> func = Handle<Function>::Cast(value); Handle<Value> args[1]; args[0] = anArray; Handle<Value> result = func->Call(mObject, 1, args); if(result.IsEmpty()) { ThrowException(Exception::TypeError(String::New("wrong return value. it's empty. return the number of written characters"))); return 0; } else if(result->IsNumber()) { return result->ToNumber()->Uint32Value(); } else { ThrowException(Exception::TypeError(String::New("wrong return value. write should return the number of written characters"))); return 0; } }
Handle<Value> ScriptMatch::_call(const ConstOsmMapPtr& map, Handle<Object> plugin) { HandleScope handleScope; Context::Scope context_scope(_script->getContext()); plugin = Handle<Object>::Cast(_script->getContext()->Global()->Get(String::New("plugin"))); Handle<v8::Value> value = plugin->Get(String::New("matchScore")); Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(value); Handle<Value> jsArgs[3]; if (func.IsEmpty() || func->IsFunction() == false) { throw IllegalArgumentException("matchScore must be a valid function."); } Handle<Object> mapObj = OsmMapJs::create(map); int argc = 0; jsArgs[argc++] = mapObj; jsArgs[argc++] = ElementJs::New(map->getElement(_eid1)); jsArgs[argc++] = ElementJs::New(map->getElement(_eid2)); TryCatch trycatch; Handle<Value> result = func->Call(plugin, argc, jsArgs); HootExceptionJs::checkV8Exception(result, trycatch); return handleScope.Close(result); }
void test_Exception() { HandleScope handle_scope; Persistent<Context> context = Context::New(); Handle<Script> script = Script::New(String::New("function foo(x) { throw x; };")); Context::Scope scope(context); TryCatch trycatch; Handle<Value> v = script->Run(); do_check_true(!v.IsEmpty()); do_check_true(!trycatch.HasCaught()); Handle<Function> fn = context->Global()->Get(String::NewSymbol("foo")).As<Function>(); do_check_true(!fn.IsEmpty()); Local<Value> args[1] = { Integer::New(4) }; v = fn->Call(context->Global(), 1, args); do_check_true(v.IsEmpty()); do_check_true(trycatch.HasCaught()); Handle<Value> exn = trycatch.Exception(); do_check_true(exn->IsInt32()); do_check_eq(exn->Int32Value(), 4); context.Dispose(); }
v8::Handle<v8::Value> V8::parseJsonConfigurationFile(const v8::Arguments &args) { if (args.Length() < 1) return v8::Undefined(); HandleScope scope; std::string filename = System::resourceLocation() + V8::StringToStdString( args[0]->ToString() ); if (!boost::filesystem::exists(boost::filesystem3::path(filename))) { return ThrowException( String::New(("parseJsonConfigurationFile(): " + filename + " doesn't exist!").c_str()) ); } Handle<Value> callbackArgs[] = { parseJson(v8::String::New(System::fileToString(filename).c_str())) }; Handle<Function> callback = args[1].As<Function>(); callback->Call(Context::GetCurrent()->Global(), 1, callbackArgs); return Undefined(); }
/* * This is meant to run one time when the match creator is initialized. */ void customScriptInit() { Context::Scope context_scope(_script->getContext()); HandleScope handleScope; Persistent<Object> plugin = getPlugin(); Handle<String> initStr = String::New("init"); if (plugin->Has(initStr) == false) { throw HootException("Error finding 'init' function."); } Handle<v8::Value> value = plugin->Get(initStr); if (value->IsFunction() == false) { throw HootException("init is not a function."); } Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(value); Handle<Value> jsArgs[1]; int argc = 0; HandleScope scope; assert(_map.get()); OsmMapPtr copiedMap(new OsmMap(_map)); jsArgs[argc++] = OsmMapJs::create(copiedMap); func->Call(plugin, argc, jsArgs); //this is meant to have been set externally in a js rules file _searchRadius = getNumber(plugin, "searchRadius", -1.0, 15.0); }
void OnEnumeration(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char * replyDomain, void * context) { if ( ! context) return; HandleScope scope; ServiceRef * serviceRef = static_cast<ServiceRef*>(context); Handle<Function> callback = serviceRef->GetCallback(); Handle<Object> this_ = serviceRef->GetThis(); const size_t argc(6); Local<Value> args[argc]; args[0] = Local<Object>::New(serviceRef->handle_); args[1] = Integer::New(flags); args[2] = Integer::New(interfaceIndex); args[3] = Integer::New(errorCode); args[4] = String::New(replyDomain); if (serviceRef->GetContext().IsEmpty()) { args[5] = Local<Value>::New(Null()); } else { args[5] = Local<Value>::New(serviceRef->GetContext()); } callback->Call(this_, argc, args); }
static Handle<Value> NodePopen(const Arguments& args) { HandleScope scope; int length = args.Length(); // Expect a callback function for stdout Handle<String> Command = Handle<String >::Cast(args[0]); Handle<Function> cbout = Handle<Function>::Cast(args[1]); // Get Command char* command( *v8::String::Utf8Value(Command) ); char buffer[MAX_BUFFER]; FILE *stream = popen( command, "r" ); Handle<Value> argv[1]; while ( std::fgets(buffer, MAX_BUFFER, stream) != NULL ) { // Do callback here! argv[0] = String::New( buffer ); if(length>1) cbout->Call(Context::GetCurrent()->Global(), 1, argv); } int code = pclose(stream); return scope.Close(Integer::New(code)); }
JNIEXPORT void JNICALL Java_org_appcelerator_kroll_runtime_v8_V8Object_nativeSetWindow (JNIEnv *env, jobject javaKrollWindow, jlong ptr, jobject javaWindow) { ENTER_V8(V8Runtime::globalContext); titanium::JNIScope jniScope(env); Handle<Object> jsKrollWindow; if (ptr != 0) { jsKrollWindow = Persistent<Object>((Object *) ptr); } else { jsKrollWindow = TypeConverter::javaObjectToJsValue(env, javaKrollWindow)->ToObject(); } Handle<Value> setWindowValue = jsKrollWindow->Get(String::New("setWindow")); if (!setWindowValue->IsFunction()) { return; } Handle<Function> setWindow = Handle<Function>::Cast(setWindowValue->ToObject()); Handle<Value> jsWindow = TypeConverter::javaObjectToJsValue(env, javaWindow); TryCatch tryCatch; if (!jsWindow->IsNull()) { Handle<Value> args[] = { jsWindow }; setWindow->Call(jsKrollWindow, 1, args); } if (tryCatch.HasCaught()) { V8Util::openJSErrorDialog(tryCatch); V8Util::reportException(tryCatch); } }
Handle<Value> CursorWrap::getCommon(const Arguments& args, MDB_cursor_op op, void (*setKey)(const Arguments& args, MDB_val&), Handle<Value> (*convertFunc)(MDB_val &data)) { int al = args.Length(); CursorWrap *cw = ObjectWrap::Unwrap<CursorWrap>(args.This()); MDB_val key, data; if (setKey) { setKey(args, key); } int rc = mdb_cursor_get(cw->cursor, &key, &data, op); if (rc == MDB_NOTFOUND) { return Null(); } else if (rc != 0) { ThrowException(Exception::Error(String::New(mdb_strerror(rc)))); return Undefined(); } if (convertFunc && al > 0 && args[al - 1]->IsFunction()) { // In this case, we expect the key/data pair to be correctly filled const unsigned argc = 2; Handle<Value> argv[argc] = { keyToHandle(key), convertFunc(data) }; Handle<Function> callback = Handle<Function>::Cast(args[args.Length() - 1]); return callback->Call(Context::GetCurrent()->Global(), argc, argv); } return Undefined(); }
void DNSSD_API OnResolve(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char * fullname, const char * hosttarget, uint16_t port, uint16_t txtLen, const unsigned char * txtRecord, void * context) { HandleScope scope; ServiceRef * serviceRef = static_cast<ServiceRef*>(context); Handle<Function> callback = serviceRef->GetCallback(); Handle<Object> this_ = serviceRef->GetThis(); const size_t argc(9); Local<Value> args[argc]; args[0] = Local<Object>::New(serviceRef->handle_); args[1] = Integer::New(flags); args[2] = Integer::New(interfaceIndex); args[3] = Integer::New(errorCode); args[4] = String::New(fullname); args[5] = String::New(hosttarget); args[6] = Integer::New( ntohs(port) ); Buffer * buffer = Buffer::New(txtLen); memcpy(Buffer::Data(buffer->handle_), txtRecord, txtLen); args[7] = Local<Value>::New(buffer->handle_); if (serviceRef->GetContext().IsEmpty()) { args[8] = Local<Value>::New(Undefined()); } else { args[8] = Local<Value>::New(serviceRef->GetContext()); } callback->Call(this_, argc, args); }
IOBasicTypes::LongBufferSizeType ObjectByteReaderWithPosition::Read(IOBasicTypes::Byte* inBuffer,IOBasicTypes::LongBufferSizeType inBufferSize) { CREATE_ISOLATE_CONTEXT; CREATE_ESCAPABLE_SCOPE; Handle<Value> value = OBJECT_FROM_PERSISTENT(mObject)->Get(NEW_STRING("read")); if(value->IsUndefined()) return 0; Handle<Function> func = Handle<Function>::Cast(value); Handle<Value> args[1]; args[0] = NEW_NUMBER(inBufferSize); Handle<Value> result = func->Call(OBJECT_FROM_PERSISTENT(mObject), 1, args); if(!result->IsArray()) return 0; IOBasicTypes::LongBufferSizeType bufferLength = result->ToObject()->Get(NEW_STRING("length"))->ToObject()->Uint32Value(); for(IOBasicTypes::LongBufferSizeType i=0;i < bufferLength;++i) inBuffer[i] = (IOBasicTypes::Byte)(result->ToObject()->Get((uint32_t)i)->ToNumber()->Uint32Value()); return bufferLength; }
int FSCoreDB::Callback(void *pArg, int argc, char **argv, char **columnNames) { FSCoreDB *dbo = static_cast<FSCoreDB *>(pArg); HandleScope handle_scope(dbo->GetIsolate()); int x = 0; if (!dbo) { return 0; } if (dbo->_callback.IsEmpty()) { dbo->GetIsolate()->ThrowException(String::NewFromUtf8(dbo->GetIsolate(), "No callback specified")); return 0; } Handle<Array> arg = Array::New(dbo->GetIsolate(), argc); for (x = 0; x < argc; x++) { if (columnNames[x] && argv[x]) { arg->Set(String::NewFromUtf8(dbo->GetIsolate(), columnNames[x]), String::NewFromUtf8(dbo->GetIsolate(), argv[x])); } } HandleScope scope(dbo->GetIsolate()); Handle<Function> func = Local<Function>::New(dbo->GetIsolate(), dbo->_callback); Handle<Value> jsargv[1] = { arg }; func->Call(dbo->GetIsolate()->GetCurrentContext()->Global(), 1, jsargv); return 0; }
Handle<Value> js_call(Handle<Function> f, int arg_count) { TryCatch t; Handle<Value> R = f->Call(glxwin, arg_count, ARGS); if (R.IsEmpty()) { printf("%s\n", *v8_error_as_string(& t).compat()); } return R; }
Handle<Value> CallFunc(Handle<Object>& self,Handle<Function>& func,int argc,Handle<Value>* argv){ TryCatch err; Handle<Value> ret = func->Call(self,argc,argv); if(err.HasCaught()){ ReportError(err); return Undefined(); } return ret; }
int PDFDateDriver::GetIntValueFromDateFunction(Handle<Date> inDate, const char* inFunctionName) { HandleScope scope; Handle<v8::Value> value = inDate->Get(String::New(inFunctionName)); Handle<Function> func = Handle<Function>::Cast(value); Handle<Value> result; result = func->Call(inDate, 0, NULL); return result->ToNumber()->Int32Value(); }
IOBasicTypes::LongFilePositionType ObjectByteWriterWithPosition::GetCurrentPosition() { HandleScope handle; Handle<Value> value = mObject->Get(String::New("getCurrentPosition")); if(value->IsUndefined()) return true; Handle<Function> func = Handle<Function>::Cast(value); return (func->Call(mObject, 0, NULL)->ToNumber()->Value()); }
Local<String> Object::ObjectProtoToString() { Object proto(JS_GetPrototype(cx(), *this)); Handle<Function> toString = proto.Get(String::New("toString")).As<Function>(); if (toString.IsEmpty()) { TryCatch::CheckForException(); return Local<String>(); } return toString->Call(this, 0, NULL).As<String>(); }
bool ObjectByteReader::NotEnded() { HandleScope handle; Handle<Value> value = mObject->Get(String::New("notEnded")); if(value->IsUndefined()) return true; Handle<Function> func = Handle<Function>::Cast(value); return (func->Call(mObject, 0, NULL)->ToBoolean()->Value()); }
LongFilePositionType ObjectByteReaderWithPosition::GetCurrentPosition() { CREATE_ISOLATE_CONTEXT; CREATE_ESCAPABLE_SCOPE; Handle<Value> value = OBJECT_FROM_PERSISTENT(mObject)->Get(NEW_STRING("getCurrentPosition")); if(value->IsUndefined()) return true; Handle<Function> func = Handle<Function>::Cast(value); return (func->Call(OBJECT_FROM_PERSISTENT(mObject), 0, NULL)->ToNumber()->Value()); }
std::string v8ScriptService::preCompileCode(const std::string &code, const boost::filesystem::path &filename) { HandleScope scope; std::string filenameString = filename.string(); bool isCoffee = false; bool isLiterateCoffee = false; if (boost::regex_search( filenameString, regex(".*\\.coffee$") )) { isCoffee = true; } if (boost::regex_search( filenameString, regex(".*\\.litcoffee$") )) { isCoffee = true; isLiterateCoffee = true; } // Compile coffeescript to JS. if (isCoffee) { TryCatch exception; Handle<Object> CoffeeScript = Context::GetCurrent()->Global()->Get(String::New("CoffeeScript")).As<Object>(); Handle<Function> compile = CoffeeScript->Get(String::New("compile")).As<Function>(); Handle<Object> options = Object::New(); options->Set(String::New("filename"), String::New( filenameString.c_str() )); options->Set(String::New("literate"), Boolean::New(isLiterateCoffee)); Handle<Value> args[] = { String::New(code.c_str()), options }; Handle<Value> result = compile->Call(compile, 2, args); if (exception.HasCaught()) { throw script_precompilation_error(V8::stringifyException(exception, true)); } return V8::stringToStdString(result->ToString()); } else { return code; } }
bool ObjectByteReaderWithPosition::NotEnded() { CREATE_ISOLATE_CONTEXT; CREATE_ESCAPABLE_SCOPE; Handle<Value> value = OBJECT_FROM_PERSISTENT(mObject)->Get(NEW_STRING("notEnded")); if(value->IsUndefined()) return true; Handle<Function> func = Handle<Function>::Cast(value); return (func->Call(OBJECT_FROM_PERSISTENT(mObject), 0, NULL)->ToBoolean()->Value()); }