dolphindb 3.0.115 → 3.0.118

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/browser.d.ts CHANGED
@@ -594,6 +594,7 @@ export interface DdbEvalOptions {
594
594
  urgent?: boolean;
595
595
  listener?: DdbMessageListener;
596
596
  parse_object?: boolean;
597
+ iife?: boolean;
597
598
  }
598
599
  export interface DdbExecuteOptions extends DdbEvalOptions, ConvertOptions {
599
600
  }
@@ -783,8 +784,9 @@ export declare class DDB {
783
784
  不做解析,以便后续转发、序列化
784
785
  Set parse_object during this rpc, and restore the original after the end.
785
786
  When it is false, the returned DdbObj only contains buffer and le without parsing,
786
- so as to facilitate subsequent forwarding and serialization */
787
- eval<T extends DdbObj>(script: string, { urgent, listener, parse_object, }?: DdbEvalOptions): Promise<T>;
787
+ so as to facilitate subsequent forwarding and serialization
788
+ - iife?: 使用 `def () { ... } ()` 包裹脚本,return 最后一行,避免变量泄漏 */
789
+ eval<T extends DdbObj>(script: string, { urgent, listener, parse_object, iife, }?: DdbEvalOptions): Promise<T>;
788
790
  /** call function through websocket (function command)
789
791
  - func: 函数名 function name
790
792
  - args?: `[ ]` 调用参数 (传入的原生 string 和 boolean 会被自动转换为 DdbObj<string> 和 DdbObj<boolean>)
package/browser.js CHANGED
@@ -3104,8 +3104,19 @@ export class DDB {
3104
3104
  不做解析,以便后续转发、序列化
3105
3105
  Set parse_object during this rpc, and restore the original after the end.
3106
3106
  When it is false, the returned DdbObj only contains buffer and le without parsing,
3107
- so as to facilitate subsequent forwarding and serialization */
3108
- async eval(script, { urgent, listener, parse_object, } = {}) {
3107
+ so as to facilitate subsequent forwarding and serialization
3108
+ - iife?: 使用 `def () { ... } ()` 包裹脚本,return 最后一行,避免变量泄漏 */
3109
+ async eval(script, { urgent, listener, parse_object, iife, } = {}) {
3110
+ if (iife) {
3111
+ const lines = script.split_lines();
3112
+ if (lines.length < 2)
3113
+ throw new Error(t('iife 执行的脚本行数应该至少为 2 行'));
3114
+ script =
3115
+ 'def () {\n' +
3116
+ lines.slice(0, -1).indent().join_lines() +
3117
+ ` return ${lines.last}\n`;
3118
+ '} ()\n';
3119
+ }
3109
3120
  return this.rpc('script', { script, urgent, listener, parse_object });
3110
3121
  }
3111
3122
  /** call function through websocket (function command)