JS: extracted ThrowExceptionReporter

This commit is contained in:
Alexey Tsvetkov
2015-02-20 13:15:35 +03:00
parent b01aa5e0a5
commit ae970044e2
2 changed files with 29 additions and 26 deletions
@@ -0,0 +1,27 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.gwt.dev.js
import com.google.gwt.dev.js.rhino.*
import com.google.gwt.dev.js.parserExceptions.*
public object ThrowExceptionOnErrorReporter : ErrorReporter {
override fun warning(message: String, startPosition: CodePosition, endPosition: CodePosition) {}
override fun error(message: String, startPosition: CodePosition, endPosition: CodePosition) =
throw JsParserException(message, startPosition)
}
@@ -19,11 +19,8 @@ package org.jetbrains.kotlin.js.translate.reference;
import com.google.dart.compiler.backend.js.ast.*;
import com.google.dart.compiler.backend.js.ast.metadata.MetadataPackage;
import com.google.dart.compiler.common.SourceInfoImpl;
import com.google.gwt.dev.js.AbortParsingException;
import com.google.gwt.dev.js.JsParser;
import com.google.gwt.dev.js.JsParserException;
import com.google.gwt.dev.js.rhino.CodePosition;
import com.google.gwt.dev.js.rhino.ErrorReporter;
import com.google.gwt.dev.js.ThrowExceptionOnErrorReporter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.InlineStrategy;
@@ -48,7 +45,6 @@ import org.jetbrains.kotlin.types.JetType;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilPackage.getFunctionResolvedCallWithAssert;
@@ -153,32 +149,12 @@ public final class CallExpressionTranslator extends AbstractCallExpressionTransl
assert jsCode != null: jsCodeExpression.toString();
List<JsStatement> statements = new ArrayList<JsStatement>();
ErrorReporter errorReporter = new ErrorReporter() {
@Override
public void warning(
@NotNull String message, @NotNull CodePosition startPosition, @NotNull CodePosition endPosition
) {
}
@Override
public void error(
@NotNull String message, @NotNull CodePosition startPosition, @NotNull CodePosition endPosition
) {
throw new IllegalStateException("JS parser error in backend (must have been checked in frontend): " + message);
}
};
try {
SourceInfoImpl info = new SourceInfoImpl(null, 0, 0, 0, 0);
JsScope scope = context().scope();
StringReader reader = new StringReader(jsCode);
statements.addAll(JsParser.parse(info, scope, reader, errorReporter, /* insideFunction= */ true));
} catch (AbortParsingException e) {
/** @see JsCodeErrorReporter#error */
return Collections.emptyList();
} catch (JsParserException e) {
throw new RuntimeException(e);
statements.addAll(JsParser.parse(info, scope, reader, ThrowExceptionOnErrorReporter.INSTANCE$, /* insideFunction= */ true));
} catch (IOException e) {
throw new RuntimeException(e);
}