Skip to content

Commit ae8993b

Browse files
committed
Added function name to the error message
1 parent 3fb2995 commit ae8993b

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

package.json

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

src/evaluator/evaluator.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ export class Evaluator {
230230
if (node.type === "funcCall") {
231231
const funcCallNode = node as FunctionCallNode;
232232
const func = blockContext.blockScope.get(funcCallNode.name) as (...args: unknown[]) => unknown;
233+
if(typeof func !== 'function') {
234+
throw Error(`'${funcCallNode.name}' is not a function or not defined.`)
235+
}
236+
233237
const pms = funcCallNode.paramNodes?.map(n => this.evalNode(n, blockContext)) || []
234238

235239
return this.invokeFunction(func, pms);
@@ -296,6 +300,10 @@ export class Evaluator {
296300
const funcCallNode = nestedProp as FunctionCallNode;
297301
const func = startObject[funcCallNode.name] as (...args: unknown[]) => unknown;
298302

303+
if(typeof func !== 'function') {
304+
throw Error(`'${funcCallNode.name}' is not a function or not defined.`)
305+
}
306+
299307
if (func === undefined
300308
&& (dotObject.nestedProps[i - 1] as unknown as IsNullCoelsing).nullCoelsing) {
301309
continue;

src/evaluator/evaluatorAsync.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,12 @@ export class EvaluatorAsync {
237237
if (node.type === "funcCall") {
238238
const funcCallNode = node as FunctionCallNode;
239239
const func = blockContext.blockScope.get(funcCallNode.name) as (...args: unknown[]) => unknown;
240-
const pms = []
240+
241+
if(typeof func !== 'function') {
242+
throw Error(`'${funcCallNode.name}' is not a function or not defined.`)
243+
}
244+
245+
const pms = [];
241246
for (let p of funcCallNode.paramNodes || []) {
242247
pms.push(await this.evalNodeAsync(p, blockContext));
243248
}
@@ -311,6 +316,9 @@ export class EvaluatorAsync {
311316
continue;
312317
}
313318

319+
if(typeof(func) !== 'function'){
320+
throw Error(`'${funcCallNode.name}' is not a function or not defined.`)
321+
}
314322
const pms = []
315323
for (let p of funcCallNode.paramNodes || []) {
316324
pms.push(await this.evalNodeAsync(p, blockContext));

src/initialScope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { parseDatetimeOrNull } from "./common/utils";
22

33
export const INITIAL_SCOPE = {
44
jsPython(): string {
5-
return [`JSPython v2.0.4`, "(c) FalconSoft Ltd"].join('\n')
5+
return [`JSPython v2.0.7`, "(c) FalconSoft Ltd"].join('\n')
66
},
77
dateTime: (str: number | string | any = null) => (str && str.length)
88
? parseDatetimeOrNull(str) || new Date() : new Date(),

0 commit comments

Comments
 (0)