1// Copyright 2014 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 "mojo/public/js/core" 6// 7// Note: This file is for documentation purposes only. The code here is not 8// actually executed. The real module is implemented natively in Mojo. 9// 10// This module provides the JavaScript bindings for mojo/public/c/system/core.h. 11// Refer to that file for more detailed documentation for equivalent methods. 12 13while (1); 14 15/** 16 * MojoHandle: An opaque handles to a Mojo object (e.g. a message pipe). 17 */ 18var kInvalidHandle; 19 20/** 21 * MojoResult {number}: Result codes for Mojo operations. 22 * See core.h for more information. 23 */ 24var RESULT_OK; 25var RESULT_CANCELLED; 26var RESULT_UNKNOWN; 27var RESULT_INVALID_ARGUMENT; 28var RESULT_DEADLINE_EXCEEDED; 29var RESULT_NOT_FOUND; 30var RESULT_ALREADY_EXISTS; 31var RESULT_PERMISSION_DENIED; 32var RESULT_RESOURCE_EXHAUSTED; 33var RESULT_FAILED_PRECONDITION; 34var RESULT_ABORTED; 35var RESULT_OUT_OF_RANGE; 36var RESULT_UNIMPLEMENTED; 37var RESULT_INTERNAL; 38var RESULT_UNAVAILABLE; 39var RESULT_DATA_LOSS; 40var RESULT_BUSY; 41var RESULT_SHOULD_WAIT; 42 43/** 44 * MojoDeadline {number}: Used to specify deadlines (timeouts), in microseconds. 45 * See core.h for more information. 46 */ 47var DEADLINE_INDEFINITE; 48 49/** 50 * MojoHandleSignals: Used to specify signals that can be waited on for a handle 51 *(and which can be triggered), e.g., the ability to read or write to 52 * the handle. 53 * See core.h for more information. 54 */ 55var HANDLE_SIGNAL_NONE; 56var HANDLE_SIGNAL_READABLE; 57var HANDLE_SIGNAL_WRITABLE; 58var HANDLE_SIGNAL_PEER_CLOSED; 59 60/** 61 * MojoCreateDataMessageOptions: Used to specify creation parameters for a data 62 * pipe to |createDataMessage()|. 63 * See core.h for more information. 64 */ 65dictionary MojoCreateDataMessageOptions { 66 MojoCreateDataMessageOptionsFlags flags; // See below. 67}; 68 69// MojoCreateDataMessageOptionsFlags 70var CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE; 71 72/* 73 * MojoWriteMessageFlags: Used to specify different modes to |writeMessage()|. 74 * See core.h for more information. 75 */ 76var WRITE_MESSAGE_FLAG_NONE; 77 78/** 79 * MojoReadMessageFlags: Used to specify different modes to |readMessage()|. 80 * See core.h for more information. 81 */ 82var READ_MESSAGE_FLAG_NONE; 83var READ_MESSAGE_FLAG_MAY_DISCARD; 84 85/** 86 * MojoCreateDataPipeOptions: Used to specify creation parameters for a data 87 * pipe to |createDataPipe()|. 88 * See core.h for more information. 89 */ 90dictionary MojoCreateDataPipeOptions { 91 MojoCreateDataPipeOptionsFlags flags; // See below. 92 int32 elementNumBytes; // The size of an element, in bytes. 93 int32 capacityNumBytes; // The capacity of the data pipe, in bytes. 94}; 95 96// MojoCreateDataPipeOptionsFlags 97var CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; 98 99/* 100 * MojoWriteDataFlags: Used to specify different modes to |writeData()|. 101 * See core.h for more information. 102 */ 103var WRITE_DATA_FLAG_NONE; 104var WRITE_DATA_FLAG_ALL_OR_NONE; 105 106/** 107 * MojoReadDataFlags: Used to specify different modes to |readData()|. 108 * See core.h for more information. 109 */ 110var READ_DATA_FLAG_NONE; 111var READ_DATA_FLAG_ALL_OR_NONE; 112var READ_DATA_FLAG_DISCARD; 113var READ_DATA_FLAG_QUERY; 114var READ_DATA_FLAG_PEEK; 115 116/** 117 * Closes the given |handle|. See MojoClose for more info. 118 * @param {MojoHandle} Handle to close. 119 * @return {MojoResult} Result code. 120 */ 121function close(handle) { [native code] } 122 123/** 124 * Waits on the given handle until a signal indicated by |signals| is 125 * satisfied or until |deadline| is passed. See MojoWait for more information. 126 * 127 * @param {MojoHandle} handle Handle to wait on. 128 * @param {MojoHandleSignals} signals Specifies the condition to wait for. 129 * @param {MojoDeadline} deadline Stops waiting if this is reached. 130 * @return {MojoResult} Result code. 131 */ 132function wait(handle, signals, deadline) { [native code] } 133 134/** 135 * Waits on |handles[0]|, ..., |handles[handles.length-1]| for at least one of 136 * them to satisfy the state indicated by |flags[0]|, ..., 137 * |flags[handles.length-1]|, respectively, or until |deadline| has passed. 138 * See MojoWaitMany for more information. 139 * 140 * @param {Array.MojoHandle} handles Handles to wait on. 141 * @param {Array.MojoHandleSignals} signals Specifies the condition to wait for, 142 * for each corresponding handle. Must be the same length as |handles|. 143 * @param {MojoDeadline} deadline Stops waiting if this is reached. 144 * @return {MojoResult} Result code. 145 */ 146function waitMany(handles, signals, deadline) { [native code] } 147 148/** 149 * Creates a message pipe. This function always succeeds. 150 * See MojoCreateMessagePipe for more information on message pipes. 151 * 152 * @param {MojoCreateMessagePipeOptions} optionsDict Options to control the 153 * message pipe parameters. May be null. 154 * @return {MessagePipe} An object of the form { 155 * handle0, 156 * handle1, 157 * } 158 * where |handle0| and |handle1| are MojoHandles to each end of the channel. 159 */ 160function createMessagePipe(optionsDict) { [native code] } 161 162/** 163 * Writes a message to the message pipe endpoint given by |handle|. See 164 * MojoWriteMessage for more information, including return codes. 165 * 166 * @param {MojoHandle} handle The endpoint to write to. 167 * @param {ArrayBufferView} buffer The message data. May be empty. 168 * @param {Array.MojoHandle} handlesArray Any handles to attach. Handles are 169 * transferred on success and will no longer be valid. May be empty. 170 * @param {MojoWriteMessageFlags} flags Flags. 171 * @return {MojoResult} Result code. 172 */ 173function writeMessage(handle, buffer, handlesArray, flags) { [native code] } 174 175/** 176 * Reads a message from the message pipe endpoint given by |handle|. See 177 * MojoReadMessage for more information, including return codes. 178 * 179 * @param {MojoHandle} handle The endpoint to read from. 180 * @param {MojoReadMessageFlags} flags Flags. 181 * @return {object} An object of the form { 182 * result, // |RESULT_OK| on success, error code otherwise. 183 * buffer, // An ArrayBufferView of the message data (only on success). 184 * handles // An array of MojoHandles transferred, if any. 185 * } 186 */ 187function readMessage(handle, flags) { [native code] } 188 189/** 190 * Creates a data pipe, which is a unidirectional communication channel for 191 * unframed data, with the given options. See MojoCreateDataPipe for more 192 * more information, including return codes. 193 * 194 * @param {MojoCreateDataPipeOptions} optionsDict Options to control the data 195 * pipe parameters. May be null. 196 * @return {object} An object of the form { 197 * result, // |RESULT_OK| on success, error code otherwise. 198 * producerHandle, // MojoHandle to use with writeData (only on success). 199 * consumerHandle, // MojoHandle to use with readData (only on success). 200 * } 201 */ 202function createDataPipe(optionsDict) { [native code] } 203 204/** 205 * Writes the given data to the data pipe producer given by |handle|. See 206 * MojoWriteData for more information, including return codes. 207 * 208 * @param {MojoHandle} handle A producerHandle returned by createDataPipe. 209 * @param {ArrayBufferView} buffer The data to write. 210 * @param {MojoWriteDataFlags} flags Flags. 211 * @return {object} An object of the form { 212 * result, // |RESULT_OK| on success, error code otherwise. 213 * numBytes, // The number of bytes written. 214 * } 215 */ 216function writeData(handle, buffer, flags) { [native code] } 217 218/** 219 * Reads data from the data pipe consumer given by |handle|. May also 220 * be used to discard data. See MojoReadData for more information, including 221 * return codes. 222 * 223 * @param {MojoHandle} handle A consumerHandle returned by createDataPipe. 224 * @param {MojoReadDataFlags} flags Flags. 225 * @return {object} An object of the form { 226 * result, // |RESULT_OK| on success, error code otherwise. 227 * buffer, // An ArrayBufferView of the data read (only on success). 228 * } 229 */ 230function readData(handle, flags) { [native code] } 231 232/** 233 * True if the argument is a message or data pipe handle. 234 * 235 * @param {value} an arbitrary JS value. 236 * @return true or false 237 */ 238function isHandle(value) { [native code] } 239