result_t util_base::map(v8::Local<v8::Value> list, v8::Local<v8::Function> iterator, v8::Local<v8::Value> context, v8::Local<v8::Array> &retVal) { Isolate* isolate = Isolate::current(); v8::Local<v8::Array> arr = v8::Array::New(isolate->m_isolate); if (!list->IsObject()) { retVal = arr; return 0; } v8::Local<v8::Value> args[3]; args[2] = list; v8::Local<v8::Object> o = v8::Local<v8::Object>::Cast(list); v8::Local<v8::Value> v = o->Get(isolate->NewFromUtf8("length")); int32_t cnt = 0; if (IsEmpty(v)) { v8::Local<v8::Array> keys = o->GetPropertyNames(); int32_t len = keys->Length(); int32_t i; for (i = 0; i < len; i ++) { args[1] = keys->Get(i); args[0] = o->Get(args[1]); v = iterator->Call(context, 3, args); if (v.IsEmpty()) return CALL_E_JAVASCRIPT; arr->Set(cnt ++, v); } } else { int32_t len = v->Int32Value(); int32_t i; for (i = 0; i < len; i ++) { args[1] = v8::Int32::New(isolate->m_isolate, i); args[0] = o->Get(args[1]); v = iterator->Call(context, 3, args); if (v.IsEmpty()) return CALL_E_JAVASCRIPT; arr->Set(cnt ++, v); } } retVal = arr; return 0; }
v8::Local<v8::Value> List::array::_call(v8::Local<v8::Function> func, v8::Local<v8::Object> thisp, int i) { v8::Local<v8::Value> args[] = { m_array[i], v8::Number::New(isolate, i) }; return func->Call(thisp, 2, args); }
result_t LruCache::get(const char *name, v8::Local<v8::Function> updater, v8::Local<v8::Value> &retVal) { static _linkedNode newNode; v8::Handle<v8::Object> o = wrap(); v8::Handle<v8::String> n = v8::String::NewFromUtf8(Isolate::now()->m_isolate, name); std::string sname(name); v8::Handle<v8::Value> a = n; std::map<std::string, _linkedNode>::iterator find; cleanup(); while (true) { obj_ptr<Event_base> e; find = m_datas.find(sname); if (find != m_datas.end()) break; if (updater.IsEmpty()) return 0; std::map<std::string, obj_ptr<Event_base> >::iterator padding; padding = m_paddings.find(sname); if (padding == m_paddings.end()) { e = new Event(); padding = m_paddings.insert(std::pair<std::string, obj_ptr<Event_base> >(sname, e)).first; v8::Local<v8::Value> v = updater->Call(o, 1, &a); m_paddings.erase(padding); e->set(); if (v.IsEmpty()) return CALL_E_JAVASCRIPT; find = m_datas.insert(std::pair<std::string, _linkedNode>(sname, newNode)).first; insert(find); if (m_timeout > 0) find->second.insert.now(); o->SetHiddenValue(n, v); retVal = v; return 0; } e = padding->second; e->wait(); } update(find); retVal = o->GetHiddenValue(n); return 0; }
v8::MaybeLocal<v8::Value> V8ScriptRunner::callInternalFunction(v8::Local<v8::Function> function, v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> args[], v8::Isolate* isolate) { TRACE_EVENT0("v8", "v8.callFunction"); TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); V8RecursionScope::MicrotaskSuppression recursionScope(isolate); v8::MaybeLocal<v8::Value> result = function->Call(isolate->GetCurrentContext(), receiver, argc, args); crashIfV8IsDead(); return result; }
void JSFiber::callFunction1(v8::Local<v8::Function> func, v8::Local<v8::Value> *args, int argCount, v8::Local<v8::Value> &retVal) { TryCatch try_catch; retVal = func->Call(wrap(), argCount, args); if (try_catch.HasCaught()) { m_error = true; ReportException(try_catch, 0); } }
result_t profiler_base::diff(v8::Local<v8::Function> test, v8::Local<v8::Object>& retVal) { obj_ptr<HeapSnapshot_base> s1, s2; takeSnapshot(s1); test->Call(v8::Undefined(Isolate::now()->m_isolate), 0, NULL); takeSnapshot(s2); s2->diff(s1, retVal); deleteAllHeapSnapshots(); return 0; }
result_t test_base::describe(const char *name, v8::Local<v8::Function> block) { _case::init(); _case *last = s_now; result_t hr = _case::enter(name); if (hr < 0) return hr; block->Call(v8::Undefined(isolate), 0, NULL); s_now = last; return 0; }
result_t profiler_base::diff(v8::Local<v8::Function> test, v8::Local<v8::Object>& retVal) { Isolate* isolate = Isolate::current(); v8::HeapProfiler* profiler = isolate->m_isolate->GetHeapProfiler(); obj_ptr<HeapSnapshot_base> s1, s2; global_base::GC(); s1 = new HeapSnapshotProxy(profiler->TakeHeapSnapshot()); test->Call(v8::Undefined(isolate->m_isolate), 0, NULL); global_base::GC(); s2 = new HeapSnapshotProxy(profiler->TakeHeapSnapshot()); return s2->diff(s1, retVal); }
result_t MongoCursor::forEach(v8::Local<v8::Function> func) { result_t hr; v8::Local<v8::Object> o; Isolate* isolate = Isolate::now(); while ((hr = next(o)) != CALL_RETURN_NULL) { v8::Local<v8::Value> a = o; v8::Local<v8::Value> v = func->Call(v8::Undefined(isolate->m_isolate), 1, &a); if (v.IsEmpty()) return CALL_E_JAVASCRIPT; } return hr < 0 ? hr : 0; }
v8::MaybeLocal<v8::Value> V8ScriptRunner::callFunction(v8::Local<v8::Function> function, ExecutionContext* context, v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> args[], v8::Isolate* isolate) { TRACE_EVENT0("v8", "v8.callFunction"); TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth) return v8::MaybeLocal<v8::Value>(throwStackOverflowExceptionIfNeeded(isolate)); RELEASE_ASSERT(!context->isIteratingOverObservers()); if (ScriptForbiddenScope::isScriptForbidden()) { throwScriptForbiddenException(isolate); return v8::MaybeLocal<v8::Value>(); } V8RecursionScope recursionScope(isolate); v8::MaybeLocal<v8::Value> result = function->Call(isolate->GetCurrentContext(), receiver, argc, args); crashIfV8IsDead(); return result; }
result_t MongoCursor::map(v8::Local<v8::Function> func, v8::Local<v8::Array> &retVal) { result_t hr; Isolate* isolate = Isolate::now(); v8::Local<v8::Object> o; v8::Local<v8::Array> as = v8::Array::New(isolate->m_isolate); int32_t n = 0; while ((hr = next(o)) != CALL_RETURN_NULL) { v8::Local<v8::Value> a = o; v8::Local<v8::Value> v = func->Call(v8::Undefined(isolate->m_isolate), 1, &a); if (v.IsEmpty()) return CALL_E_JAVASCRIPT; as->Set(n, v); n++; } retVal = as; return hr < 0 ? hr : 0; }