Closed Bug 2056687 Opened 4 months ago Closed 4 months ago

[wpt-sync] Sync PR 61457 - WebMCP: Document and test Object arguments

Categories

(Testing :: web-platform-tests, task, P4)

task

Tracking

(firefox155 fixed)

RESOLVED FIXED
155 Branch
Tracking Status
firefox155 --- fixed

People

(Reporter: wpt-sync, Unassigned)

References

()

Details

(Whiteboard: [wptsync downstream])

Sync web-platform-tests PR 61457 into mozilla-central (this bug is closed when the sync is complete).

PR: https://github.com/web-platform-tests/wpt/pull/61457
Details from upstream follow.

Dominic Farolino <dom@chromium.org> wrote:

WebMCP: Document and test Object arguments

WebMCP has a helper JSONStringToScriptObject() to convert a string
into a JSON Object passed into the WebMCP tool execution callback, to
give the callback its arguments from the tool caller.

Before this CL, JSONStringToScriptObject() had an error branch for
handling v8::String::NewFromUtf8() failures. At first I thought this
was to handle two cases:

  1. Invalid UTF-8 strings
  2. Whatever else might fail, which to my knowledge is only OOMs (and
    we're generally comfortable crashing the renderer process for those)

Upon further investigation, I found that (1) above was not possible,
because mojo strings are deserialized into blink::String objects via
blink::String::FromUTF8(), which is not a lenient conversion
mechanism, and returns a null string, which translates to a plain old
empty std::string when we call json_string.Utf8() later.

So I originally replaced this error branch with:

  v8::Local\<v8::String> v8_json_string =
      v8::String::NewFromUtf8(script_state->GetIsolate(),
                              json_string.Utf8().c_str())
          .ToLocalChecked();

But this still seemed wasteful:

  • At mojo deserialization time, we perform full UTF-8 validation on a
    std::string, and assign its contents to a blink::String.
  • Later, we call blink::String::UTF8(), re-running UTF-8 validation
    and producing a std::string.
  • Finally calling v8::String::NewFromUtf8(), which allocates a whole
    new string (and performs UTF-8 validation again, as I understand).

So I found that there was a V8String() helper in the Blink bindings
layer specifically for converting blink::String values to JavaScript
strings. This helper avoids all of the UTF-8 re-validation, and handles
OOM renderer crashing.


Separately, this CL also adds more tests for another condition in that
same helper, which confirms that arrays are treated like Objects by
v8 and ECMAScript. Whether this is the exact behavior we want is a
matter of discussion in
https://github.com/webmachinelearning/webmcp/issues/92. But this CL just
aims to more-rigorously test and document the current behavior.

R=beaufort.francois@gmail.com

Bug: 489045948
Change-Id: I8ea2bfdc9bb81402afbe9d1fa5f5c45a7ed79ad1
Reviewed-on: https://chromium-review.googlesource.com/8123202
WPT-Export-Revision: 559094c69d9431db7a04ad8afb9990934bc3147a

CI Results

Ran 9 Firefox configurations based on mozilla-central, and Firefox, Chrome, and Safari on GitHub CI

Total 39 tests and 1 subtests

Status Summary

Firefox

OK : 1[GitHub] 35[Gecko-android-em-14-x86_64-debug-geckoview, Gecko-android-em-14-x86_64-lite-opt-geckoview, Gecko-android-em-14-x86_64-opt-geckoview, Gecko-linux2404-64-debug, Gecko-linux2404-64-opt, Gecko-windows11-32-25h2-debug, Gecko-windows11-32-25h2-opt, Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt]
PASS : 2
FAIL : 1[GitHub] 71[Gecko-android-em-14-x86_64-debug-geckoview, Gecko-android-em-14-x86_64-lite-opt-geckoview, Gecko-android-em-14-x86_64-opt-geckoview, Gecko-linux2404-64-debug, Gecko-linux2404-64-opt, Gecko-windows11-32-25h2-debug, Gecko-windows11-32-25h2-opt, Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt]
ERROR: 1

Chrome

OK : 1
PASS : 1

Safari

OK : 1
FAIL : 1

Links

Gecko CI (Treeherder)
GitHub PR Head
GitHub PR Base

Details

New Tests That Don't Pass

Tests Disabled in Gecko Infrastructure

Status: NEW → RESOLVED
Closed: 4 months ago
Resolution: --- → FIXED
Target Milestone: --- → 155 Branch
You need to log in before you can comment on or make changes to this bug.