Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src,node-api: fix napi_check_object_type_tag() #43788

Closed
wants to merge 2 commits into from
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
12 changes: 10 additions & 2 deletions src/js_native_api_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2452,8 +2452,16 @@ napi_status NAPI_CDECL napi_check_object_type_tag(napi_env env,
napi_type_tag tag;
val.As<v8::BigInt>()->ToWordsArray(
&sign, &size, reinterpret_cast<uint64_t*>(&tag));
if (size == 2 && sign == 0)
*result = (tag.lower == type_tag->lower && tag.upper == type_tag->upper);
if (sign == 0) {
if (size == 2) {
*result =
(tag.lower == type_tag->lower && tag.upper == type_tag->upper);
} else if (size == 1) {
*result = (tag.lower == type_tag->lower);
daeyeon marked this conversation as resolved.
Show resolved Hide resolved
} else if (size == 0) {
*result = (type_tag->lower == 0 && type_tag->upper == 0);
}
}
}

return GET_RETURN_STATUS(env);
Expand Down
4 changes: 4 additions & 0 deletions test/js-native-api/test_object/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,14 @@ assert.strictEqual(newObject.test_string, 'test string');
// Verify that objects can be type-tagged and type-tag-checked.
const obj1 = test_object.TypeTaggedInstance(0);
const obj2 = test_object.TypeTaggedInstance(1);
const obj3 = test_object.TypeTaggedInstance(2);
const obj4 = test_object.TypeTaggedInstance(3);

// Verify that type tags are correctly accepted.
assert.strictEqual(test_object.CheckTypeTag(0, obj1), true);
assert.strictEqual(test_object.CheckTypeTag(1, obj2), true);
assert.strictEqual(test_object.CheckTypeTag(2, obj3), true);
assert.strictEqual(test_object.CheckTypeTag(3, obj4), true);

// Verify that wrongly tagged objects are rejected.
assert.strictEqual(test_object.CheckTypeTag(0, obj2), false);
Expand Down
6 changes: 4 additions & 2 deletions test/js-native-api/test_object/test_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,11 @@ static napi_value TestSeal(napi_env env,
}

// We create two type tags. They are basically 128-bit UUIDs.
static const napi_type_tag type_tags[2] = {
static const napi_type_tag type_tags[4] = {
{ 0xdaf987b3cc62481a, 0xb745b0497f299531 },
{ 0xbb7936c374084d9b, 0xa9548d0762eeedb9 }
{ 0xbb7936c374084d9b, 0xa9548d0762eeedb9 },
{ 0xa5ed9ce2e4c00c38, 0 },
{ 0, 0 },
};

static napi_value
Expand Down