Skip to content

Commit d143d7c

Browse files
authored
fix(ext/node): deep assert compatibility (denoland#32434)
1 parent be569cf commit d143d7c

File tree

5 files changed

+57
-29
lines changed

5 files changed

+57
-29
lines changed

ext/crypto/00_crypto.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ const {
9090
import * as webidl from "ext:deno_webidl/00_webidl.js";
9191
import { createFilteredInspectProxy } from "ext:deno_web/01_console.js";
9292
import { DOMException } from "ext:deno_web/01_dom_exception.js";
93+
import { kKeyObject } from "ext:deno_node/internal/crypto/constants.ts";
9394

9495
const supportedNamedCurves = ["P-256", "P-384", "P-521"];
9596
const recognisedUsages = [
@@ -365,6 +366,8 @@ class CryptoKey {
365366
[_usages];
366367
/** @type {object} */
367368
[_handle];
369+
/** @type {object} */
370+
[kKeyObject];
368371

369372
constructor() {
370373
webidl.illegalConstructor();
@@ -431,6 +434,7 @@ function constructKey(type, extractable, usages, algorithm, handle) {
431434
key[_usages] = usages;
432435
key[_algorithm] = algorithm;
433436
key[_handle] = handle;
437+
key[kKeyObject] = WeakMapPrototypeGet(KEY_STORE, handle);
434438
return key;
435439
}
436440

ext/node/ops/util.rs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ pub fn op_node_get_own_non_index_properties<'s>(
227227
scope: &mut v8::PinScope<'s, '_>,
228228
obj: v8::Local<'s, v8::Object>,
229229
#[smi] filter: u32,
230-
) -> Result<v8::Local<'s, v8::Array>, JsErrorBox> {
230+
) -> Result<v8::Local<'s, v8::Value>, JsErrorBox> {
231231
let mut property_filter = v8::PropertyFilter::ALL_PROPERTIES;
232232
if filter & 1 << 0 != 0 {
233233
property_filter = property_filter | v8::PropertyFilter::ONLY_WRITABLE;
@@ -245,19 +245,33 @@ pub fn op_node_get_own_non_index_properties<'s>(
245245
property_filter = property_filter | v8::PropertyFilter::SKIP_SYMBOLS;
246246
}
247247

248-
obj
249-
.get_property_names(
250-
scope,
251-
v8::GetPropertyNamesArgs {
252-
index_filter: v8::IndexFilter::SkipIndices,
253-
property_filter,
254-
key_conversion: v8::KeyConversionMode::NoNumbers,
255-
mode: v8::KeyCollectionMode::OwnOnly,
256-
},
257-
)
258-
.ok_or_else(|| {
259-
JsErrorBox::type_error("Failed to get own non-index properties")
260-
})
248+
v8::tc_scope!(let tc_scope, scope);
249+
250+
let result = obj.get_property_names(
251+
tc_scope,
252+
v8::GetPropertyNamesArgs {
253+
index_filter: v8::IndexFilter::SkipIndices,
254+
property_filter,
255+
key_conversion: v8::KeyConversionMode::NoNumbers,
256+
mode: v8::KeyCollectionMode::OwnOnly,
257+
},
258+
);
259+
260+
match result {
261+
Some(names) => Ok(names.into()),
262+
None => {
263+
if tc_scope.has_caught() || tc_scope.has_terminated() {
264+
tc_scope.rethrow();
265+
// Dummy value, this result will be discarded because an error was thrown.
266+
let v = v8::undefined(tc_scope);
267+
Ok(v.into())
268+
} else {
269+
Err(JsErrorBox::type_error(
270+
"Failed to get own non-index properties",
271+
))
272+
}
273+
}
274+
}
261275
}
262276

263277
#[op2]

ext/node/polyfills/internal/util/comparisons.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
isFloat64Array,
1616
isKeyObject,
1717
isMap,
18-
isNativeError,
1918
isNumberObject,
2019
isRegExp,
2120
isSet,
@@ -33,6 +32,7 @@ import {
3332
import { primordials } from "ext:core/mod.js";
3433
import assert from "node:assert";
3534
import { kKeyObject } from "ext:deno_node/internal/crypto/constants.ts";
35+
import { isError } from "ext:deno_node/internal/util.mjs";
3636
import { isURL } from "ext:deno_node/internal/url.ts";
3737

3838
const {
@@ -51,7 +51,6 @@ const {
5151
Date,
5252
DatePrototypeGetTime,
5353
Error,
54-
ErrorPrototype,
5554
Float32Array,
5655
Float64Array,
5756
Function,
@@ -69,7 +68,6 @@ const {
6968
ObjectKeys,
7069
ObjectPrototypeHasOwnProperty: hasOwn,
7170
ObjectPrototypePropertyIsEnumerable: hasEnumerable,
72-
ObjectPrototypeIsPrototypeOf,
7371
ObjectPrototypeToString,
7472
Promise,
7573
RegExp,
@@ -419,11 +417,11 @@ function objectComparisonStart(
419417
) {
420418
return false;
421419
}
422-
} else if (ObjectPrototypeIsPrototypeOf(ErrorPrototype, val1)) {
420+
} else if (isError(val1)) {
423421
// Do not compare the stack as it might differ even though the error itself
424422
// is otherwise identical.
425423
if (
426-
!ObjectPrototypeIsPrototypeOf(ErrorPrototype, val2) ||
424+
!isError(val2) ||
427425
!isEnumerableOrIdentical(val1, val2, "message", mode, memos) ||
428426
!isEnumerableOrIdentical(val1, val2, "name", mode, memos) ||
429427
!isEnumerableOrIdentical(val1, val2, "cause", mode, memos) ||
@@ -451,8 +449,7 @@ function objectComparisonStart(
451449
isRegExp(val2) ||
452450
isAnyArrayBuffer(val2) ||
453451
isBoxedPrimitive(val2) ||
454-
isNativeError(val2) ||
455-
ObjectPrototypeIsPrototypeOf(ErrorPrototype, val2)
452+
isError(val2)
456453
) {
457454
return false;
458455
} else if (isURL(val1)) {

ext/web/01_console.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
op_preview_entries,
3535
} from "ext:core/ops";
3636
import * as ops from "ext:core/ops";
37+
import { URLPrototype } from "ext:deno_web/00_url.js";
3738
const {
3839
AggregateError,
3940
AggregateErrorPrototype,
@@ -71,6 +72,7 @@ const {
7172
DatePrototype,
7273
DatePrototypeGetTime,
7374
DatePrototypeToISOString,
75+
DatePrototypeToString,
7476
Error,
7577
ErrorCaptureStackTrace,
7678
ErrorPrototype,
@@ -847,14 +849,16 @@ function formatRaw(ctx, value, recurseTimes, typedArray, proxyDetails) {
847849
(proxyDetails === null && isDate(value)) ||
848850
(proxyDetails !== null && isDate(proxyDetails[0]))
849851
) {
850-
const date = proxyDetails?.[0] ?? value;
851-
if (NumberIsNaN(DatePrototypeGetTime(date))) {
852-
return ctx.stylize("Invalid Date", "date");
853-
} else {
854-
base = DatePrototypeToISOString(date);
855-
if (keys.length === 0 && protoProps === undefined) {
856-
return ctx.stylize(base, "date");
857-
}
852+
value = proxyDetails?.[0] ?? value;
853+
base = NumberIsNaN(DatePrototypeGetTime(value))
854+
? DatePrototypeToString(value)
855+
: DatePrototypeToISOString(value);
856+
const prefix = getPrefix(constructor, tag, "Date");
857+
if (prefix !== "Date ") {
858+
base = `${prefix}${base}`;
859+
}
860+
if (keys.length === 0 && protoProps === undefined) {
861+
return ctx.stylize(base, "date");
858862
}
859863
} else if (
860864
proxyDetails === null &&
@@ -969,6 +973,14 @@ function formatRaw(ctx, value, recurseTimes, typedArray, proxyDetails) {
969973
if (keys.length === 0 && protoProps === undefined) {
970974
return base;
971975
}
976+
} else if (
977+
ObjectPrototypeIsPrototypeOf(URLPrototype, value) &&
978+
!(recurseTimes > ctx.depth && ctx.depth !== null)
979+
) {
980+
base = value.href;
981+
if (keys.length === 0 && protoProps === undefined) {
982+
return base;
983+
}
972984
} else {
973985
if (keys.length === 0 && protoProps === undefined) {
974986
// TODO(wafuwafu13): Implement

tests/node_compat/config.jsonc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"parallel/test-assert-class-destructuring.js": {},
6868
"parallel/test-assert-class.js": {},
6969
"parallel/test-assert-deep-with-error.js": {},
70+
"parallel/test-assert-deep.js": {},
7071
"parallel/test-assert-esm-cjs-message-verify.js": {},
7172
"parallel/test-assert-fail-deprecation.js": {},
7273
"parallel/test-assert-fail.js": {},

0 commit comments

Comments
 (0)