<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[279448] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/279448">279448</a></dd>
<dt>Author</dt> <dd>ysuzuki@apple.com</dd>
<dt>Date</dt> <dd>2021-06-30 19:12:20 -0700 (Wed, 30 Jun 2021)</dd>
</dl>
<h3>Log Message</h3>
<pre>[JSC] Stop generating default parameter code if class constructor is called without 'new'
https://bugs.webkit.org/show_bug.cgi?id=227547
rdar://78821453
Reviewed by Mark Lam.
JSTests:
* stress/calling-non-callable-constructors.js: Added.
(shouldThrow):
Source/JavaScriptCore:
We already do not generate body bytecode when class constructor is called without 'new' because many features including "super()" assume
that they generate bytecode only when it is called as a constructor. But we are not doing that for default parameters' bytecode generation.
This patch stops generating bytecode for default parameters if class constructor is called without 'new'.
* bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::generate):
(JSC::BytecodeGenerator::BytecodeGenerator):
* runtime/ConstructorKind.h:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkJSTestsChangeLog">trunk/JSTests/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecompilerBytecodeGeneratorcpp">trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreparserParsercpp">trunk/Source/JavaScriptCore/parser/Parser.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreparserParserh">trunk/Source/JavaScriptCore/parser/Parser.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeConstructorKindh">trunk/Source/JavaScriptCore/runtime/ConstructorKind.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkJSTestsstresscallingnoncallableconstructorsjs">trunk/JSTests/stress/calling-non-callable-constructors.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkJSTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/JSTests/ChangeLog (279447 => 279448)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JSTests/ChangeLog 2021-07-01 02:03:55 UTC (rev 279447)
+++ trunk/JSTests/ChangeLog 2021-07-01 02:12:20 UTC (rev 279448)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2021-06-30 Yusuke Suzuki <ysuzuki@apple.com>
+
+ [JSC] Stop generating default parameter code if class constructor is called without 'new'
+ https://bugs.webkit.org/show_bug.cgi?id=227547
+ rdar://78821453
+
+ Reviewed by Mark Lam.
+
+ * stress/calling-non-callable-constructors.js: Added.
+ (shouldThrow):
+
</ins><span class="cx"> 2021-06-29 Yusuke Suzuki <ysuzuki@apple.com>
</span><span class="cx">
</span><span class="cx"> [JSC] Private names should be handled by usedVariables mechanism
</span></span></pre></div>
<a id="trunkJSTestsstresscallingnoncallableconstructorsjs"></a>
<div class="addfile"><h4>Added: trunk/JSTests/stress/calling-non-callable-constructors.js (0 => 279448)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JSTests/stress/calling-non-callable-constructors.js (rev 0)
+++ trunk/JSTests/stress/calling-non-callable-constructors.js 2021-07-01 02:12:20 UTC (rev 279448)
</span><span class="lines">@@ -0,0 +1,31 @@
</span><ins>+function shouldThrow(func, errorMessage) {
+ var errorThrown = false;
+ var error = null;
+ try {
+ func();
+ } catch (e) {
+ errorThrown = true;
+ error = e;
+ }
+ if (!errorThrown)
+ throw new Error('not thrown');
+ if (String(error) !== errorMessage)
+ throw new Error(`bad error: ${String(error)}`);
+}
+
+shouldThrow(() => {
+ class C extends Object {
+ constructor(t = super()) {}
+ }
+
+ C();
+}, `TypeError: Cannot call a class constructor without |new|`);
+
+shouldThrow(() => {
+ Promise();
+}, `TypeError: Cannot call a constructor without |new|`);
+
+shouldThrow(() => {
+ class DerivedPromise extends Promise { }
+ DerivedPromise();
+}, `TypeError: Cannot call a class constructor without |new|`);
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (279447 => 279448)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog 2021-07-01 02:03:55 UTC (rev 279447)
+++ trunk/Source/JavaScriptCore/ChangeLog 2021-07-01 02:12:20 UTC (rev 279448)
</span><span class="lines">@@ -1,5 +1,22 @@
</span><span class="cx"> 2021-06-30 Yusuke Suzuki <ysuzuki@apple.com>
</span><span class="cx">
</span><ins>+ [JSC] Stop generating default parameter code if class constructor is called without 'new'
+ https://bugs.webkit.org/show_bug.cgi?id=227547
+ rdar://78821453
+
+ Reviewed by Mark Lam.
+
+ We already do not generate body bytecode when class constructor is called without 'new' because many features including "super()" assume
+ that they generate bytecode only when it is called as a constructor. But we are not doing that for default parameters' bytecode generation.
+ This patch stops generating bytecode for default parameters if class constructor is called without 'new'.
+
+ * bytecompiler/BytecodeGenerator.cpp:
+ (JSC::BytecodeGenerator::generate):
+ (JSC::BytecodeGenerator::BytecodeGenerator):
+ * runtime/ConstructorKind.h:
+
+2021-06-30 Yusuke Suzuki <ysuzuki@apple.com>
+
</ins><span class="cx"> [JSC] Private names should be handled by usedVariables mechanism
</span><span class="cx"> https://bugs.webkit.org/show_bug.cgi?id=227476
</span><span class="cx"> rdar://76049469
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecompilerBytecodeGeneratorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp (279447 => 279448)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp 2021-07-01 02:03:55 UTC (rev 279447)
+++ trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp 2021-07-01 02:12:20 UTC (rev 279448)
</span><span class="lines">@@ -152,68 +152,69 @@
</span><span class="cx"> if (UNLIKELY(m_outOfMemoryDuringConstruction))
</span><span class="cx"> return ParserError(ParserError::OutOfMemory);
</span><span class="cx">
</span><ins>+ bool callingNonCallableConstructor = false;
+ switch (constructorKind()) {
+ case ConstructorKind::None:
+ break;
+ case ConstructorKind::Naked:
+ case ConstructorKind::Base:
+ case ConstructorKind::Extends:
+ callingNonCallableConstructor = !isConstructor();
+ break;
+ }
+
</ins><span class="cx"> m_codeBlock->setThisRegister(m_thisRegister.virtualRegister());
</span><span class="cx">
</span><span class="cx"> emitLogShadowChickenPrologueIfNecessary();
</span><span class="cx">
</span><del>- // If we have declared a variable named "arguments" and we are using arguments then we should
- // perform that assignment now.
- if (m_needToInitializeArguments)
- initializeVariable(variable(propertyNames().arguments), m_argumentsRegister);
</del><ins>+ if (!callingNonCallableConstructor) {
+ // If we have declared a variable named "arguments" and we are using arguments then we should
+ // perform that assignment now.
+ if (m_needToInitializeArguments)
+ initializeVariable(variable(propertyNames().arguments), m_argumentsRegister);
</ins><span class="cx">
</span><del>- if (m_restParameter)
- m_restParameter->emit(*this);
</del><ins>+ if (m_restParameter)
+ m_restParameter->emit(*this);
</ins><span class="cx">
</span><del>- {
- RefPtr<RegisterID> temp = newTemporary();
- RefPtr<RegisterID> tolLevelScope;
- for (auto functionPair : m_functionsToInitialize) {
- FunctionMetadataNode* metadata = functionPair.first;
- FunctionVariableType functionType = functionPair.second;
- emitNewFunction(temp.get(), metadata);
- if (functionType == NormalFunctionVariable)
- initializeVariable(variable(metadata->ident()), temp.get());
- else if (functionType == TopLevelFunctionVariable) {
- if (!tolLevelScope) {
- // We know this will resolve to the top level scope or global object because our parser/global initialization code
- // doesn't allow let/const/class variables to have the same names as functions.
- // This is a top level function, and it's an error to ever create a top level function
- // name that would resolve to a lexical variable. E.g:
- // ```
- // function f() {
- // {
- // let x;
- // {
- // //// error thrown here
- // eval("function x(){}");
- // }
- // }
- // }
- // ```
- // Therefore, we're guaranteed to have this resolve to a top level variable.
- RefPtr<RegisterID> tolLevelObjectScope = emitResolveScope(nullptr, Variable(metadata->ident()));
- tolLevelScope = newBlockScopeVariable();
- move(tolLevelScope.get(), tolLevelObjectScope.get());
- }
- emitPutToScope(tolLevelScope.get(), Variable(metadata->ident()), temp.get(), ThrowIfNotFound, InitializationMode::NotInitialization);
- } else
- RELEASE_ASSERT_NOT_REACHED();
</del><ins>+ {
+ RefPtr<RegisterID> temp = newTemporary();
+ RefPtr<RegisterID> tolLevelScope;
+ for (auto functionPair : m_functionsToInitialize) {
+ FunctionMetadataNode* metadata = functionPair.first;
+ FunctionVariableType functionType = functionPair.second;
+ emitNewFunction(temp.get(), metadata);
+ if (functionType == NormalFunctionVariable)
+ initializeVariable(variable(metadata->ident()), temp.get());
+ else if (functionType == TopLevelFunctionVariable) {
+ if (!tolLevelScope) {
+ // We know this will resolve to the top level scope or global object because our parser/global initialization code
+ // doesn't allow let/const/class variables to have the same names as functions.
+ // This is a top level function, and it's an error to ever create a top level function
+ // name that would resolve to a lexical variable. E.g:
+ // ```
+ // function f() {
+ // {
+ // let x;
+ // {
+ // //// error thrown here
+ // eval("function x(){}");
+ // }
+ // }
+ // }
+ // ```
+ // Therefore, we're guaranteed to have this resolve to a top level variable.
+ RefPtr<RegisterID> tolLevelObjectScope = emitResolveScope(nullptr, Variable(metadata->ident()));
+ tolLevelScope = newBlockScopeVariable();
+ move(tolLevelScope.get(), tolLevelObjectScope.get());
+ }
+ emitPutToScope(tolLevelScope.get(), Variable(metadata->ident()), temp.get(), ThrowIfNotFound, InitializationMode::NotInitialization);
+ } else
+ RELEASE_ASSERT_NOT_REACHED();
+ }
</ins><span class="cx"> }
</span><del>- }
</del><span class="cx">
</span><del>- bool callingClassConstructor = false;
- switch (constructorKind()) {
- case ConstructorKind::None:
- case ConstructorKind::Naked:
- break;
- case ConstructorKind::Base:
- case ConstructorKind::Extends:
- callingClassConstructor = !isConstructor();
- break;
- }
- if (!callingClassConstructor)
</del><span class="cx"> m_scopeNode->emitBytecode(*this);
</span><del>- else {
</del><ins>+ } else {
</ins><span class="cx"> // At this point we would have emitted an unconditional throw followed by some nonsense that's
</span><span class="cx"> // just an artifact of how this generator is structured. That code never runs, but it confuses
</span><span class="cx"> // bytecode analyses because it constitutes an unterminated basic block. So, we terminate the
</span><span class="lines">@@ -441,6 +442,24 @@
</span><span class="cx"> allocateAndEmitScope();
</span><span class="cx">
</span><span class="cx"> emitCheckTraps();
</span><ins>+
+ switch (constructorKind()) {
+ case ConstructorKind::None:
+ break;
+ case ConstructorKind::Naked:
+ if (!isConstructor()) {
+ emitThrowTypeError("Cannot call a constructor without |new|");
+ return;
+ }
+ break;
+ case ConstructorKind::Base:
+ case ConstructorKind::Extends:
+ if (!isConstructor()) {
+ emitThrowTypeError("Cannot call a class constructor without |new|");
+ return;
+ }
+ break;
+ }
</ins><span class="cx">
</span><span class="cx"> if (functionNameIsInScope(functionNode->ident(), functionNode->functionMode())) {
</span><span class="cx"> ASSERT(parseMode != SourceParseMode::GeneratorBodyMode);
</span><span class="lines">@@ -699,61 +718,60 @@
</span><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ case SourceParseMode::ArrowFunctionMode:
+ break;
+
</ins><span class="cx"> default: {
</span><del>- if (SourceParseMode::ArrowFunctionMode != parseMode) {
- if (isConstructor()) {
- if (m_newTargetRegister)
- move(m_newTargetRegister, &m_thisRegister);
- switch (constructorKind()) {
- case ConstructorKind::Naked:
- // Naked constructor not create |this| automatically.
- break;
- case ConstructorKind::None:
- case ConstructorKind::Base:
- emitCreateThis(&m_thisRegister);
- if (Options::usePrivateMethods() && privateBrandRequirement() == PrivateBrandRequirement::Needed)
- emitInstallPrivateBrand(&m_thisRegister);
</del><ins>+ if (isConstructor()) {
+ if (m_newTargetRegister)
+ move(m_newTargetRegister, &m_thisRegister);
+ switch (constructorKind()) {
+ case ConstructorKind::Naked:
+ // Naked constructor not create |this| automatically.
+ break;
+ case ConstructorKind::None:
+ case ConstructorKind::Base:
+ emitCreateThis(&m_thisRegister);
+ if (Options::usePrivateMethods() && privateBrandRequirement() == PrivateBrandRequirement::Needed)
+ emitInstallPrivateBrand(&m_thisRegister);
</ins><span class="cx">
</span><del>- emitInstanceFieldInitializationIfNeeded(&m_thisRegister, &m_calleeRegister, m_scopeNode->position(), m_scopeNode->position(), m_scopeNode->position());
- break;
- case ConstructorKind::Extends:
- moveEmptyValue(&m_thisRegister);
- break;
</del><ins>+ emitInstanceFieldInitializationIfNeeded(&m_thisRegister, &m_calleeRegister, m_scopeNode->position(), m_scopeNode->position(), m_scopeNode->position());
+ break;
+ case ConstructorKind::Extends:
+ moveEmptyValue(&m_thisRegister);
+ break;
+ }
+ } else {
+ switch (constructorKind()) {
+ case ConstructorKind::None: {
+ bool shouldEmitToThis = false;
+ if (functionNode->usesThis() || usesEval() || m_scopeNode->doAnyInnerArrowFunctionsUseThis() || m_scopeNode->doAnyInnerArrowFunctionsUseEval())
+ shouldEmitToThis = true;
+ else if ((functionNode->usesSuperProperty() || m_scopeNode->doAnyInnerArrowFunctionsUseSuperProperty()) && !ecmaMode.isStrict()) {
+ // We must emit to_this when we're not in strict mode because we
+ // will convert |this| to an object, and that object may be passed
+ // to a strict function as |this|. This is observable because that
+ // strict function's to_this will just return the object.
+ //
+ // We don't need to emit this for strict-mode code because
+ // strict-mode code may call another strict function, which will
+ // to_this if it directly uses this; this is OK, because we defer
+ // to_this until |this| is used directly. Strict-mode code might
+ // also call a sloppy mode function, and that will to_this, which
+ // will defer the conversion, again, until necessary.
+ shouldEmitToThis = true;
</ins><span class="cx"> }
</span><del>- } else {
- switch (constructorKind()) {
- case ConstructorKind::None: {
- bool shouldEmitToThis = false;
- if (functionNode->usesThis() || usesEval() || m_scopeNode->doAnyInnerArrowFunctionsUseThis() || m_scopeNode->doAnyInnerArrowFunctionsUseEval())
- shouldEmitToThis = true;
- else if ((functionNode->usesSuperProperty() || m_scopeNode->doAnyInnerArrowFunctionsUseSuperProperty()) && !ecmaMode.isStrict()) {
- // We must emit to_this when we're not in strict mode because we
- // will convert |this| to an object, and that object may be passed
- // to a strict function as |this|. This is observable because that
- // strict function's to_this will just return the object.
- //
- // We don't need to emit this for strict-mode code because
- // strict-mode code may call another strict function, which will
- // to_this if it directly uses this; this is OK, because we defer
- // to_this until |this| is used directly. Strict-mode code might
- // also call a sloppy mode function, and that will to_this, which
- // will defer the conversion, again, until necessary.
- shouldEmitToThis = true;
- }
</del><span class="cx">
</span><del>- if (shouldEmitToThis)
- emitToThis();
- break;
- }
- case ConstructorKind::Naked:
- emitThrowTypeError("Cannot call a constructor without |new|");
- break;
- case ConstructorKind::Base:
- case ConstructorKind::Extends:
- emitThrowTypeError("Cannot call a class constructor without |new|");
- break;
- }
</del><ins>+ if (shouldEmitToThis)
+ emitToThis();
+ break;
</ins><span class="cx"> }
</span><ins>+ case ConstructorKind::Naked:
+ case ConstructorKind::Base:
+ case ConstructorKind::Extends:
+ RELEASE_ASSERT_NOT_REACHED();
+ break;
+ }
</ins><span class="cx"> }
</span><span class="cx"> break;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreparserParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/parser/Parser.cpp (279447 => 279448)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/parser/Parser.cpp 2021-07-01 02:03:55 UTC (rev 279447)
+++ trunk/Source/JavaScriptCore/parser/Parser.cpp 2021-07-01 02:12:20 UTC (rev 279448)
</span><span class="lines">@@ -5113,16 +5113,15 @@
</span><span class="cx"> next();
</span><span class="cx"> failIfTrue(match(OPENPAREN) && currentScope()->evalContextType() == EvalContextType::InstanceFieldEvalContext, "super call is not valid in this context");
</span><span class="cx"> ScopeRef functionScope = currentFunctionScope();
</span><del>- if (!functionScope->setNeedsSuperBinding()) {
- // It unnecessary to check of using super during reparsing one more time. Also it can lead to syntax error
- // in case of arrow function because during reparsing we don't know whether we currently parse the arrow function
- // inside of the constructor or method.
- if (!m_lexer->isReparsingFunction()) {
- SuperBinding functionSuperBinding = !functionScope->isArrowFunction() && !closestOrdinaryFunctionScope->isEvalContext()
- ? functionScope->expectedSuperBinding()
- : closestOrdinaryFunctionScope->expectedSuperBinding();
- semanticFailIfTrue(functionSuperBinding == SuperBinding::NotNeeded && !isClassFieldInitializer, "super is not valid in this context");
- }
</del><ins>+ functionScope->setNeedsSuperBinding();
+ // It unnecessary to check of using super during reparsing one more time. Also it can lead to syntax error
+ // in case of arrow function because during reparsing we don't know whether we currently parse the arrow function
+ // inside of the constructor or method.
+ if (!m_lexer->isReparsingFunction()) {
+ SuperBinding functionSuperBinding = !functionScope->isArrowFunction() && !closestOrdinaryFunctionScope->isEvalContext()
+ ? functionScope->expectedSuperBinding()
+ : closestOrdinaryFunctionScope->expectedSuperBinding();
+ semanticFailIfTrue(functionSuperBinding == SuperBinding::NotNeeded && !isClassFieldInitializer, "super is not valid in this context");
</ins><span class="cx"> }
</span><span class="cx"> } else if (baseIsImport) {
</span><span class="cx"> next();
</span><span class="lines">@@ -5231,18 +5230,17 @@
</span><span class="cx"> failIfFalse(arguments, "Cannot parse call arguments");
</span><span class="cx"> if (baseIsSuper) {
</span><span class="cx"> ScopeRef functionScope = currentFunctionScope();
</span><del>- if (!functionScope->setHasDirectSuper()) {
- // It unnecessary to check of using super during reparsing one more time. Also it can lead to syntax error
- // in case of arrow function because during reparsing we don't know whether we currently parse the arrow function
- // inside of the constructor or method.
- if (!m_lexer->isReparsingFunction()) {
- ScopeRef closestOrdinaryFunctionScope = closestParentOrdinaryFunctionNonLexicalScope();
- ConstructorKind functionConstructorKind = !functionScope->isArrowFunction() && !closestOrdinaryFunctionScope->isEvalContext()
- ? functionScope->constructorKind()
- : closestOrdinaryFunctionScope->constructorKind();
- semanticFailIfTrue(functionConstructorKind == ConstructorKind::None, "super is not valid in this context");
- semanticFailIfTrue(functionConstructorKind != ConstructorKind::Extends, "super is not valid in this context");
- }
</del><ins>+ functionScope->setHasDirectSuper();
+ // It unnecessary to check of using super during reparsing one more time. Also it can lead to syntax error
+ // in case of arrow function because during reparsing we don't know whether we currently parse the arrow function
+ // inside of the constructor or method.
+ if (!m_lexer->isReparsingFunction()) {
+ ScopeRef closestOrdinaryFunctionScope = closestParentOrdinaryFunctionNonLexicalScope();
+ ConstructorKind functionConstructorKind = !functionScope->isArrowFunction() && !closestOrdinaryFunctionScope->isEvalContext()
+ ? functionScope->constructorKind()
+ : closestOrdinaryFunctionScope->constructorKind();
+ semanticFailIfTrue(functionConstructorKind == ConstructorKind::None, "super is not valid in this context");
+ semanticFailIfTrue(functionConstructorKind != ConstructorKind::Extends, "super is not valid in this context");
</ins><span class="cx"> }
</span><span class="cx"> if (currentScope()->isArrowFunction())
</span><span class="cx"> functionScope->setInnerArrowFunctionUsesSuperCall();
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreparserParserh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/parser/Parser.h (279447 => 279448)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/parser/Parser.h 2021-07-01 02:03:55 UTC (rev 279447)
+++ trunk/Source/JavaScriptCore/parser/Parser.h 2021-07-01 02:12:20 UTC (rev 279448)
</span><span class="lines">@@ -622,10 +622,10 @@
</span><span class="cx"> bool isArrowFunction() { return m_isArrowFunction; }
</span><span class="cx">
</span><span class="cx"> bool hasDirectSuper() const { return m_hasDirectSuper; }
</span><del>- bool setHasDirectSuper() { return std::exchange(m_hasDirectSuper, true); }
</del><ins>+ void setHasDirectSuper() { m_hasDirectSuper = true; }
</ins><span class="cx">
</span><span class="cx"> bool needsSuperBinding() const { return m_needsSuperBinding; }
</span><del>- bool setNeedsSuperBinding() { return std::exchange(m_needsSuperBinding, true); }
</del><ins>+ void setNeedsSuperBinding() { m_needsSuperBinding = true; }
</ins><span class="cx">
</span><span class="cx"> void setEvalContextType(EvalContextType evalContextType) { m_evalContextType = evalContextType; }
</span><span class="cx"> EvalContextType evalContextType() { return m_evalContextType; }
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeConstructorKindh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/ConstructorKind.h (279447 => 279448)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/ConstructorKind.h 2021-07-01 02:03:55 UTC (rev 279447)
+++ trunk/Source/JavaScriptCore/runtime/ConstructorKind.h 2021-07-01 02:12:20 UTC (rev 279448)
</span><span class="lines">@@ -28,9 +28,9 @@
</span><span class="cx"> namespace JSC {
</span><span class="cx">
</span><span class="cx"> enum class ConstructorKind : uint8_t {
</span><del>- None,
- Base,
- Extends,
</del><ins>+ None, // All the other functions
+ Base, // Class base constructor
+ Extends, // Class derived constructor
</ins><span class="cx"> Naked, // Naked constructor, only used for builtin functions
</span><span class="cx"> };
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>