diff options
author | Adam Cozzette <acozzette@google.com> | 2018-11-09 11:28:22 -0800 |
---|---|---|
committer | Adam Cozzette <acozzette@google.com> | 2018-11-09 11:28:22 -0800 |
commit | 0894e07536af88065d462cdc9d8e807c0723ef4d (patch) | |
tree | c36164c9042a389e481b3fd13d887ab1c65fe91f /js/message.js | |
parent | d52f2bb9e45f6f92743ef632add29f6b15832d3b (diff) | |
download | protobuf-0894e07536af88065d462cdc9d8e807c0723ef4d.tar.gz |
Integrated internal changes from Google
Diffstat (limited to 'js/message.js')
-rw-r--r-- | js/message.js | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/js/message.js b/js/message.js index 6a37745b1..17b562e16 100644 --- a/js/message.js +++ b/js/message.js @@ -427,6 +427,24 @@ jspb.Message.isArray_ = function(o) { goog.isArray(o); }; +/** + * Returns true if the provided argument is an extension object. + * @param {*} o The object to classify as array or not. + * @return {boolean} True if the provided object is an extension object. + * @private + */ +jspb.Message.isExtensionObject_ = function(o) { + // Normal fields are never objects, so we can be sure that if we find an + // object here, then it's the extension object. However, we must ensure that + // the object is not an array, since arrays are valid field values (bytes + // fields can also be array). + // NOTE(lukestebbing): We avoid looking at .length to avoid a JIT bug + // in Safari on iOS 8. See the description of CL/86511464 for details. + return (o !== null && typeof o == 'object' && + !jspb.Message.isArray_(o) && + !(jspb.Message.SUPPORTS_UINT8ARRAY_ && o instanceof Uint8Array)); +}; + /** * If the array contains an extension object in its last position, then the @@ -452,13 +470,7 @@ jspb.Message.initPivotAndExtensionObject_ = function(msg, suggestedPivot) { if (msgLength) { lastIndex = msgLength - 1; var obj = msg.array[lastIndex]; - // Normal fields are never objects, so we can be sure that if we find an - // object here, then it's the extension object. However, we must ensure that - // the object is not an array, since arrays are valid field values. - // NOTE(lukestebbing): We avoid looking at .length to avoid a JIT bug - // in Safari on iOS 8. See the description of CL/86511464 for details. - if (obj && typeof obj == 'object' && !jspb.Message.isArray_(obj) && - !(jspb.Message.SUPPORTS_UINT8ARRAY_ && obj instanceof Uint8Array)) { + if (jspb.Message.isExtensionObject_(obj)) { msg.pivot_ = jspb.Message.getFieldNumber_(msg, lastIndex); msg.extensionObject_ = obj; return; |