feat(codemode): support JSON callbacks (#38006)
This commit is contained in:
parent
39fdd67123
commit
065b108bba
9 changed files with 431 additions and 61 deletions
|
|
@ -8,6 +8,7 @@ import {
|
|||
GlobalNamespace,
|
||||
IntrinsicReference,
|
||||
InterpreterRuntimeError,
|
||||
JsonMethodReference,
|
||||
PromiseCapabilityFunction,
|
||||
PromiseNamespace,
|
||||
UriFunction,
|
||||
|
|
@ -25,7 +26,6 @@ import {
|
|||
isCodeModeValue,
|
||||
} from "../values.js"
|
||||
import { dateSetterArgumentCount, invokeDateMethod, invokeDateStatic } from "../stdlib/date.js"
|
||||
import { invokeJsonMethod } from "../stdlib/json.js"
|
||||
import { invokeMathMethod } from "../stdlib/math.js"
|
||||
import { invokeNumberMethod, invokeNumberStatic } from "../stdlib/number.js"
|
||||
import { invokeObjectMethod } from "../stdlib/object.js"
|
||||
|
|
@ -54,6 +54,7 @@ export type SupportedCallback =
|
|||
| UriFunction
|
||||
| PromiseCapabilityFunction
|
||||
| GlobalMethodReference
|
||||
| JsonMethodReference
|
||||
| IntrinsicReference
|
||||
| ErrorConstructorReference
|
||||
| GlobalNamespace
|
||||
|
|
@ -65,6 +66,7 @@ export const isSupportedCallback = (value: unknown): value is SupportedCallback
|
|||
value instanceof UriFunction ||
|
||||
value instanceof PromiseCapabilityFunction ||
|
||||
value instanceof GlobalMethodReference ||
|
||||
value instanceof JsonMethodReference ||
|
||||
value instanceof IntrinsicReference ||
|
||||
value instanceof ErrorConstructorReference ||
|
||||
// Callable namespaces dispatch like JS: Array/Object/Date/RegExp construct,
|
||||
|
|
@ -168,7 +170,7 @@ export const invokeGlobalMethod = (ref: GlobalMethodReference, args: Array<unkno
|
|||
if (ref.namespace === "Map" || ref.namespace === "Set" || ref.namespace === "URLSearchParams") {
|
||||
throw new InterpreterRuntimeError(`${ref.namespace}.${ref.name} is not available in CodeMode.`, node)
|
||||
}
|
||||
return invokeJsonMethod(ref.name, args, node)
|
||||
throw new InterpreterRuntimeError(`${ref.namespace}.${ref.name} is not available in CodeMode.`, node)
|
||||
}
|
||||
|
||||
const requireDataArgument = (name: string, index: number, arg: unknown, node: AstNode): unknown => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue