mirror of
https://github.com/openharmony/js_worker_module.git
synced 2026-07-19 11:22:56 -04:00
!7 modify run_buffer_script to support ark
Merge pull request !7 from yaojian16/master
This commit is contained in:
@@ -88,13 +88,16 @@ void Worker::PrepareForWorkerInstance(const Worker* worker)
|
||||
}
|
||||
std::vector<uint8_t> scriptContent;
|
||||
OHOS::CCRuntime::Worker::WorkerCore::getAssertFunc(worker->GetScript(), scriptContent);
|
||||
std::string stringContent(scriptContent.begin(), scriptContent.end());
|
||||
HILOG_INFO("worker:: stringContent = %{private}s", stringContent.c_str());
|
||||
napi_value scriptStringNapiValue = nullptr;
|
||||
napi_create_string_utf8(env, stringContent.c_str(), stringContent.length(), &scriptStringNapiValue);
|
||||
|
||||
napi_value execScriptResult = nullptr;
|
||||
#ifdef USE_ARK_ENGINE
|
||||
napi_run_buffer_script(env, scriptContent, &execScriptResult);
|
||||
#else
|
||||
napi_value scriptStringNapiValue = nullptr;
|
||||
napi_create_string_utf8(
|
||||
env, reinterpret_cast<char*>(scriptContent.data()), scriptContent.size(), &scriptStringNapiValue);
|
||||
napi_run_script(env, scriptStringNapiValue, &execScriptResult);
|
||||
#endif
|
||||
if (execScriptResult == nullptr) {
|
||||
// An exception occurred when running the script.
|
||||
HILOG_ERROR("worker:: run script exception occurs, will handle exception");
|
||||
@@ -406,7 +409,7 @@ napi_value Worker::PostMessage(napi_env env, napi_callback_info cbinfo)
|
||||
{
|
||||
size_t argc = NapiValueHelp::GetCallbackInfoArgc(env, cbinfo);
|
||||
if (argc < 1) {
|
||||
napi_throw_error(env, nullptr, "Worker param count must be more than 1 with new");
|
||||
napi_throw_error(env, nullptr, "Worker param count must be more than 1 with postMessage");
|
||||
return nullptr;
|
||||
}
|
||||
napi_value* argv = new napi_value[argc];
|
||||
|
||||
Reference in New Issue
Block a user