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

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

Issue 798163002: Add failure messages to gin and js mojom encoder (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 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
« no previous file with comments | « gin/function_template.h ('k') | mojo/public/js/codec_unittests.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/unicode", 6 "mojo/public/js/unicode",
7 "mojo/public/js/buffer", 7 "mojo/public/js/buffer",
8 ], function(unicode, buffer) { 8 ], function(unicode, buffer) {
9 9
10 var kErrorUnsigned = "Passing negative value to unsigned"; 10 var kErrorUnsigned = "Passing negative value to unsigned";
11 var kErrorArray = "Passing non-array-like to array";
11 12
12 // Memory ------------------------------------------------------------------- 13 // Memory -------------------------------------------------------------------
13 14
14 var kAlignment = 8; 15 var kAlignment = 8;
15 16
16 function align(size) { 17 function align(size) {
17 return size + (kAlignment - (size % kAlignment)) % kAlignment; 18 return size + (kAlignment - (size % kAlignment)) % kAlignment;
18 } 19 }
19 20
20 function isAligned(offset) { 21 function isAligned(offset) {
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 var encoder = this.createAndEncodeEncoder(cls.encodedSize); 346 var encoder = this.createAndEncodeEncoder(cls.encodedSize);
346 cls.encode(encoder, val); 347 cls.encode(encoder, val);
347 }; 348 };
348 349
349 Encoder.prototype.encodeArrayPointer = function(cls, val) { 350 Encoder.prototype.encodeArrayPointer = function(cls, val) {
350 if (val == null) { 351 if (val == null) {
351 // Also handles undefined, since undefined == null. 352 // Also handles undefined, since undefined == null.
352 this.encodePointer(val); 353 this.encodePointer(val);
353 return; 354 return;
354 } 355 }
356 if (val.length === undefined) {
357 throw new Error(kErrorArray);
hansmuller 2014/12/15 16:56:17 I suppose another indication that val isn't an arr
358 }
355 var numberOfElements = val.length; 359 var numberOfElements = val.length;
356 var encodedSize = kArrayHeaderSize + ((cls === PackedBool) ? 360 var encodedSize = kArrayHeaderSize + ((cls === PackedBool) ?
357 Math.ceil(numberOfElements / 8) : cls.encodedSize * numberOfElements); 361 Math.ceil(numberOfElements / 8) : cls.encodedSize * numberOfElements);
358 var encoder = this.createAndEncodeEncoder(encodedSize); 362 var encoder = this.createAndEncodeEncoder(encodedSize);
359 encoder.encodeArray(cls, val, numberOfElements, encodedSize); 363 encoder.encodeArray(cls, val, numberOfElements, encodedSize);
360 }; 364 };
361 365
362 Encoder.prototype.encodeStringPointer = function(val) { 366 Encoder.prototype.encodeStringPointer = function(val) {
363 if (val == null) { 367 if (val == null) {
364 // Also handles undefined, since undefined == null. 368 // Also handles undefined, since undefined == null.
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 exports.NullablePointerTo = NullablePointerTo; 810 exports.NullablePointerTo = NullablePointerTo;
807 exports.ArrayOf = ArrayOf; 811 exports.ArrayOf = ArrayOf;
808 exports.NullableArrayOf = NullableArrayOf; 812 exports.NullableArrayOf = NullableArrayOf;
809 exports.PackedBool = PackedBool; 813 exports.PackedBool = PackedBool;
810 exports.Handle = Handle; 814 exports.Handle = Handle;
811 exports.NullableHandle = NullableHandle; 815 exports.NullableHandle = NullableHandle;
812 exports.MapOf = MapOf; 816 exports.MapOf = MapOf;
813 exports.NullableMapOf = NullableMapOf; 817 exports.NullableMapOf = NullableMapOf;
814 return exports; 818 return exports;
815 }); 819 });
OLDNEW
« no previous file with comments | « gin/function_template.h ('k') | mojo/public/js/codec_unittests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698