Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: access global property to illicit error status
  • Loading branch information
gabrielschulhof committed May 18, 2023
commit 95137f5c8a774d90a85b17414ac70945062168c8
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
Comment thread
legendecas marked this conversation as resolved.
Resolved
"target_defaults": {
"sources": [
"../entry_point.c",
]
},
"targets": [
{
"target_name": "test_cannot_run_js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
// strong reference created herein will attempt to call `napi_call_function()`
// and will abort the process if the API doesn't return the correct status.

const { buildType } = require('../../common');
const { buildType, mustNotCall } = require('../../common');
const addon_v8 = require(`./build/${buildType}/test_pending_exception`);
const addon_new = require(`./build/${buildType}/test_cannot_run_js`);

function runTests(addon, isVersion8) {
addon.createRef(common.mustNotCall());
addon.createRef(mustNotCall());
}

function runAllTests() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#include <node_api.h>
#include "../../js-native-api/common.h"
#include <js_native_api.h>
#include "../common.h"
#include "stdlib.h"

static void Finalize(napi_env env, void* data, void* hint) {
napi_value cb;
napi_value global, set_timeout;
napi_ref* ref = data;
#ifdef NAPI_EXPERIMENTAL
napi_status expected_status = napi_cannot_run_js;
#else
napi_status expected_status = napi_pending_exception;
#endif // NAPI_EXPERIMENTAL

if (napi_get_reference_value(env, *ref, &cb) != napi_ok) abort();
if (napi_delete_reference(env, *ref) != napi_ok) abort();
if (napi_call_function(env, cb, cb, 0, NULL, NULL) != expected_status)
abort();
if (napi_get_global(env, &global) != napi_ok) abort();
if (napi_get_named_property(env, global, "setTimeout", &set_timeout) != expected_status) abort();
free(ref);
}

Expand All @@ -32,7 +31,8 @@ static napi_value CreateRef(napi_env env, napi_callback_info info) {
return cb;
}

NAPI_MODULE_INIT() {
EXTERN_C_START
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor properties[] = {
DECLARE_NODE_API_PROPERTY("createRef", CreateRef),
};
Expand All @@ -44,3 +44,4 @@ NAPI_MODULE_INIT() {

return exports;
}
EXTERN_C_END