Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: ios/web/webui/resources/handle_util.js

Issue 2946383002: Support new-style Mojo JS core API on IOS. (Closed)
Patch Set: . Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/web/webui/resources/core.js ('k') | ios/web/webui/resources/interface_provider.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Module "ios/mojo/public/js/handle_util"
6 //
7 // This module provides utilities to work with mojo handles.
8 // JavaScript and native code use different types for Mojo handles.
9 // In JavaScript handles are objects of type
10 // {nativeHandle: number, isValidMojoHandle: bool}. In native code handle is
11 // an integer and corresponds to {@code nativeHandle } field of JavaScript
12 // handle object.
13
14 define("ios/mojo/public/js/handle_util", [], function() {
15
16 /**
17 * Returns JavaScript handle from the given native handle.
18 * @param {!MojoHandle} Native mojo handle to convert.
19 * @return {!Object} JavaScript Mojo handle.
20 */
21 function getJavaScriptHandle(nativeHandle) {
22 return {
23 nativeHandle: nativeHandle,
24 isValidMojoHandle: true
25 };
26 };
27
28 /**
29 * Returns native handle from the given JavaScript handle.
30 * @param {Object} javaScriptHandle Handle to convert.
31 * @return {MojoHandle} native Mojo handle.
32 */
33 function getNativeHandle(javaScriptHandle) {
34 return javaScriptHandle ? javaScriptHandle.nativeHandle : null;
35 };
36
37 /**
38 * Returns native handles from the given JavaScript handles.
39 * @param {!Array<Object>} javaScriptHandles Handles to unwrap.
40 * @return {!Array<MojoHandle>} array of native Mojo handles.
41 */
42 function getNativeHandles(javaScriptHandles) {
43 return javaScriptHandles.map(function(handle) {
44 return getNativeHandle(handle);
45 });
46 };
47
48 /**
49 * @param {!Object} JavaScript handle to check.
50 * @return {boolean} true if the given JavaScript handle is a valid handle.
51 */
52 function isValidHandle(handle) {
53 return handle.isValidMojoHandle;
54 };
55
56 /**
57 * Invalidates the given JavaScript handle.
58 *
59 * Subsequent {@code isValidHandle} calls will return true for this handle.
60 * @param {!Object} handle JavaScript handle to invalidate.
61 */
62 function invalidateHandle(handle) {
63 handle.isValidMojoHandle = false;
64 };
65
66 var exports = {};
67 exports.getJavaScriptHandle = getJavaScriptHandle;
68 exports.getNativeHandle = getNativeHandle;
69 exports.getNativeHandles = getNativeHandles;
70 exports.isValidHandle = isValidHandle;
71 exports.invalidateHandle = invalidateHandle;
72 return exports;
73 });
OLDNEW
« no previous file with comments | « ios/web/webui/resources/core.js ('k') | ios/web/webui/resources/interface_provider.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698