summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-24 22:38:45 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-24 22:38:45 +0000
commit8608e138796081bfd56e7cd6e79771b0b6f98b31 (patch)
treecee6f1d7350f9a9a7884a36b330a52985d53f595
parentfe3493e5a5e0f6d24b0b0f22b8f880da5490b80c (diff)
downloadchromium_src-8608e138796081bfd56e7cd6e79771b0b6f98b31.zip
chromium_src-8608e138796081bfd56e7cd6e79771b0b6f98b31.tar.gz
chromium_src-8608e138796081bfd56e7cd6e79771b0b6f98b31.tar.bz2
Added mojo JS bindings for beginWriteData and endWriteData.
BUG=354281 Review URL: https://codereview.chromium.org/207413002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@259042 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--mojo/bindings/js/core.cc22
-rw-r--r--mojo/bindings/js/core_unittests.js27
2 files changed, 49 insertions, 0 deletions
diff --git a/mojo/bindings/js/core.cc b/mojo/bindings/js/core.cc
index 3aaf629..c7b1f5c 100644
--- a/mojo/bindings/js/core.cc
+++ b/mojo/bindings/js/core.cc
@@ -133,6 +133,26 @@ gin::Dictionary WriteData(const gin::Arguments& args,
return dictionary;
}
+gin::Dictionary BeginWriteData(const gin::Arguments& args,
+ MojoHandle handle,
+ uint32_t num_bytes,
+ MojoWriteDataFlags flags) {
+ void* data = NULL;
+ MojoResult result = MojoBeginWriteData(handle, &data, &num_bytes, flags);
+ gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate());
+ dictionary.Set("result", result);
+ if (result == MOJO_RESULT_OK) {
+ v8::Handle<v8::Value> buffer =
+ v8::ArrayBuffer::New(args.isolate(), data, num_bytes);
+ dictionary.Set("buffer", buffer);
+ }
+ return dictionary;
+}
+
+MojoResult EndWriteData(MojoHandle handle, uint32_t num_bytes_written) {
+ return MojoEndWriteData(handle, num_bytes_written);
+}
+
gin::Dictionary ReadData(const gin::Arguments& args,
MojoHandle handle,
MojoReadDataFlags flags) {
@@ -182,6 +202,8 @@ v8::Local<v8::Value> Core::GetModule(v8::Isolate* isolate) {
.SetMethod("readMessage", ReadMessage)
.SetMethod("createDataPipe", CreateDataPipe)
.SetMethod("writeData", WriteData)
+ .SetMethod("beginWriteData", BeginWriteData)
+ .SetMethod("endWriteData", EndWriteData)
.SetMethod("readData", ReadData)
// TODO(vtl): Change name of "kInvalidHandle", now that there's no such
diff --git a/mojo/bindings/js/core_unittests.js b/mojo/bindings/js/core_unittests.js
index a05a5b20..e6a6c7f 100644
--- a/mojo/bindings/js/core_unittests.js
+++ b/mojo/bindings/js/core_unittests.js
@@ -10,6 +10,7 @@ define([
runWithMessagePipe(testReadAndWriteMessage);
runWithDataPipe(testNop);
runWithDataPipe(testReadAndWriteDataPipe);
+ runWithDataPipe(testBeginWriteDataPipe);
this.result = "PASS";
function runWithMessagePipe(test) {
@@ -86,4 +87,30 @@ define([
expect(memory[i]).toBe((i * i) & 0xFF);
}
+ function testBeginWriteDataPipe(pipe) {
+ var write = core.beginWriteData(
+ pipe.producerHandle, 42,
+ core.WRITE_DATA_FLAG_ALL_OR_NONE);
+
+ expect(write.result).toBe(core.RESULT_OK);
+ expect(write.buffer.byteLength).toBeGreaterThan(41);
+
+ var memory = new Uint8Array(write.buffer);
+ for (var i = 0; i < 42; ++i)
+ memory[i] = i * i;
+
+ var result = core.endWriteData(pipe.producerHandle, 42);
+ expect(result).toBe(core.RESULT_OK);
+
+ var read = core.readData(
+ pipe.consumerHandle, core.READ_DATA_FLAG_ALL_OR_NONE);
+
+ expect(read.result).toBe(core.RESULT_OK);
+ expect(read.buffer.byteLength).toBe(42);
+
+ var memory = new Uint8Array(read.buffer);
+ for (var i = 0; i < memory.length; ++i)
+ expect(memory[i]).toBe((i * i) & 0xFF);
+ }
+
});