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

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

Issue 2556353004: Mojo JS bindings: code generator maps interface ptr and request to InterfacePtr and InterfaceReques… (Closed)
Patch Set: . Created 4 years 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
Index: mojo/public/js/codec.js
diff --git a/mojo/public/js/codec.js b/mojo/public/js/codec.js
index 70df758559967e150a117267d196d6a3303b436c..3ee2274b26e04d4ecf139148cdd643c95470d0cb 100644
--- a/mojo/public/js/codec.js
+++ b/mojo/public/js/codec.js
@@ -3,9 +3,10 @@
// found in the LICENSE file.
define("mojo/public/js/codec", [
- "mojo/public/js/unicode",
"mojo/public/js/buffer",
-], function(unicode, buffer) {
+ "mojo/public/js/interface_types",
+ "mojo/public/js/unicode",
+], function(buffer, types, unicode) {
var kErrorUnsigned = "Passing negative value to unsigned";
var kErrorArray = "Passing non Array for array type";
@@ -802,33 +803,54 @@ define("mojo/public/js/codec", [
NullableHandle.encode = Handle.encode;
- function Interface() {
+ function Interface(cls) {
+ this.cls = cls;
}
- Interface.encodedSize = 8;
+ Interface.prototype.encodedSize = 8;
- Interface.decode = function(decoder) {
- var handle = decoder.decodeHandle();
- // Ignore the version field for now.
- decoder.readUint32();
+ Interface.prototype.decode = function(decoder) {
+ var interfacePtrInfo = new types.InterfacePtrInfo(
+ decoder.decodeHandle(), decoder.readUint32());
+ var interfacePtr = new this.cls();
+ interfacePtr.ptr.bind(interfacePtrInfo);
+ return interfacePtr;
+ };
- return handle;
+ Interface.prototype.encode = function(encoder, val) {
+ var interfacePtrInfo =
+ val ? val.ptr.passInterface() : new InterfacePtrInfo(null, 0);
+ encoder.encodeHandle(interfacePtrInfo.handle);
+ encoder.writeUint32(interfacePtrInfo.version);
};
- Interface.encode = function(encoder, val) {
- encoder.encodeHandle(val);
- // Set the version field to 0 for now.
- encoder.writeUint32(0);
+ function NullableInterface(cls) {
+ Interface.call(this, cls);
+ }
+
+ NullableInterface.prototype = Object.create(Interface.prototype);
+
+ function InterfaceRequest() {
+ }
+
+ InterfaceRequest.encodedSize = 4;
+
+ InterfaceRequest.decode = function(decoder) {
+ return new types.InterfaceRequest(decoder.decodeHandle());
+ };
+
+ InterfaceRequest.encode = function(encoder, val) {
+ encoder.encodeHandle(val ? val.handle : null);
};
- function NullableInterface() {
+ function NullableInterfaceRequest() {
}
- NullableInterface.encodedSize = Interface.encodedSize;
+ NullableInterfaceRequest.encodedSize = InterfaceRequest.encodedSize;
- NullableInterface.decode = Interface.decode;
+ NullableInterfaceRequest.decode = InterfaceRequest.decode;
- NullableInterface.encode = Interface.encode;
+ NullableInterfaceRequest.encode = InterfaceRequest.encode;
function MapOf(keyClass, valueClass) {
this.keyClass = keyClass;
@@ -888,6 +910,8 @@ define("mojo/public/js/codec", [
exports.NullableHandle = NullableHandle;
exports.Interface = Interface;
exports.NullableInterface = NullableInterface;
+ exports.InterfaceRequest = InterfaceRequest;
+ exports.NullableInterfaceRequest = NullableInterfaceRequest;
exports.MapOf = MapOf;
exports.NullableMapOf = NullableMapOf;
return exports;

Powered by Google App Engine
This is Rietveld 408576698