Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(748)

Unified Diff: src/json-stringifier.cc

Issue 2328523002: [JSON] call replacer function with correct holder in JSON.stringify (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/json-stringifier.cc
diff --git a/src/json-stringifier.cc b/src/json-stringifier.cc
index e407f5e02df13c83ce65025e396bef91d7db30a7..84f1b96ddff7fe4745504be50473de2b28b9083e 100644
--- a/src/json-stringifier.cc
+++ b/src/json-stringifier.cc
@@ -212,23 +212,25 @@ MaybeHandle<Object> JsonStringifier::ApplyToJsonFunction(Handle<Object> object,
}
MaybeHandle<Object> JsonStringifier::ApplyReplacerFunction(
- Handle<Object> object, Handle<Object> key) {
+ Handle<Object> object, Handle<Object> key, Handle<Object> initial_value) {
Camillo Bruni 2016/09/08 15:45:26 nit: I'd prefer value vs. object and initial_objec
caitp 2016/09/08 15:47:24 sgtm for both (or maybe 'initial_holder' to match
HandleScope scope(isolate_);
if (key->IsSmi()) key = factory()->NumberToString(key);
Handle<Object> argv[] = {key, object};
- Handle<JSReceiver> holder = CurrentHolder(object);
+ Handle<JSReceiver> holder = CurrentHolder(object, initial_value);
ASSIGN_RETURN_ON_EXCEPTION(
isolate_, object,
Execution::Call(isolate_, replacer_function_, holder, 2, argv), Object);
return scope.CloseAndEscape(object);
}
-Handle<JSReceiver> JsonStringifier::CurrentHolder(Handle<Object> value) {
+Handle<JSReceiver> JsonStringifier::CurrentHolder(
+ Handle<Object> value, Handle<Object> initial_value) {
int length = Smi::cast(stack_->length())->value();
if (length == 0) {
Handle<JSObject> holder =
factory()->NewJSObject(isolate_->object_function());
- JSObject::AddProperty(holder, factory()->empty_string(), value, NONE);
+ JSObject::AddProperty(holder, factory()->empty_string(), initial_value,
+ NONE);
return holder;
} else {
FixedArray* elements = FixedArray::cast(stack_->elements());
@@ -273,6 +275,7 @@ JsonStringifier::Result JsonStringifier::Serialize_(Handle<Object> object,
bool comma,
Handle<Object> key) {
StackLimitCheck interrupt_check(isolate_);
+ Handle<Object> initial_value = object;
if (interrupt_check.InterruptRequested() &&
isolate_->stack_guard()->HandleInterrupts()->IsException(isolate_)) {
return EXCEPTION;
@@ -283,7 +286,8 @@ JsonStringifier::Result JsonStringifier::Serialize_(Handle<Object> object,
}
if (!replacer_function_.is_null()) {
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
- isolate_, object, ApplyReplacerFunction(object, key), EXCEPTION);
+ isolate_, object, ApplyReplacerFunction(object, key, initial_value),
+ EXCEPTION);
}
if (object->IsSmi()) {

Powered by Google App Engine
This is Rietveld 408576698