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

Unified Diff: mojo/public/bindings/js/codec.js

Issue 63033010: Mojo's C++ and JavaScript bindings should produce identical messages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gin/test/file_runner.cc ('k') | mojo/public/bindings/js/codec_unittests.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/bindings/js/codec.js
diff --git a/mojo/public/bindings/js/codec.js b/mojo/public/bindings/js/codec.js
index 2df9c469571dc19d64a86333389583d62a5db641..d2d108ac547fa4e6b7ef5339d1cf9327041dc4b7 100644
--- a/mojo/public/bindings/js/codec.js
+++ b/mojo/public/bindings/js/codec.js
@@ -81,6 +81,10 @@ define(function() {
this.memory = newMemory;
};
+ Buffer.prototype.createViewOfAllocatedMemory = function() {
+ return new Uint8Array(this.memory.buffer, 0, this.next);
+ };
+
// Constants ----------------------------------------------------------------
var kArrayHeaderSize = 8;
@@ -212,7 +216,7 @@ define(function() {
};
Encoder.prototype.createAndEncodeEncoder = function(size) {
- var pointer = this.buffer.alloc(size);
+ var pointer = this.buffer.alloc(align(size));
this.encodePointer(pointer);
return new Encoder(this.buffer, this.handles, pointer);
};
@@ -277,6 +281,8 @@ define(function() {
// MessageBuilder -----------------------------------------------------------
function MessageBuilder(messageName, payloadSize) {
+ // Currently, we don't compute the payload size correctly ahead of time.
+ // Instead, we overwrite this field at the end.
var numberOfBytes = kMessageHeaderSize + payloadSize;
this.buffer = new Buffer(numberOfBytes);
this.handles = [];
@@ -295,7 +301,11 @@ define(function() {
};
MessageBuilder.prototype.finish = function() {
- var message = new Message(this.buffer.memory, this.handles);
+ // TODO(abarth): Rather than resizing the buffer at the end, we could
+ // compute the size we need ahead of time, like we do in C++.
+ var memory = this.buffer.createViewOfAllocatedMemory();
+ store32(memory, 0, memory.length);
+ var message = new Message(memory, this.handles);
this.buffer = null;
this.handles = null;
this.encoder = null;
« no previous file with comments | « gin/test/file_runner.cc ('k') | mojo/public/bindings/js/codec_unittests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698