Skip to content

Commit 3c83e47

Browse files
committed
fixup: handle c++ error properly
1 parent 6e7cf50 commit 3c83e47

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/node_util.cc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,21 @@ static void GetOwnNonIndicesProperties(
2121
Environment* env = Environment::GetCurrent(args);
2222
Local<Context> context = env->context();
2323

24+
if (!args[0]->IsObject())
25+
return;
26+
2427
v8::Local<v8::Object> object = args[0].As<v8::Object>();
2528

2629
// Return only non-enumerable properties by default.
27-
v8::Local<v8::Array> properties = object
28-
->GetPropertyNames(context, v8::KeyCollectionMode::kOwnOnly,
29-
v8::ONLY_ENUMERABLE,
30-
v8::IndexFilter::kSkipIndices)
31-
.ToLocalChecked();
30+
v8::Local<v8::Array> properties;
31+
32+
if (!object->GetPropertyNames(
33+
context, v8::KeyCollectionMode::kOwnOnly,
34+
v8::ONLY_ENUMERABLE,
35+
v8::IndexFilter::kSkipIndices)
36+
.ToLocal(&properties)) {
37+
return;
38+
}
3239
args.GetReturnValue().Set(properties);
3340
}
3441

test/parallel/test-assert-deep.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,17 @@ assert.deepStrictEqual(obj1, obj2);
893893
' [\n 1,\n+ 2\n- 2,\n- 3\n ]' }
894894
);
895895
util.inspect.defaultOptions = tmp;
896+
897+
const invalidTrap = new Proxy([1, 2, 3], {
898+
ownKeys() { return []; }
899+
});
900+
assert.throws(
901+
() => assert.deepStrictEqual(invalidTrap, [1, 2, 3]),
902+
{
903+
name: 'TypeError',
904+
message: "'ownKeys' on proxy: trap result did not include 'length'"
905+
}
906+
);
896907
}
897908

898909
// Basic valueOf check.

0 commit comments

Comments
 (0)