Skip to content
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
Prev Previous commit
fixup: handle c++ error properly
  • Loading branch information
BridgeAR committed Aug 19, 2018
commit 3c83e47e2287efaca45506b69d8e1a9078c3c88a
17 changes: 12 additions & 5 deletions src/node_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@ static void GetOwnNonIndicesProperties(
Environment* env = Environment::GetCurrent(args);
Local<Context> context = env->context();

if (!args[0]->IsObject())
return;

v8::Local<v8::Object> object = args[0].As<v8::Object>();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't see if we have a check for this in-place. Will we crash if this fails? That said, does it ever really realistically fail?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would crash. But this API is only used internally and not exposed. That's why I did not add a safeguard against wrong input values.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a check for that as well.


// Return only non-enumerable properties by default.
v8::Local<v8::Array> properties = object
->GetPropertyNames(context, v8::KeyCollectionMode::kOwnOnly,
v8::ONLY_ENUMERABLE,
v8::IndexFilter::kSkipIndices)
.ToLocalChecked();
v8::Local<v8::Array> properties;

if (!object->GetPropertyNames(
context, v8::KeyCollectionMode::kOwnOnly,
v8::ONLY_ENUMERABLE,
v8::IndexFilter::kSkipIndices)
.ToLocal(&properties)) {
return;
}
args.GetReturnValue().Set(properties);
}

Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-assert-deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,17 @@ assert.deepStrictEqual(obj1, obj2);
' [\n 1,\n+ 2\n- 2,\n- 3\n ]' }
);
util.inspect.defaultOptions = tmp;

const invalidTrap = new Proxy([1, 2, 3], {
ownKeys() { return []; }
});
assert.throws(
() => assert.deepStrictEqual(invalidTrap, [1, 2, 3]),
{
name: 'TypeError',
message: "'ownKeys' on proxy: trap result did not include 'length'"
}
);
}

// Basic valueOf check.
Expand Down