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

Side by Side Diff: mojo/public/js/bindings/codec.js

Issue 247013008: Add support for Float/Double types for JS Mojo bindings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: M_PI not present on some of the windows platforms. Created 6 years, 8 months 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 | Annotate | Revision Log
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/bindings/codec", [ 5 define("mojo/public/js/bindings/codec", [
6 "mojo/public/js/bindings/unicode" 6 "mojo/public/js/bindings/unicode"
7 ], function(unicode) { 7 ], function(unicode) {
8 8
9 var kErrorUnsigned = "Passing negative value to unsigned"; 9 var kErrorUnsigned = "Passing negative value to unsigned";
10 10
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 return result; 171 return result;
172 }; 172 };
173 173
174 Decoder.prototype.readUint64 = function() { 174 Decoder.prototype.readUint64 = function() {
175 var result = getUint64( 175 var result = getUint64(
176 this.buffer.dataView, this.next, kHostIsLittleEndian); 176 this.buffer.dataView, this.next, kHostIsLittleEndian);
177 this.next += 8; 177 this.next += 8;
178 return result; 178 return result;
179 }; 179 };
180 180
181 Decoder.prototype.readFloat32 = function() { 181 Decoder.prototype.readFloat = function() {
182 var result = this.buffer.dataView.readFloat32( 182 var result = this.buffer.dataView.getFloat32(
183 this.next, kHostIsLittleEndian); 183 this.next, kHostIsLittleEndian);
184 this.next += 4; 184 this.next += 4;
185 return result; 185 return result;
186 }; 186 };
187 187
188 Decoder.prototype.readFloat64 = function() { 188 Decoder.prototype.readDouble = function() {
189 var result = this.buffer.dataView.readFloat64( 189 var result = this.buffer.dataView.getFloat64(
190 this.next, kHostIsLittleEndian); 190 this.next, kHostIsLittleEndian);
191 this.next += 8; 191 this.next += 8;
192 return result; 192 return result;
193 }; 193 };
194 194
195 Decoder.prototype.decodePointer = function() { 195 Decoder.prototype.decodePointer = function() {
196 // TODO(abarth): To correctly decode a pointer, we need to know the real 196 // TODO(abarth): To correctly decode a pointer, we need to know the real
197 // base address of the array buffer. 197 // base address of the array buffer.
198 var offsetPointer = this.next; 198 var offsetPointer = this.next;
199 var offset = this.readUint64(); 199 var offset = this.readUint64();
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 }; 301 };
302 302
303 Encoder.prototype.writeUint64 = function(val) { 303 Encoder.prototype.writeUint64 = function(val) {
304 if (val < 0) { 304 if (val < 0) {
305 throw new Error(kErrorUnsigned); 305 throw new Error(kErrorUnsigned);
306 } 306 }
307 setUint64(this.buffer.dataView, this.next, val); 307 setUint64(this.buffer.dataView, this.next, val);
308 this.next += 8; 308 this.next += 8;
309 }; 309 };
310 310
311 Encoder.prototype.writeFloat32 = function(val) { 311 Encoder.prototype.writeFloat = function(val) {
312 this.buffer.dataView.setFloat32(val, kHostIsLittleEndian); 312 this.buffer.dataView.setFloat32(this.next, val, kHostIsLittleEndian);
313 this.next += 4; 313 this.next += 4;
314 }; 314 };
315 315
316 Encoder.prototype.writeFloat64 = function(val) { 316 Encoder.prototype.writeDouble = function(val) {
317 this.buffer.dataView.setFloat64(val, kHostIsLittleEndian); 317 this.buffer.dataView.setFloat64(this.next, val, kHostIsLittleEndian);
318 this.next += 8; 318 this.next += 8;
319 }; 319 };
320 320
321 Encoder.prototype.encodePointer = function(pointer) { 321 Encoder.prototype.encodePointer = function(pointer) {
322 if (!pointer) 322 if (!pointer)
323 return this.writeUint64(0); 323 return this.writeUint64(0);
324 // TODO(abarth): To correctly encode a pointer, we need to know the real 324 // TODO(abarth): To correctly encode a pointer, we need to know the real
325 // base address of the array buffer. 325 // base address of the array buffer.
326 var offset = pointer - this.next; 326 var offset = pointer - this.next;
327 this.writeUint64(offset); 327 this.writeUint64(offset);
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 551
552 Uint32.decode = function(decoder) { 552 Uint32.decode = function(decoder) {
553 return decoder.readUint32(); 553 return decoder.readUint32();
554 }; 554 };
555 555
556 Uint32.encode = function(encoder, val) { 556 Uint32.encode = function(encoder, val) {
557 encoder.writeUint32(val); 557 encoder.writeUint32(val);
558 }; 558 };
559 559
560 function Int64() { 560 function Int64() {
561 }; 561 }
562 562
563 Int64.encodedSize = 8; 563 Int64.encodedSize = 8;
564 564
565 Int64.decode = function(decoder) { 565 Int64.decode = function(decoder) {
566 return decoder.readInt64(); 566 return decoder.readInt64();
567 }; 567 };
568 568
569 Int64.encode = function(encoder, val) { 569 Int64.encode = function(encoder, val) {
570 encoder.writeInt64(val); 570 encoder.writeInt64(val);
571 }; 571 };
572 572
573 function Uint64() { 573 function Uint64() {
574 }; 574 }
575 575
576 Uint64.encodedSize = 8; 576 Uint64.encodedSize = 8;
577 577
578 Uint64.decode = function(decoder) { 578 Uint64.decode = function(decoder) {
579 return decoder.readUint64(); 579 return decoder.readUint64();
580 }; 580 };
581 581
582 Uint64.encode = function(encoder, val) { 582 Uint64.encode = function(encoder, val) {
583 encoder.writeUint64(val); 583 encoder.writeUint64(val);
584 }; 584 };
585 585
586 // TODO(abarth): Add missing types:
587 // * String
588
589 function Float() {
590 }
591
592 Float.encodedSize = 4;
593
594 Float.decode = function(decoder) {
595 return decoder.readFloat();
596 };
597
598 Float.encode = function(encoder, val) {
599 encoder.writeFloat(val);
600 };
601
602 function Double() {
603 }
604
605 Double.encodedSize = 8;
606
607 Double.decode = function(decoder) {
608 return decoder.readDouble();
609 };
610
611 Double.encode = function(encoder, val) {
612 encoder.writeDouble(val);
613 };
614
586 function PointerTo(cls) { 615 function PointerTo(cls) {
587 this.cls = cls; 616 this.cls = cls;
588 }; 617 }
589
590 // TODO(abarth): Add missing types:
591 // * String
592 // * Float
593 // * Double
594 // * Signed integers
595 618
596 PointerTo.prototype.encodedSize = 8; 619 PointerTo.prototype.encodedSize = 8;
597 620
598 PointerTo.prototype.decode = function(decoder) { 621 PointerTo.prototype.decode = function(decoder) {
599 return this.cls.decode(decoder.decodeAndCreateDecoder()); 622 return this.cls.decode(decoder.decodeAndCreateDecoder());
600 }; 623 };
601 624
602 PointerTo.prototype.encode = function(encoder, val) { 625 PointerTo.prototype.encode = function(encoder, val) {
603 var objectEncoder = encoder.createAndEncodeEncoder(this.cls.encodedSize); 626 var objectEncoder = encoder.createAndEncodeEncoder(this.cls.encodedSize);
604 this.cls.encode(objectEncoder, val); 627 this.cls.encode(objectEncoder, val);
605 }; 628 };
606 629
607 function ArrayOf(cls) { 630 function ArrayOf(cls) {
608 this.cls = cls; 631 this.cls = cls;
609 }; 632 }
610 633
611 ArrayOf.prototype.encodedSize = 8; 634 ArrayOf.prototype.encodedSize = 8;
612 635
613 ArrayOf.prototype.decode = function(decoder) { 636 ArrayOf.prototype.decode = function(decoder) {
614 return decoder.decodeArrayPointer(self.cls); 637 return decoder.decodeArrayPointer(self.cls);
615 }; 638 };
616 639
617 ArrayOf.prototype.encode = function(encoder, val) { 640 ArrayOf.prototype.encode = function(encoder, val) {
618 encoder.encodeArrayPointer(self.cls, val); 641 encoder.encodeArrayPointer(self.cls, val);
619 }; 642 };
(...skipping 24 matching lines...) Expand all
644 exports.kMessageExpectsResponse = kMessageExpectsResponse; 667 exports.kMessageExpectsResponse = kMessageExpectsResponse;
645 exports.kMessageIsResponse = kMessageIsResponse; 668 exports.kMessageIsResponse = kMessageIsResponse;
646 exports.Int8 = Int8; 669 exports.Int8 = Int8;
647 exports.Uint8 = Uint8; 670 exports.Uint8 = Uint8;
648 exports.Int16 = Int16; 671 exports.Int16 = Int16;
649 exports.Uint16 = Uint16; 672 exports.Uint16 = Uint16;
650 exports.Int32 = Int32; 673 exports.Int32 = Int32;
651 exports.Uint32 = Uint32; 674 exports.Uint32 = Uint32;
652 exports.Int64 = Int64; 675 exports.Int64 = Int64;
653 exports.Uint64 = Uint64; 676 exports.Uint64 = Uint64;
677 exports.Float = Float;
678 exports.Double = Double;
654 exports.PointerTo = PointerTo; 679 exports.PointerTo = PointerTo;
655 exports.ArrayOf = ArrayOf; 680 exports.ArrayOf = ArrayOf;
656 exports.Handle = Handle; 681 exports.Handle = Handle;
657 return exports; 682 return exports;
658 }); 683 });
OLDNEW
« no previous file with comments | « content/test/data/web_ui_test_mojo_bindings.mojom ('k') | mojo/public/tools/bindings/generators/mojom_js_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698