From 6b7eba485b63feedc66214fcea3684f0205e263a Mon Sep 17 00:00:00 2001 From: Roman Artemev Date: Tue, 5 Mar 2019 20:18:19 +0300 Subject: [PATCH] [JS] Run all js tests in v8 --- .../kotlin/integration/AntTaskJsTest.java | 4 +- .../jetbrains/kotlin/js/test/BasicBoxTest.kt | 17 +- .../kotlin/js/test/BasicIrBoxTest.kt | 4 +- .../jetbrains/kotlin/js/test/JsTestChecker.kt | 173 +++++++++++------- .../js/test/interop/GlobalRuntimeContext.kt | 8 - .../kotlin/js/test/interop/ScriptEngine.kt | 4 +- .../js/test/interop/ScriptEngineNashorn.kt | 22 ++- .../kotlin/js/test/interop/ScriptEngineV8.kt | 50 ++++- .../semantics/AbstractWebDemoExamplesTest.kt | 9 +- .../js/test/semantics/MultiModuleOrderTest.kt | 7 +- .../semantics/WebDemoCanvasExamplesTest.java | 18 +- 11 files changed, 211 insertions(+), 105 deletions(-) delete mode 100644 js/js.tests/test/org/jetbrains/kotlin/js/test/interop/GlobalRuntimeContext.kt diff --git a/js/js.tests/test/org/jetbrains/kotlin/integration/AntTaskJsTest.java b/js/js.tests/test/org/jetbrains/kotlin/integration/AntTaskJsTest.java index 9f7b480c576..3b56e215df7 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/integration/AntTaskJsTest.java +++ b/js/js.tests/test/org/jetbrains/kotlin/integration/AntTaskJsTest.java @@ -21,6 +21,7 @@ import kotlin.collections.CollectionsKt; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.js.test.NashornJsTestChecker; +import org.jetbrains.kotlin.js.test.V8JsTestChecker; import org.jetbrains.kotlin.test.KotlinTestUtils; import java.io.File; @@ -31,6 +32,7 @@ import java.util.List; public class AntTaskJsTest extends AbstractAntTaskTest { private static final String JS_OUT_FILE = "out.js"; + private static final Boolean useHashorn = Boolean.getBoolean("kotlin.js.useNashorn"); @NotNull private String getTestDataDir() { @@ -58,7 +60,7 @@ public class AntTaskJsTest extends AbstractAntTaskTest { List filePaths = CollectionsKt.map(fileNames, s -> getOutputFileByName(s).getAbsolutePath()); - NashornJsTestChecker.INSTANCE.check(filePaths, "out", "foo", "box", "OK", withModuleSystem); + (useHashorn ? NashornJsTestChecker.INSTANCE : V8JsTestChecker.INSTANCE).check(filePaths, "out", "foo", "box", "OK", withModuleSystem); } private void doJsAntTestForPostfixPrefix(@Nullable String prefix, @Nullable String postfix) throws Exception { diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt index 381176351b3..1cbf6f65f9a 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt @@ -43,6 +43,8 @@ import org.jetbrains.kotlin.js.parser.sourcemaps.SourceMapParser import org.jetbrains.kotlin.js.parser.sourcemaps.SourceMapSuccess import org.jetbrains.kotlin.js.sourceMap.SourceFilePathResolver import org.jetbrains.kotlin.js.sourceMap.SourceMap3Builder +import org.jetbrains.kotlin.js.test.interop.ScriptEngineNashorn +import org.jetbrains.kotlin.js.test.interop.ScriptEngineV8Lazy import org.jetbrains.kotlin.js.test.utils.* import org.jetbrains.kotlin.js.util.TextOutputImpl import org.jetbrains.kotlin.metadata.DebugProtoBuf @@ -63,6 +65,7 @@ import org.jetbrains.kotlin.utils.JsMetadataVersion import org.jetbrains.kotlin.utils.KotlinJavascriptMetadata import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils import java.io.* +import java.lang.Boolean.getBoolean import java.nio.charset.Charset import java.util.regex.Pattern @@ -84,10 +87,12 @@ abstract class BasicBoxTest( protected open fun getOutputPostfixFile(testFilePath: String): File? = null protected open val runMinifierByDefault: Boolean = false - protected open val skipMinification = System.getProperty("kotlin.js.skipMinificationTest", "false")!!.toBoolean() + protected open val skipMinification = getBoolean("kotlin.js.skipMinificationTest") protected open val incrementalCompilationChecksEnabled = true + protected open val testChecker get() = if (runTestInNashorn) NashornJsTestChecker else V8JsTestChecker + fun doTest(filePath: String) { doTest(filePath, "OK", MainCallParameters.noCall()) } @@ -262,7 +267,7 @@ abstract class BasicBoxTest( withModuleSystem: Boolean, runtime: JsIrTestRuntime ) { - NashornJsTestChecker.check(jsFiles, testModuleName, testPackage, testFunction, expectedResult, withModuleSystem) + testChecker.check(jsFiles, testModuleName, testPackage, testFunction, expectedResult, withModuleSystem) } protected open fun performAdditionalChecks(generatedJsFiles: List, outputPrefixFile: File?, outputPostfixFile: File?) {} @@ -685,7 +690,7 @@ abstract class BasicBoxTest( val result = engineForMinifier.runAndRestoreContext { runList.forEach(this::loadFile) overrideAsserter() - eval(NashornJsTestChecker.SETUP_KOTLIN_OUTPUT) + eval(SETUP_KOTLIN_OUTPUT) runTestFunction(testModuleName, testPackage, testFunction, withModuleSystem) } TestCase.assertEquals(expectedResult, result) @@ -825,13 +830,15 @@ abstract class BasicBoxTest( private val CALL_MAIN_PATTERN = Pattern.compile("^// *CALL_MAIN *$", Pattern.MULTILINE) private val KJS_WITH_FULL_RUNTIME = Pattern.compile("^// *KJS_WITH_FULL_RUNTIME *\$", Pattern.MULTILINE) + @JvmStatic + protected val runTestInNashorn = getBoolean("kotlin.js.useNashorn") + val TEST_MODULE = "JS_TESTS" private val DEFAULT_MODULE = "main" private val TEST_FUNCTION = "box" private val OLD_MODULE_SUFFIX = "-old" const val KOTLIN_TEST_INTERNAL = "\$kotlin_test_internal\$" - - private val engineForMinifier = createScriptEngine() + private val engineForMinifier = if (runTestInNashorn) ScriptEngineNashorn() else ScriptEngineV8Lazy() } } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt index 63d81352016..fa24a8b2538 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt @@ -52,6 +52,8 @@ abstract class BasicIrBoxTest( super.doTest(filePath, expectedResult, mainCallParameters, coroutinesPackage) } + override val testChecker get() = if (runTestInNashorn) NashornIrJsTestChecker() else V8IrJsTestChecker + private val runtimes = mapOf(JsIrTestRuntime.DEFAULT to defaultRuntimeKlib, JsIrTestRuntime.FULL to fullRuntimeKlib) @@ -141,7 +143,7 @@ abstract class BasicIrBoxTest( // TODO: should we do anything special for module systems? // TODO: return list of js from translateFiles and provide then to this function with other js files - V8IrJsTestChecker.check(jsFiles, testModuleName, null, testFunction, expectedResult, withModuleSystem) + testChecker.check(jsFiles, testModuleName, null, testFunction, expectedResult, withModuleSystem) } } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/JsTestChecker.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/JsTestChecker.kt index 3faaab73516..d1086f1a9e8 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/JsTestChecker.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/JsTestChecker.kt @@ -5,8 +5,6 @@ package org.jetbrains.kotlin.js.test -import jdk.nashorn.internal.runtime.ScriptRuntime -import org.jetbrains.kotlin.js.test.interop.GlobalRuntimeContext import org.jetbrains.kotlin.js.test.interop.ScriptEngine import org.jetbrains.kotlin.js.test.interop.ScriptEngineNashorn import org.jetbrains.kotlin.js.test.interop.ScriptEngineV8 @@ -65,48 +63,39 @@ abstract class AbstractJsTestChecker { runTestFunction(testModuleName, testPackageName, testFunctionName, withModuleSystem) } - protected abstract fun run(files: List, f: ScriptEngine.() -> Any?): Any? -} - -fun ScriptEngine.runAndRestoreContext( - globalObject: GlobalRuntimeContext = getGlobalContext(), - originalState: Map = globalObject.toMap(), - f: ScriptEngine.() -> Any? -): Any? { - return try { - this.f() - } finally { - for (key in globalObject.keys) { - globalObject[key] = originalState[key] ?: ScriptRuntime.UNDEFINED - } - } -} - -abstract class AbstractNashornJsTestChecker: AbstractJsTestChecker() { - - private var engineUsageCnt = 0 - - private var engineCache: ScriptEngine? = null - private var globalObject: GlobalRuntimeContext? = null - private var originalState: Map? = null - - protected val engine - get() = engineCache ?: createScriptEngineForTest().also { - engineCache = it - globalObject = it.getGlobalContext() - originalState = globalObject?.toMap() - } fun run(files: List) { run(files) { null } } + abstract fun checkStdout(files: List, expectedResult: String) + + protected abstract fun run(files: List, f: ScriptEngine.() -> Any?): Any? +} + +fun ScriptEngine.runAndRestoreContext(f: ScriptEngine.() -> Any?): Any? { + return try { + saveState() + f() + } finally { + restoreState() + } +} + +abstract class AbstractNashornJsTestChecker : AbstractJsTestChecker() { + + private var engineUsageCnt = 0 + + private var engineCache: ScriptEngineNashorn? = null + + protected val engine: ScriptEngineNashorn + get() = engineCache ?: createScriptEngineForTest().also { + engineCache = it + } + protected open fun beforeRun() {} - override fun run( - files: List, - f: ScriptEngine.() -> Any? - ): Any? { + override fun run(files: List, f: ScriptEngine.() -> Any?): Any? { // Recreate the engine once in a while if (engineUsageCnt++ > 100) { engineUsageCnt = 0 @@ -115,37 +104,46 @@ abstract class AbstractNashornJsTestChecker: AbstractJsTestChecker() { beforeRun() - return engine.runAndRestoreContext(globalObject!!, originalState!!) { - files.forEach(engine::loadFile) - engine.f() + return engine.runAndRestoreContext { + files.forEach { loadFile(it) } + f() } } - protected abstract fun createScriptEngineForTest(): ScriptEngine -} - -object NashornJsTestChecker : AbstractNashornJsTestChecker() { - const val SETUP_KOTLIN_OUTPUT = "kotlin.kotlin.io.output = new kotlin.kotlin.io.BufferedOutput();" - private const val GET_KOTLIN_OUTPUT = "kotlin.kotlin.io.output.buffer;" - - override fun beforeRun() { - engine.evalVoid(SETUP_KOTLIN_OUTPUT) - } - - fun checkStdout(files: List, expectedResult: String) { + override fun checkStdout(files: List, expectedResult: String) { run(files) val actualResult = engine.eval(GET_KOTLIN_OUTPUT) Assert.assertEquals(expectedResult, actualResult) } - override fun createScriptEngineForTest(): ScriptEngine { - val engine = createScriptEngine() + protected abstract val preloadedScripts: List - listOf( - BasicBoxTest.TEST_DATA_DIR_PATH + "nashorn-polyfills.js", - BasicBoxTest.DIST_DIR_JS_PATH + "kotlin.js", - BasicBoxTest.DIST_DIR_JS_PATH + "kotlin-test.js" - ).forEach(engine::loadFile) + protected open fun createScriptEngineForTest(): ScriptEngineNashorn { + val engine = ScriptEngineNashorn() + + preloadedScripts.forEach { engine.loadFile(it) } + + return engine + } +} + +const val SETUP_KOTLIN_OUTPUT = "kotlin.kotlin.io.output = new kotlin.kotlin.io.BufferedOutput();" +const val GET_KOTLIN_OUTPUT = "kotlin.kotlin.io.output.buffer;" + +object NashornJsTestChecker : AbstractNashornJsTestChecker() { + + override fun beforeRun() { + engine.evalVoid(SETUP_KOTLIN_OUTPUT) + } + + override val preloadedScripts = listOf( + BasicBoxTest.TEST_DATA_DIR_PATH + "nashorn-polyfills.js", + BasicBoxTest.DIST_DIR_JS_PATH + "kotlin.js", + BasicBoxTest.DIST_DIR_JS_PATH + "kotlin-test.js" + ) + + override fun createScriptEngineForTest(): ScriptEngineNashorn { + val engine = super.createScriptEngineForTest() engine.overrideAsserter() @@ -154,22 +152,61 @@ object NashornJsTestChecker : AbstractNashornJsTestChecker() { } class NashornIrJsTestChecker : AbstractNashornJsTestChecker() { - override fun createScriptEngineForTest(): ScriptEngine { - val engine = createScriptEngine() + override val preloadedScripts = listOf( + BasicBoxTest.TEST_DATA_DIR_PATH + "nashorn-polyfills.js", + "libraries/stdlib/js/src/js/polyfills.js" + ) +} - listOfNotNull( - BasicBoxTest.TEST_DATA_DIR_PATH + "nashorn-polyfills.js", - "libraries/stdlib/js/src/js/polyfills.js" - ).forEach(engine::loadFile) +abstract class AbstractV8JsTestChecker : AbstractJsTestChecker() { + protected abstract val engine: ScriptEngineV8 - return engine + override fun checkStdout(files: List, expectedResult: String) { + run(files) { + val actualResult = engine.eval(GET_KOTLIN_OUTPUT) + Assert.assertEquals(expectedResult, actualResult) + } } } -object V8IrJsTestChecker : AbstractJsTestChecker() { +object V8JsTestChecker : AbstractV8JsTestChecker() { + override val engine get() = tlsEngine.get() + + private val tlsEngine = object : ThreadLocal() { + override fun initialValue() = createV8Engine() + override fun remove() { + get().release() + } + } + + private fun createV8Engine(): ScriptEngineV8 { + val v8 = ScriptEngineV8() + + listOf( + BasicBoxTest.DIST_DIR_JS_PATH + "kotlin.js", + BasicBoxTest.DIST_DIR_JS_PATH + "kotlin-test.js" + ).forEach { v8.loadFile(it) } + + v8.overrideAsserter() + + return v8 + } + + override fun run(files: List, f: ScriptEngine.() -> Any?): Any? { + engine.evalVoid(SETUP_KOTLIN_OUTPUT) + return engine.runAndRestoreContext { + files.forEach { loadFile(it) } + f() + } + } +} + +object V8IrJsTestChecker : AbstractV8JsTestChecker() { + override val engine get() = ScriptEngineV8() + override fun run(files: List, f: ScriptEngine.() -> Any?): Any? { - val v8 = ScriptEngineV8() + val v8 = engine val v = try { files.forEach { v8.loadFile(it) } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/interop/GlobalRuntimeContext.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/interop/GlobalRuntimeContext.kt deleted file mode 100644 index 61da2ce353f..00000000000 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/interop/GlobalRuntimeContext.kt +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.js.test.interop - -typealias GlobalRuntimeContext = MutableMap \ No newline at end of file diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/interop/ScriptEngine.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/interop/ScriptEngine.kt index a40b535b6ea..8828f2e4b2c 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/interop/ScriptEngine.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/interop/ScriptEngine.kt @@ -7,10 +7,12 @@ package org.jetbrains.kotlin.js.test.interop interface ScriptEngine { fun eval(script: String): T - fun getGlobalContext(): GlobalRuntimeContext fun evalVoid(script: String) fun callMethod(obj: Any, name: String, vararg args: Any?): T fun loadFile(path: String) fun release() fun releaseObject(t: T) + + fun saveState() + fun restoreState() } \ No newline at end of file diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/interop/ScriptEngineNashorn.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/interop/ScriptEngineNashorn.kt index d8a234138d9..c90c0692bae 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/interop/ScriptEngineNashorn.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/interop/ScriptEngineNashorn.kt @@ -6,9 +6,12 @@ package org.jetbrains.kotlin.js.test.interop import jdk.nashorn.api.scripting.NashornScriptEngineFactory +import jdk.nashorn.internal.runtime.ScriptRuntime import javax.script.Invocable class ScriptEngineNashorn : ScriptEngine { + private var savedState: Map? = null + // TODO use "-strict" private val myEngine = NashornScriptEngineFactory().getScriptEngine("--language=es5", "--no-java", "--no-syntax-extensions") @@ -21,10 +24,6 @@ class ScriptEngineNashorn : ScriptEngine { myEngine.eval(script) } - override fun getGlobalContext(): GlobalRuntimeContext { - return eval("this") - } - @Suppress("UNCHECKED_CAST") override fun callMethod(obj: Any, name: String, vararg args: Any?): T { return (myEngine as Invocable).invokeMethod(obj, name, *args) as T @@ -36,4 +35,19 @@ class ScriptEngineNashorn : ScriptEngine { override fun release() {} override fun releaseObject(t: T) {} + + + private fun getGlobalState(): MutableMap = eval("this") + + override fun saveState() { + savedState = getGlobalState().toMap() + } + + override fun restoreState() { + val globalState = getGlobalState() + val originalState = savedState!! + for (key in globalState.keys) { + globalState[key] = originalState[key] ?: ScriptRuntime.UNDEFINED + } + } } \ No newline at end of file diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/interop/ScriptEngineV8.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/interop/ScriptEngineV8.kt index f933497dd88..22297dbc830 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/interop/ScriptEngineV8.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/interop/ScriptEngineV8.kt @@ -22,10 +22,32 @@ class ScriptEngineV8 : ScriptEngine { (t as? V8Object)?.release() } - override fun getGlobalContext(): GlobalRuntimeContext { - val v8result = eval("this") - val context = V8ObjectUtils.toMap(v8result) as GlobalRuntimeContext - return context.also { v8result.release() } + private var savedState: List? = null + + override fun restoreState() { + val scriptBuilder = StringBuilder() + + val globalState = getGlobalPropertyNames() + val originalState = savedState!! + for (key in globalState) { + if (key !in originalState) { + scriptBuilder.append("this['$key'] = void 0;\n") + } + } + evalVoid(scriptBuilder.toString()) + } + + private fun getGlobalPropertyNames(): List { + val v8Array = eval("Object.getOwnPropertyNames(this)") + val javaArray = V8ObjectUtils.toList(v8Array) as List + v8Array.release() + return javaArray + } + + override fun saveState() { + if (savedState == null) { + savedState = getGlobalPropertyNames() + } } private val myRuntime: V8 = V8.createV8Runtime("global", LIBRARY_PATH_BASE) @@ -58,4 +80,24 @@ class ScriptEngineV8 : ScriptEngine { override fun release() { myRuntime.release() } +} + +class ScriptEngineV8Lazy : ScriptEngine { + override fun eval(script: String) = engine.eval(script) + + override fun saveState() = engine.saveState() + + override fun evalVoid(script: String) = engine.evalVoid(script) + + override fun callMethod(obj: Any, name: String, vararg args: Any?) = engine.callMethod(obj, name, args) + + override fun loadFile(path: String) = engine.loadFile(path) + + override fun release() = engine.release() + + override fun releaseObject(t: T) = engine.releaseObject(t) + + override fun restoreState() = engine.restoreState() + + private val engine by lazy { ScriptEngineV8() } } \ No newline at end of file diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/AbstractWebDemoExamplesTest.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/AbstractWebDemoExamplesTest.kt index 7b8bc0b6258..f3eec91a437 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/AbstractWebDemoExamplesTest.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/AbstractWebDemoExamplesTest.kt @@ -5,12 +5,11 @@ package org.jetbrains.kotlin.js.test.semantics +import com.eclipsesource.v8.V8ScriptException import com.google.common.collect.Lists import com.intellij.openapi.util.text.StringUtil import org.jetbrains.kotlin.js.facade.MainCallParameters -import org.jetbrains.kotlin.js.test.BasicBoxTest -import org.jetbrains.kotlin.js.test.JsIrTestRuntime -import org.jetbrains.kotlin.js.test.NashornJsTestChecker +import org.jetbrains.kotlin.js.test.* import java.io.File import javax.script.ScriptException @@ -28,10 +27,10 @@ abstract class AbstractWebDemoExamplesTest(relativePath: String) : BasicBoxTest( withModuleSystem: Boolean, runtime: JsIrTestRuntime ) { - NashornJsTestChecker.checkStdout(jsFiles, expectedResult) + testChecker.checkStdout(jsFiles, expectedResult) } - @Throws(ScriptException::class) + @Throws(ScriptException::class, V8ScriptException::class) protected fun runMainAndCheckOutput(fileName: String, expectedResult: String, vararg args: String) { doTest(pathToTestDir + fileName, expectedResult, MainCallParameters.mainWithArguments(Lists.newArrayList(*args))) } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/MultiModuleOrderTest.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/MultiModuleOrderTest.kt index d1af3346bfc..6cdcb0ff9af 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/MultiModuleOrderTest.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/MultiModuleOrderTest.kt @@ -16,8 +16,8 @@ package org.jetbrains.kotlin.js.test.semantics +import com.eclipsesource.v8.V8ScriptException import org.jetbrains.kotlin.js.test.BasicBoxTest -import org.jetbrains.kotlin.js.test.NashornJsTestChecker import java.io.File import javax.script.ScriptException @@ -44,9 +44,10 @@ class MultiModuleOrderTest : BasicBoxTest(pathToTestGroupDir, testGroupDir) { val mainJsFile = File(parentDir, "$name-main_v5.js").path val libJsFile = File(parentDir, "$name-lib_v5.js").path try { - NashornJsTestChecker.run(listOf(mainJsFile, libJsFile)) + testChecker.run(listOf(mainJsFile, libJsFile)) } - catch (e: ScriptException) { + catch (e: RuntimeException) { + assertTrue(e is ScriptException || e is V8ScriptException) val message = e.message!! assertTrue("Exception message should contain reference to dependency (lib)", "'lib'" in message) assertTrue("Exception message should contain reference to module that failed to load (main)", "'main'" in message) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/WebDemoCanvasExamplesTest.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/WebDemoCanvasExamplesTest.java index 0f1b26652a8..7ab7b229db8 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/WebDemoCanvasExamplesTest.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/WebDemoCanvasExamplesTest.java @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.js.test.semantics; +import com.eclipsesource.v8.V8ScriptException; import org.jetbrains.annotations.NotNull; import javax.script.ScriptException; @@ -52,11 +53,18 @@ public final class WebDemoCanvasExamplesTest extends AbstractWebDemoExamplesTest fail(); } catch (ScriptException e) { - String expectedErrorMessage = "ReferenceError: \"" + firstUnknownSymbolEncountered + "\" is not defined"; - assertTrue("Unexpected error when running compiled canvas examples with rhino.\n" + - "Expected: " + expectedErrorMessage + "\n" + - "Actual: " + e.getMessage(), - e.getMessage().startsWith(expectedErrorMessage)); + verifyException("\"" + firstUnknownSymbolEncountered + "\"", e.getMessage()); + } + catch (V8ScriptException e) { + verifyException(firstUnknownSymbolEncountered, e.getJSMessage()); } } + + private static void verifyException(@NotNull String firstUnknownSymbolEncountered, @NotNull String message) { + String expectedErrorMessage = "ReferenceError: " + firstUnknownSymbolEncountered + " is not defined"; + assertTrue("Unexpected error when running compiled canvas examples with rhino.\n" + + "Expected: " + expectedErrorMessage + "\n" + + "Actual: " + message, + message.startsWith(expectedErrorMessage)); + } }