Skip to content

Commit b5289ec

Browse files
committed
test: add test for napi_set_prototype
1 parent 80ab216 commit b5289ec

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

test/js-native-api/test_general/test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@ class ExtendedClass extends BaseClass {
1818

1919
const baseObject = new BaseClass();
2020
const extendedObject = new ExtendedClass();
21+
const nullProtoObject = { __proto__: null };
2122

2223
// Test napi_strict_equals
2324
assert.ok(test_general.testStrictEquals(val1, val1));
2425
assert.strictEqual(test_general.testStrictEquals(val1, val2), false);
2526
assert.ok(test_general.testStrictEquals(val2, val3));
2627

28+
// Test napi_set_prototype
29+
test_general.testSetPrototype(nullProtoObject, Object.prototype);
30+
assert.strictEqual(Object.getPrototypeOf(nullProtoObject),
31+
Object.prototype);
32+
2733
// Test napi_get_prototype
2834
assert.strictEqual(test_general.testGetPrototype(baseObject),
2935
Object.getPrototypeOf(baseObject));

test/js-native-api/test_general/test_general.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ static napi_value testStrictEquals(napi_env env, napi_callback_info info) {
2323
return result;
2424
}
2525

26+
static napi_value testSetPrototype(napi_env env, napi_callback_info info) {
27+
size_t argc = 2;
28+
napi_value args[2];
29+
NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
30+
31+
NODE_API_CALL(env, napi_set_prototype(env, args[0], args[1]));
32+
33+
return NULL;
34+
}
35+
2636
static napi_value testGetPrototype(napi_env env, napi_callback_info info) {
2737
size_t argc = 1;
2838
napi_value args[1];
@@ -287,6 +297,7 @@ EXTERN_C_START
287297
napi_value Init(napi_env env, napi_value exports) {
288298
napi_property_descriptor descriptors[] = {
289299
DECLARE_NODE_API_PROPERTY("testStrictEquals", testStrictEquals),
300+
DECLARE_NODE_API_PROPERTY("testSetPrototype", testSetPrototype),
290301
DECLARE_NODE_API_PROPERTY("testGetPrototype", testGetPrototype),
291302
DECLARE_NODE_API_PROPERTY("testGetVersion", testGetVersion),
292303
DECLARE_NODE_API_PROPERTY("testNapiRun", testNapiRun),

0 commit comments

Comments
 (0)