Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion proposal.html
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,13 @@ <h1>(<emu-xref href="#sec-createdynamicfunction">19.2.1.1.1</emu-xref>) Runtime
</emu-clause>


<emu-clause id="proposal-sec-hosthassourcetextavailable">
<h1>HostHasSourceTextAvailable ( _func_ )</h1>
<p>HostHasSourceTextAvailable is an implementation-defined abstract operation that allows host environments to prevent the source text from being provided for a given function.</p>
<p>An implementation of HostHasSourceTextAvailable may complete normally or abruptly. Any abrupt completions will be propagated to its callers. The default implementation of HostHasSourceTextAvailable is to unconditionally return a normal completion with a value of *true*.</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we need the flexibility to return abruptly, but it doesn't hurt anything.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured since toString can already return abruptly today, it didn't hurt to allow the engine to control that as well.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allowing abrupt completions doesn't seem useful to me. Function.prototype.toString is currently spec'ed to either return a string or throw a TypeError. With this change, it either returns a string or throws any value, so the error case is no longer restricted to TypeError.

For example test262 tests will need to be written as:

function f() {}

var errored = false;
var source;
try {
  source = f.toString();
} catch {
  // HostHasSourceTextAvailable is allowed to return abruptly, unconditionally pass in this case.
  errored = true;
}

if (!errored) {
  // NATIVE_FUNCTION_RE is defined in test262/harness/nativeFunctionMatcher.js
  assert(source === "function f() {}" || NATIVE_FUNCTION_RE.test(source));
}

If we don't allow abrupt completions, the test can be written as:

function f() {}

var source = f.toString();
assert(source === "function f() {}" || NATIVE_FUNCTION_RE.test(source));

Nit: The result must be compared to true, so HostHasSourceTextAvailable(func) is true, then return ... instead of HostHasSourceTextAvailable(func), then return .... And we should probably require HostHasSourceTextAvailable to return a boolean value.

And I assume not requiring stable results is intentional? So HostHasSourceTextAvailable is allowed to return different results over time even when the same argument is passed to it?

</emu-clause>


<!-- 19.2.3.5 -->
<emu-clause id="proposal-sec-function.prototype.tostring">
<h1>(<emu-xref href="#sec-function.prototype.tostring">19.2.3.5</emu-xref>) Function.prototype.toString ( )</h1>
Expand All @@ -549,7 +556,7 @@ <h1>(<emu-xref href="#sec-function.prototype.tostring">19.2.3.5</emu-xref>) Func
<ins class="block">
<emu-alg>
1. If _func_ is a <emu-xref href="#sec-bound-function-exotic-objects">Bound Function exotic object</emu-xref> or a <emu-xref href="#sec-ecmascript-standard-built-in-objects">built-in Function object</emu-xref>, then return an implementation-dependent String source code representation of _func_. The representation must have the syntax of a |NativeFunction|. Additionally, if _func_ is a <emu-xref href="#sec-well-known-intrinsic-objects">Well-known Intrinsic Object</emu-xref>, the portion of the returned String that would be matched by |IdentifierName| must be the initial value of the *name* property of _func_.
1. If _func_ has a [[SourceText]] internal slot and Type(_func_.[[SourceText]]) is String, then return _func_.[[SourceText]].
1. If _func_ has a [[SourceText]] internal slot and Type(_func_.[[SourceText]]) is String and ? HostHasSourceTextAvailable(_func_), then return _func_.[[SourceText]].
1. If Type(_func_) is Object and IsCallable(_func_) is *true*, then return an implementation-dependent String source code representation of _func_. The representation must have the syntax of a |NativeFunction|.
1. Throw a *TypeError* exception.
</emu-alg>
Expand Down