forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mojo: Introduce Mojo JS bindings modules
This CL introduces generated mojom.m.js modules for mojom JS bindings, allowing most JS bindings consumers to import bindings with the convenience and efficiency afforded by JS modules. These modules can be used as-is by Component Extensions, Web Platform Tests, and Blink Web Tests. A follow-up change will introduce a slight variation on these modules to support consumption by WebUI pages. Bug: 1004256 Change-Id: Ic2b4a6bcadf68023d2078bf065befafce3ccb19b Tbr: sky@chromium.org Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2451589 Commit-Queue: Ken Rockot <rockot@google.com> Reviewed-by: Oksana Zhuravlova <oksamyt@chromium.org> Cr-Commit-Position: refs/heads/master@{#815471}
- Loading branch information
Showing
23 changed files
with
1,018 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
module mojo_bindings_test.mojom; | ||
|
||
// NOTE: This import exists to exercise automatic dependency loading in | ||
// generated JS modules. | ||
import "content/test/data/mojo_bindings_web_test_types.test-mojom"; | ||
|
||
// An interface whose definition covers various types of message signatures in | ||
// order to exercise the lite JS mojom bindings. | ||
interface TestMessageTarget { | ||
enum NestedEnum { | ||
kFoo, | ||
kBar, | ||
}; | ||
|
||
// Zero arguments, no reply. | ||
Poke(); | ||
|
||
// Zero-argument request, zero-argument reply. | ||
Ping() => (); | ||
|
||
// Request and reply both with arguments. | ||
Repeat(string? message, array<int32>? numbers) | ||
=> (string? message, array<int32>? numbers); | ||
|
||
Echo(NestedEnum nested) => (NestedEnum nested); | ||
|
||
Deconstruct(TestStruct test_struct) | ||
=> (int32 x, int32 y, | ||
// Using TestStruct.StructEnum causes a compile failure. Use | ||
// int32 instead. | ||
// TODO(crbug.com/1011660): Change |z| to TestStruct.StructEnum. | ||
int32 z); | ||
|
||
Flatten(array<TestStruct> values) => (array<int32> values); | ||
FlattenUnions(array<TestUnion> unions) => (array<int32> x, array<int32> s); | ||
|
||
RequestSubinterface(pending_receiver<Subinterface> receiver, | ||
pending_remote<SubinterfaceClient> client); | ||
}; | ||
|
||
interface Subinterface { | ||
Push(int32 value); | ||
Flush(); | ||
}; | ||
|
||
interface SubinterfaceClient { | ||
DidFlush(array<int32> values); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
module mojo_bindings_test.mojom; | ||
|
||
struct TestStruct { | ||
enum StructEnum { | ||
kZero = 0, | ||
kOne = 1, | ||
}; | ||
|
||
const int32 kStructConst = 2; | ||
|
||
int32 x; | ||
int32 y = kStructConst; | ||
StructEnum z = StructEnum.kOne; | ||
const bool isValid = false; | ||
}; | ||
|
||
union TestUnion { | ||
int32 x; | ||
TestStruct s; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const mojoTmp = self['mojo']; | ||
delete self['mojo']; | ||
export const mojo = mojoTmp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const mojo = { | ||
internal: { interfaceSupport: {} }, | ||
interfaceControl: {} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {mojo}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
goog.require('mojo.interfaceControl.RUN_MESSAGE_ID'); | ||
goog.require('mojo.interfaceControl.RunResponseMessageParamsSpec'); | ||
goog.require('mojo.internal'); | ||
|
||
goog.provide('mojo.internal.interfaceSupport'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
goog.provide('mojo.internal'); | ||
|
||
// "self" is always defined as opposed to "this", which isn't defined in | ||
// modules, or "window", which isn't defined in workers. | ||
/** @const {!Object} */ | ||
mojo.internal.globalScope = self; | ||
|
||
/** | ||
* This is effectively the same as goog.provide, but it's made available under | ||
* the mojo.internal namespace to avoid potential collisions in certain | ||
* compilation environments. | ||
* | ||
* @param {string} namespace | ||
* @export | ||
*/ | ||
mojo.internal.exportModule = function(namespace) { | ||
let current = mojo.internal.globalScope; | ||
const parts = namespace.split('.'); | ||
|
||
for (let part; parts.length && (part = parts.shift());) { | ||
if (!current[part]) | ||
current[part] = {}; | ||
current = current[part]; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 3 additions & 14 deletions
17
mojo/public/tools/bindings/generators/js_templates/lite/enum_definition_for_module.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.