Skip to content
Permalink
Browse files

core, feat: check the result of NewFunction.

  • Loading branch information...
xicilion committed Oct 3, 2018
1 parent 6c886d6 commit d1cf7fa0aadc26a7b6e351774435e3ae1d53a77d
@@ -80,7 +80,8 @@ class Isolate : public exlib::linkitem {
v8::Local<v8::Value> data = v8::Local<v8::Value>())
{
v8::Local<v8::Function> func = v8::Function::New(m_isolate, callback, data);
func->SetName(NewString(funcName));
if (!func.IsEmpty())
func->SetName(NewString(funcName));
return func;
}

@@ -255,6 +255,9 @@ class JSTrigger {
_data->Set(NewString("_ev"), NewString(ev));

v8::Local<v8::Function> wrap = _isolate->NewFunction("_onceWrap", _onceWrap, _data);
if (wrap.IsEmpty())
return CHECK_ERROR(Runtime::setError("function alloc error."));

wrap->Set(NewString("_func"), func);
_data->Set(NewString("_wrap"), wrap);

@@ -277,6 +280,8 @@ class JSTrigger {
_data->Set(NewString("_ev"), NewString(ev));

v8::Local<v8::Function> wrap = _isolate->NewFunction("_onceWrap", _onceWrap, _data);
if (wrap.IsEmpty())
return CHECK_ERROR(Runtime::setError("function alloc error."));

_data->Set(NewString("_wrap"), wrap);

@@ -66,6 +66,8 @@ result_t JSHandler::invoke(object_base* v, obj_ptr<Handler_base>& retVal,
argv[i + 1] = v;
}
argv[len + 1] = isolate->NewFunction("done", _done, retVal->wrap());
if (argv[len + 1].IsEmpty())
return CHECK_ERROR(Runtime::setError("function alloc error."));

proc->Call(v8::Undefined(isolate->m_isolate), len + 2, argv.data());
return 0;
@@ -69,9 +69,12 @@ result_t profiler_base::start(exlib::string fname, int32_t time, int32_t interva
} else
_data->Set(isolate->NewString("_time"), v8::Number::New(isolate->m_isolate, INFINITY));

v8::Local<v8::Function> func = isolate->NewFunction("_cpu_profiler", cpu_profiler, _data);
if (func.IsEmpty())
return CHECK_ERROR(Runtime::setError("function alloc error."));

obj_ptr<Timer_base> t;
timers_base::setHrInterval(isolate->NewFunction("_cpu_profiler", cpu_profiler, _data),
interval, args, t);
timers_base::setHrInterval(func, interval, args, t);

return t->unref(retVal);
}
@@ -36,6 +36,8 @@ result_t JsonLoader::run(SandBox::Context* ctx, Buffer_base* src, exlib::string
{
Isolate* isolate = ctx->m_sb->holder();
v8::Local<v8::Function> func = isolate->NewFunction("json_loader", _json_loader, src->wrap());
if (func.IsEmpty())
return CHECK_ERROR(Runtime::setError("function alloc error."));

v8::Local<v8::Object> module = v8::Local<v8::Object>::Cast(args[5]);
module->SetPrivate(module->CreationContext(),
@@ -47,6 +47,10 @@ static void sync_stub(const v8::FunctionCallbackInfo<v8::Value>& args)
argv[i] = args[i];

argv[i] = isolate->NewFunction("sync_callback", sync_callback, _data);
if (argv[i].IsEmpty()) {
ThrowError("function alloc error.");
return;
}

v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(args.Data());

@@ -130,8 +134,17 @@ static void async_promise(const v8::FunctionCallbackInfo<v8::Value>& args)
}

v = isolate->NewFunction("promise_then", promise_then, args[len - 1]);
if (v.IsEmpty()) {
ThrowError("function alloc error.");
return;
}
_then->Call(result, 1, &v);

v = isolate->NewFunction("promise_catch", promise_catch, args[len - 1]);
if (v.IsEmpty()) {
ThrowError("function alloc error.");
return;
}
_catch->Call(result, 1, &v);
}

@@ -140,10 +153,16 @@ result_t util_base::sync(v8::Local<v8::Function> func, bool async_func, v8::Loca
Isolate* isolate = Isolate::current();
v8::Local<v8::Function> func1;

if (async_func || func->IsAsyncFunction())
if (async_func || func->IsAsyncFunction()) {
func = isolate->NewFunction("async_promise", async_promise, func);
if (func.IsEmpty())
return CHECK_ERROR(Runtime::setError("function alloc error."));
}

func1 = isolate->NewFunction("sync", sync_stub, func);
if (func1.IsEmpty())
return CHECK_ERROR(Runtime::setError("function alloc error."));

func1->SetPrivate(func1->CreationContext(),
v8::Private::ForApi(isolate->m_isolate, isolate->NewString("_async")), func);

0 comments on commit d1cf7fa

Please sign in to comment.
You can’t perform that action at this time.