Skip to content

Commit

Permalink
[docs] translate api
Browse files Browse the repository at this point in the history
  • Loading branch information
Siubaak committed Sep 14, 2022
1 parent b369b4d commit d40f6cb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
30 changes: 20 additions & 10 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,34 @@ Debug scripts. Two arguments accepted, which are script code string `script` and

The `script` can be not only the source code, but also the transformed result generated by the `transform` method. And the `debuggerId` is the script url normally. If missing `debuggerId`, the debugging script will be treated as a temporary script, and a random `debuggerId` will be generated.

The `debug` method will return an execution function called `run`, for code real execution. Therefore, before `run` calls, you can use other APIs like `setBreakpoint` to modify breakpoints. If inputed arguments is invalid, or current environment does't support debug, The `debug` method will return `false`.
This method returns an execution function called `run`, for code real execution. Therefore, before `run` calls, you can use other APIs like `setBreakpoint` to modify breakpoints. If inputed arguments is invalid, or current environment does't support debug, this method returns `false`.

```ts
function debug(script: string, debuggerId?: string): (() => void) | false
```

## `transform`

转换需要调试的脚本。接受两个参数,分别是脚本字符串 `script` 和调试ID `debuggerId`,其中调试ID通常为脚本的URL。调试ID可选,不传时会当作临时脚本,分配随机的调试ID。该接口会返回转换结果,用于运行时传入 `debug` 接口进行调试。当传入参数不合法或者当前环境不支持断点调试的时候,该接口会返回 `false`
Transform scripts. Two arguments accepted, which are script code string `script` and script debug id `debuggerId`, respectively.

The `debuggerId` is the script url normally. If missing `debuggerId`, the debugging script will be treated as a temporary script, and a random `debuggerId` will be generated.

This method returns a code transformed result, which can be passed to the `debug` method for debugging scripts at runtime. If inputed arguments is invalid, this method returns `false`.

```ts
function transform(script: string, debuggerId?: string): string | false
```

## `resume`

当命中断点暂停时,使用该接口恢复执行。接受一个可选的单步调试参数,可选值为 `stepInto``stepOver` `stepOut`
Resume execution when paused by hitting breakpoints. One optional argument accepted, which can be `stepInto`, `stepOver` or `stepOut`:

1. 不传时默认直接继续执行;
2. `stepInto` 时遇到子函数就进入并且继续单步执行;
3. `stepOver` 时遇到子函数时不会进入子函数内单步执行;
4. `stepOut` 时执行完当前函数剩余部分,并返回到上一层函数;
1. continue executing by default if missing
2. step into child process if passing `stepInto`
3. step over child process if passing `stepOver`
4. step out to parent process if passing `stepOut`

该接口返回的布尔值用于标记是否恢复成功。
This method returns a boolean to inform whether resume succeeds.

```ts
function resume(type?: ResumeType): boolean
Expand All @@ -41,15 +45,21 @@ type ResumeType = 'stepInto' | 'stepOver' | 'stepOut'

## `evaluate`

在特定作用域环境中执行脚本。接受两个参数,分别是脚本字符串 `script` 和调用栈ID `callFrameId`,其中调用栈ID可选,可通过 `getPausedInfo` 接口或 `paused` 事件的断点相关信息中作用域链 `scopeChain` 获取得到。如果传了调用栈ID,将会在对应调用栈的作用域中执行脚本;如果没传,默认在顶层全局作用域中执行脚本。
Evaluate expressions in the specific scope. Two arguments accepted, which are expression code string `expression` and call frame id `callFrameId`, respectively.

The `callFrameId` is optional, which can be achieved from the `scopeChain` of paused info, by `getPausedInfo` method or `paused` event. If `callFrameId` inputed, the `expression` will be evaluated in the corresponding scope. Or, if `callFrameId` missed, the `expression` will be evaluated in the global scope.

```ts
function evaluate<Result = unknown>(expression: string, callFrameId?: number): Result | false
```

## `setBreakpoint`

设置断点。接受三个参数,分别是调试ID `debuggerId`、行号 `lineNumber` 和可选条件 `condition`。其中可选条件为一段脚本,当该脚本返回为 `true` 时会中断执行,如果没有条件,则默认到该脚本对应行时都中断执行。如果设置成功,该接口会返回断点信息,包括断点ID `id` 和实际行号 `lineNumber`;如果设置不成功,则返回 `false`
Set breakpoints. Three arguments accepted, which are script debug id `debuggerId`, line number `lineNumber` and optional break condition `condition`.

The `condition` is an expression string, and execution will be paused if the evaluation returns `true`. If `condition` missed, execution will be paused when hitting the corresponding line defined by `lineNumber`, by default.

If set succeeds, this method returns the breakpoint info, including breakpoint id `id` and exact break line number `lineNumber`. Or, if set fails, this method returns `false`.

```ts
function setBreakpoint(debuggerId: string, lineNumber: number, condition?: string): Breakpoint | false
Expand Down
16 changes: 13 additions & 3 deletions docs/API_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ function debug(script: string, debuggerId?: string): (() => void) | false

