Skip to content

Commit

Permalink
Don't pass numeric form keys to JSProxy functions
Browse files Browse the repository at this point in the history
Summary:
Internally, Hermes will sometimes keep keys as numbers for
efficiency.  In copyDataPropertiesSlowPath_RJS, which is for Proxy,
ensure numeric keys are converted to strings before calling functions
which might call into JSProxy.

Reviewed By: avp

Differential Revision: D23834086

fbshipit-source-id: b1df8e16573c15b63e3993793f6f484848bb89af
  • Loading branch information
mhorowitz authored and facebook-github-bot committed Sep 26, 2020
1 parent ba8c4f6 commit 2f07b10
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/VM/JSLib/HermesBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,15 @@ CallResult<HermesValue> copyDataPropertiesSlowPath_RJS(
++nextKeyIdx) {
marker.flush();
nextKeyHandle = keys->at(runtime, nextKeyIdx);
if (nextKeyHandle->isNumber()) {
CallResult<PseudoHandle<StringPrimitive>> strRes =
toString_RJS(runtime, nextKeyHandle);
if (LLVM_UNLIKELY(strRes == ExecutionStatus::EXCEPTION)) {
return ExecutionStatus::EXCEPTION;
}
nextKeyHandle = strRes->getHermesValue();
}

// b. For each element e of excludedItems in List order, do
// i. If SameValue(e, nextKey) is true, then
// 1. Set excluded to true.
Expand Down
14 changes: 14 additions & 0 deletions test/hermes/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2143,6 +2143,20 @@ f.a = 1;
f.b = 2;
checkDeep({...f})(_ => ({a:1, b:2}));

// spread passes string not numeric arguments to traps
var output = [];
var p = new Proxy({1:""}, {
getOwnPropertyDescriptor(t, k) {
output.push(typeof k)
return Object.getOwnPropertyDescriptor(t, k);
},
get(t, k) {
output.push(typeof k)
return t[k];
}});
({...p});
assert.arrayEqual(output, ["string", "string"]);

// newTarget.prototype for Proxy ctor is !== Object.prototype does not throw
Reflect.construct(Proxy, [{}, {}], WeakSet);

Expand Down

0 comments on commit 2f07b10

Please sign in to comment.