Fix #3773: Generated JS now avoids the flatbuffers object

This commit is contained in:
Evan Wallace
2016-02-25 01:06:16 -08:00
parent 959866b848
commit 31b30335f6
4 changed files with 98 additions and 21 deletions

View File

@@ -88,6 +88,16 @@ flatbuffers.Long = function(low, high) {
this.high = high | 0;
};
/**
* @param {number} high
* @param {number} low
* @returns {flatbuffers.Long}
*/
flatbuffers.Long.create = function(low, high) {
// Special-case zero to avoid GC overhead for default values
return low == 0 && high == 0 ? flatbuffers.Long.ZERO : new flatbuffers.Long(low, high);
};
/**
* @returns {number}
*/
@@ -751,6 +761,17 @@ flatbuffers.Builder.prototype.createString = function(s) {
}
return this.endVector();
};
/**
* A helper function to avoid generated code depending on this file directly.
*
* @param {number} low
* @param {number} high
* @returns {flatbuffers.Long}
*/
flatbuffers.Builder.prototype.createLong = function(low, high) {
return flatbuffers.Long.create(low, high);
};
////////////////////////////////////////////////////////////////////////////////
/// @cond FLATBUFFERS_INTERNAL
/**
@@ -1101,6 +1122,17 @@ flatbuffers.ByteBuffer.prototype.__has_identifier = function(ident) {
return true;
};
/**
* A helper function to avoid generated code depending on this file directly.
*
* @param {number} low
* @param {number} high
* @returns {flatbuffers.Long}
*/
flatbuffers.ByteBuffer.prototype.createLong = function(low, high) {
return flatbuffers.Long.create(low, high);
};
// Exports for Node.js and RequireJS
this.flatbuffers = flatbuffers;