Commit 8221d587 authored by qsr@chromium.org's avatar qsr@chromium.org

Add support for MojoCreateMessagePipeOptions struct to JS bindings

BUG=386892
R=mpcomplete@chromium.org

Review URL: https://codereview.chromium.org/392923002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283514 0039d316-1c4b-4281-b951-d872f2087c98
parent 2e371483
...@@ -44,13 +44,37 @@ MojoResult WaitMany( ...@@ -44,13 +44,37 @@ MojoResult WaitMany(
} }
gin::Dictionary CreateMessagePipe(const gin::Arguments& args) { gin::Dictionary CreateMessagePipe(const gin::Arguments& args) {
gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate());
dictionary.Set("result", MOJO_RESULT_INVALID_ARGUMENT);
MojoHandle handle0 = MOJO_HANDLE_INVALID; MojoHandle handle0 = MOJO_HANDLE_INVALID;
MojoHandle handle1 = MOJO_HANDLE_INVALID; MojoHandle handle1 = MOJO_HANDLE_INVALID;
// TODO(vtl): Add support for the options struct. MojoResult result = MOJO_RESULT_OK;
MojoResult result = MojoCreateMessagePipe(NULL, &handle0, &handle1);
CHECK(result == MOJO_RESULT_OK);
gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate()); v8::Handle<v8::Value> options_value = args.PeekNext();
if (options_value.IsEmpty() || options_value->IsNull() ||
options_value->IsUndefined()) {
result = MojoCreateMessagePipe(NULL, &handle0, &handle1);
} else if (options_value->IsObject()) {
gin::Dictionary options_dict(args.isolate(), options_value->ToObject());
MojoCreateMessagePipeOptions options;
// For future struct_size, we can probably infer that from the presence of
// properties in options_dict. For now, it's always 8.
options.struct_size = 8;
// Ideally these would be optional. But the interface makes it hard to
// typecheck them then.
if (!options_dict.Get("flags", &options.flags)) {
return dictionary;
}
result = MojoCreateMessagePipe(&options, &handle0, &handle1);
} else {
return dictionary;
}
CHECK_EQ(MOJO_RESULT_OK, result);
dictionary.Set("result", result);
dictionary.Set("handle0", mojo::Handle(handle0)); dictionary.Set("handle0", mojo::Handle(handle0));
dictionary.Set("handle1", mojo::Handle(handle1)); dictionary.Set("handle1", mojo::Handle(handle1));
return dictionary; return dictionary;
...@@ -118,8 +142,7 @@ gin::Dictionary ReadMessage(const gin::Arguments& args, ...@@ -118,8 +142,7 @@ gin::Dictionary ReadMessage(const gin::Arguments& args,
return dictionary; return dictionary;
} }
gin::Dictionary CreateDataPipe(const gin::Arguments& args, gin::Dictionary CreateDataPipe(const gin::Arguments& args) {
v8::Handle<v8::Value> options_value) {
gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate()); gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate());
dictionary.Set("result", MOJO_RESULT_INVALID_ARGUMENT); dictionary.Set("result", MOJO_RESULT_INVALID_ARGUMENT);
...@@ -127,7 +150,11 @@ gin::Dictionary CreateDataPipe(const gin::Arguments& args, ...@@ -127,7 +150,11 @@ gin::Dictionary CreateDataPipe(const gin::Arguments& args,
MojoHandle consumer_handle = MOJO_HANDLE_INVALID; MojoHandle consumer_handle = MOJO_HANDLE_INVALID;
MojoResult result = MOJO_RESULT_OK; MojoResult result = MOJO_RESULT_OK;
if (options_value->IsObject()) { v8::Handle<v8::Value> options_value = args.PeekNext();
if (options_value.IsEmpty() || options_value->IsNull() ||
options_value->IsUndefined()) {
result = MojoCreateDataPipe(NULL, &producer_handle, &consumer_handle);
} else if (options_value->IsObject()) {
gin::Dictionary options_dict(args.isolate(), options_value->ToObject()); gin::Dictionary options_dict(args.isolate(), options_value->ToObject());
MojoCreateDataPipeOptions options; MojoCreateDataPipeOptions options;
// For future struct_size, we can probably infer that from the presence of // For future struct_size, we can probably infer that from the presence of
...@@ -142,8 +169,6 @@ gin::Dictionary CreateDataPipe(const gin::Arguments& args, ...@@ -142,8 +169,6 @@ gin::Dictionary CreateDataPipe(const gin::Arguments& args,
} }
result = MojoCreateDataPipe(&options, &producer_handle, &consumer_handle); result = MojoCreateDataPipe(&options, &producer_handle, &consumer_handle);
} else if (options_value->IsNull() || options_value->IsUndefined()) {
result = MojoCreateDataPipe(NULL, &producer_handle, &consumer_handle);
} else { } else {
return dictionary; return dictionary;
} }
...@@ -246,6 +271,9 @@ v8::Local<v8::Value> Core::GetModule(v8::Isolate* isolate) { ...@@ -246,6 +271,9 @@ v8::Local<v8::Value> Core::GetModule(v8::Isolate* isolate) {
.SetValue("HANDLE_SIGNAL_READABLE", MOJO_HANDLE_SIGNAL_READABLE) .SetValue("HANDLE_SIGNAL_READABLE", MOJO_HANDLE_SIGNAL_READABLE)
.SetValue("HANDLE_SIGNAL_WRITABLE", MOJO_HANDLE_SIGNAL_WRITABLE) .SetValue("HANDLE_SIGNAL_WRITABLE", MOJO_HANDLE_SIGNAL_WRITABLE)
.SetValue("CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE",
MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE)
.SetValue("WRITE_MESSAGE_FLAG_NONE", MOJO_WRITE_MESSAGE_FLAG_NONE) .SetValue("WRITE_MESSAGE_FLAG_NONE", MOJO_WRITE_MESSAGE_FLAG_NONE)
.SetValue("READ_MESSAGE_FLAG_NONE", MOJO_READ_MESSAGE_FLAG_NONE) .SetValue("READ_MESSAGE_FLAG_NONE", MOJO_READ_MESSAGE_FLAG_NONE)
......
...@@ -9,13 +9,30 @@ define([ ...@@ -9,13 +9,30 @@ define([
], function(expect, core, gc) { ], function(expect, core, gc) {
runWithMessagePipe(testNop); runWithMessagePipe(testNop);
runWithMessagePipe(testReadAndWriteMessage); runWithMessagePipe(testReadAndWriteMessage);
runWithMessagePipeWithOptions(testNop);
runWithMessagePipeWithOptions(testReadAndWriteMessage);
runWithDataPipe(testNop); runWithDataPipe(testNop);
runWithDataPipe(testReadAndWriteDataPipe); runWithDataPipe(testReadAndWriteDataPipe);
runWithDataPipeWithOptions(testNop);
runWithDataPipeWithOptions(testReadAndWriteDataPipe);
gc.collectGarbage(); // should not crash gc.collectGarbage(); // should not crash
this.result = "PASS"; this.result = "PASS";
function runWithMessagePipe(test) { function runWithMessagePipe(test) {
var pipe = core.createMessagePipe(); var pipe = core.createMessagePipe();
expect(pipe.result).toBe(core.RESULT_OK);
test(pipe);
expect(core.close(pipe.handle0)).toBe(core.RESULT_OK);
expect(core.close(pipe.handle1)).toBe(core.RESULT_OK);
}
function runWithMessagePipeWithOptions(test) {
var pipe = core.createMessagePipe({
flags: core.CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE
});
expect(pipe.result).toBe(core.RESULT_OK);
test(pipe); test(pipe);
...@@ -24,6 +41,16 @@ define([ ...@@ -24,6 +41,16 @@ define([
} }
function runWithDataPipe(test) { function runWithDataPipe(test) {
var pipe = core.createDataPipe();
expect(pipe.result).toBe(core.RESULT_OK);
test(pipe);
expect(core.close(pipe.producerHandle)).toBe(core.RESULT_OK);
expect(core.close(pipe.consumerHandle)).toBe(core.RESULT_OK);
}
function runWithDataPipeWithOptions(test) {
var pipe = core.createDataPipe({ var pipe = core.createDataPipe({
flags: core.CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, flags: core.CREATE_DATA_PIPE_OPTIONS_FLAG_NONE,
elementNumBytes: 1, elementNumBytes: 1,
......
...@@ -56,6 +56,18 @@ var HANDLE_SIGNAL_NONE; ...@@ -56,6 +56,18 @@ var HANDLE_SIGNAL_NONE;
var HANDLE_SIGNAL_READABLE; var HANDLE_SIGNAL_READABLE;
var HANDLE_SIGNAL_WRITABLE; var HANDLE_SIGNAL_WRITABLE;
/**
* MojoCreateDataMessageOptions: Used to specify creation parameters for a data
* pipe to |createDataMessage()|.
* See core.h for more information.
*/
dictionary MojoCreateDataMessageOptions {
MojoCreateDataMessageOptionsFlags flags; // See below.
};
// MojoCreateDataMessageOptionsFlags
var CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE;
/* /*
* MojoWriteMessageFlags: Used to specify different modes to |writeMessage()|. * MojoWriteMessageFlags: Used to specify different modes to |writeMessage()|.
* See core.h for more information. * See core.h for more information.
...@@ -136,13 +148,15 @@ function waitMany(handles, signals, deadline) { [native code] } ...@@ -136,13 +148,15 @@ function waitMany(handles, signals, deadline) { [native code] }
* Creates a message pipe. This function always succeeds. * Creates a message pipe. This function always succeeds.
* See MojoCreateMessagePipe for more information on message pipes. * See MojoCreateMessagePipe for more information on message pipes.
* *
* @param {MojoCreateMessagePipeOptions} optionsDict Options to control the
* message pipe parameters. May be null.
* @return {MessagePipe} An object of the form { * @return {MessagePipe} An object of the form {
* handle0, * handle0,
* handle1, * handle1,
* } * }
* where |handle0| and |handle1| are MojoHandles to each end of the channel. * where |handle0| and |handle1| are MojoHandles to each end of the channel.
*/ */
function createMessagePipe() { [native code] } function createMessagePipe(optionsDict) { [native code] }
/** /**
* Writes a message to the message pipe endpoint given by |handle|. See * Writes a message to the message pipe endpoint given by |handle|. See
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment