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.
5 // Module "mojo/public/js/bindings/core"
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.
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.
16 * MojoHandle: An opaque handles to a Mojo object (e.g. a message pipe).
21 * MojoResult {number}: Result codes for Mojo operations.
22 * See core.h for more information.
27 var RESULT_INVALID_ARGUMENT;
28 var RESULT_DEADLINE_EXCEEDED;
30 var RESULT_ALREADY_EXISTS;
31 var RESULT_PERMISSION_DENIED;
32 var RESULT_RESOURCE_EXHAUSTED;
33 var RESULT_FAILED_PRECONDITION;
35 var RESULT_OUT_OF_RANGE;
36 var RESULT_UNIMPLEMENTED;
38 var RESULT_UNAVAILABLE;
41 var RESULT_SHOULD_WAIT;
44 * MojoDeadline {number}: Used to specify deadlines (timeouts), in microseconds.
45 * See core.h for more information.
47 var DEADLINE_INDEFINITE;
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
53 * See core.h for more information.
55 var HANDLE_SIGNAL_NONE;
56 var HANDLE_SIGNAL_READABLE;
57 var HANDLE_SIGNAL_WRITABLE;
60 * MojoCreateDataMessageOptions: Used to specify creation parameters for a data
61 * pipe to |createDataMessage()|.
62 * See core.h for more information.
64 dictionary MojoCreateDataMessageOptions {
65 MojoCreateDataMessageOptionsFlags flags; // See below.
68 // MojoCreateDataMessageOptionsFlags
69 var CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE;
72 * MojoWriteMessageFlags: Used to specify different modes to |writeMessage()|.
73 * See core.h for more information.
75 var WRITE_MESSAGE_FLAG_NONE;
78 * MojoReadMessageFlags: Used to specify different modes to |readMessage()|.
79 * See core.h for more information.
81 var READ_MESSAGE_FLAG_NONE;
82 var READ_MESSAGE_FLAG_MAY_DISCARD;
85 * MojoCreateDataPipeOptions: Used to specify creation parameters for a data
86 * pipe to |createDataPipe()|.
87 * See core.h for more information.
89 dictionary MojoCreateDataPipeOptions {
90 MojoCreateDataPipeOptionsFlags flags; // See below.
91 int32 elementNumBytes; // The size of an element, in bytes.
92 int32 capacityNumBytes; // The capacity of the data pipe, in bytes.
95 // MojoCreateDataPipeOptionsFlags
96 var CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
97 var CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD;
100 * MojoWriteDataFlags: Used to specify different modes to |writeData()|.
101 * See core.h for more information.
103 var WRITE_DATA_FLAG_NONE;
104 var WRITE_DATA_FLAG_ALL_OR_NONE;
107 * MojoReadDataFlags: Used to specify different modes to |readData()|.
108 * See core.h for more information.
110 var READ_DATA_FLAG_NONE;
111 var READ_DATA_FLAG_ALL_OR_NONE;
112 var READ_DATA_FLAG_DISCARD;
113 var READ_DATA_FLAG_QUERY;
116 * Closes the given |handle|. See MojoClose for more info.
117 * @param {MojoHandle} Handle to close.
118 * @return {MojoResult} Result code.
120 function close(handle) { [native code] }
123 * Waits on the given handle until a signal indicated by |signals| is
124 * satisfied or until |deadline| is passed. See MojoWait for more information.
126 * @param {MojoHandle} handle Handle to wait on.
127 * @param {MojoHandleSignals} signals Specifies the condition to wait for.
128 * @param {MojoDeadline} deadline Stops waiting if this is reached.
129 * @return {MojoResult} Result code.
131 function wait(handle, signals, deadline) { [native code] }
134 * Waits on |handles[0]|, ..., |handles[handles.length-1]| for at least one of
135 * them to satisfy the state indicated by |flags[0]|, ...,
136 * |flags[handles.length-1]|, respectively, or until |deadline| has passed.
137 * See MojoWaitMany for more information.
139 * @param {Array.MojoHandle} handles Handles to wait on.
140 * @param {Array.MojoHandleSignals} signals Specifies the condition to wait for,
141 * for each corresponding handle. Must be the same length as |handles|.
142 * @param {MojoDeadline} deadline Stops waiting if this is reached.
143 * @return {MojoResult} Result code.
145 function waitMany(handles, signals, deadline) { [native code] }
148 * Creates a message pipe. This function always succeeds.
149 * See MojoCreateMessagePipe for more information on message pipes.
151 * @param {MojoCreateMessagePipeOptions} optionsDict Options to control the
152 * message pipe parameters. May be null.
153 * @return {MessagePipe} An object of the form {
157 * where |handle0| and |handle1| are MojoHandles to each end of the channel.
159 function createMessagePipe(optionsDict) { [native code] }
162 * Writes a message to the message pipe endpoint given by |handle|. See
163 * MojoWriteMessage for more information, including return codes.
165 * @param {MojoHandle} handle The endpoint to write to.
166 * @param {ArrayBufferView} buffer The message data. May be empty.
167 * @param {Array.MojoHandle} handlesArray Any handles to attach. Handles are
168 * transferred on success and will no longer be valid. May be empty.
169 * @param {MojoWriteMessageFlags} flags Flags.
170 * @return {MojoResult} Result code.
172 function writeMessage(handle, buffer, handlesArray, flags) { [native code] }
175 * Reads a message from the message pipe endpoint given by |handle|. See
176 * MojoReadMessage for more information, including return codes.
178 * @param {MojoHandle} handle The endpoint to read from.
179 * @param {MojoReadMessageFlags} flags Flags.
180 * @return {object} An object of the form {
181 * result, // |RESULT_OK| on success, error code otherwise.
182 * buffer, // An ArrayBufferView of the message data (only on success).
183 * handles // An array of MojoHandles transferred, if any.
186 function readMessage(handle, flags) { [native code] }
189 * Creates a data pipe, which is a unidirectional communication channel for
190 * unframed data, with the given options. See MojoCreateDataPipe for more
191 * more information, including return codes.
193 * @param {MojoCreateDataPipeOptions} optionsDict Options to control the data
194 * pipe parameters. May be null.
195 * @return {object} An object of the form {
196 * result, // |RESULT_OK| on success, error code otherwise.
197 * producerHandle, // MojoHandle to use with writeData (only on success).
198 * consumerHandle, // MojoHandle to use with readData (only on success).
201 function createDataPipe(optionsDict) { [native code] }
204 * Writes the given data to the data pipe producer given by |handle|. See
205 * MojoWriteData for more information, including return codes.
207 * @param {MojoHandle} handle A producerHandle returned by createDataPipe.
208 * @param {ArrayBufferView} buffer The data to write.
209 * @param {MojoWriteDataFlags} flags Flags.
210 * @return {object} An object of the form {
211 * result, // |RESULT_OK| on success, error code otherwise.
212 * numBytes, // The number of bytes written.
215 function writeData(handle, buffer, flags) { [native code] }
218 * Reads data from the data pipe consumer given by |handle|. May also
219 * be used to discard data. See MojoReadData for more information, including
222 * @param {MojoHandle} handle A consumerHandle returned by createDataPipe.
223 * @param {MojoReadDataFlags} flags Flags.
224 * @return {object} An object of the form {
225 * result, // |RESULT_OK| on success, error code otherwise.
226 * buffer, // An ArrayBufferView of the data read (only on success).
229 function readData(handle, flags) { [native code] }