• Home
  • Raw
  • Download

Lines Matching full:v8

24 #include "v8-debug.h"
25 #include "v8-internal.h"
26 #include "v8-local-handle.h"
27 #include "v8-primitive.h"
28 #include "v8-statistics.h"
29 #include "v8-version-string.h"
38 #include "libplatform/v8-tracing.h"
56 // Always compare the final element of IsolateDataSlot with v8 limit.
57 static_assert(K_ISOLATE_HANDLER_POOL_SLOT < v8::internal::Internals::kNumIsolateDataSlots);
91 static IsolateHandlerPool* GetIsolateHandlerPool(v8::Isolate* isolate) in GetIsolateHandlerPool()
97 static IsolateHandlerPool* GetOrCreateIsolateHandlerPool(v8::Isolate* isolate) in GetOrCreateIsolateHandlerPool()
112 static JSVM_Env GetEnvByContext(v8::Local<v8::Context> context) in GetEnvByContext()
119 IsolateData(v8::StartupData* blob) : blob(blob) {} in IsolateData()
126 v8::StartupData* blob;
127 v8::Eternal<v8::Private> typeTagKey;
128 v8::Eternal<v8::Private> wrapperKey;
131 static void CreateIsolateData(v8::Isolate* isolate, v8::StartupData* blob) in CreateIsolateData()
134 v8::Isolate::Scope isolateScope(isolate); in CreateIsolateData()
135 v8::HandleScope handleScope(isolate); in CreateIsolateData()
139 auto wrapperKey = isolate->GetDataFromSnapshotOnce<v8::Private>(0); in CreateIsolateData()
140 auto typeTagKey = isolate->GetDataFromSnapshotOnce<v8::Private>(1); in CreateIsolateData()
144 data->wrapperKey.Set(isolate, v8::Private::New(isolate)); in CreateIsolateData()
145 data->typeTagKey.Set(isolate, v8::Private::New(isolate)); in CreateIsolateData()
150 static IsolateData* GetIsolateData(v8::Isolate* isolate) in GetIsolateData()
156 static void SetIsolateSnapshotCreator(v8::Isolate* isolate, v8::SnapshotCreator* creator) in SetIsolateSnapshotCreator()
161 static v8::SnapshotCreator* GetIsolateSnapshotCreator(v8::Isolate* isolate) in GetIsolateSnapshotCreator()
164 return reinterpret_cast<v8::SnapshotCreator*>(data); in GetIsolateSnapshotCreator()
167 static void SetContextEnv(v8::Local<v8::Context> context, JSVM_Env env) in SetContextEnv()
172 static JSVM_Env GetContextEnv(v8::Local<v8::Context> context) in GetContextEnv()
178 class OutputStream : public v8::OutputStream {
205 static std::unique_ptr<v8::Platform> g_platform = v8::platform::NewDefaultPlatform();
211 static std::unique_ptr<v8::ArrayBuffer::Allocator> defaultArrayBufferAllocator;
217 "v8",
218 TRACE_DISABLED_BY_DEFAULT("v8.compile"),
219 "v8.execute",
220 TRACE_DISABLED_BY_DEFAULT("v8.runtime"),
221 TRACE_DISABLED_BY_DEFAULT("v8.stack_trace"),
222 "v8.wasm",
223 TRACE_DISABLED_BY_DEFAULT("v8.wasm.detailed"),
230 static v8::ArrayBuffer::Allocator* GetOrCreateDefaultArrayBufferAllocator() in GetOrCreateDefaultArrayBufferAllocator()
233 defaultArrayBufferAllocator.reset(v8::ArrayBuffer::Allocator::NewDefaultAllocator()); in GetOrCreateDefaultArrayBufferAllocator()
304 v8::Local<v8::Name>* result) in V8NameFromPropertyDescriptor()
309 v8::Local<v8::Value> propertyValue = v8impl::V8LocalValueFromJsValue(p->name); in V8NameFromPropertyDescriptor()
312 *result = propertyValue.As<v8::Name>(); in V8NameFromPropertyDescriptor()
318 // convert from jsvm-api property attributes to v8::PropertyAttribute
319 v8::PropertyAttribute V8PropertyAttributesFromDescriptor(const JSVM_PropertyDescriptor* descriptor) in V8PropertyAttributesFromDescriptor()
321 unsigned int attributeFlags = v8::PropertyAttribute::None; in V8PropertyAttributesFromDescriptor()
324 // V8 would throw `TypeError`s on assignment with nonexistence of a setter. in V8PropertyAttributesFromDescriptor()
327 attributeFlags |= v8::PropertyAttribute::ReadOnly; in V8PropertyAttributesFromDescriptor()
331 attributeFlags |= v8::PropertyAttribute::DontEnum; in V8PropertyAttributesFromDescriptor()
334 attributeFlags |= v8::PropertyAttribute::DontDelete; in V8PropertyAttributesFromDescriptor()
337 return static_cast<v8::PropertyAttribute>(attributeFlags); in V8PropertyAttributesFromDescriptor()
341 inline v8::Maybe<bool> ConcludeDeferred(JSVM_Env env, JSVM_Deferred deferred, JSVM_Value result) in ConcludeDeferred()
343 v8::Local<v8::Context> context = env->context(); in ConcludeDeferred()
344 v8impl::Persistent<v8::Value>* deferredRef = PersistentFromJsDeferred(deferred); in ConcludeDeferred()
345 v8::Local<v8::Value> v8Deferred = v8::Local<v8::Value>::New(env->isolate, *deferredRef); in ConcludeDeferred()
347 auto resolver = v8Deferred.As<v8::Promise::Resolver>(); in ConcludeDeferred()
349v8::Maybe<bool> success = isResolved ? resolver->Resolve(context, v8impl::V8LocalValueFromJsValue(… in ConcludeDeferred()
367 v8::Local<v8::Context> context = env->context(); in Unwrap()
369 v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(jsObject); in Unwrap()
371 v8::Local<v8::Object> obj = value.As<v8::Object>(); in Unwrap()
375 …RuntimeReference* reference = static_cast<v8impl::RuntimeReference*>(val.As<v8::External>()->Value… in Unwrap()
392 // exposed to JavaScript. The structure is stored in a v8::External which gets
401 static inline v8::Local<v8::Value> New(JSVM_Env env, JSVM_Callback cb) in New()
403 return v8::External::New(env->isolate, cb); in New()
406 static inline v8::Local<v8::Value> New(JSVM_Env env, v8impl::JSVM_PropertyHandlerCfgStruct* cb) in New()
408 return v8::External::New(env->isolate, cb); in New()
412 // Base class extended by classes that wrap V8 function and property callback
449 …inline CallbackWrapperBase(const v8::FunctionCallbackInfo<v8::Value>& cbinfo, const size_t argsLen… in CallbackWrapperBase()
452 cb = static_cast<JSVM_Callback>(cbinfo.Data().As<v8::External>()->Value()); in CallbackWrapperBase()
457 inline const v8::FunctionCallbackInfo<v8::Value>& GetCbInfo() in GetCbInfo()
474 [&](JSVM_Env env, v8::Local<v8::Value> value) { in InvokeCallback()
488 const v8::FunctionCallbackInfo<v8::Value>& cbinfo;
494 static void Invoke(const v8::FunctionCallbackInfo<v8::Value>& info) in Invoke()
500 …static inline JSVM_Status NewFunction(JSVM_Env env, JSVM_Callback cb, v8::Local<v8::Function>* res… in NewFunction()
502 v8::Local<v8::Value> cbdata = v8impl::CallbackBundle::New(env, cb); in NewFunction()
505v8::MaybeLocal<v8::Function> maybeFunction = v8::Function::New(env->context(), Invoke, cbdata); in NewFunction()
514 v8::Local<v8::FunctionTemplate>* result, in NewTemplate()
515 v8::Local<v8::Signature> sig = v8::Local<v8::Signature>()) in NewTemplate()
517 v8::Local<v8::Value> cbdata = v8impl::CallbackBundle::New(env, cb); in NewTemplate()
520 *result = v8::FunctionTemplate::New(env->isolate, Invoke, cbdata, sig); in NewTemplate()
524 explicit FunctionCallbackWrapper(const v8::FunctionCallbackInfo<v8::Value>& cbinfo) in FunctionCallbackWrapper()
549 … JSVM_Value undefined = v8impl::JsValueFromV8LocalValue(v8::Undefined(info.GetIsolate())); in GetArgs()
559 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in SetReturnValue()
568 v8::Local<v8::Name> property, in PropertyCallbackWrapperBase()
569 v8::Local<v8::Value> value, in PropertyCallbackWrapperBase()
570 const v8::PropertyCallbackInfo<T>& cbinfo, in PropertyCallbackWrapperBase()
576 …static_cast<v8impl::JSVM_PropertyHandlerCfgStruct*>(cbinfo.Data().template As<v8::External>()->Val… in PropertyCallbackWrapperBase()
611 [&](JSVM_Env env, v8::Local<v8::Value> v8Value) { in NameSetterInvokeCallback()
645 [&](JSVM_Env env, v8::Local<v8::Value> v8Value) { in NameGetterInvokeCallback()
680 [&](JSVM_Env env, v8::Local<v8::Value> v8Value) { in NameDeleterInvokeCallback()
716 [&](JSVM_Env env, v8::Local<v8::Value> v8Value) { in NameEnumeratorInvokeCallback()
745 … JSVM_Value v8Index = JsValueFromV8LocalValue(v8::Integer::NewFromUnsigned(env->isolate, index)); in IndexSetterInvokeCallback()
754 [&](JSVM_Env env, v8::Local<v8::Value> v8Value) { in IndexSetterInvokeCallback()
781 … JSVM_Value v8Index = JsValueFromV8LocalValue(v8::Integer::NewFromUnsigned(env->isolate, index)); in IndexGetterInvokeCallback()
789 [&](JSVM_Env env, v8::Local<v8::Value> v8Value) { in IndexGetterInvokeCallback()
816 … JSVM_Value v8Index = JsValueFromV8LocalValue(v8::Integer::NewFromUnsigned(env->isolate, index)); in IndexDeleterInvokeCallback()
824 [&](JSVM_Env env, v8::Local<v8::Value> v8Value) { in IndexDeleterInvokeCallback()
860 [&](JSVM_Env env, v8::Local<v8::Value> v8Value) { in IndexEnumeratorInvokeCallback()
874 const v8::PropertyCallbackInfo<T>& cbinfo;
876 v8::Local<v8::Name> property;
877 v8::Local<v8::Value> value;
884 static void NameSetterInvoke(v8::Local<v8::Name> property, in NameSetterInvoke()
885 v8::Local<v8::Value> value, in NameSetterInvoke()
886 const v8::PropertyCallbackInfo<v8::Value>& info) in NameSetterInvoke()
888 PropertyCallbackWrapper<v8::Value> propertyCbWrapper(property, value, info); in NameSetterInvoke()
892 …static void NameGetterInvoke(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Valu… in NameGetterInvoke()
894 … PropertyCallbackWrapper<v8::Value> propertyCbWrapper(property, v8::Local<v8::Value>(), info); in NameGetterInvoke()
898 …static void NameDeleterInvoke(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Boo… in NameDeleterInvoke()
900 … PropertyCallbackWrapper<v8::Boolean> propertyCbWrapper(property, v8::Local<v8::Value>(), info); in NameDeleterInvoke()
904 static void NameEnumeratorInvoke(const v8::PropertyCallbackInfo<v8::Array>& info) in NameEnumeratorInvoke()
906 …PropertyCallbackWrapper<v8::Array> propertyCbWrapper(v8::Local<v8::Name>(), v8::Local<v8::Value>()… in NameEnumeratorInvoke()
911 v8::Local<v8::Value> value, in IndexSetterInvoke()
912 const v8::PropertyCallbackInfo<v8::Value>& info) in IndexSetterInvoke()
914 PropertyCallbackWrapper<v8::Value> propertyCbWrapper(index, value, info); in IndexSetterInvoke()
918 static void IndexGetterInvoke(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) in IndexGetterInvoke()
920 PropertyCallbackWrapper<v8::Value> propertyCbWrapper(index, v8::Local<v8::Value>(), info); in IndexGetterInvoke()
924 … static void IndexDeleterInvoke(uint32_t index, const v8::PropertyCallbackInfo<v8::Boolean>& info) in IndexDeleterInvoke()
926 PropertyCallbackWrapper<v8::Boolean> propertyCbWrapper(index, v8::Local<v8::Value>(), info); in IndexDeleterInvoke()
930 static void IndexEnumeratorInvoke(const v8::PropertyCallbackInfo<v8::Array>& info) in IndexEnumeratorInvoke()
932 PropertyCallbackWrapper<v8::Array> propertyCbWrapper(0, v8::Local<v8::Value>(), info); in IndexEnumeratorInvoke()
936 explicit PropertyCallbackWrapper(v8::Local<v8::Name> name, in PropertyCallbackWrapper()
937 v8::Local<v8::Value> value, in PropertyCallbackWrapper()
938 const v8::PropertyCallbackInfo<T>& cbinfo) in PropertyCallbackWrapper()
943 v8::Local<v8::Value> value, in PropertyCallbackWrapper()
944 const v8::PropertyCallbackInfo<T>& cbinfo) in PropertyCallbackWrapper()
945 … : PropertyCallbackWrapperBase<T>(index, v8::Local<v8::Name>(), value, cbinfo, 0), cbinfo(cbinfo) in PropertyCallbackWrapper()
951 v8::Local<T> val = v8impl::V8LocalValueFromJsValue(value).As<T>(); in SetReturnValue()
956 const v8::PropertyCallbackInfo<T>& cbinfo;
969 v8::Local<v8::Context> context = env->context(); in Wrap()
971 v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(jsObject); in Wrap()
973 v8::Local<v8::Object> obj = value.As<v8::Object>(); in Wrap()
985 …CHECK(obj->SetPrivate(context, JSVM_PRIVATE_KEY(env->isolate, wrapper), v8::External::New(env->iso… in Wrap()
995 v8::Platform* JSVM_Env__::platform() in platform()
1010 v8::V8::InitializePlatform(v8impl::g_platform.get()); in OH_JSVM_Init()
1015 v8::V8::SetFlagsFromCommandLine(options->argc, options->argv, options->removeFlags); in OH_JSVM_Init()
1017 v8::V8::Initialize(); in OH_JSVM_Init()
1040 v8::Isolate::CreateParams createParams; in OH_JSVM_CreateVM()
1044 v8::StartupData* snapshotBlob = nullptr; in OH_JSVM_CreateVM()
1046 snapshotBlob = new v8::StartupData(); in OH_JSVM_CreateVM()
1057 v8::Isolate* isolate; in OH_JSVM_CreateVM()
1059 isolate = v8::Isolate::Allocate(); in OH_JSVM_CreateVM()
1060 auto creator = new v8::SnapshotCreator(isolate, externalReferences); in OH_JSVM_CreateVM()
1064 isolate = v8::Isolate::New(createParams); in OH_JSVM_CreateVM()
1079 auto isolate = reinterpret_cast<v8::Isolate*>(vm); in OH_JSVM_DestroyVM()
1102 auto isolate = reinterpret_cast<v8::Isolate*>(vm); in OH_JSVM_OpenVMScope()
1103 auto scope = new v8::Isolate::Scope(isolate); in OH_JSVM_OpenVMScope()
1110 auto v8scope = reinterpret_cast<v8::Isolate::Scope*>(scope); in OH_JSVM_CloseVMScope()
1120 auto isolate = reinterpret_cast<v8::Isolate*>(vm); in OH_JSVM_CreateEnv()
1122 v8::HandleScope handleScope(isolate); in OH_JSVM_CreateEnv()
1123 auto globalTemplate = v8::ObjectTemplate::New(isolate); in OH_JSVM_CreateEnv()
1133 v8::Local<v8::Name> propertyName = in OH_JSVM_CreateEnv()
1134v8::String::NewFromUtf8(isolate, p->utf8name, v8::NewStringType::kInternalized).ToLocalChecked(); in OH_JSVM_CreateEnv()
1136 v8::PropertyAttribute attributes = v8impl::V8PropertyAttributesFromDescriptor(p); in OH_JSVM_CreateEnv()
1139 v8::Local<v8::FunctionTemplate> getterTpl; in OH_JSVM_CreateEnv()
1140 v8::Local<v8::FunctionTemplate> setterTpl; in OH_JSVM_CreateEnv()
1150 v8::Local<v8::FunctionTemplate> methodTpl; in OH_JSVM_CreateEnv()
1155 v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(p->value); in OH_JSVM_CreateEnv()
1160 v8::Local<v8::Context> context = v8::Context::New(isolate, nullptr, globalTemplate); in OH_JSVM_CreateEnv()
1170 auto isolate = reinterpret_cast<v8::Isolate*>(vm); in OH_JSVM_CreateEnvFromSnapshot()
1171 v8::HandleScope handleScope(isolate); in OH_JSVM_CreateEnvFromSnapshot()
1173 auto maybe = v8::Context::FromSnapshot(isolate, index); in OH_JSVM_CreateEnvFromSnapshot()
1196 auto v8scope = new v8::Context::Scope(env->context()); in OH_JSVM_OpenEnvScope()
1203 auto v8scope = reinterpret_cast<v8::Context::Scope*>(scope); in OH_JSVM_CloseEnvScope()
1220 v8::Local<v8::Value> v8Script = v8impl::V8LocalValueFromJsValue(script); in OH_JSVM_CompileScript()
1224 v8::Local<v8::Context> context = env->context(); in OH_JSVM_CompileScript()
1226 v8::ScriptCompiler::CachedData* cache = in OH_JSVM_CompileScript()
1227 cachedData ? new v8::ScriptCompiler::CachedData(cachedData, cachedDataLength) : nullptr; in OH_JSVM_CompileScript()
1228 v8::ScriptCompiler::Source scriptSource(v8Script.As<v8::String>(), cache); in OH_JSVM_CompileScript()
1229 auto option = cache ? v8::ScriptCompiler::kConsumeCodeCache in OH_JSVM_CompileScript()
1230 … : (eagerCompile ? v8::ScriptCompiler::kEagerCompile : v8::ScriptCompiler::kNoCompileOptions); in OH_JSVM_CompileScript()
1232 auto maybeScript = v8::ScriptCompiler::Compile(context, &scriptSource, option); in OH_JSVM_CompileScript()
1239 v8::Local<v8::Script> compiledScript = maybeScript.ToLocalChecked(); in OH_JSVM_CompileScript()
1245 v8::ScriptOrigin CreateScriptOrigin(v8::Isolate* isolate, v8::Local<v8::String> resourceName, v8::S… in CreateScriptOrigin()
1249 auto options = v8::PrimitiveArray::New(isolate, kOptionsLength); in CreateScriptOrigin()
1250 options->Set(isolate, 0, v8::Uint32::New(isolate, kOptionsMagicConstant)); in CreateScriptOrigin()
1252 …return v8::ScriptOrigin(isolate, resourceName, 0, 0, false, -1, v8::Local<v8::Value>(), false, fal… in CreateScriptOrigin()
1253 type == v8::ScriptType::kModule, options); in CreateScriptOrigin()
1256 v8::MaybeLocal<v8::Value> PrepareStackTraceCallback(v8::Local<v8::Context> context, in PrepareStackTraceCallback()
1257 v8::Local<v8::Value> error, in PrepareStackTraceCallback()
1258 v8::Local<v8::Array> trace) in PrepareStackTraceCallback()
1261 v8::TryCatch tryCatch(isolate); in PrepareStackTraceCallback()
1262v8::Local<v8::String> moduleName = v8::String::NewFromUtf8(isolate, "sourcemap").ToLocalChecked(); in PrepareStackTraceCallback()
1263 v8::Local<v8::String> moduleSourceString = in PrepareStackTraceCallback()
1264 v8::String::NewFromUtf8(isolate, SourceMapRunner.c_str()).ToLocalChecked(); in PrepareStackTraceCallback()
1266v8::ScriptOrigin moduleOrigin = CreateScriptOrigin(isolate, moduleName, v8::ScriptType::kClassic); in PrepareStackTraceCallback()
1267 v8::Local<v8::Context> moduleContext = v8::Context::New(isolate); in PrepareStackTraceCallback()
1268 v8::ScriptCompiler::Source moduleSource(moduleSourceString, moduleOrigin); in PrepareStackTraceCallback()
1269 …auto script = v8::Script::Compile(moduleContext, moduleSourceString, &moduleOrigin).ToLocalChecked… in PrepareStackTraceCallback()
1271 auto resultFunc = v8::Local<v8::Function>::Cast(result); in PrepareStackTraceCallback()
1273 v8::Local<v8::Value> element = trace->Get(context, 0).ToLocalChecked(); in PrepareStackTraceCallback()
1277 … auto getFileName = v8::String::NewFromUtf8(isolate, "getFileName", v8::NewStringType::kNormal); in PrepareStackTraceCallback()
1279 auto lineNumberFunction = v8::Local<v8::Function>::Cast(function); in PrepareStackTraceCallback()
1281 fileName = std::string(*v8::String::Utf8Value(isolate, fileNameObj.ToLocalChecked())); in PrepareStackTraceCallback()
1308 v8::Local<v8::Value> v8Script = v8impl::V8LocalValueFromJsValue(script); in OH_JSVM_CompileScriptWithOrigin()
1312 v8::Local<v8::Context> context = env->context(); in OH_JSVM_CompileScriptWithOrigin()
1320 ? v8::Local<v8::Value>() in OH_JSVM_CompileScriptWithOrigin()
1321 … : v8::String::NewFromUtf8(isolate, origin->sourceMapUrl).ToLocalChecked().As<v8::Value>(); in OH_JSVM_CompileScriptWithOrigin()
1322 auto resourceName = v8::String::NewFromUtf8(isolate, origin->resourceName).ToLocalChecked(); in OH_JSVM_CompileScriptWithOrigin()
1323v8::ScriptOrigin scriptOrigin(isolate, resourceName, origin->resourceLineOffset, origin->resourceC… in OH_JSVM_CompileScriptWithOrigin()
1326 v8::ScriptCompiler::CachedData* cache = in OH_JSVM_CompileScriptWithOrigin()
1327 cachedData ? new v8::ScriptCompiler::CachedData(cachedData, cachedDataLength) : nullptr; in OH_JSVM_CompileScriptWithOrigin()
1328 v8::ScriptCompiler::Source scriptSource(v8Script.As<v8::String>(), scriptOrigin, cache); in OH_JSVM_CompileScriptWithOrigin()
1329 auto option = cache ? v8::ScriptCompiler::kConsumeCodeCache in OH_JSVM_CompileScriptWithOrigin()
1330 … : (eagerCompile ? v8::ScriptCompiler::kEagerCompile : v8::ScriptCompiler::kNoCompileOptions); in OH_JSVM_CompileScriptWithOrigin()
1332 auto maybeScript = v8::ScriptCompiler::Compile(context, &scriptSource, option); in OH_JSVM_CompileScriptWithOrigin()
1338 v8::Local<v8::Script> compiledScript = maybeScript.ToLocalChecked(); in OH_JSVM_CompileScriptWithOrigin()
1346 CompileOptionResolver(size_t length, JSVM_CompileOptions options[], v8::Isolate* isolate) in CompileOptionResolver()
1357 … cache->cache ? new v8::ScriptCompiler::CachedData(cache->cache, cache->length) : nullptr; in CompileOptionResolver()
1381 … ? v8::String::NewFromUtf8(isolate, jsvmOrigin->sourceMapUrl).ToLocalChecked().As<v8::Value>() in CompileOptionResolver()
1382 : v8::Local<v8::Value>(); in CompileOptionResolver()
1383 auto resourceName = v8::String::NewFromUtf8(isolate, sourceString.c_str()).ToLocalChecked(); in CompileOptionResolver()
1384 …v8Origin = new v8::ScriptOrigin(isolate, resourceName, jsvmOrigin ? jsvmOrigin->resourceLineOffset… in CompileOptionResolver()
1390 if (v8Option == v8::ScriptCompiler::kConsumeCodeCache && !cachedData) { in CompileOptionResolver()
1401 v8::ScriptCompiler::CompileOptions v8Option = v8::ScriptCompiler::kNoCompileOptions;
1402 v8::ScriptCompiler::CachedData* cachedData = nullptr;
1403 v8::ScriptOrigin* v8Origin = nullptr;
1411 v8::ScriptCompiler::CompileOptions jsvmToOptions[] = {
1412 v8::ScriptCompiler::kNoCompileOptions,
1413 v8::ScriptCompiler::kConsumeCodeCache,
1414 v8::ScriptCompiler::kEagerCompile,
1415 v8::ScriptCompiler::kProduceCompileHints,
1416 v8::ScriptCompiler::kConsumeCompileHints};
1440 v8::Local<v8::Context> context = env->context(); in OH_JSVM_CompileScriptWithOptions()
1445 v8::Local<v8::Value> v8Script = v8impl::V8LocalValueFromJsValue(script); in OH_JSVM_CompileScriptWithOptions()
1449 v8::ScriptCompiler::Source scriptSource(v8Script.As<v8::String>(), *optionResolver.v8Origin, in OH_JSVM_CompileScriptWithOptions()
1451 auto maybeScript = v8::ScriptCompiler::Compile(context, &scriptSource, optionResolver.v8Option); in OH_JSVM_CompileScriptWithOptions()
1453 v8::Local<v8::Script> compiledScript = maybeScript.ToLocalChecked(); in OH_JSVM_CompileScriptWithOptions()
1467 auto v8script = jsvmData->ToV8Local<v8::Script>(env->isolate); in OH_JSVM_CreateCodeCache()
1469v8::ScriptCompiler::CachedData* cache = v8::ScriptCompiler::CreateCodeCache(v8script->GetUnboundSc… in OH_JSVM_CreateCodeCache()
1476 cache->buffer_policy = v8::ScriptCompiler::CachedData::BufferNotOwned; in OH_JSVM_CreateCodeCache()
1488 auto v8script = jsvmData->ToV8Local<v8::Script>(env->isolate); in OH_JSVM_RunScript()
1501 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(json_string); in OH_JSVM_JsonParse()
1504 auto maybe = v8::JSON::Parse(env->context(), val.As<v8::String>()); in OH_JSVM_JsonParse()
1516 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(json_object); in OH_JSVM_JsonStringify()
1518 auto maybe = v8::JSON::Stringify(env->context(), val); in OH_JSVM_JsonStringify()
1531 auto isolate = reinterpret_cast<v8::Isolate*>(vm); in OH_JSVM_CreateSnapshot()
1537 v8::HandleScope scope(isolate); in OH_JSVM_CreateSnapshot()
1538 v8::Local<v8::Context> defaultContext = v8::Context::New(isolate); in OH_JSVM_CreateSnapshot()
1551 auto blob = creator->CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kKeep); in OH_JSVM_CreateSnapshot()
1561 result->engine = "v8"; in OH_JSVM_GetVMInfo()
1563 result->cachedDataVersionTag = v8::ScriptCompiler::CachedDataVersionTag(); in OH_JSVM_GetVMInfo()
1570 env->isolate->MemoryPressureNotification(v8::MemoryPressureLevel(level)); in OH_JSVM_MemoryPressureNotification()
1576 auto isolate = reinterpret_cast<v8::Isolate*>(vm); in OH_JSVM_GetHeapStatistics()
1577 v8::HeapStatistics stats; in OH_JSVM_GetHeapStatistics()
1597 auto isolate = reinterpret_cast<v8::Isolate*>(vm); in OH_JSVM_StartCpuProfiler()
1598 auto profiler = v8::CpuProfiler::New(isolate); in OH_JSVM_StartCpuProfiler()
1599 v8::HandleScope scope(isolate); in OH_JSVM_StartCpuProfiler()
1600 v8::CpuProfilingOptions options; in OH_JSVM_StartCpuProfiler()
1601 profiler->Start(v8::String::Empty(isolate), std::move(options)); in OH_JSVM_StartCpuProfiler()
1612 auto isolate = reinterpret_cast<v8::Isolate*>(vm); in OH_JSVM_StopCpuProfiler()
1613 auto v8profiler = reinterpret_cast<v8::CpuProfiler*>(profiler); in OH_JSVM_StopCpuProfiler()
1614 v8::HandleScope scope(isolate); in OH_JSVM_StopCpuProfiler()
1615 auto profile = v8profiler->StopProfiling(v8::String::Empty(isolate)); in OH_JSVM_StopCpuProfiler()
1624 auto isolate = reinterpret_cast<v8::Isolate*>(vm); in OH_JSVM_TakeHeapSnapshot()
1678 auto isolate = reinterpret_cast<v8::Isolate*>(vm); in OH_JSVM_PumpMessageLoop()
1679 *result = v8::platform::PumpMessageLoop(v8impl::g_platform.get(), isolate); in OH_JSVM_PumpMessageLoop()
1685 auto isolate = reinterpret_cast<v8::Isolate*>(vm); in OH_JSVM_PerformMicrotaskCheckpoint()
1754 v8::Local<v8::Function> returnValue; in OH_JSVM_CreateFunction()
1755 v8::EscapableHandleScope scope(env->isolate); in OH_JSVM_CreateFunction()
1756 v8::Local<v8::Function> fn; in OH_JSVM_CreateFunction()
1761 v8::Local<v8::String> nameString; in OH_JSVM_CreateFunction()
1789 v8::Local<v8::Value> v8Script = v8impl::V8LocalValueFromJsValue(script); in OH_JSVM_CreateFunctionWithScript()
1793 v8::ScriptCompiler::Source scriptSource(v8Script.As<v8::String>()); in OH_JSVM_CreateFunctionWithScript()
1795 v8::Local<v8::Context> context = env->context(); in OH_JSVM_CreateFunctionWithScript()
1797 v8::MaybeLocal<v8::Function> maybeFunc = in OH_JSVM_CreateFunctionWithScript()
1798 v8::ScriptCompiler::CompileFunction(context, &scriptSource, argc, in OH_JSVM_CreateFunctionWithScript()
1799 … reinterpret_cast<v8::Local<v8::String>*>(const_cast<JSVM_Value*>(argv))); in OH_JSVM_CreateFunctionWithScript()
1802 v8::Local<v8::Function> func = maybeFunc.ToLocalChecked(); in OH_JSVM_CreateFunctionWithScript()
1805 v8::Local<v8::String> funcNameString; in OH_JSVM_CreateFunctionWithScript()
1831 v8::Isolate* isolate = env->isolate; in OH_JSVM_DefineClass()
1833 v8::EscapableHandleScope scope(isolate); in OH_JSVM_DefineClass()
1834 v8::Local<v8::FunctionTemplate> tpl; in OH_JSVM_DefineClass()
1837 v8::Local<v8::String> nameString; in OH_JSVM_DefineClass()
1851 v8::Local<v8::Name> propertyName; in OH_JSVM_DefineClass()
1854 v8::PropertyAttribute attributes = v8impl::V8PropertyAttributesFromDescriptor(p); in OH_JSVM_DefineClass()
1861 v8::Local<v8::FunctionTemplate> getterTpl; in OH_JSVM_DefineClass()
1862 v8::Local<v8::FunctionTemplate> setterTpl; in OH_JSVM_DefineClass()
1871 v8::AccessControl::DEFAULT); in OH_JSVM_DefineClass()
1873 v8::Local<v8::FunctionTemplate> t; in OH_JSVM_DefineClass()
1878 …v8impl::FunctionCallbackWrapper::NewTemplate(env, p->method, &t, v8::Signature::New(isolate, tpl))… in OH_JSVM_DefineClass()
1883 v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(p->value); in OH_JSVM_DefineClass()
1888 v8::Local<v8::Context> context = env->context(); in OH_JSVM_DefineClass()
1925 v8::Local<v8::Context> context = env->context(); in OH_JSVM_GetAllPropertyNames()
1926 v8::Local<v8::Object> obj; in OH_JSVM_GetAllPropertyNames()
1929 v8::PropertyFilter filter = v8::PropertyFilter::ALL_PROPERTIES; in OH_JSVM_GetAllPropertyNames()
1931 filter = static_cast<v8::PropertyFilter>(filter | v8::PropertyFilter::ONLY_WRITABLE); in OH_JSVM_GetAllPropertyNames()
1934 filter = static_cast<v8::PropertyFilter>(filter | v8::PropertyFilter::ONLY_ENUMERABLE); in OH_JSVM_GetAllPropertyNames()
1937 filter = static_cast<v8::PropertyFilter>(filter | v8::PropertyFilter::ONLY_CONFIGURABLE); in OH_JSVM_GetAllPropertyNames()
1940 filter = static_cast<v8::PropertyFilter>(filter | v8::PropertyFilter::SKIP_STRINGS); in OH_JSVM_GetAllPropertyNames()
1943 filter = static_cast<v8::PropertyFilter>(filter | v8::PropertyFilter::SKIP_SYMBOLS); in OH_JSVM_GetAllPropertyNames()
1945 v8::KeyCollectionMode collectionMode; in OH_JSVM_GetAllPropertyNames()
1946 v8::KeyConversionMode conversionMode; in OH_JSVM_GetAllPropertyNames()
1950 collectionMode = v8::KeyCollectionMode::kIncludePrototypes; in OH_JSVM_GetAllPropertyNames()
1953 collectionMode = v8::KeyCollectionMode::kOwnOnly; in OH_JSVM_GetAllPropertyNames()
1961 conversionMode = v8::KeyConversionMode::kKeepNumbers; in OH_JSVM_GetAllPropertyNames()
1964 conversionMode = v8::KeyConversionMode::kConvertToString; in OH_JSVM_GetAllPropertyNames()
1970 v8::MaybeLocal<v8::Array> maybeAllPropertynames = in OH_JSVM_GetAllPropertyNames()
1971 …obj->GetPropertyNames(context, collectionMode, filter, v8::IndexFilter::kIncludeIndices, conversio… in OH_JSVM_GetAllPropertyNames()
1985 v8::Local<v8::Context> context = env->context(); in OH_JSVM_SetProperty()
1986 v8::Local<v8::Object> obj; in OH_JSVM_SetProperty()
1990 v8::Local<v8::Value> k = v8impl::V8LocalValueFromJsValue(key); in OH_JSVM_SetProperty()
1991 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_SetProperty()
1993 v8::Maybe<bool> setMaybe = obj->Set(context, k, val); in OH_JSVM_SetProperty()
2004 v8::Local<v8::Context> context = env->context(); in OH_JSVM_HasProperty()
2005 v8::Local<v8::Object> obj; in OH_JSVM_HasProperty()
2009 v8::Local<v8::Value> k = v8impl::V8LocalValueFromJsValue(key); in OH_JSVM_HasProperty()
2010 v8::Maybe<bool> hasMaybe = obj->Has(context, k); in OH_JSVM_HasProperty()
2023 v8::Local<v8::Context> context = env->context(); in OH_JSVM_GetProperty()
2024 v8::Local<v8::Value> k = v8impl::V8LocalValueFromJsValue(key); in OH_JSVM_GetProperty()
2025 v8::Local<v8::Object> obj; in OH_JSVM_GetProperty()
2032 v8::Local<v8::Value> val = getMaybe.ToLocalChecked(); in OH_JSVM_GetProperty()
2042 v8::Local<v8::Context> context = env->context(); in OH_JSVM_DeleteProperty()
2043 v8::Local<v8::Value> k = v8impl::V8LocalValueFromJsValue(key); in OH_JSVM_DeleteProperty()
2044 v8::Local<v8::Object> obj; in OH_JSVM_DeleteProperty()
2047 v8::Maybe<bool> deleteMaybe = obj->Delete(context, k); in OH_JSVM_DeleteProperty()
2062 v8::Local<v8::Context> context = env->context(); in OH_JSVM_HasOwnProperty()
2063 v8::Local<v8::Object> obj; in OH_JSVM_HasOwnProperty()
2066 v8::Local<v8::Value> k = v8impl::V8LocalValueFromJsValue(key); in OH_JSVM_HasOwnProperty()
2068 v8::Maybe<bool> hasMaybe = obj->HasOwnProperty(context, k.As<v8::Name>()); in OH_JSVM_HasOwnProperty()
2080 v8::Local<v8::Context> context = env->context(); in OH_JSVM_SetNamedProperty()
2081 v8::Local<v8::Object> obj; in OH_JSVM_SetNamedProperty()
2085 v8::Local<v8::Name> key; in OH_JSVM_SetNamedProperty()
2088 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_SetNamedProperty()
2090 v8::Maybe<bool> setMaybe = obj->Set(context, key, val); in OH_JSVM_SetNamedProperty()
2100 v8::Local<v8::Context> context = env->context(); in OH_JSVM_HasNamedProperty()
2101 v8::Local<v8::Object> obj; in OH_JSVM_HasNamedProperty()
2105 v8::Local<v8::Name> key; in OH_JSVM_HasNamedProperty()
2108 v8::Maybe<bool> hasMaybe = obj->Has(context, key); in OH_JSVM_HasNamedProperty()
2120 v8::Local<v8::Context> context = env->context(); in OH_JSVM_GetNamedProperty()
2122 v8::Local<v8::Name> key; in OH_JSVM_GetNamedProperty()
2125 v8::Local<v8::Object> obj; in OH_JSVM_GetNamedProperty()
2132 v8::Local<v8::Value> val = getMaybe.ToLocalChecked(); in OH_JSVM_GetNamedProperty()
2142 v8::Local<v8::Context> context = env->context(); in OH_JSVM_SetElement()
2143 v8::Local<v8::Object> obj; in OH_JSVM_SetElement()
2147 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_SetElement()
2159 v8::Local<v8::Context> context = env->context(); in OH_JSVM_HasElement()
2160 v8::Local<v8::Object> obj; in OH_JSVM_HasElement()
2164 v8::Maybe<bool> hasMaybe = obj->Has(context, index); in OH_JSVM_HasElement()
2176 v8::Local<v8::Context> context = env->context(); in OH_JSVM_GetElement()
2177 v8::Local<v8::Object> obj; in OH_JSVM_GetElement()
2192 v8::Local<v8::Context> context = env->context(); in OH_JSVM_DeleteElement()
2193 v8::Local<v8::Object> obj; in OH_JSVM_DeleteElement()
2196 v8::Maybe<bool> deleteMaybe = obj->Delete(context, index); in OH_JSVM_DeleteElement()
2215 v8::Local<v8::Context> context = env->context(); in OH_JSVM_DefineProperties()
2217 v8::Local<v8::Object> obj; in OH_JSVM_DefineProperties()
2223 v8::Local<v8::Name> propertyName; in OH_JSVM_DefineProperties()
2227 v8::Local<v8::Function> localGetter; in OH_JSVM_DefineProperties()
2228 v8::Local<v8::Function> localSetter; in OH_JSVM_DefineProperties()
2237 v8::PropertyDescriptor descriptor(localGetter, localSetter); in OH_JSVM_DefineProperties()
2246 v8::Local<v8::Function> method; in OH_JSVM_DefineProperties()
2248 v8::PropertyDescriptor descriptor(method, (p->attributes & JSVM_WRITABLE) != 0); in OH_JSVM_DefineProperties()
2257 v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(p->value); in OH_JSVM_DefineProperties()
2266 v8::PropertyDescriptor descriptor(value, (p->attributes & JSVM_WRITABLE) != 0); in OH_JSVM_DefineProperties()
2287 v8::Local<v8::Context> context = env->context(); in OH_JSVM_ObjectFreeze()
2288 v8::Local<v8::Object> obj; in OH_JSVM_ObjectFreeze()
2292 v8::Maybe<bool> setFrozen = obj->SetIntegrityLevel(context, v8::IntegrityLevel::kFrozen); in OH_JSVM_ObjectFreeze()
2303 v8::Local<v8::Context> context = env->context(); in OH_JSVM_ObjectSeal()
2304 v8::Local<v8::Object> obj; in OH_JSVM_ObjectSeal()
2308 v8::Maybe<bool> setSealed = obj->SetIntegrityLevel(context, v8::IntegrityLevel::kSealed); in OH_JSVM_ObjectSeal()
2321 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsArray()
2333 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsRegExp()
2345 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_GetArrayLength()
2348 v8::Local<v8::Array> arr = val.As<v8::Array>(); in OH_JSVM_GetArrayLength()
2361 v8::Local<v8::Value> a = v8impl::V8LocalValueFromJsValue(lhs); in OH_JSVM_StrictEquals()
2362 v8::Local<v8::Value> b = v8impl::V8LocalValueFromJsValue(rhs); in OH_JSVM_StrictEquals()
2375 v8::Local<v8::Value> a = v8impl::V8LocalValueFromJsValue(lhs); in OH_JSVM_Equals()
2376 v8::Local<v8::Value> b = v8impl::V8LocalValueFromJsValue(rhs); in OH_JSVM_Equals()
2377 v8::Local<v8::Context> context = env->context(); in OH_JSVM_Equals()
2388 v8::Local<v8::Context> context = env->context(); in OH_JSVM_GetPrototype()
2390 v8::Local<v8::Object> obj; in OH_JSVM_GetPrototype()
2393 v8::Local<v8::Value> val = obj->GetPrototype(); in OH_JSVM_GetPrototype()
2403 *result = v8impl::JsValueFromV8LocalValue(v8::Object::New(env->isolate)); in OH_JSVM_CreateObject()
2413 *result = v8impl::JsValueFromV8LocalValue(v8::Array::New(env->isolate)); in OH_JSVM_CreateArray()
2423 *result = v8impl::JsValueFromV8LocalValue(v8::Array::New(env->isolate, length)); in OH_JSVM_CreateArrayWithLength()
2430 return v8impl::NewString(env, str, length, result, [&](v8::Isolate* isolate) { in OH_JSVM_CreateStringLatin1()
2431 …return v8::String::NewFromOneByte(isolate, reinterpret_cast<const uint8_t*>(str), v8::NewStringTyp… in OH_JSVM_CreateStringLatin1()
2438 return v8impl::NewString(env, str, length, result, [&](v8::Isolate* isolate) { in OH_JSVM_CreateStringUtf8()
2439 …return v8::String::NewFromUtf8(isolate, str, v8::NewStringType::kNormal, static_cast<int>(length)); in OH_JSVM_CreateStringUtf8()
2445 return v8impl::NewString(env, str, length, result, [&](v8::Isolate* isolate) { in OH_JSVM_CreateStringUtf16()
2446 …return v8::String::NewFromTwoByte(isolate, reinterpret_cast<const uint16_t*>(str), v8::NewStringTy… in OH_JSVM_CreateStringUtf16()
2456 *result = v8impl::JsValueFromV8LocalValue(v8::Number::New(env->isolate, value)); in OH_JSVM_CreateDouble()
2466 *result = v8impl::JsValueFromV8LocalValue(v8::Integer::New(env->isolate, value)); in OH_JSVM_CreateInt32()
2476 *result = v8impl::JsValueFromV8LocalValue(v8::Integer::NewFromUnsigned(env->isolate, value)); in OH_JSVM_CreateUint32()
2486 …*result = v8impl::JsValueFromV8LocalValue(v8::Number::New(env->isolate, static_cast<double>(value)… in OH_JSVM_CreateInt64()
2496 *result = v8impl::JsValueFromV8LocalValue(v8::BigInt::New(env->isolate, value)); in OH_JSVM_CreateBigintInt64()
2506 *result = v8impl::JsValueFromV8LocalValue(v8::BigInt::NewFromUnsigned(env->isolate, value)); in OH_JSVM_CreateBigintUint64()
2521 v8::Local<v8::Context> context = env->context(); in OH_JSVM_CreateBigintWords()
2525 v8::MaybeLocal<v8::BigInt> b = v8::BigInt::NewFromWords(context, signBit, wordCount, words); in OH_JSVM_CreateBigintWords()
2538 v8::Isolate* isolate = env->isolate; in OH_JSVM_GetBoolean()
2541 *result = v8impl::JsValueFromV8LocalValue(v8::True(isolate)); in OH_JSVM_GetBoolean()
2543 *result = v8impl::JsValueFromV8LocalValue(v8::False(isolate)); in OH_JSVM_GetBoolean()
2554 v8::Isolate* isolate = env->isolate; in OH_JSVM_CreateSymbol()
2557 *result = v8impl::JsValueFromV8LocalValue(v8::Symbol::New(isolate)); in OH_JSVM_CreateSymbol()
2559 v8::Local<v8::Value> desc = v8impl::V8LocalValueFromJsValue(description); in OH_JSVM_CreateSymbol()
2562 *result = v8impl::JsValueFromV8LocalValue(v8::Symbol::New(isolate, desc.As<v8::String>())); in OH_JSVM_CreateSymbol()
2575v8::Local<v8::String> descriptionString = v8impl::V8LocalValueFromJsValue(jsDescriptionString).As< in OH_JSVM_SymbolFor()
2577 *result = v8impl::JsValueFromV8LocalValue(v8::Symbol::For(env->isolate, descriptionString)); in OH_JSVM_SymbolFor()
2582 static JSVM_Status SetErrorCode(JSVM_Env env, v8::Local<v8::Value> error, JSVM_Value code, const ch… in SetErrorCode()
2585 v8::Local<v8::Context> context = env->context(); in SetErrorCode()
2586 v8::Local<v8::Object> errObject = error.As<v8::Object>(); in SetErrorCode()
2588 v8::Local<v8::Value> codeValue = v8impl::V8LocalValueFromJsValue(code); in SetErrorCode()
2596 v8::Local<v8::Name> codeKey; in SetErrorCode()
2599 v8::Maybe<bool> setMaybe = errObject->Set(context, codeKey, codeValue); in SetErrorCode()
2611 v8::Local<v8::Value> messageValue = v8impl::V8LocalValueFromJsValue(msg); in OH_JSVM_CreateError()
2614 v8::Local<v8::Value> errorObj = v8::Exception::Error(messageValue.As<v8::String>()); in OH_JSVM_CreateError()
2628 v8::Local<v8::Value> messageValue = v8impl::V8LocalValueFromJsValue(msg); in OH_JSVM_CreateTypeError()
2631 v8::Local<v8::Value> errorObj = v8::Exception::TypeError(messageValue.As<v8::String>()); in OH_JSVM_CreateTypeError()
2645 v8::Local<v8::Value> messageValue = v8impl::V8LocalValueFromJsValue(msg); in OH_JSVM_CreateRangeError()
2648 v8::Local<v8::Value> errorObj = v8::Exception::RangeError(messageValue.As<v8::String>()); in OH_JSVM_CreateRangeError()
2662 v8::Local<v8::Value> messageValue = v8impl::V8LocalValueFromJsValue(msg); in OH_JSVM_CreateSyntaxError()
2665 v8::Local<v8::Value> errorObj = v8::Exception::SyntaxError(messageValue.As<v8::String>()); in OH_JSVM_CreateSyntaxError()
2675 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw in OH_JSVM_Typeof()
2681 v8::Local<v8::Value> v = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_Typeof()
2708 // Should not get here unless V8 has added some new kind of value. in OH_JSVM_Typeof()
2720 *result = v8impl::JsValueFromV8LocalValue(v8::Undefined(env->isolate)); in OH_JSVM_GetUndefined()
2730 *result = v8impl::JsValueFromV8LocalValue(v8::Null(env->isolate)); in OH_JSVM_GetNull()
2791 v8::Local<v8::Context> context = env->context(); in OH_JSVM_CallFunction()
2793 v8::Local<v8::Value> v8recv = v8impl::V8LocalValueFromJsValue(recv); in OH_JSVM_CallFunction()
2795 v8::Local<v8::Function> v8func; in OH_JSVM_CallFunction()
2799 …v8func->Call(context, v8recv, argc, reinterpret_cast<v8::Local<v8::Value>*>(const_cast<JSVM_Value*… in OH_JSVM_CallFunction()
2825 v8::Isolate* isolate = env->isolate; in OH_JSVM_Throw()
2837 v8::Isolate* isolate = env->isolate; in OH_JSVM_ThrowError()
2838 v8::Local<v8::String> str; in OH_JSVM_ThrowError()
2841 v8::Local<v8::Value> errorObj = v8::Exception::Error(str); in OH_JSVM_ThrowError()
2854 v8::Isolate* isolate = env->isolate; in OH_JSVM_ThrowTypeError()
2855 v8::Local<v8::String> str; in OH_JSVM_ThrowTypeError()
2858 v8::Local<v8::Value> errorObj = v8::Exception::TypeError(str); in OH_JSVM_ThrowTypeError()
2871 v8::Isolate* isolate = env->isolate; in OH_JSVM_ThrowRangeError()
2872 v8::Local<v8::String> str; in OH_JSVM_ThrowRangeError()
2875 v8::Local<v8::Value> errorObj = v8::Exception::RangeError(str); in OH_JSVM_ThrowRangeError()
2888 v8::Isolate* isolate = env->isolate; in OH_JSVM_ThrowSyntaxError()
2889 v8::Local<v8::String> str; in OH_JSVM_ThrowSyntaxError()
2892 v8::Local<v8::Value> errorObj = v8::Exception::SyntaxError(str); in OH_JSVM_ThrowSyntaxError()
2903 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot in OH_JSVM_IsError()
2909 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsError()
2917 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw in OH_JSVM_GetValueDouble()
2923 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_GetValueDouble()
2926 *result = val.As<v8::Number>()->Value(); in OH_JSVM_GetValueDouble()
2933 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw in OH_JSVM_GetValueInt32()
2939 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_GetValueInt32()
2942 *result = val.As<v8::Int32>()->Value(); in OH_JSVM_GetValueInt32()
2947 v8::Local<v8::Context> context; in OH_JSVM_GetValueInt32()
2956 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw in OH_JSVM_GetValueUint32()
2962 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_GetValueUint32()
2965 *result = val.As<v8::Uint32>()->Value(); in OH_JSVM_GetValueUint32()
2970 v8::Local<v8::Context> context; in OH_JSVM_GetValueUint32()
2979 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw in OH_JSVM_GetValueInt64()
2985 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_GetValueInt64()
2989 *result = val.As<v8::Int32>()->Value(); in OH_JSVM_GetValueInt64()
2995 // v8::Value::IntegerValue() converts NaN, +Inf, and -Inf to INT64_MIN, in OH_JSVM_GetValueInt64()
2996 // inconsistent with v8::Value::Int32Value() which converts those values to 0. in OH_JSVM_GetValueInt64()
2998 double doubleValue = val.As<v8::Number>()->Value(); in OH_JSVM_GetValueInt64()
3001 v8::Local<v8::Context> context; in OH_JSVM_GetValueInt64()
3017 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_GetValueBigintInt64()
3021 *result = val.As<v8::BigInt>()->Int64Value(lossless); in OH_JSVM_GetValueBigintInt64()
3033 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_GetValueBigintUint64()
3037 *result = val.As<v8::BigInt>()->Uint64Value(lossless); in OH_JSVM_GetValueBigintUint64()
3052 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_GetValueBigintWords()
3056 v8::Local<v8::BigInt> big = val.As<v8::BigInt>(); in OH_JSVM_GetValueBigintWords()
3075 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw in OH_JSVM_GetValueBool()
3081 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_GetValueBool()
3084 *result = val.As<v8::Boolean>()->Value(); in OH_JSVM_GetValueBool()
3102 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_GetValueStringLatin1()
3107 *result = val.As<v8::String>()->Length(); in OH_JSVM_GetValueStringLatin1()
3109 …int copied = val.As<v8::String>()->WriteOneByte(env->isolate, reinterpret_cast<uint8_t*>(buf), 0, … in OH_JSVM_GetValueStringLatin1()
3110 v8::String::NO_NULL_TERMINATION); in OH_JSVM_GetValueStringLatin1()
3136 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_GetValueStringUtf8()
3141 *result = val.As<v8::String>()->Utf8Length(env->isolate); in OH_JSVM_GetValueStringUtf8()
3144 val.As<v8::String>()->WriteUtf8(env->isolate, buf, bufsize - 1, nullptr, in OH_JSVM_GetValueStringUtf8()
3145v8::String::REPLACE_INVALID_UTF8 | v8::String::NO_NULL_TERMINATION); in OH_JSVM_GetValueStringUtf8()
3171 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_GetValueStringUtf16()
3176 // V8 assumes UTF-16 length is the same as the number of characters. in OH_JSVM_GetValueStringUtf16()
3177 *result = val.As<v8::String>()->Length(); in OH_JSVM_GetValueStringUtf16()
3179 …int copied = val.As<v8::String>()->Write(env->isolate, reinterpret_cast<uint16_t*>(buf), 0, bufsiz… in OH_JSVM_GetValueStringUtf16()
3180 v8::String::NO_NULL_TERMINATION); in OH_JSVM_GetValueStringUtf16()
3199 v8::Isolate* isolate = env->isolate; in OH_JSVM_CoerceToBool()
3200 v8::Local<v8::Boolean> b = v8impl::V8LocalValueFromJsValue(value)->ToBoolean(isolate); in OH_JSVM_CoerceToBool()
3212v8::Local<v8::Context> context = env->context(); \
3213v8::Local<v8::MixedCaseName> str; \
3257 v8::Isolate* isolate = env->isolate; in OH_JSVM_CreateExternal()
3259 v8::Local<v8::Value> externalValue = v8::External::New(isolate, data); in OH_JSVM_CreateExternal()
3271 v8::Local<v8::Context> context = env->context(); in OH_JSVM_TypeTagObject()
3272 v8::Local<v8::Object> obj; in OH_JSVM_TypeTagObject()
3281 auto tag = v8::BigInt::NewFromWords(context, 0, 2, reinterpret_cast<const uint64_t*>(typeTag)); in OH_JSVM_TypeTagObject()
3294 v8::Local<v8::Context> context = env->context(); in OH_JSVM_CheckObjectTypeTag()
3295 v8::Local<v8::Object> obj; in OH_JSVM_CheckObjectTypeTag()
3302 v8::Local<v8::Value> val = maybeValue.ToLocalChecked(); in OH_JSVM_CheckObjectTypeTag()
3312 val.As<v8::BigInt>()->ToWordsArray(&sign, &size, reinterpret_cast<uint64_t*>(&tag)); in OH_JSVM_CheckObjectTypeTag()
3333 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_GetValueExternal()
3336 v8::Local<v8::External> externalValue = val.As<v8::External>(); in OH_JSVM_GetValueExternal()
3345 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw in OH_JSVM_CreateReference()
3351 v8::Local<v8::Value> v8Value = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_CreateReference()
3362 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw in OH_JSVM_DeleteReference()
3379 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw in OH_JSVM_ReferenceRef()
3400 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw in OH_JSVM_ReferenceUnref()
3425 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw in OH_JSVM_GetReferenceValue()
3439 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw in OH_JSVM_OpenHandleScope()
3451 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw in OH_JSVM_CloseHandleScope()
3467 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw in OH_JSVM_OpenEscapableHandleScope()
3480 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw in OH_JSVM_CloseEscapableHandleScope()
3495 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw in OH_JSVM_EscapeHandle()
3523 v8::Local<v8::Context> context = env->context(); in OH_JSVM_NewInstance()
3525 v8::Local<v8::Function> ctor; in OH_JSVM_NewInstance()
3529 …ctor->NewInstance(context, argc, reinterpret_cast<v8::Local<v8::Value>*>(const_cast<JSVM_Value*>(a… in OH_JSVM_NewInstance()
3544 v8::Local<v8::Object> ctor; in OH_JSVM_Instanceof()
3545 v8::Local<v8::Context> context = env->context(); in OH_JSVM_Instanceof()
3557 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(object); in OH_JSVM_Instanceof()
3586 …*result = v8impl::JsValueFromV8LocalValue(v8::Local<v8::Value>::New(env->isolate, env->lastExcepti… in OH_JSVM_GetAndClearLastException()
3599 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsArraybuffer()
3610 v8::Isolate* isolate = env->isolate; in OH_JSVM_CreateArraybuffer()
3611 v8::Local<v8::ArrayBuffer> buffer = v8::ArrayBuffer::New(isolate, byteLength); in OH_JSVM_CreateArraybuffer()
3661v8::ArrayBuffer::NewBackingStore(dataPtr, arrayBufferSize, v8::BackingStore::EmptyDeleter, nullptr… in OH_JSVM_CreateArrayBufferFromBackingStoreData()
3662v8::Local<v8::ArrayBuffer> arrayBuffer = v8::ArrayBuffer::New(env->isolate, std::move(backingStore… in OH_JSVM_CreateArrayBufferFromBackingStoreData()
3672 v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(arraybuffer); in OH_JSVM_GetArraybufferInfo()
3675 v8::Local<v8::ArrayBuffer> ab = value.As<v8::ArrayBuffer>(); in OH_JSVM_GetArraybufferInfo()
3694 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsTypedarray()
3711 v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(arraybuffer); in OH_JSVM_CreateTypedarray()
3714 v8::Local<v8::ArrayBuffer> buffer = value.As<v8::ArrayBuffer>(); in OH_JSVM_CreateTypedarray()
3715 v8::Local<v8::TypedArray> typedArray; in OH_JSVM_CreateTypedarray()
3770 v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(typedarray); in OH_JSVM_GetTypedarrayInfo()
3773 v8::Local<v8::TypedArray> array = value.As<v8::TypedArray>(); in OH_JSVM_GetTypedarrayInfo()
3805 v8::Local<v8::ArrayBuffer> buffer; in OH_JSVM_GetTypedarrayInfo()
3837 v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(arraybuffer); in OH_JSVM_CreateDataview()
3840 v8::Local<v8::ArrayBuffer> buffer = value.As<v8::ArrayBuffer>(); in OH_JSVM_CreateDataview()
3848 v8::Local<v8::DataView> DataView = v8::DataView::New(buffer, byteOffset, byteLength); in OH_JSVM_CreateDataview()
3860 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsDataview()
3876 v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(dataview); in OH_JSVM_GetDataviewInfo()
3879 v8::Local<v8::DataView> array = value.As<v8::DataView>(); in OH_JSVM_GetDataviewInfo()
3885 v8::Local<v8::ArrayBuffer> buffer; in OH_JSVM_GetDataviewInfo()
3921 auto maybe = v8::Promise::Resolver::New(env->context()); in OH_JSVM_CreatePromise()
3925 auto v8Deferred = new v8impl::Persistent<v8::Value>(); in OH_JSVM_CreatePromise()
3971 v8::MaybeLocal<v8::Value> maybeDate = v8::Date::New(env->context(), time); in OH_JSVM_CreateDate()
3996 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_GetDateValue()
3999 v8::Local<v8::Date> date = val.As<v8::Date>(); in OH_JSVM_GetDateValue()
4012 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw in OH_JSVM_AddFinalizer()
4018 v8::Local<v8::Value> v8Value = v8impl::V8LocalValueFromJsValue(jsObject); in OH_JSVM_AddFinalizer()
4073 v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(arraybuffer); in OH_JSVM_DetachArraybuffer()
4076 v8::Local<v8::ArrayBuffer> it = value.As<v8::ArrayBuffer>(); in OH_JSVM_DetachArraybuffer()
4090 v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(arraybuffer); in OH_JSVM_IsDetachedArraybuffer()
4092 *result = value->IsArrayBuffer() && value.As<v8::ArrayBuffer>()->WasDetached(); in OH_JSVM_IsDetachedArraybuffer()
4117 v8::Isolate* isolate = env->isolate; in OH_JSVM_DefineClassWithPropertyHandler()
4118 v8::EscapableHandleScope scope(isolate); in OH_JSVM_DefineClassWithPropertyHandler()
4119 v8::Local<v8::FunctionTemplate> tpl; in OH_JSVM_DefineClassWithPropertyHandler()
4122 v8::Local<v8::String> nameString; in OH_JSVM_DefineClassWithPropertyHandler()
4136 v8::Local<v8::Name> propertyName; in OH_JSVM_DefineClassWithPropertyHandler()
4138 v8::PropertyAttribute attributes = v8impl::V8PropertyAttributesFromDescriptor(p); in OH_JSVM_DefineClassWithPropertyHandler()
4145 v8::Local<v8::FunctionTemplate> getterTpl; in OH_JSVM_DefineClassWithPropertyHandler()
4146 v8::Local<v8::FunctionTemplate> setterTpl; in OH_JSVM_DefineClassWithPropertyHandler()
4155 v8::AccessControl::DEFAULT); in OH_JSVM_DefineClassWithPropertyHandler()
4157 v8::Local<v8::FunctionTemplate> t; in OH_JSVM_DefineClassWithPropertyHandler()
4162 …v8impl::FunctionCallbackWrapper::NewTemplate(env, p->method, &t, v8::Signature::New(isolate, tpl))… in OH_JSVM_DefineClassWithPropertyHandler()
4167 v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(p->value); in OH_JSVM_DefineClassWithPropertyHandler()
4177 v8::Local<v8::Value> cbdata = v8impl::CallbackBundle::New(env, propertyHandleCfg); in OH_JSVM_DefineClassWithPropertyHandler()
4180 v8::NamedPropertyHandlerConfiguration namedPropertyHandler; in OH_JSVM_DefineClassWithPropertyHandler()
4182 namedPropertyHandler.getter = v8impl::PropertyCallbackWrapper<v8::Value>::NameGetterInvoke; in OH_JSVM_DefineClassWithPropertyHandler()
4185 namedPropertyHandler.setter = v8impl::PropertyCallbackWrapper<v8::Value>::NameSetterInvoke; in OH_JSVM_DefineClassWithPropertyHandler()
4188 … namedPropertyHandler.deleter = v8impl::PropertyCallbackWrapper<v8::Boolean>::NameDeleterInvoke; in OH_JSVM_DefineClassWithPropertyHandler()
4191 …namedPropertyHandler.enumerator = v8impl::PropertyCallbackWrapper<v8::Array>::NameEnumeratorInvoke; in OH_JSVM_DefineClassWithPropertyHandler()
4197 v8::IndexedPropertyHandlerConfiguration indexPropertyHandler; in OH_JSVM_DefineClassWithPropertyHandler()
4199 indexPropertyHandler.getter = v8impl::PropertyCallbackWrapper<v8::Value>::IndexGetterInvoke; in OH_JSVM_DefineClassWithPropertyHandler()
4202 indexPropertyHandler.setter = v8impl::PropertyCallbackWrapper<v8::Value>::IndexSetterInvoke; in OH_JSVM_DefineClassWithPropertyHandler()
4205 … indexPropertyHandler.deleter = v8impl::PropertyCallbackWrapper<v8::Boolean>::IndexDeleterInvoke; in OH_JSVM_DefineClassWithPropertyHandler()
4208 …indexPropertyHandler.enumerator = v8impl::PropertyCallbackWrapper<v8::Array>::IndexEnumeratorInvok… in OH_JSVM_DefineClassWithPropertyHandler()
4215 v8::Local<v8::Value> funcCbdata = v8impl::CallbackBundle::New(env, callAsFunctionCallback); in OH_JSVM_DefineClassWithPropertyHandler()
4219 v8::Local<v8::Context> context = env->context(); in OH_JSVM_DefineClassWithPropertyHandler()
4247 *isLocked = v8::Locker::IsLocked(env->isolate); in OH_JSVM_IsLocked()
4256 bool isLocked = v8::Locker::IsLocked(env->isolate); in OH_JSVM_AcquireLock()
4258 env->locker = new v8::Locker(env->isolate); in OH_JSVM_AcquireLock()
4268 bool isLocked = v8::Locker::IsLocked(env->isolate); in OH_JSVM_ReleaseLock()
4283 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsCallable()
4291 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 in OH_JSVM_IsUndefined()
4297 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsUndefined()
4305 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 in OH_JSVM_IsNull()
4311 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsNull()
4319 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 in OH_JSVM_IsNullOrUndefined()
4325 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsNullOrUndefined()
4333 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 in OH_JSVM_IsBoolean()
4339 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsBoolean()
4347 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 in OH_JSVM_IsNumber()
4353 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsNumber()
4361 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 in OH_JSVM_IsString()
4367 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsString()
4375 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 in OH_JSVM_IsSymbol()
4381 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsSymbol()
4389 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 in OH_JSVM_IsFunction()
4395 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsFunction()
4403 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 in OH_JSVM_IsObject()
4409 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsObject()
4417 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 in OH_JSVM_IsBigInt()
4423 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsBigInt()
4435 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsConstructor()
4440 v8::Local<v8::Object> obj = val.As<v8::Object>(); in OH_JSVM_IsConstructor()
4452 v8::Local<v8::Value> pattern = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_CreateRegExp()
4454 v8::Local<v8::Context> context = env->context(); in OH_JSVM_CreateRegExp()
4455 v8::MaybeLocal<v8::RegExp> regExp = in OH_JSVM_CreateRegExp()
4456 v8::RegExp::New(context, pattern.As<v8::String>(), static_cast<v8::RegExp::Flags>(flags)); in OH_JSVM_CreateRegExp()
4468 *result = v8impl::JsValueFromV8LocalValue(v8::Map::New(env->isolate)); in OH_JSVM_CreateMap()
4479 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsMap()
4492 …jsvmData->taggedPointer = v8::Global<v8::Script>(env->isolate, jsvmData->ToV8Local<v8::Script>(env… in OH_JSVM_RetainScript()
4505 std::get<v8::Global<v8::Script>>(jsvmData->taggedPointer).Reset(); in OH_JSVM_ReleaseScript()
4529 *result = v8impl::JsValueFromV8LocalValue(v8::Set::New(env->isolate)); in OH_JSVM_CreateSet()
4540 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsSet()
4551 v8::Local<v8::Context> context = env->context(); in OH_JSVM_ObjectGetPrototypeOf()
4553 v8::Local<v8::Object> obj; in OH_JSVM_ObjectGetPrototypeOf()
4556 v8::Local<v8::Value> val = obj->GetPrototypeV2(); in OH_JSVM_ObjectGetPrototypeOf()
4566 v8::Local<v8::Context> context = env->context(); in OH_JSVM_ObjectSetPrototypeOf()
4568 v8::Local<v8::Object> obj; in OH_JSVM_ObjectSetPrototypeOf()
4571 v8::Local<v8::Value> type = v8impl::V8LocalValueFromJsValue(prototype); in OH_JSVM_ObjectSetPrototypeOf()
4573 v8::Maybe<bool> setMaybe = obj->SetPrototypeV2(context, type); in OH_JSVM_ObjectSetPrototypeOf()
4590 v8::MaybeLocal<v8::WasmModuleObject> maybeModule; in OH_JSVM_CompileWasmModule()
4592 … maybeModule = v8::WasmModuleObject::Compile(env->isolate, { wasmBytecode, wasmBytecodeLength }); in OH_JSVM_CompileWasmModule()
4596 …maybeModule = v8::WasmModuleObject::DeserializeOrCompile(env->isolate, { wasmBytecode, wasmBytecod… in OH_JSVM_CompileWasmModule()
4602 …// To avoid the status code caused by exception being override, check exception once v8 API finish… in OH_JSVM_CompileWasmModule()
4616 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(wasmModule); in OH_JSVM_CompileWasmFunction()
4619 v8::Local<v8::WasmModuleObject> v8WasmModule = val.As<v8::WasmModuleObject>(); in OH_JSVM_CompileWasmFunction()
4620 v8::WasmExecutionTier tier = v8::WasmExecutionTier::kNone; in OH_JSVM_CompileWasmFunction()
4622 // v8 liftoff has bug, keep BASELINE same as HIGH. in OH_JSVM_CompileWasmFunction()
4623 tier = v8::WasmExecutionTier::kTurbofan; in OH_JSVM_CompileWasmFunction()
4625 tier = v8::WasmExecutionTier::kTurbofan; in OH_JSVM_CompileWasmFunction()
4631 …// To avoid the status code caused by exception being override, check exception once v8 API finish… in OH_JSVM_CompileWasmFunction()
4639 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 in OH_JSVM_IsWasmModuleObject()
4645 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsWasmModuleObject()
4658 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(wasmModule); in OH_JSVM_CreateWasmCache()
4661 v8::Local<v8::WasmModuleObject> v8WasmModule = val.As<v8::WasmModuleObject>(); in OH_JSVM_CreateWasmCache()
4662 v8::CompiledWasmModule compiledWasmModule = v8WasmModule->GetCompiledModule(); in OH_JSVM_CreateWasmCache()
4663 v8::OwnedBuffer serializedBytes = compiledWasmModule.Serialize(); in OH_JSVM_CreateWasmCache()
4664 …// To avoid the status code caused by exception being override, check exception once v8 API finish… in OH_JSVM_CreateWasmCache()
4699 v8::Local<v8::Value> v = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsBooleanObject()
4711 v8::Local<v8::Value> v = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsBigIntObject()
4723 v8::Local<v8::Value> v = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsStringObject()
4735 v8::Local<v8::Value> v = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsNumberObject()
4747 v8::Local<v8::Value> v = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsSymbolObject()
4758 v8::Local<v8::Symbol> symbolToStringTag = v8::Symbol::GetToStringTag(env->isolate); in OH_JSVM_GetSymbolToStringTag()
4769 v8::Local<v8::Symbol> symbolIterator = v8::Symbol::GetIterator(env->isolate); in OH_JSVM_GetSymbolIterator()
4780 v8::Local<v8::Symbol> symbolAsyncIterator = v8::Symbol::GetAsyncIterator(env->isolate); in OH_JSVM_GetSymbolAsyncIterator()
4791 v8::Local<v8::Symbol> symbolHasInstance = v8::Symbol::GetHasInstance(env->isolate); in OH_JSVM_GetSymbolHasInstance()
4802 v8::Local<v8::Symbol> symbolUnscopables = v8::Symbol::GetUnscopables(env->isolate); in OH_JSVM_GetSymbolUnscopables()
4813v8::Local<v8::Symbol> symbolIsConcatSpreadable = v8::Symbol::GetIsConcatSpreadable(env->isolate); in OH_JSVM_GetSymbolIsConcatSpreadable()
4824 v8::Local<v8::Symbol> symbolMatch = v8::Symbol::GetMatch(env->isolate); in OH_JSVM_GetSymbolMatch()
4835 v8::Local<v8::Symbol> symbolReplace = v8::Symbol::GetReplace(env->isolate); in OH_JSVM_GetSymbolReplace()
4846 v8::Local<v8::Symbol> symbolSearch = v8::Symbol::GetSearch(env->isolate); in OH_JSVM_GetSymbolSearch()
4857 v8::Local<v8::Symbol> symbolSplit = v8::Symbol::GetSplit(env->isolate); in OH_JSVM_GetSymbolSplit()
4868 v8::Local<v8::Symbol> symbolToPrimitive = v8::Symbol::GetToPrimitive(env->isolate); in OH_JSVM_GetSymbolToPrimitive()
4876 static constexpr v8::MicrotasksPolicy converter[] = { v8::MicrotasksPolicy::kExplicit, in OH_JSVM_SetMicrotaskPolicy()
4877 v8::MicrotasksPolicy::kAuto }; in OH_JSVM_SetMicrotaskPolicy()
4883 auto isolate = reinterpret_cast<v8::Isolate*>(vm); in OH_JSVM_SetMicrotaskPolicy()
4897 // Check target and handler are v8 Object in OH_JSVM_CreateProxy()
4903 v8::Local<v8::Context> context = env->context(); in OH_JSVM_CreateProxy()
4905 v8::MaybeLocal<v8::Proxy> maybeProxy = in OH_JSVM_CreateProxy()
4906 v8::Proxy::New(context, localTarget.As<v8::Object>(), localHandler.As<v8::Object>()); in OH_JSVM_CreateProxy()
4910 v8::Local<v8::Proxy> proxy = maybeProxy.ToLocalChecked(); in OH_JSVM_CreateProxy()
4922 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_IsProxy()
4934 v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); in OH_JSVM_ProxyGetTarget()
4938 *result = v8impl::JsValueFromV8LocalValue(val.As<v8::Proxy>()->GetTarget()); in OH_JSVM_ProxyGetTarget()
4945 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw in OH_JSVM_CreateDataReference()
4952 v8::Local<v8::Data> v8_value = v8impl::V8LocalDataFromJsData(data); in OH_JSVM_CreateDataReference()
4964 // Omit JSVM_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw in OH_JSVM_GetReferenceData()
4982 v8::Isolate* isolate = env->isolate; in OH_JSVM_CreatePrivate()
4985 *result = v8impl::JsDataFromV8LocalData(v8::Private::New(isolate)); in OH_JSVM_CreatePrivate()
4987 v8::Local<v8::Value> v8Name = v8impl::V8LocalValueFromJsValue(description); in OH_JSVM_CreatePrivate()
4990 *result = v8impl::JsDataFromV8LocalData(v8::Private::New(isolate, v8Name.As<v8::String>())); in OH_JSVM_CreatePrivate()
5010 auto set_maybe = obj.As<v8::Object>()->SetPrivate(context, privateKey.As<v8::Private>(), val); in OH_JSVM_SetPrivate()
5029 auto getMaybe = obj.As<v8::Object>()->GetPrivate(context, privateKey.As<v8::Private>()); in OH_JSVM_GetPrivate()
5032 v8::Local<v8::Value> val = getMaybe.ToLocalChecked(); in OH_JSVM_GetPrivate()
5049 auto deleteMaybe = obj.As<v8::Object>()->DeletePrivate(context, privateKey.As<v8::Private>()); in OH_JSVM_DeletePrivate()
5065 OH_JSVM_CreateStringLatin1, [&](v8::Isolate* isolate) { in OH_JSVM_CreateExternalStringLatin1()
5072 return v8::String::NewExternalOneByte(isolate, resource); in OH_JSVM_CreateExternalStringLatin1()
5086 OH_JSVM_CreateStringUtf16, [&](v8::Isolate* isolate) { in OH_JSVM_CreateExternalStringUtf16()
5093 return v8::String::NewExternalTwoByte(isolate, resource); in OH_JSVM_CreateExternalStringUtf16()
5097 JSVM_GCType GetJSVMGCType(v8::GCType gcType) in GetJSVMGCType()
5100 case v8::GCType::kGCTypeScavenge: in GetJSVMGCType()
5102 case v8::GCType::kGCTypeMinorMarkCompact: in GetJSVMGCType()
5104 case v8::GCType::kGCTypeMarkSweepCompact: in GetJSVMGCType()
5106 case v8::GCType::kGCTypeIncrementalMarking: in GetJSVMGCType()
5108 case v8::GCType::kGCTypeProcessWeakCallbacks: in GetJSVMGCType()
5115 static v8::GCType GetV8GCType(JSVM_GCType gcType) in GetV8GCType()
5119 return v8::GCType::kGCTypeScavenge; in GetV8GCType()
5121 return v8::GCType::kGCTypeMinorMarkCompact; in GetV8GCType()
5123 return v8::GCType::kGCTypeMarkSweepCompact; in GetV8GCType()
5125 return v8::GCType::kGCTypeIncrementalMarking; in GetV8GCType()
5127 return v8::GCType::kGCTypeProcessWeakCallbacks; in GetV8GCType()
5129 return v8::GCType::kGCTypeAll; in GetV8GCType()
5133 JSVM_GCCallbackFlags GetJSVMGCCallbackFlags(v8::GCCallbackFlags flag) in GetJSVMGCCallbackFlags()
5136 case v8::GCCallbackFlags::kGCCallbackFlagConstructRetainedObjectInfos: in GetJSVMGCCallbackFlags()
5138 case v8::GCCallbackFlags::kGCCallbackFlagForced: in GetJSVMGCCallbackFlags()
5140 case v8::GCCallbackFlags::kGCCallbackFlagSynchronousPhantomCallbackProcessing: in GetJSVMGCCallbackFlags()
5142 case v8::GCCallbackFlags::kGCCallbackFlagCollectAllAvailableGarbage: in GetJSVMGCCallbackFlags()
5144 case v8::GCCallbackFlags::kGCCallbackFlagCollectAllExternalMemory: in GetJSVMGCCallbackFlags()
5146 case v8::GCCallbackFlags::kGCCallbackScheduleIdleGarbageCollection: in GetJSVMGCCallbackFlags()
5153 static void OnBeforeGC(v8::Isolate* isolate, v8::GCType type, v8::GCCallbackFlags flags, void* data) in OnBeforeGC()
5163 static void OnAfterGC(v8::Isolate* isolate, v8::GCType type, v8::GCCallbackFlags flags, void* data) in OnAfterGC()
5182 auto* isolate = reinterpret_cast<v8::Isolate*>(vm); in OH_JSVM_AddHandlerForGC()
5211 auto* isolate = reinterpret_cast<v8::Isolate*>(vm); in OH_JSVM_RemoveHandlerForGC()
5235 static void OnOOMError(const char* location, const v8::OOMDetails& details) in OnOOMError()
5237 auto* isolate = v8::Isolate::GetCurrent(); in OnOOMError()
5254 auto* isolate = reinterpret_cast<v8::Isolate*>(vm); in OH_JSVM_SetHandlerForOOMError()
5263 auto* isolate = v8::Isolate::GetCurrent(); in OnFatalError()
5280 auto* isolate = reinterpret_cast<v8::Isolate*>(vm); in OH_JSVM_SetHandlerForFatalError()
5287 static void OnPromiseReject(v8::PromiseRejectMessage rejectMessage) in OnPromiseReject()
5289 auto* isolate = v8::Isolate::GetCurrent(); in OnPromiseReject()
5300 v8::HandleScope scope(isolate); in OnPromiseReject()
5301 v8::Local<v8::Object> rejectInfo = v8::Object::New(isolate); in OnPromiseReject()
5302 auto strPromise = v8::String::NewFromUtf8(isolate, "promise").ToLocalChecked(); in OnPromiseReject()
5304 auto strValue = v8::String::NewFromUtf8(isolate, "value").ToLocalChecked(); in OnPromiseReject()
5309 case v8::kPromiseRejectWithNoHandler: { in OnPromiseReject()
5313 case v8::kPromiseHandlerAddedAfterReject: { in OnPromiseReject()
5317 case v8::kPromiseRejectAfterResolved: { in OnPromiseReject()
5321 case v8::kPromiseResolveAfterResolved: { in OnPromiseReject()
5337 auto* isolate = reinterpret_cast<v8::Isolate*>(vm); in OH_JSVM_SetHandlerForPromiseReject()
5359 using namespace v8::platform::tracing; in OH_JSVM_TraceStart()
5371 v8::Platform* platform = v8impl::g_platform.get(); in OH_JSVM_TraceStart()
5403 using namespace v8::platform::tracing; in OH_JSVM_TraceStop()
5404 v8::Platform* platform = v8impl::g_platform.get(); in OH_JSVM_TraceStop()
5420 v8::Local<v8::FunctionTemplate> tpl, in ProcessPropertyHandler()
5430 v8::Local<v8::Value> cbdata = v8impl::CallbackBundle::New(env, *propertyHandlerCfgStruct); in ProcessPropertyHandler()
5433 v8::NamedPropertyHandlerConfiguration namedPropertyHandler; in ProcessPropertyHandler()
5435 namedPropertyHandler.getter = v8impl::PropertyCallbackWrapper<v8::Value>::NameGetterInvoke; in ProcessPropertyHandler()
5438 namedPropertyHandler.setter = v8impl::PropertyCallbackWrapper<v8::Value>::NameSetterInvoke; in ProcessPropertyHandler()
5441 … namedPropertyHandler.deleter = v8impl::PropertyCallbackWrapper<v8::Boolean>::NameDeleterInvoke; in ProcessPropertyHandler()
5444 …namedPropertyHandler.enumerator = v8impl::PropertyCallbackWrapper<v8::Array>::NameEnumeratorInvoke; in ProcessPropertyHandler()
5450 v8::IndexedPropertyHandlerConfiguration indexPropertyHandler; in ProcessPropertyHandler()
5452 indexPropertyHandler.getter = v8impl::PropertyCallbackWrapper<v8::Value>::IndexGetterInvoke; in ProcessPropertyHandler()
5455 indexPropertyHandler.setter = v8impl::PropertyCallbackWrapper<v8::Value>::IndexSetterInvoke; in ProcessPropertyHandler()
5458 … indexPropertyHandler.deleter = v8impl::PropertyCallbackWrapper<v8::Boolean>::IndexDeleterInvoke; in ProcessPropertyHandler()
5461 …indexPropertyHandler.enumerator = v8impl::PropertyCallbackWrapper<v8::Array>::IndexEnumeratorInvok… in ProcessPropertyHandler()
5468 v8::Local<v8::Value> funcCbdata = v8impl::CallbackBundle::New(env, callAsFunctionCallback); in ProcessPropertyHandler()
5479 v8::Local<v8::FunctionTemplate> tpl) in ProcessOptions()
5490 v8::Local<v8::ObjectTemplate> instance_templ = tpl->InstanceTemplate(); in ProcessOptions()
5553 v8::Isolate* isolate = env->isolate; in OH_JSVM_DefineClassWithOptions()
5554 v8::EscapableHandleScope scope(isolate); in OH_JSVM_DefineClassWithOptions()
5555 v8::Local<v8::FunctionTemplate> tpl; in OH_JSVM_DefineClassWithOptions()
5558 v8::Local<v8::String> nameString; in OH_JSVM_DefineClassWithOptions()
5571 v8::Local<v8::Name> propertyName; in OH_JSVM_DefineClassWithOptions()
5573 v8::PropertyAttribute attributes = v8impl::V8PropertyAttributesFromDescriptor(p); in OH_JSVM_DefineClassWithOptions()
5579 v8::Local<v8::FunctionTemplate> getterTpl; in OH_JSVM_DefineClassWithOptions()
5580 v8::Local<v8::FunctionTemplate> setterTpl; in OH_JSVM_DefineClassWithOptions()
5589 v8::AccessControl::DEFAULT); in OH_JSVM_DefineClassWithOptions()
5591 v8::Local<v8::FunctionTemplate> temp; in OH_JSVM_DefineClassWithOptions()
5593 …v8impl::FunctionCallbackWrapper::NewTemplate(env, p->method, &temp, v8::Signature::New(isolate, tp… in OH_JSVM_DefineClassWithOptions()
5597 v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(p->value); in OH_JSVM_DefineClassWithOptions()
5603 v8::Local<v8::Function> parentFunc; in OH_JSVM_DefineClassWithOptions()
5617 v8::Local<v8::Context> context = env->context(); in OH_JSVM_DefineClassWithOptions()
5652 v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(promise); in OH_JSVM_PromiseRegisterHandler()
5654 auto localPromise = value.As<v8::Promise>(); in OH_JSVM_PromiseRegisterHandler()
5656 v8::Local<v8::Context> ctx = env->context(); in OH_JSVM_PromiseRegisterHandler()
5657 v8::MaybeLocal<v8::Promise> maybe; in OH_JSVM_PromiseRegisterHandler()
5659 // Only pass onRejected, call v8::Promise::Catch in OH_JSVM_PromiseRegisterHandler()
5662 maybe = localPromise->Catch(ctx, rejectedHandler.As<v8::Function>()); in OH_JSVM_PromiseRegisterHandler()
5664 // Only pass onFulfilled, call v8::Promise::Then in OH_JSVM_PromiseRegisterHandler()
5667 maybe = value.As<v8::Promise>()->Then(ctx, fulfiledHandler.As<v8::Function>()); in OH_JSVM_PromiseRegisterHandler()
5669 // Pass onFulfilled and onRejected, call v8::Promise::Then in OH_JSVM_PromiseRegisterHandler()
5675 …value.As<v8::Promise>()->Then(ctx, fulfiledHandler.As<v8::Function>(), rejectedHandler.As<v8::Func… in OH_JSVM_PromiseRegisterHandler()