toValue is hungry
This commit is contained in:
parent
f4e24f427f
commit
bd1736b474
10
src/vm.ts
10
src/vm.ts
|
|
@ -253,7 +253,7 @@ export class VM {
|
|||
const value = this.scope.get(varName)
|
||||
|
||||
if (value === undefined)
|
||||
this.stack.push(toValue(varName))
|
||||
this.stack.push(toValue(varName, this))
|
||||
else
|
||||
this.stack.push(value)
|
||||
|
||||
|
|
@ -455,10 +455,10 @@ export class VM {
|
|||
const target = this.stack.pop()!
|
||||
|
||||
if (target.type === 'array')
|
||||
this.stack.push(toValue(target.value?.[Number(index.value)]))
|
||||
this.stack.push(toValue(target.value?.[Number(index.value)], this))
|
||||
|
||||
else if (target.type === 'dict')
|
||||
this.stack.push(toValue(target.value?.get(String(index.value))))
|
||||
this.stack.push(toValue(target.value?.get(String(index.value)), this))
|
||||
|
||||
else
|
||||
throw new Error(`DOT_GET: ${target.type} not supported`)
|
||||
|
|
@ -590,7 +590,7 @@ export class VM {
|
|||
}
|
||||
// Convert dict to plain JavaScript object for the native function
|
||||
const namedObj = fromValue({ type: 'dict', value: namedDict }, this)
|
||||
nativeArgs.push(toValue(namedObj))
|
||||
nativeArgs.push(toValue(namedObj, this))
|
||||
}
|
||||
|
||||
// Handle variadic parameter (TypeScript rest parameters)
|
||||
|
|
@ -834,6 +834,6 @@ export class VM {
|
|||
}
|
||||
|
||||
const result = await originalFn.call(this, ...args)
|
||||
return toValue(result)
|
||||
return toValue(result, this)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user