-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Normative: Allow CodeLike object evaluation #3294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lukewarlow
wants to merge
2
commits into
tc39:main
Choose a base branch
from
lukewarlow:codelike-hostensurecancompilestrings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+41
−14
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19444,7 +19444,7 @@ <h1>Runtime Semantics: Evaluation</h1> | |||||
| 1. If _argList_ has no elements, return *undefined*. | ||||||
| 1. Let _evalArg_ be the first element of _argList_. | ||||||
| 1. If IsStrict(this |CallExpression|) is *true*, let _strictCaller_ be *true*; else let _strictCaller_ be *false*. | ||||||
| 1. [id="step-callexpression-evaluation-direct-eval"] Return ? PerformEval(_evalArg_, _strictCaller_, *true*). | ||||||
| 1. [id="step-callexpression-evaluation-direct-eval"] Return ? PerformEval(_evalArg_, _strictCaller_, ~direct-eval~). | ||||||
| 1. Let _thisCall_ be this |CallExpression|. | ||||||
| 1. Let _tailCall_ be IsInTailPosition(_thisCall_). | ||||||
| 1. Return ? EvaluateCall(_func_, _ref_, _arguments_, _tailCall_). | ||||||
|
|
@@ -29808,30 +29808,37 @@ <h1>eval ( _source_ )</h1> | |||||
| <p>This function is the <dfn>%eval%</dfn> intrinsic object.</p> | ||||||
| <p>It performs the following steps when called:</p> | ||||||
| <emu-alg> | ||||||
| 1. Return ? PerformEval(_source_, *false*, *false*). | ||||||
| 1. Return ? PerformEval(_source_, *false*, ~indirect-eval~). | ||||||
| </emu-alg> | ||||||
|
|
||||||
| <emu-clause id="sec-performeval" type="abstract operation" oldids="sec-performeval-rules-outside-functions,sec-performeval-rules-outside-methods,sec-performeval-rules-outside-constructors"> | ||||||
| <h1> | ||||||
| PerformEval ( | ||||||
| _source_: an ECMAScript language value, | ||||||
| _strictCaller_: a Boolean, | ||||||
| _direct_: a Boolean, | ||||||
| _direct_: ~direct-eval~ or ~indirect-eval~, | ||||||
| ): either a normal completion containing an ECMAScript language value or a throw completion | ||||||
| </h1> | ||||||
| <dl class="header"> | ||||||
| </dl> | ||||||
| <emu-alg> | ||||||
| 1. Assert: If _direct_ is *false*, then _strictCaller_ is also *false*. | ||||||
| 1. If _source_ is not a String, return _source_. | ||||||
| 1. Assert: If _direct_ is ~indirect-eval~, then _strictCaller_ is *false*. | ||||||
| 1. If _source_ is a String, then | ||||||
| 1. Let _sourceStr_ be _source_. | ||||||
| 1. Else if _source_ is an Object, then | ||||||
| 1. Let _code_ be HostGetCodeForEval(_source_). | ||||||
| 1. If _code_ is a String, let _sourceStr_ be _code_. | ||||||
| 1. Else, return _source_. | ||||||
| 1. Else, | ||||||
| 1. Return _source_. | ||||||
| 1. Let _evalRealm_ be the current Realm Record. | ||||||
| 1. NOTE: In the case of a direct eval, _evalRealm_ is the realm of both the caller of `eval` and of the `eval` function itself. | ||||||
| 1. Perform ? HostEnsureCanCompileStrings(_evalRealm_, « », _source_, _direct_). | ||||||
| 1. Perform ? HostEnsureCanCompileStrings(_evalRealm_, « », _sourceStr_, _sourceStr_, _direct_, « », _source_). | ||||||
| 1. Let _inFunction_ be *false*. | ||||||
| 1. Let _inMethod_ be *false*. | ||||||
| 1. Let _inDerivedConstructor_ be *false*. | ||||||
| 1. Let _inClassFieldInitializer_ be *false*. | ||||||
| 1. If _direct_ is *true*, then | ||||||
| 1. If _direct_ is ~direct-eval~, then | ||||||
| 1. Let _thisEnvRec_ be GetThisEnvironment(). | ||||||
| 1. If _thisEnvRec_ is a Function Environment Record, then | ||||||
| 1. Let _func_ be _thisEnvRec_.[[FunctionObject]]. | ||||||
|
|
@@ -29841,7 +29848,7 @@ <h1> | |||||
| 1. Let _classFieldInitializerName_ be _func_.[[ClassFieldInitializerName]]. | ||||||
| 1. If _classFieldInitializerName_ is not ~empty~, set _inClassFieldInitializer_ to *true*. | ||||||
| 1. Perform the following substeps in an implementation-defined order, possibly interleaving parsing and error detection: | ||||||
| 1. Let _script_ be ParseText(_source_, |Script|). | ||||||
| 1. Let _script_ be ParseText(_sourceStr_, |Script|). | ||||||
| 1. If _script_ is a List of errors, throw a *SyntaxError* exception. | ||||||
| 1. If _script_ Contains |ScriptBody| is *false*, return *undefined*. | ||||||
| 1. Let _body_ be the |ScriptBody| of _script_. | ||||||
|
|
@@ -29852,8 +29859,8 @@ <h1> | |||||
| 1. If _strictCaller_ is *true*, let _strictEval_ be *true*. | ||||||
| 1. Else, let _strictEval_ be ScriptIsStrict of _script_. | ||||||
| 1. Let _runningContext_ be the running execution context. | ||||||
| 1. NOTE: If _direct_ is *true*, _runningContext_ will be the execution context that performed the direct eval. If _direct_ is *false*, _runningContext_ will be the execution context for the invocation of the `eval` function. | ||||||
| 1. If _direct_ is *true*, then | ||||||
| 1. NOTE: If _direct_ is ~direct-eval~, _runningContext_ will be the execution context that performed the direct eval. If _direct_ is ~indirect-eval~, _runningContext_ will be the execution context for the invocation of the `eval` function. | ||||||
| 1. If _direct_ is ~direct-eval~, then | ||||||
| 1. Let _lexEnv_ be NewDeclarativeEnvironment(_runningContext_'s LexicalEnvironment). | ||||||
| 1. Let _varEnv_ be _runningContext_'s VariableEnvironment. | ||||||
| 1. Let _privateEnv_ be _runningContext_'s PrivateEnvironment. | ||||||
|
|
@@ -29891,20 +29898,39 @@ <h1> | |||||
| _calleeRealm_: a Realm Record, | ||||||
| _parameterStrings_: a List of Strings, | ||||||
| _bodyString_: a String, | ||||||
| _direct_: a Boolean, | ||||||
| _codeString_: a String, | ||||||
| _compilationType_: ~direct-eval~, ~indirect-eval~, or ~function~, | ||||||
| _parameterArgs: a List of ECMAScript language values, | ||||||
| _bodyArg_: an ECMAScript language value, | ||||||
| ): either a normal completion containing ~unused~ or a throw completion | ||||||
| </h1> | ||||||
| <dl class="header"> | ||||||
| <dt>description</dt> | ||||||
| <dd>It allows host environments to block certain ECMAScript functions which allow developers to interpret and evaluate strings as ECMAScript code.</dd> | ||||||
| </dl> | ||||||
| <p> | ||||||
| _parameterStrings_ represents the strings that, when using one of the function constructors, will be concatenated together to build the parameters list. _bodyString_ represents the function body or the string passed to an `eval` call. | ||||||
| _direct_ signifies whether the evaluation is a direct eval. | ||||||
| _parameterStrings_ represents the strings that, when using one of the function constructors, will be concatenated together to build the parameters list. | ||||||
| _bodyString_ represents the function body or the string passed to an `eval` call. | ||||||
| _codeString_ represents the compiled string for a Function or the string passed to an `eval` call. | ||||||
| _parameterArgs_ are the values passed as the leading parameters to one of the Function constructors. _bodyArg_ is either the final parameter passed to one of the Function constructors or the value passed to an `eval` call. | ||||||
| </p> | ||||||
| <p>The default implementation of HostEnsureCanCompileStrings is to return NormalCompletion(~unused~).</p> | ||||||
| </emu-clause> | ||||||
|
|
||||||
| <emu-clause id="sec-hostgetcodeforeval" type="host-defined abstract operation"> | ||||||
| <h1> | ||||||
| HostGetCodeForEval ( | ||||||
| _argument_: an Object, | ||||||
| ): a String or ~no-code~ | ||||||
| </h1> | ||||||
| <dl class="header"> | ||||||
| <dt>description</dt> | ||||||
| <dd>It allows host environments to return a String of code from _argument_ to be used by eval, rather than eval returning _argument_.</dd> | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| </dl> | ||||||
| <p>_argument_ represents the Object to be checked for code.</p> | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would remove this, it's repeating what the |
||||||
| <p>The default implementation of HostGetCodeForEval is to return ~no-code~.</p> | ||||||
| </emu-clause> | ||||||
|
|
||||||
| <emu-clause id="sec-evaldeclarationinstantiation" type="abstract operation" oldids="sec-web-compat-evaldeclarationinstantiation"> | ||||||
| <h1> | ||||||
| EvalDeclarationInstantiation ( | ||||||
|
|
@@ -31179,7 +31205,6 @@ <h1> | |||||
| 1. Append ? ToString(_arg_) to _parameterStrings_. | ||||||
| 1. Let _bodyString_ be ? ToString(_bodyArg_). | ||||||
| 1. Let _currentRealm_ be the current Realm Record. | ||||||
| 1. Perform ? HostEnsureCanCompileStrings(_currentRealm_, _parameterStrings_, _bodyString_, *false*). | ||||||
| 1. Let _parameterString_ be the empty String. | ||||||
| 1. If _argCount_ > 0, then | ||||||
| 1. Set _parameterString_ to _parameterStrings_[0]. | ||||||
|
|
@@ -31190,6 +31215,7 @@ <h1> | |||||
| 1. Set _k_ to _k_ + 1. | ||||||
| 1. Let _bodyParseString_ be the string-concatenation of 0x000A (LINE FEED), _bodyString_, and 0x000A (LINE FEED). | ||||||
| 1. Let _sourceString_ be the string-concatenation of _prefix_, *" anonymous("*, _parameterString_, 0x000A (LINE FEED), *") {"*, _bodyParseString_, and *"}"*. | ||||||
| 1. Perform ? HostEnsureCanCompileStrings(_currentRealm_, _parameterStrings_, _bodyString_, _sourceString_, ~function~, _parameterArgs_, _bodyArg_). | ||||||
| 1. Let _sourceText_ be StringToCodePoints(_sourceString_). | ||||||
| 1. Let _parameters_ be ParseText(_parameterString_, _parameterSym_). | ||||||
| 1. If _parameters_ is a List of errors, throw a *SyntaxError* exception. | ||||||
|
|
@@ -53683,6 +53709,7 @@ <h1>Host Hooks</h1> | |||||
| <p><b>HostGetImportMetaProperties(...)</b></p> | ||||||
| <p><b>HostGrowSharedArrayBuffer(...)</b></p> | ||||||
| <p><b>HostHasSourceTextAvailable(...)</b></p> | ||||||
| <p><b>HostGetCodeForEval(...)</b></p> | ||||||
| <p><b>HostLoadImportedModule(...)</b></p> | ||||||
| <p><b>HostGetSupportedImportAttributes(...)</b></p> | ||||||
| <p><b>HostMakeJobCallback(...)</b></p> | ||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This list is missing
_compilationType_.Also, it's has so many entries now that maybe it should be a
<ol>list, even though that's slightly unusual. @tc39/ecma262-editors thoughts?