src: fix napi_check_object_type_tag()
This fixes a comparison failure occurring when the upper value of a type tag is 0, or a type tag value is 0. Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com PR-URL: https://github.com/nodejs/node/pull/43788 Fixes: https://github.com/nodejs/node/issues/43786 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
parent
11d346f11c
commit
cc7d4ab493
@ -2452,8 +2452,16 @@ napi_status NAPI_CDECL napi_check_object_type_tag(napi_env env,
|
|||||||
napi_type_tag tag;
|
napi_type_tag tag;
|
||||||
val.As<v8::BigInt>()->ToWordsArray(
|
val.As<v8::BigInt>()->ToWordsArray(
|
||||||
&sign, &size, reinterpret_cast<uint64_t*>(&tag));
|
&sign, &size, reinterpret_cast<uint64_t*>(&tag));
|
||||||
if (size == 2 && sign == 0)
|
if (sign == 0) {
|
||||||
*result = (tag.lower == type_tag->lower && tag.upper == type_tag->upper);
|
if (size == 2) {
|
||||||
|
*result =
|
||||||
|
(tag.lower == type_tag->lower && tag.upper == type_tag->upper);
|
||||||
|
} else if (size == 1) {
|
||||||
|
*result = (tag.lower == type_tag->lower && 0 == type_tag->upper);
|
||||||
|
} else if (size == 0) {
|
||||||
|
*result = (0 == type_tag->lower && 0 == type_tag->upper);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return GET_RETURN_STATUS(env);
|
return GET_RETURN_STATUS(env);
|
||||||
|
@ -163,14 +163,23 @@ assert.strictEqual(newObject.test_string, 'test string');
|
|||||||
// Verify that objects can be type-tagged and type-tag-checked.
|
// Verify that objects can be type-tagged and type-tag-checked.
|
||||||
const obj1 = test_object.TypeTaggedInstance(0);
|
const obj1 = test_object.TypeTaggedInstance(0);
|
||||||
const obj2 = test_object.TypeTaggedInstance(1);
|
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.
|
// Verify that type tags are correctly accepted.
|
||||||
assert.strictEqual(test_object.CheckTypeTag(0, obj1), true);
|
assert.strictEqual(test_object.CheckTypeTag(0, obj1), true);
|
||||||
assert.strictEqual(test_object.CheckTypeTag(1, obj2), 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.
|
// Verify that wrongly tagged objects are rejected.
|
||||||
assert.strictEqual(test_object.CheckTypeTag(0, obj2), false);
|
assert.strictEqual(test_object.CheckTypeTag(0, obj2), false);
|
||||||
assert.strictEqual(test_object.CheckTypeTag(1, obj1), false);
|
assert.strictEqual(test_object.CheckTypeTag(1, obj1), false);
|
||||||
|
assert.strictEqual(test_object.CheckTypeTag(0, obj3), false);
|
||||||
|
assert.strictEqual(test_object.CheckTypeTag(1, obj4), false);
|
||||||
|
assert.strictEqual(test_object.CheckTypeTag(2, obj4), false);
|
||||||
|
assert.strictEqual(test_object.CheckTypeTag(3, obj3), false);
|
||||||
|
assert.strictEqual(test_object.CheckTypeTag(4, obj3), false);
|
||||||
|
|
||||||
// Verify that untagged objects are rejected.
|
// Verify that untagged objects are rejected.
|
||||||
assert.strictEqual(test_object.CheckTypeTag(0, {}), false);
|
assert.strictEqual(test_object.CheckTypeTag(0, {}), false);
|
||||||
|
@ -605,9 +605,12 @@ static napi_value TestSeal(napi_env env,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We create two type tags. They are basically 128-bit UUIDs.
|
// 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[5] = {
|
||||||
{ 0xdaf987b3cc62481a, 0xb745b0497f299531 },
|
{ 0xdaf987b3cc62481a, 0xb745b0497f299531 },
|
||||||
{ 0xbb7936c374084d9b, 0xa9548d0762eeedb9 }
|
{ 0xbb7936c374084d9b, 0xa9548d0762eeedb9 },
|
||||||
|
{ 0xa5ed9ce2e4c00c38, 0 },
|
||||||
|
{ 0, 0 },
|
||||||
|
{ 0xa5ed9ce2e4c00c38, 0xdaf987b3cc62481a },
|
||||||
};
|
};
|
||||||
|
|
||||||
static napi_value
|
static napi_value
|
||||||
|
Loading…
x
Reference in New Issue
Block a user