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

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

Powered by Google App Engine
This is Rietveld 408576698