MAINT Replace var ==> let and added semicolons (#979)

This commit is contained in:
Hood Chatham 2021-01-13 13:20:39 -08:00 committed by GitHub
parent 170c52d6ea
commit 40bd09348b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 34 additions and 34 deletions

View File

@ -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*

View File

@ -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:

View File

@ -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;

View File

@ -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];
}

View File

@ -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());
};
});
</script>
</body>

View File

@ -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 ?

View File

@ -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")

View File

@ -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;
"""
)