diff --git a/docs/js-api/pyodide_pyimport.md b/docs/js-api/pyodide_pyimport.md index aa45af5ad..21ea680fa 100644 --- a/docs/js-api/pyodide_pyimport.md +++ b/docs/js-api/pyodide_pyimport.md @@ -5,7 +5,7 @@ Access a Python object in the global namespace from Javascript. For example, to access the `foo` Python object from Javascript: ```javascript -var foo = pyodide.pyimport('foo') +let foo = pyodide.pyimport('foo'); ``` *Parameters* diff --git a/docs/type_conversions.md b/docs/type_conversions.md index a8e7fc26a..e0c570179 100644 --- a/docs/type_conversions.md +++ b/docs/type_conversions.md @@ -36,7 +36,7 @@ access arrays on the Javascript heap), and the data type is preserved. This makes it easy to correctly convert it to a Numpy array using `numpy.asarray`: ```javascript -array = Float32Array([1, 2, 3]) +let array = Float32Array([1, 2, 3]); ``` ```python @@ -112,7 +112,7 @@ Therefore, custom Python objects must be manually destroyed when passed to Javas they will leak. To do this, call `.destroy()` on the object, after which Javascript will no longer have access to the object. ```javascript -var foo = pyodide.pyimport('foo'); +let foo = pyodide.pyimport('foo'); foo.call_method(); foo.destroy(); foo.call_method(); // This will raise an exception, since the object has been @@ -127,7 +127,7 @@ giving the name of the variable, and returns the object, converted to Javascript. ```javascript -var sys = pyodide.pyimport('sys'); +let sys = pyodide.pyimport('sys'); ``` (type_conversions_using_js_obj_from_py)= ## Using Javascript objects from Python @@ -152,7 +152,7 @@ Python, you may want to store it in a Python variable or use the `from js import For example, given this large Javascript variable: ```javascript -var x = new Array(1000).fill(0) +let x = new Array(1000).fill(0); ``` Use it from Python as follows: diff --git a/docs/using_pyodide_from_webworker.md b/docs/using_pyodide_from_webworker.md index c8004b01b..93e5a9fd8 100644 --- a/docs/using_pyodide_from_webworker.md +++ b/docs/using_pyodide_from_webworker.md @@ -114,7 +114,7 @@ async function loadPythonPackages(){ pythonLoading = self.pyodide.loadPackage(['numpy', 'pytz']); } -var onmessage = async(event) => { +let onmessage = async(event) => { await languagePluginLoader; // since loading package is asynchronous, we need to make sure loading is done: await pythonLoading; diff --git a/src/pyodide.js b/src/pyodide.js index d802d45cc..4547b7f4a 100644 --- a/src/pyodide.js +++ b/src/pyodide.js @@ -2,11 +2,11 @@ * The main bootstrap script for loading pyodide. */ -var languagePluginLoader = new Promise((resolve, reject) => { +globalThis.languagePluginLoader = new Promise((resolve, reject) => { // Note: PYODIDE_BASE_URL is an environement variable replaced in // in this template in the Makefile. It's recommended to always set // languagePluginUrl in any case. - var baseURL = self.languagePluginUrl || '{{ PYODIDE_BASE_URL }}'; + let baseURL = self.languagePluginUrl || '{{ PYODIDE_BASE_URL }}'; baseURL = baseURL.substr(0, baseURL.lastIndexOf('/')) + '/'; //////////////////////////////////////////////////////////// @@ -316,7 +316,7 @@ var languagePluginLoader = new Promise((resolve, reject) => { ]; function makePublicAPI(module, public_api) { - var namespace = {_module : module}; + let namespace = {_module : module}; for (let name of public_api) { namespace[name] = module[name]; } diff --git a/src/templates/console.html b/src/templates/console.html index c85e916fa..32003a2df 100644 --- a/src/templates/console.html +++ b/src/templates/console.html @@ -19,7 +19,7 @@ handleResult(c.push(line)) } - var term = $('body').terminal( + let term = $('body').terminal( pushCode, { greetings: "Welcome to the Pyodide terminal emulator 🐍", @@ -40,20 +40,20 @@ _c = Console(locals=globals()) `) - var c = pyodide.pyimport('_c') + let c = pyodide.pyimport('_c'); function handleResult(result) { if (result) { - term.set_prompt('[[;gray;]... ]') + term.set_prompt('[[;gray;]... ]'); } else { - term.set_prompt('[[;red;]>>> ]') - var stderr = pyodide.runPython("sys.stderr.getvalue()").trim() + term.set_prompt('[[;red;]>>> ]'); + let stderr = pyodide.runPython("sys.stderr.getvalue()").trim(); if (stderr) { - term.echo(`[[;red;]${stderr}]`) + term.echo(`[[;red;]${stderr}]`); } else { - var stdout = pyodide.runPython("sys.stdout.getvalue()") + let stdout = pyodide.runPython("sys.stdout.getvalue()"); if (stdout) { - term.echo(stdout.trim()) + term.echo(stdout.trim()); } } } @@ -62,22 +62,22 @@ term.runPython = function(code) { pyodide.runPythonAsync(code).then( term.handlePythonResult, term.handlePythonError - ) - } + ); + }; term.handlePythonResult = function(result) { if (result === undefined) { - return + return; } else if (result['_repr_html_'] !== undefined) { - term.echo(result['_repr_html_'], {raw: true}) + term.echo(result['_repr_html_'], {raw: true}); } else { - term.echo(result.toString()) + term.echo(result.toString()); } - } + }; term.handlePythonError = function(result) { - term.error(result.toString()) - } + term.error(result.toString()); + }; }); diff --git a/src/tests/test_jsproxy.py b/src/tests/test_jsproxy.py index 484ca9ed7..1a0ae627b 100644 --- a/src/tests/test_jsproxy.py +++ b/src/tests/test_jsproxy.py @@ -143,7 +143,7 @@ def test_jsproxy_iter(selenium): selenium.run_js( """ function makeIterator(array) { - var nextIndex = 0; + let nextIndex = 0; return { next: function() { return nextIndex < array.length ? diff --git a/src/tests/test_python.py b/src/tests/test_python.py index 84f92304b..9713c818a 100644 --- a/src/tests/test_python.py +++ b/src/tests/test_python.py @@ -75,7 +75,7 @@ def test_load_package_after_convert_string(selenium): See #93. """ selenium.run("import sys\n" "x = sys.version") - selenium.run_js("var x = pyodide.pyimport('x')\n" "console.log(x)") + selenium.run_js("let x = pyodide.pyimport('x');\n" "console.log(x);") selenium.load_package("kiwisolver") selenium.run("import kiwisolver") diff --git a/src/tests/test_typeconversions.py b/src/tests/test_typeconversions.py index 0d09c651a..0aa22a01c 100644 --- a/src/tests/test_typeconversions.py +++ b/src/tests/test_typeconversions.py @@ -170,7 +170,7 @@ def test_typed_arrays(selenium, wasm_heap, jstype, pytype): else: selenium.run_js( f""" - var buffer = pyodide._module._malloc( + let buffer = pyodide._module._malloc( 4 * {jstype}.BYTES_PER_ELEMENT); window.array = new {jstype}( pyodide._module.HEAPU8.buffer, buffer, 4); @@ -210,7 +210,7 @@ def test_array_buffer(selenium): def assert_js_to_py_to_js(selenium, name): selenium.run_js(f"window.obj = {name};") selenium.run("from js import obj") - assert selenium.run_js("return pyodide.globals['obj'] === obj") + assert selenium.run_js("return pyodide.globals['obj'] === obj;") def assert_py_to_js_to_py(selenium, name): @@ -230,7 +230,7 @@ def test_recursive_list_to_js(selenium_standalone): x.append(x) """ ) - selenium_standalone.run_js("x = pyodide.pyimport('x')") + selenium_standalone.run_js("x = pyodide.pyimport('x');") def test_recursive_dict_to_js(selenium_standalone): @@ -240,7 +240,7 @@ def test_recursive_dict_to_js(selenium_standalone): x[0] = x """ ) - selenium_standalone.run_js("x = pyodide.pyimport('x')") + selenium_standalone.run_js("x = pyodide.pyimport('x');") def test_list_from_js(selenium): @@ -272,7 +272,7 @@ def test_jsproxy_attribute_error(selenium): this.y = y; } } - window.point = new Point(42, 43) + window.point = new Point(42, 43); """ ) selenium.run( @@ -309,7 +309,7 @@ def test_javascript_error(selenium): def test_javascript_error_back_to_js(selenium): selenium.run_js( """ - window.err = new Error("This is a js error") + window.err = new Error("This is a js error"); """ ) assert ( @@ -324,7 +324,7 @@ def test_javascript_error_back_to_js(selenium): ) assert selenium.run_js( """ - return pyodide.globals["py_err"] === err + return pyodide.globals["py_err"] === err; """ )