| OLD | NEW |
| (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 }); | |
| OLD | NEW |