Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5dccf62

Browse filesBrowse files
committed
fixed issue with square brakets object access
1 parent 4f97e34 commit 5dccf62
Copy full SHA for 5dccf62

File tree

Expand file treeCollapse file tree

4 files changed

+23
-4
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+23
-4
lines changed

‎index.html

Copy file name to clipboardExpand all lines: index.html
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
<div class="container">
2929
<h4>JSPython development console</h4>
3030
<div id="editor">
31-
"".trim().length
31+
x = {}
32+
x["prop1"]
3233
</div>
3334
<button onclick="runInterpreter()">Run</button>
3435
<textarea id="result"></textarea>

‎package.json

Copy file name to clipboardExpand all lines: package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jspython-interpreter",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"description": "JSPython is a javascript implementation of Python language that runs within web browser or NodeJS environment",
55
"keywords": [
66
"python",

‎src/eval/eval.expression.ts

Copy file name to clipboardExpand all lines: src/eval/eval.expression.ts
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,10 @@ export class EvalExpression {
266266
} else {
267267
const tokens = this.splitParameterToken(ind);
268268
const pName = this.evalExpression(context, tokens)
269-
return obj[pName];
269+
270+
// if it is undefined means does not exists. So, we have to return null, but still gracely handle 0 (zero)
271+
const v = obj[pName]
272+
return v !== undefined? v : null;
270273
}
271274

272275
}
@@ -279,7 +282,7 @@ export class EvalExpression {
279282
} else {
280283
const value = getValue(context.blockScope, token);
281284
if (value === undefined) {
282-
throw Error(`Can't resolve property '${token}' of undefined object`);
285+
throw Error(`Unknown symbol '${token}'`);
283286
}
284287
return value;
285288
}

‎src/interpreter.spec.ts

Copy file name to clipboardExpand all lines: src/interpreter.spec.ts
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,21 @@ describe('Interpreter', () => {
14821482

14831483
})
14841484

1485+
it('should return NULL gracely', async () => {
1486+
expect(await e.evaluate(`
1487+
x = {}
1488+
x["prop1"]`)).toBe(null);
1489+
1490+
// has to be 0
1491+
expect(await e.evaluate(`
1492+
x = {prop1: 0}
1493+
x["prop1"]`)).toBe(0);
1494+
1495+
expect(await e.evaluate(`
1496+
x = {prop1: null}
1497+
x["prop1"]`)).toBe(null);
1498+
});
1499+
14851500
it('subset of dynamic', async () => {
14861501
expect(await e.evaluate(`
14871502
issue = {}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.