Skip to content

Commit

Permalink
vm: fixed Node 10 support being broken due to the usage of globalThis…
Browse files Browse the repository at this point in the history
… for browser detection
  • Loading branch information
holgerd77 committed Mar 16, 2021
1 parent eb08be9 commit da3a642
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/vm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)

- Fixes for [EIP2929](https://eips.ethereum.org/EIPS/eip-2929) (Gas cost increases for state access opcodes), PR [#1124](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1124)
- Integration of [EIP2718](https://eips.ethereum.org/EIPS/eip-2718) (Typed Transactions) and [EIP2930](https://eips.ethereum.org/EIPS/eip-2930) (Access List Transaction), PR [#1048](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1048). VM now has support for access list transactions.
- Fixes VM Node 10 support being broken due to the usage of `globalThis` for browser detection, PR [#1151](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1151)

**CI and Test Improvements**

Expand Down
10 changes: 5 additions & 5 deletions packages/vm/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import runBlockchain from './runBlockchain'
const AsyncEventEmitter = require('async-eventemitter')
const promisify = require('util.promisify')

// eslint-disable-next-line no-undef
const IS_BROWSER = typeof (<any>globalThis).window === 'object' // very ugly way to detect if we are running in a browser
// very ugly way to detect if we are running in a browser
const isBrowser = new Function('try {return this===window;}catch(e){ return false;}')
let mcl: any
let mclInitPromise: any

if (!IS_BROWSER) {
if (!isBrowser()) {
mcl = require('mcl-wasm')
mclInitPromise = mcl.init(mcl.BLS12_381)
}
Expand Down Expand Up @@ -218,7 +218,7 @@ export default class VM extends AsyncEventEmitter {
this._hardforkByBlockNumber = opts.hardforkByBlockNumber ?? false

if (this._common.isActivatedEIP(2537)) {
if (IS_BROWSER) {
if (isBrowser()) {
throw new Error('EIP-2537 is currently not supported in browsers')
} else {
this._mcl = mcl
Expand Down Expand Up @@ -252,7 +252,7 @@ export default class VM extends AsyncEventEmitter {
}

if (this._common.isActivatedEIP(2537)) {
if (IS_BROWSER) {
if (isBrowser()) {
throw new Error('EIP-2537 is currently not supported in browsers')
} else {
const mcl = this._mcl
Expand Down

0 comments on commit da3a642

Please sign in to comment.