Skip to content

Commit 78f26f1

Browse files
dagedudavid-risney
andauthored
Apply suggestions from code review
Co-authored-by: David Risney <dave@deletethis.net>
1 parent 07f19c5 commit 78f26f1

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

specs/ExecuteScriptWithResult.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# Background
2-
Since the current ExecuteStrip interface is a little shabby, it is necessary
3-
to provide a new interface to let the user get more infomation, and easier to use.
4-
The new interface will provide the exception infomation if the script execute
5-
failed, and provide a new method to try to get the string to resolve the problem
6-
that the old interface is not friendly to the string return type.
2+
Our end developers have pointed out gaps in the existing CoreWebView2.ExecuteScript method, and it is necessary
3+
to provide a new method to let our end developers get more information in a more convenient manner.
4+
The new ExecuteScriptWithResult method will provide exception information if the executed script
5+
failed, and provides a new method to try to get the script execution result as a string rather than as JSON
6+
in order to make it more convenient to interact with string results.
77

88
In this document we describe the updated API. We'd appreciate your feedback.
99

1010
# Description
1111
We propose extending `CoreWebView2` to provide an `ExecuteScriptWithResult`
12-
method. The method will return a struct to manage the execute result, which can
13-
get the raw result and string if execute success, and can get exception when
14-
execute failed.
12+
method. The method acts like ExecuteScript, but returns a CoreWebView2ExecuteScriptResult object that can be used to
13+
get the script execution result as a JSON string or as a string value if execution succeeds, and can be used to get the exception when
14+
execution failed.
1515

1616
# Examples
1717
The following code snippets demonstrate how the ExecuteScriptWithResult can be used:
@@ -161,12 +161,16 @@ void ExecuteScriptWithResultAsync(String script)
161161
# API Details
162162
## Win32 C++
163163
```c++
164-
/// This is the exception struct when ExecuteScriptWithResult return false, user can
164+
/// This interface represents a JavaScript exception. If the CoreWebView2.ExecuteScriptWithResult result has IsSuccessful as false, you can use the result's Exception property to get the script exception.
165165
/// use get_Exception to get it.
166166
[uuid(82F22B72-1B22-403E-A0B9-A8816C9C8E45), object, pointer_default(unique)]
167167
interface ICoreWebView2ExecuteScriptException : IUnknown {
168+
/// The line number of the source where the exception occurred.
169+
[propget] HRESULT LineNumber([out, retval] UINT* value);
170+
/// The column number of the source where the exception occurred.
171+
[propget] HRESULT ColumnNumber([out, retval] UINT* value);
168172

169-
/// This will return the exception className, it would be got from the
173+
/// The Name is the exception's class name. In the JSON it is `exceptionDetail.exception.className`. This is the empty string if the exception doesn't have a class name. This can happen if the script throws a non-Error object such as `throw "abc";`
170174
/// `result.exceptionDetail.exception.className` in json result, this
171175
/// could be empty if the exception doesn't have the specified element,
172176
/// such as user active throw an exception like `throw "abc"`.
@@ -178,10 +182,10 @@ interface ICoreWebView2ExecuteScriptException : IUnknown {
178182
/// such as user active throw an exception like `throw "abc"`.
179183
[propget] HRESULT Message([out, retval] LPWSTR* value);
180184

181-
/// This will return the exception detail, it's a json struct with complete information for
185+
/// This will return all details of the exception as a JSON string. In the case that script has thrown a non-Error object such as `throw "abc";` or any other non-Error object, you can get object specific properties.
182186
/// exception, if get_Name and get_Exception is not enough, user can use this interface and
183187
/// get what they want.
184-
[propget] HRESULT Detail([out, retval] LPWSTR* detail);
188+
[propget] HRESULT ExceptionAsJSON([out, retval] LPWSTR* value);
185189
}
186190

187191
/// This is the result for ExecuteScriptWithResult.

0 commit comments

Comments
 (0)