mirror of
https://github.com/facebookarchive/prepack.git
synced 2024-10-26 23:32:02 +03:00
Provide a way to temporarily disable effects tracking (#2304)
Summary: Release note: Provide a way to temporarily disable effects tracking The default error handler constructs a new Error object in order to reuse its logic for obtaining a call stack. Since the object is then thrown a away, it makes no sense to keep tracking its properties and doing so makes debugging more painful. Pull Request resolved: https://github.com/facebook/prepack/pull/2304 Differential Revision: D8945121 Pulled By: hermanventer fbshipit-source-id: 68fb8b84c2ef937fcdf3ecaccdff5041779424d5
This commit is contained in:
parent
f80b4af956
commit
7480608e79
28
src/realm.js
28
src/realm.js
@ -854,8 +854,32 @@ export class Realm {
|
||||
return [effects, nodeAst, nodeIO];
|
||||
}
|
||||
|
||||
// Use this to evaluate code for internal purposes, so that the tracked state does not get polluted
|
||||
evaluateWithoutEffects<T>(f: () => T): T {
|
||||
// Save old state and set up undefined state
|
||||
let savedGenerator = this.generator;
|
||||
let savedBindings = this.modifiedBindings;
|
||||
let savedProperties = this.modifiedProperties;
|
||||
let savedCreatedObjects = this.createdObjects;
|
||||
let saved_completion = this.savedCompletion;
|
||||
try {
|
||||
this.generator = undefined;
|
||||
this.modifiedBindings = undefined;
|
||||
this.modifiedProperties = undefined;
|
||||
this.createdObjects = undefined;
|
||||
this.savedCompletion = undefined;
|
||||
return f();
|
||||
} finally {
|
||||
this.generator = savedGenerator;
|
||||
this.modifiedBindings = savedBindings;
|
||||
this.modifiedProperties = savedProperties;
|
||||
this.createdObjects = savedCreatedObjects;
|
||||
this.savedCompletion = saved_completion;
|
||||
}
|
||||
}
|
||||
|
||||
evaluateForEffects(f: () => Completion | Value, state: any, generatorName: string): Effects {
|
||||
// Save old state and set up empty state for ast
|
||||
// Save old state and set up empty state
|
||||
let [savedBindings, savedProperties] = this.getAndResetModifiedMaps();
|
||||
let saved_generator = this.generator;
|
||||
let saved_createdObjects = this.createdObjects;
|
||||
@ -1764,7 +1788,7 @@ export class Realm {
|
||||
// Return value indicates whether the caller should try to recover from the error or not.
|
||||
handleError(diagnostic: CompilerDiagnostic): ErrorHandlerResult {
|
||||
if (!diagnostic.callStack && this.contextStack.length > 0) {
|
||||
let error = Construct(this, this.intrinsics.Error);
|
||||
let error = this.evaluateWithoutEffects(() => Construct(this, this.intrinsics.Error));
|
||||
let stack = error._SafeGetDataPropertyValue("stack");
|
||||
if (stack instanceof StringValue) diagnostic.callStack = stack.value;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user