toValue is hungry

This commit is contained in:
Chris Wanstrath 2025-11-05 15:20:55 -08:00
parent f4e24f427f
commit bd1736b474

View File

@ -253,7 +253,7 @@ export class VM {
const value = this.scope.get(varName) const value = this.scope.get(varName)
if (value === undefined) if (value === undefined)
this.stack.push(toValue(varName)) this.stack.push(toValue(varName, this))
else else
this.stack.push(value) this.stack.push(value)
@ -455,10 +455,10 @@ export class VM {
const target = this.stack.pop()! const target = this.stack.pop()!
if (target.type === 'array') 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') 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 else
throw new Error(`DOT_GET: ${target.type} not supported`) 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 // Convert dict to plain JavaScript object for the native function
const namedObj = fromValue({ type: 'dict', value: namedDict }, this) const namedObj = fromValue({ type: 'dict', value: namedDict }, this)
nativeArgs.push(toValue(namedObj)) nativeArgs.push(toValue(namedObj, this))
} }
// Handle variadic parameter (TypeScript rest parameters) // Handle variadic parameter (TypeScript rest parameters)
@ -834,6 +834,6 @@ export class VM {
} }
const result = await originalFn.call(this, ...args) const result = await originalFn.call(this, ...args)
return toValue(result) return toValue(result, this)
} }
} }