## `transform`

转换需要调试的脚本。接受两个参数,分别是脚本字符串 `script` 和调试ID `debuggerId`,其中调试ID通常为脚本的URL。调试ID可选,不传时会当作临时脚本,分配随机的调试ID。该接口会返回转换结果,用于运行时传入 `debug` 接口进行调试。当传入参数不合法或者当前环境不支持断点调试的时候,该接口会返回 `false`
转换需要调试的脚本。接受两个参数,分别是脚本字符串 `script` 和调试ID `debuggerId`

其中,调试ID通常为脚本的URL。调试ID可选,不传时会当作临时脚本,分配随机的调试ID

该接口会返回转换结果,用于运行时传入 `debug` 接口进行调试。当传入参数不合法的时候,该接口会返回 `false`

```ts
function transform(script: string, debuggerId?: string): string | false
Expand All @@ -41,15 +45,21 @@ type ResumeType = 'stepInto' | 'stepOver' | 'stepOut'

## `evaluate`

在特定作用域环境中执行脚本。接受两个参数,分别是脚本字符串 `script` 和调用栈ID `callFrameId`,其中调用栈ID可选,可通过 `getPausedInfo` 接口或 `paused` 事件的断点相关信息中作用域链 `scopeChain` 获取得到。如果传了调用栈ID,将会在对应调用栈的作用域中执行脚本;如果没传,默认在顶层全局作用域中执行脚本。
在特定作用域环境中执行表达式。接受两个参数,分别是表达式字符串 `expression` 和调用栈ID `callFrameId`

其中,调用栈ID可选,可通过 `getPausedInfo` 接口或 `paused` 事件的断点相关信息中作用域链 `scopeChain` 获取得到。如果传了调用栈ID,将会在对应调用栈的作用域中执行表达式;如果没传,默认在顶层全局作用域中执行表达式。

```ts
function evaluate<Result = unknown>(expression: string, callFrameId?: number): Result | false
```

## `setBreakpoint`

设置断点。接受三个参数,分别是调试ID `debuggerId`、行号 `lineNumber` 和可选条件 `condition`。其中可选条件为一段脚本,当该脚本返回为 `true` 时会中断执行,如果没有条件,则默认到该脚本对应行时都中断执行。如果设置成功,该接口会返回断点信息,包括断点ID `id` 和实际行号 `lineNumber`;如果设置不成功,则返回 `false`
设置断点。接受三个参数,分别是调试ID `debuggerId`、行号 `lineNumber` 和可选条件 `condition`

其中,可选条件为一段脚本,当该脚本返回为 `true` 时会中断执行,如果没有条件,则默认到该脚本对应行时都中断执行。

如果设置成功,该接口会返回断点信息,包括断点ID `id` 和实际行号 `lineNumber`;如果设置不成功,则返回 `false`

```ts
function setBreakpoint(debuggerId: string, lineNumber: number, condition?: string): Breakpoint | false
Expand Down

0 comments on commit d40f6cb

Please sign in to comment.