From 2dc860726926c923df1b14275cfc5686bf39132c Mon Sep 17 00:00:00 2001 From: Herman Venter Date: Mon, 16 Jul 2018 18:17:42 -0700 Subject: [PATCH] Compose subsequent effects with currently applied affects (#2271) Summary: Release note: none This fixes a problem reported as a comment in PR #2258. The underlying problem was that Realm.evaluateForEffects would just append the normal effects, captured since the last non complete join, into the saved partially normal completion that becomes the result of the returned Effects. This is not quite right because applying the resulting Effects should restore the complete set of normal effects that were in force when evaluateForEffects completed. Pull Request resolved: https://github.com/facebook/prepack/pull/2271 Differential Revision: D8870763 Pulled By: hermanventer fbshipit-source-id: 027924f2b250174393c60d90c2feefdb5a55eec3 --- src/methods/call.js | 2 +- src/realm.js | 1 + .../optimized-functions/ObjectAssign9.js | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 test/serializer/optimized-functions/ObjectAssign9.js diff --git a/src/methods/call.js b/src/methods/call.js index 4a416a5f5..3ad5e9a1f 100644 --- a/src/methods/call.js +++ b/src/methods/call.js @@ -306,7 +306,7 @@ function callNativeFunctionValue( mightBecomeAnObject(contextVal) ); let completion = f.callCallback( - // this is to get around Flow not understand the above invariant + // this is to get around Flow not understanding the above invariant ((contextVal: any): AbstractObjectValue | ObjectValue | NullValue | UndefinedValue), argumentsList, env.environmentRecord.$NewTarget diff --git a/src/realm.js b/src/realm.js index caf658378..a0a43bca3 100644 --- a/src/realm.js +++ b/src/realm.js @@ -877,6 +877,7 @@ export class Realm { this.stopEffectCaptureAndUndoEffects(c); Join.updatePossiblyNormalCompletionWithSubsequentEffects(this, c, subsequentEffects); this.savedCompletion = undefined; + this.applyEffects(subsequentEffects, "subsequentEffects", true); } invariant(this.generator !== undefined); diff --git a/test/serializer/optimized-functions/ObjectAssign9.js b/test/serializer/optimized-functions/ObjectAssign9.js new file mode 100644 index 000000000..11c8d3acd --- /dev/null +++ b/test/serializer/optimized-functions/ObjectAssign9.js @@ -0,0 +1,19 @@ +function fn2(shouldError) { + if (shouldError) { + throw new Error("Error"); + } + return { + thisValueShouldExist: true, + }; +} + +function fn(shouldError) { + var a = Object.assign({}, fn2(shouldError)); + return a.thisValueShouldExist; +} + +this.__optimize && __optimize(fn); + +inspect = function() { + return fn(false); +};