klipse icon indicating copy to clipboard operation
klipse copied to clipboard

JavaScript evaluation: x is not a function, a.split is not a function in klipse_plugin.min.js

Open lechten opened this issue 5 years ago • 9 comments

When using klipse_plugin.min.js instead of klipse_plugin.js, the console shows the following two errors with Firefox (62.0 and 60.1.0esr on GNU/Linux):

  • TypeError: x is not a function[Learn More] klipse_plugin.min.js:1799:43
  • TypeError: a.split is not a function[Learn More] klipse_plugin.min.js:306:123

Minimal example:

<!DOCTYPE html>
<html>
    <head>
	<meta charset="utf-8"/>
	<link rel= "stylesheet" type= "text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">
	<script>
	 window.klipse_settings = { selector_eval_js: ".klipse" };
	</script>
    </head>
    <body>
	<pre><code class="klipse" >
var x = "Hello World!";
x
	</code></pre>
	<!-- <script src="https://storage.googleapis.com/app.klipse.tech/plugin/js/klipse_plugin.js"></script> -->
	<script src="https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"></script>
    </body>
</html>

The output "Hello World!" appears, but further edits do not have effects.

lechten avatar Jan 06 '19 16:01 lechten

The root cause of this is described in #330.

Specifically, the minified klipse_plugin.min.js exposes its global variables (including functions) to the window object. In the snippet var x refers to the global window.x. So, window.x is overwritten to become the "Hello World!" string instead of the (apparently) function that Klipse expects it to be. To fix this, the minified Klipse bundle should be built so that it properly scopes its globals and does not expose them via the window object.

polytypic avatar Jan 07 '19 05:01 polytypic

I want to contribute

codeR49 avatar Dec 13 '20 15:12 codeR49

@codeR49 Please do!

viebel avatar Dec 17 '20 18:12 viebel


let x = "Hello World!";
x
	

Screenshot from 2021-01-31 20:37:52

irynadunets avatar Jan 31 '21 18:01 irynadunets

@irynadunets started working on this issue via WorksHub.

workshub[bot] avatar Jan 31 '21 19:01 workshub[bot]

@Jacsonrai started working on this issue via WorksHub.

workshub[bot] avatar Feb 05 '21 14:02 workshub[bot]

@murtaza63 started working on this issue via WorksHub.

workshub[bot] avatar Feb 23 '21 06:02 workshub[bot]

@nbittich started working on this issue via WorksHub.

workshub[bot] avatar Nov 10 '21 12:11 workshub[bot]

@curest0x1021 started working on this issue via WorksHub.

workshub[bot] avatar Jul 14 '22 03:07 workshub[bot]