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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 define("mojo/public/js/codec", [ 5 define("mojo/public/js/codec", [
6 "mojo/public/js/buffer",
7 "mojo/public/js/interface_types",
6 "mojo/public/js/unicode", 8 "mojo/public/js/unicode",
7 "mojo/public/js/buffer", 9 ], function(buffer, types, unicode) {
8 ], function(unicode, buffer) {
9 10
10 var kErrorUnsigned = "Passing negative value to unsigned"; 11 var kErrorUnsigned = "Passing negative value to unsigned";
11 var kErrorArray = "Passing non Array for array type"; 12 var kErrorArray = "Passing non Array for array type";
12 var kErrorString = "Passing non String for string type"; 13 var kErrorString = "Passing non String for string type";
13 var kErrorMap = "Passing non Map for map type"; 14 var kErrorMap = "Passing non Map for map type";
14 15
15 // Memory ------------------------------------------------------------------- 16 // Memory -------------------------------------------------------------------
16 17
17 var kAlignment = 8; 18 var kAlignment = 8;
18 19
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 796
796 function NullableHandle() { 797 function NullableHandle() {
797 } 798 }
798 799
799 NullableHandle.encodedSize = Handle.encodedSize; 800 NullableHandle.encodedSize = Handle.encodedSize;
800 801
801 NullableHandle.decode = Handle.decode; 802 NullableHandle.decode = Handle.decode;
802 803
803 NullableHandle.encode = Handle.encode; 804 NullableHandle.encode = Handle.encode;
804 805
805 function Interface() { 806 function Interface(cls) {
807 this.cls = cls;
806 } 808 }
807 809
808 Interface.encodedSize = 8; 810 Interface.prototype.encodedSize = 8;
809 811
810 Interface.decode = function(decoder) { 812 Interface.prototype.decode = function(decoder) {
811 var handle = decoder.decodeHandle(); 813 var interfacePtrInfo = new types.InterfacePtrInfo(
812 // Ignore the version field for now. 814 decoder.decodeHandle(), decoder.readUint32());
813 decoder.readUint32(); 815 var interfacePtr = new this.cls();
814 816 interfacePtr.ptr.bind(interfacePtrInfo);
815 return handle; 817 return interfacePtr;
816 }; 818 };
817 819
818 Interface.encode = function(encoder, val) { 820 Interface.prototype.encode = function(encoder, val) {
819 encoder.encodeHandle(val); 821 var interfacePtrInfo =
820 // Set the version field to 0 for now. 822 val ? val.ptr.passInterface() : new InterfacePtrInfo(null, 0);
821 encoder.writeUint32(0); 823 encoder.encodeHandle(interfacePtrInfo.handle);
824 encoder.writeUint32(interfacePtrInfo.version);
822 }; 825 };
823 826
824 function NullableInterface() { 827 function NullableInterface(cls) {
828 Interface.call(this, cls);
825 } 829 }
826 830
827 NullableInterface.encodedSize = Interface.encodedSize; 831 NullableInterface.prototype = Object.create(Interface.prototype);
828 832
829 NullableInterface.decode = Interface.decode; 833 function InterfaceRequest() {
834 }
830 835
831 NullableInterface.encode = Interface.encode; 836 InterfaceRequest.encodedSize = 4;
837
838 InterfaceRequest.decode = function(decoder) {
839 return new types.InterfaceRequest(decoder.decodeHandle());
840 };
841
842 InterfaceRequest.encode = function(encoder, val) {
843 encoder.encodeHandle(val ? val.handle : null);
844 };
845
846 function NullableInterfaceRequest() {
847 }
848
849 NullableInterfaceRequest.encodedSize = InterfaceRequest.encodedSize;
850
851 NullableInterfaceRequest.decode = InterfaceRequest.decode;
852
853 NullableInterfaceRequest.encode = InterfaceRequest.encode;
832 854
833 function MapOf(keyClass, valueClass) { 855 function MapOf(keyClass, valueClass) {
834 this.keyClass = keyClass; 856 this.keyClass = keyClass;
835 this.valueClass = valueClass; 857 this.valueClass = valueClass;
836 } 858 }
837 859
838 MapOf.prototype.encodedSize = 8; 860 MapOf.prototype.encodedSize = 8;
839 861
840 MapOf.prototype.decode = function(decoder) { 862 MapOf.prototype.decode = function(decoder) {
841 return decoder.decodeMapPointer(this.keyClass, this.valueClass); 863 return decoder.decodeMapPointer(this.keyClass, this.valueClass);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 exports.NullableString = NullableString; 903 exports.NullableString = NullableString;
882 exports.PointerTo = PointerTo; 904 exports.PointerTo = PointerTo;
883 exports.NullablePointerTo = NullablePointerTo; 905 exports.NullablePointerTo = NullablePointerTo;
884 exports.ArrayOf = ArrayOf; 906 exports.ArrayOf = ArrayOf;
885 exports.NullableArrayOf = NullableArrayOf; 907 exports.NullableArrayOf = NullableArrayOf;
886 exports.PackedBool = PackedBool; 908 exports.PackedBool = PackedBool;
887 exports.Handle = Handle; 909 exports.Handle = Handle;
888 exports.NullableHandle = NullableHandle; 910 exports.NullableHandle = NullableHandle;
889 exports.Interface = Interface; 911 exports.Interface = Interface;
890 exports.NullableInterface = NullableInterface; 912 exports.NullableInterface = NullableInterface;
913 exports.InterfaceRequest = InterfaceRequest;
914 exports.NullableInterfaceRequest = NullableInterfaceRequest;
891 exports.MapOf = MapOf; 915 exports.MapOf = MapOf;
892 exports.NullableMapOf = NullableMapOf; 916 exports.NullableMapOf = NullableMapOf;
893 return exports; 917 return exports;
894 }); 918 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698