typename std::enable_if<!is_void_return<F>::value>::type forward_ret(v8::FunctionCallbackInfo<v8::Value> const& args) { args.GetReturnValue().Set(to_v8(args.GetIsolate(), invoke<F>(args))); }
module& set_const(char const* name, Value value) { v8::HandleScope scope(isolate_); obj_->Set(to_v8(isolate_, name), to_v8(isolate_, value), v8::PropertyAttribute(v8::ReadOnly | v8::DontDelete)); return *this; }
v8::Handle<v8::Value> context::run_script(std::string const& source, std::string const& filename) { v8::EscapableHandleScope scope(isolate_); v8::Local<v8::Script> script = v8::Script::Compile( to_v8(isolate_, source), to_v8(isolate_, filename)); v8::Local<v8::Value> result; if (!script.IsEmpty()) { result = script->Run(); } return scope.Escape(result); }
static void var_get(v8::Local<v8::String>, v8::PropertyCallbackInfo<v8::Value> const& info) { v8::Isolate* isolate = info.GetIsolate(); Variable* var = detail::get_external_data<Variable*>(info.Data()); info.GetReturnValue().Set(to_v8(isolate, *var)); }
module& set(char const* name, class_<T>& cl) { v8::HandleScope scope(isolate_); cl.class_function_template()->SetClassName(to_v8(isolate_, name)); return set(name, cl.js_function_template()->GetFunction()); }
v8::Local<v8::Function> wrap_function(v8::Isolate* isolate, char const* name, F func) { v8::Handle<v8::Function> fn = v8::Function::New(isolate, &detail::forward_function<F>, detail::set_external_data(isolate, func)); if (name && *name) { fn->SetName(to_v8(isolate, name)); } return fn; }
v8::Handle<v8::Value> call_v8(v8::Isolate* isolate, v8::Handle<v8::Function> func, v8::Handle<v8::Value> recv, Args... args) { v8::EscapableHandleScope scope(isolate); int const arg_count = sizeof...(Args); // +1 to allocate array for arg_count == 0 v8::Handle<v8::Value> v8_args[arg_count + 1] = { to_v8(isolate, args)... }; v8::Local<v8::Value> result = func->Call(recv, arg_count, v8_args); return scope.Escape(result); }
bool set_option(v8::Isolate* isolate, v8::Handle<v8::Object> options, char const* name, T const& value) { char const* dot = strchr(name, '.'); if (dot) { std::string const subname(name, dot); v8::HandleScope scope(isolate); v8::Local<v8::Object> suboptions; return get_option(isolate, options, subname.c_str(), suboptions) && set_option(isolate, suboptions, dot + 1, value); } options->Set(v8pp::to_v8(isolate, name), to_v8(isolate, value)); return true; }
typename boost::enable_if<boost::mpl::and_< detail::is_function_pointer<GetFunction>, detail::is_function_pointer<SetFunction> >, module&>::type set(char const *name, property_<GetFunction, SetFunction> prop) { v8::HandleScope scope(isolate_); v8::AccessorGetterCallback getter = property_<GetFunction, SetFunction>::template get<void>; v8::AccessorSetterCallback setter = property_<GetFunction, SetFunction>::template set<void>; if (property_<GetFunction, SetFunction>::is_readonly) { setter = NULL; } v8::Handle<v8::Value> data = detail::set_external_data(isolate_, prop); v8::PropertyAttribute const prop_attrs = v8::PropertyAttribute(v8::DontDelete | (setter? 0 : v8::ReadOnly)); obj_->SetAccessor(to_v8(isolate_, name), getter, setter, data, v8::DEFAULT, prop_attrs); return *this; }
void context::run_file(v8::FunctionCallbackInfo<v8::Value> const& args) { v8::Isolate* isolate = args.GetIsolate(); v8::EscapableHandleScope scope(isolate); v8::Local<v8::Value> result; try { std::string const filename = from_v8<std::string>(isolate, args[0], ""); if (filename.empty()) { throw std::runtime_error("run_file: require filename string argument"); } context* ctx = detail::get_external_data<context*>(args.Data()); result = to_v8(isolate, ctx->run_file(filename)); } catch (std::exception const& ex) { result = throw_ex(isolate, ex.what()); } args.GetReturnValue().Set(scope.Escape(result)); }
void set_const(v8::Isolate* isolate, v8::Handle<v8::Object> options, char const* name, T const& value) { options->ForceSet(v8pp::to_v8(isolate, name), to_v8(isolate, value), v8::PropertyAttribute(v8::ReadOnly | v8::DontDelete)); }
// Set a V8 value module& set(char const* name, v8::Handle<v8::Data> value) { obj_->Set(to_v8(isolate_, name), value); return *this; }
context& context::set(char const* name, v8::Handle<v8::Value> value) { v8::HandleScope scope(isolate_); to_local(isolate_, impl_)->Global()->Set(to_v8(isolate_, name), value); return *this; }