KJS: fix non-local return inside catch block
This commit is contained in:
@@ -10,11 +10,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
* A special scope used only for catch blocks. It only holds a single symbol:
|
||||
* the catch argument's name.
|
||||
*/
|
||||
public class JsCatchScope extends JsScope {
|
||||
public class JsCatchScope extends JsDeclarationScope {
|
||||
private final JsName name;
|
||||
|
||||
public JsCatchScope(JsScope parent, @NotNull String ident) {
|
||||
super(parent, "Catch scope");
|
||||
super(parent, "Catch scope", true);
|
||||
name = new JsName(this, ident, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.backend.ast
|
||||
|
||||
import java.util.Stack
|
||||
import java.util.*
|
||||
|
||||
class JsObjectScope(parent: JsScope, description: String) : JsScope(parent, description)
|
||||
|
||||
@@ -24,15 +24,18 @@ object JsDynamicScope : JsScope(null, "Scope for dynamic declarations") {
|
||||
override fun doCreateName(name: String) = JsName(this, name, false)
|
||||
}
|
||||
|
||||
open class JsFunctionScope(parent: JsScope, description: String) : JsScope(parent, description) {
|
||||
|
||||
private val labelScopes = Stack<LabelScope>()
|
||||
private val topLabelScope: LabelScope?
|
||||
get() = if (labelScopes.isNotEmpty()) labelScopes.peek() else null
|
||||
|
||||
open class JsFunctionScope(parent: JsScope, description: String) : JsDeclarationScope(parent, description) {
|
||||
override fun hasOwnName(name: String): Boolean = RESERVED_WORDS.contains(name) || super.hasOwnName(name)
|
||||
|
||||
open fun declareNameUnsafe(identifier: String): JsName = super.declareName(identifier)
|
||||
}
|
||||
|
||||
open class JsDeclarationScope(parent: JsScope, description: String, useParentScopeStack: Boolean = false) : JsScope(parent, description) {
|
||||
private val labelScopes: Stack<LabelScope> =
|
||||
if (parent is JsDeclarationScope && useParentScopeStack) parent.labelScopes else Stack<LabelScope>()
|
||||
|
||||
private val topLabelScope
|
||||
get() = if (labelScopes.isNotEmpty()) labelScopes.peek() else null
|
||||
|
||||
open fun enterLabel(label: String): JsName {
|
||||
val scope = LabelScope(topLabelScope, label)
|
||||
@@ -58,7 +61,7 @@ open class JsFunctionScope(parent: JsScope, description: String) : JsScope(paren
|
||||
else -> ident
|
||||
}
|
||||
|
||||
labelName = JsName(this@JsFunctionScope, freshIdent, false)
|
||||
labelName = JsName(this@JsDeclarationScope, freshIdent, false)
|
||||
}
|
||||
|
||||
override fun findOwnName(name: String): JsName? =
|
||||
|
||||
Reference in New Issue
Block a user