Created
September 24, 2018 21:20
-
-
Save TimothyGu/09e984db9ddf72c9f37f29fd5ce1c483 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/completion.mjs b/src/completion.mjs | |
index 6a89ce4..dffb911 100644 | |
--- a/src/completion.mjs | |
+++ b/src/completion.mjs | |
@@ -5,10 +5,10 @@ import { | |
import { New as NewValue } from './value.mjs'; | |
// #sec-completion-record-specification-type | |
-export class Completion { | |
+class Completion { | |
constructor(type, value, target) { | |
- if (type instanceof Completion) { | |
- return type; | |
+ if (typeof type !== 'string') { | |
+ throw new TypeError('Completion type is not a string'); | |
} | |
this.Type = type; | |
this.Value = value; | |
@@ -16,6 +16,20 @@ export class Completion { | |
} | |
} | |
+function CompletionFunction(...args) { | |
+ if (new.target !== undefined) { | |
+ return new Completion(...args); | |
+ } | |
+ const completion = args[0]; | |
+ return completion; | |
+} | |
+Object.defineProperty( | |
+ CompletionFunction, 'prototype', | |
+ Object.getOwnPropertyDescriptor(Completion, 'prototype'), | |
+); | |
+ | |
+export { CompletionFunction as Completion }; | |
+ | |
// #sec-normalcompletion | |
export class NormalCompletion { | |
constructor(value) { | |
diff --git a/src/runtime-semantics/ForStatement.mjs b/src/runtime-semantics/ForStatement.mjs | |
index d69bbc5..5d66882 100644 | |
--- a/src/runtime-semantics/ForStatement.mjs | |
+++ b/src/runtime-semantics/ForStatement.mjs | |
@@ -59,7 +59,7 @@ function ForBodyEvaluation(test, increment, stmt, perIterationBindings, labelSet | |
} | |
const result = Evaluate_Statement(stmt); | |
if (LoopContinues(result, labelSet).isFalse()) { | |
- return new Completion(UpdateEmpty(result, V)); | |
+ return Completion(UpdateEmpty(result, V)); | |
} | |
if (result.Value !== undefined) { | |
V = result.Value; | |
@@ -107,12 +107,12 @@ export function Evaluate_ForStatement(ForStatement, labelSet = []) { | |
const forDcl = Evaluate_Statement(ForStatement.init); | |
if (forDcl instanceof AbruptCompletion) { | |
surroundingAgent.runningExecutionContext.LexicalEnvironment = oldEnv; | |
- return new Completion(forDcl); | |
+ return Completion(forDcl); | |
} | |
const perIterationLets = isConst ? [] : boundNames; | |
const bodyResult = ForBodyEvaluation(ForStatement.test, ForStatement.update, ForStatement.body, perIterationLets, labelSet); | |
surroundingAgent.runningExecutionContext.LexicalEnvironment = oldEnv; | |
- return new Completion(bodyResult); | |
+ return Completion(bodyResult); | |
} | |
default: | |
throw outOfRange('Evaluate_ForStatement', ForStatement); | |
diff --git a/src/runtime-semantics/IfStatement.mjs b/src/runtime-semantics/IfStatement.mjs | |
index 93ae74e..e13c7e0 100644 | |
--- a/src/runtime-semantics/IfStatement.mjs | |
+++ b/src/runtime-semantics/IfStatement.mjs | |
@@ -33,13 +33,13 @@ export function Evaluate_IfStatement({ | |
} else { | |
stmtCompletion = Evaluate_Statement(AlternateStatement); | |
} | |
- return new Completion(UpdateEmpty(stmtCompletion, NewValue(undefined))); | |
+ return Completion(UpdateEmpty(stmtCompletion, NewValue(undefined))); | |
} else { | |
if (exprValue.isFalse()) { | |
return new NormalCompletion(undefined); | |
} else { | |
const stmtCompletion = Evaluate_Statement(Statement); | |
- return new Completion(UpdateEmpty(stmtCompletion, NewValue(undefined))); | |
+ return Completion(UpdateEmpty(stmtCompletion, NewValue(undefined))); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment