Skip to content

Commit

Permalink
default_bootstrap didn't make it
Browse files Browse the repository at this point in the history
  • Loading branch information
mmomtchev committed Aug 30, 2022
1 parent 9cefaa7 commit c2329ae
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 29 deletions.
44 changes: 23 additions & 21 deletions src/js_native_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,33 +101,35 @@ node_api_symbol_for(napi_env env,
const char* utf8description,
size_t length,
napi_value* result);
#endif // NAPI_EXPERIMENTAL

napi_status NAPI_CDECL napi_create_platform(int argc,
char** argv,
int exec_argc,
char** exec_argv,
char*** errors,
int thread_pool_size,
napi_platform* result);

napi_status NAPI_CDECL napi_destroy_platform(napi_platform platform);

napi_status NAPI_CDECL napi_create_environment(napi_platform platform,
char*** errors,
const char* main_script,
napi_env* result);
#ifdef NAPI_EMBEDDING
NAPI_EXTERN napi_status NAPI_CDECL napi_create_platform(int argc,
char** argv,
int exec_argc,
char** exec_argv,
char*** errors,
int thread_pool_size,
napi_platform* result);

const char* NAPI_CDECL napi_default_bootstrap();
NAPI_EXTERN napi_status NAPI_CDECL
napi_destroy_platform(napi_platform platform);

napi_status NAPI_CDECL napi_run_environment(napi_env env);
NAPI_EXTERN napi_status NAPI_CDECL
napi_create_environment(napi_platform platform,
char*** errors,
const char* main_script,
napi_env* result);

napi_status NAPI_CDECL napi_await_promise(napi_env env,
napi_value promise,
napi_value* result);
NAPI_EXTERN napi_status NAPI_CDECL napi_run_environment(napi_env env);

napi_status NAPI_CDECL napi_destroy_environment(napi_env env, int* exit_code);
NAPI_EXTERN napi_status NAPI_CDECL napi_await_promise(napi_env env,
napi_value promise,
napi_value* result);

#endif // NAPI_EXPERIMENTAL
NAPI_EXTERN napi_status NAPI_CDECL napi_destroy_environment(napi_env env,
int* exit_code);
#endif // NAPI_EMBEDDING
NAPI_EXTERN napi_status NAPI_CDECL napi_create_function(napi_env env,
const char* utf8name,
size_t length,
Expand Down
6 changes: 4 additions & 2 deletions src/js_native_api_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <climits> // INT_MAX
#include <cmath>
#define NAPI_EXPERIMENTAL
#define NAPI_EMBEDDING
#include "env-inl.h"
#include "js_native_api.h"
#include "js_native_api_v8.h"
Expand Down Expand Up @@ -986,11 +987,12 @@ napi_status napi_await_promise(napi_env env,
});

if (!r) return napi_closing;
if (promise_object->State() == v8::Promise::PromiseState::kRejected)
return napi_pending_exception;

*result =
v8impl::JsValueFromV8LocalValue(scope.Escape(promise_object->Result()));
if (promise_object->State() == v8::Promise::PromiseState::kRejected)
return napi_pending_exception;

return napi_ok;
}

Expand Down
1 change: 1 addition & 0 deletions src/node_api.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "async_wrap-inl.h"
#include "env-inl.h"
#define NAPI_EXPERIMENTAL
#define NAPI_EMBEDDING
#include "js_native_api_v8.h"
#include "memory_tracker-inl.h"
#include "node_api.h"
Expand Down
1 change: 1 addition & 0 deletions src/node_api_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "v8.h"
#define NAPI_EXPERIMENTAL
#define NAPI_EMBEDDING
#include "env-inl.h"
#include "js_native_api_v8.h"
#include "node_api.h"
Expand Down
1 change: 1 addition & 0 deletions src/node_binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "node.h"
#define NAPI_EXPERIMENTAL
#define NAPI_EMBEDDING
#include "node_api.h"
#include "uv.h"

Expand Down
18 changes: 13 additions & 5 deletions test/embedding/napi_embedding.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#define NAPI_EXPERIMENTAL
#define NAPI_EMBEDDING
#include <assert.h>
#include <node_api.h>

Expand Down Expand Up @@ -207,14 +208,21 @@ int waitMeWithCheese(napi_env env) {
goto fail;
}

if (napi_await_promise(env, promise, &result) != napi_ok) {
fprintf(stderr, "Failed awaiting promise\n");
napi_status r = napi_await_promise(env, promise, &result);
if (r != napi_ok && r != napi_pending_exception) {
fprintf(stderr, "Failed awaiting promise: %d\n", r);
goto fail;
}

napi_get_value_string_utf8(env, result, callback_buf, 32, &callback_buf_len);
if (strncmp(
callback_buf, "waited with cheese", strlen("waited with cheese"))) {
const char* expected;
if (r == napi_ok)
expected = "waited with cheese";
else
expected = "waited without cheese";

napi_get_value_string_utf8(
env, result, callback_buf, 32, &callback_buf_len);
if (strncmp(callback_buf, expected, strlen(expected))) {
fprintf(stderr, "Invalid value received: %s\n", callback_buf);
goto fail;
}
Expand Down
1 change: 1 addition & 0 deletions test/embedding/napi_modules.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <string.h>
#define NAPI_EXPERIMENTAL
#define NAPI_EMBEDDING
#include <node_api.h>

#define CHECK(op, msg) \
Expand Down
2 changes: 1 addition & 1 deletion test/embedding/test-napi-embedding.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ assert.strictEqual(
assert.strictEqual(
child_process.spawnSync(binary,
['function waitPromise(text)' +
'{ return new Promise((res) => setTimeout(() => res(text + " with cheese"), 1)); }'])
'{ return new Promise((res) => setTimeout(() => res(text + " with cheese"), 1)); }'])
.stdout.toString().trim(),
'waited with cheese');

Expand Down

0 comments on commit c2329ae

Please sign in to comment.