From e24502622737da16031f7544145bf19bffd694a4 Mon Sep 17 00:00:00 2001 From: Brian Hackett Date: Thu, 27 Dec 2018 13:30:56 -1000 Subject: [PATCH] Bug 1516578 Part 4 - Improve handling when encoding/decoding execution points with no position, r=lsmyth. --HG-- extra : rebase_source : 7de1af8761422eab9343d4807918aad5f5d615b6 extra : source : 9ddc5bc1e961af52dbd772f66559f3fe4199e572 --- toolkit/recordreplay/ipc/JSControl.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/toolkit/recordreplay/ipc/JSControl.cpp b/toolkit/recordreplay/ipc/JSControl.cpp index 60118e0801bd..46c2d035ebb0 100644 --- a/toolkit/recordreplay/ipc/JSControl.cpp +++ b/toolkit/recordreplay/ipc/JSControl.cpp @@ -153,16 +153,21 @@ static const char gPositionProperty[] = "position"; JSObject* ExecutionPoint::Encode(JSContext* aCx) const { RootedObject obj(aCx, JS_NewObject(aCx, nullptr)); - RootedObject position(aCx, mPosition.Encode(aCx)); - if (!obj || !position || + if (!obj || !JS_DefineProperty(aCx, obj, gCheckpointProperty, (double)mCheckpoint, JSPROP_ENUMERATE) || !JS_DefineProperty(aCx, obj, gProgressProperty, (double)mProgress, - JSPROP_ENUMERATE) || - !JS_DefineProperty(aCx, obj, gPositionProperty, position, JSPROP_ENUMERATE)) { return nullptr; } + if (HasPosition()) { + RootedObject position(aCx, mPosition.Encode(aCx)); + if (!position || + !JS_DefineProperty(aCx, obj, gPositionProperty, position, + JSPROP_ENUMERATE)) { + return nullptr; + } + } return obj; } @@ -172,9 +177,15 @@ bool ExecutionPoint::Decode(JSContext* aCx, HandleObject aObject) { return false; } - RootedObject positionObject(aCx, NonNullObject(aCx, v)); - return positionObject && mPosition.Decode(aCx, positionObject) && - GetNumberProperty(aCx, aObject, gCheckpointProperty, &mCheckpoint) && + if (v.isUndefined()) { + MOZ_RELEASE_ASSERT(!HasPosition()); + } else { + RootedObject positionObject(aCx, NonNullObject(aCx, v)); + if (!positionObject || !mPosition.Decode(aCx, positionObject)) { + return false; + } + } + return GetNumberProperty(aCx, aObject, gCheckpointProperty, &mCheckpoint) && GetNumberProperty(aCx, aObject, gProgressProperty, &mProgress); }