Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix usage of global object in browser environment #995

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/prelude.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
}

// Expose globally
var protobuf = global.protobuf = $require(entries[0]);
var protobuf = $require(entries[0]);
if (typeof global !== "undefined") {
global.protobuf = protobuf;
}

// Be nice to AMD
if (typeof define === "function" && define.amd)
Expand Down
4 changes: 2 additions & 2 deletions src/util/minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ util.emptyObject = Object.freeze ? Object.freeze({}) : /* istanbul ignore next *
* @type {boolean}
* @const
*/
util.isNode = Boolean(global.process && global.process.versions && global.process.versions.node);
util.isNode = Boolean(typeof global !== "undefined" && global.process && global.process.versions && global.process.versions.node);

/**
* Tests if the specified value is an integer.
Expand Down Expand Up @@ -164,7 +164,7 @@ util.Array = typeof Uint8Array !== "undefined" ? Uint8Array /* istanbul ignore n
* Long.js's Long class if available.
* @type {Constructor<Long>}
*/
util.Long = /* istanbul ignore next */ global.dcodeIO && /* istanbul ignore next */ global.dcodeIO.Long || util.inquire("long");
util.Long = /* istanbul ignore next */ typeof global !== "undefined" && /* istanbul ignore next */ global.dcodeIO && /* istanbul ignore next */ global.dcodeIO.Long || util.inquire("long");

/**
* Regular expression used to verify 2 bit (`bool`) map keys.
Expand Down