Liu Song’s Projects


~/Projects/chrome-devtools

git clone https://code.lsong.org/chrome-devtools

Commit

Commit
e6d48cbf2e1185dee82a5af78fab5c6fe69b01fd
Author
surunzi <[email protected]>
Date
2020-05-04 10:53:18 +0800 +0800
Diffstat
 target/domains/Runtime.ts | 13 ++++++++++++-

feat: Runtime.callFunctionOn support arguments


diff --git a/target/domains/Runtime.ts b/target/domains/Runtime.ts
index 9a4020eaf528d2b6c88f57c647a8c9908aa4678e..5ffce70e222e1b81a5c12b02d207d9c9e2b08019 100644
--- a/target/domains/Runtime.ts
+++ b/target/domains/Runtime.ts
@@ -4,6 +4,7 @@ import map from 'licia/map';
 import now from 'licia/now';
 import fnParams from 'licia/fnParams';
 import startWith from 'licia/startWith';
+import isObj from 'licia/isObj';
 import * as stringifyObj from '../lib/stringifyObj';
 import evaluateJs, { setGlobal } from '../lib/evaluate';
 
@@ -15,6 +16,16 @@ };
 
 export async function callFunctionOn(params: any) {
   const { functionDeclaration, objectId } = params;
+  let args = params.arguments;
+
+  args = map(args, (arg: any) => {
+    if (isObj(arg) && arg.objectId) {
+      const obj = stringifyObj.getObj(arg.objectId);
+      if (obj) return obj;
+    }
+
+    return arg;
+  });
 
   let ctx = null;
   if (objectId) {
@@ -22,7 +33,7 @@     ctx = stringifyObj.getObj(objectId);
   }
 
   return {
-    result: stringifyObj.wrap(await callFn(functionDeclaration, [], ctx)),
+    result: stringifyObj.wrap(await callFn(functionDeclaration, args, ctx)),
   };
 }