Skip to content
Open
Changes from all commits
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
20 changes: 20 additions & 0 deletions packages/react-native/ReactCommon/jsi/jsi/JSIDynamic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ Value valueFromDynamic(Runtime& runtime, const folly::dynamic& dynInput) {
}
case folly::dynamic::OBJECT: {
Object obj = std::move(top.obj);
// Storing a "__proto__" key into an object whose prototype is
// Object.prototype calls the inherited __proto__ setter
// (ES2026 10.1.9.2, step 6), which replaces the prototype with an
// object or null value and drops any other value
// (ES2026 20.1.3.8.2). JSON.parse makes the key an own property
// instead (ES2026 13.2.5.6, step 2), so an object with that key is
// filled while its prototype is null.
//
// JSCRuntime cuts property names at the first NUL, so on JSC a key
// such as "__proto__\0x" is stored as "__proto__" too. This lookup
// doesn't match it, so it can still call the setter.
bool hasProtoKey = top.dyn->count("__proto__");
Value prototype;
if (hasProtoKey) {
prototype = obj.getPrototype(runtime);
obj.setPrototype(runtime, Value::null());
}
for (const auto& element : top.dyn->items()) {
if (element.first.isNumber() || element.first.isString()) {
obj.setProperty(
Expand All @@ -92,6 +109,9 @@ Value valueFromDynamic(Runtime& runtime, const folly::dynamic& dynInput) {
valueFromDynamicShallow(runtime, stack, element.second));
}
}
if (hasProtoKey) {
obj.setPrototype(runtime, prototype);
}
break;
}
default:
Expand Down
Loading