Promise for minixhr:

uiCheck
LianaHus 5 years ago
parent 18dde6ec1b
commit 9ad5e3dfa5
  1. 2
      src/app/compiler/compiler-sourceVerifier-fetchAndCompile.js
  2. 52
      src/app/compiler/compiler-utils.js
  3. 88
      src/app/tabs/compileTab/compilerContainer.js

@ -107,7 +107,7 @@ export default class FetchAndCompile extends Plugin {
version: data.metadata.compiler.version, version: data.metadata.compiler.version,
languageName: data.metadata.language, languageName: data.metadata.language,
evmVersion: data.metadata.settings.evmVersion, evmVersion: data.metadata.settings.evmVersion,
optimize: data.metadata.settings.optimizer.enabled, optimize: data.metadata.settings.optimizer.enabled
} }
try { try {
setTimeout(_ => this.emit('compiling', settings), 0) setTimeout(_ => this.emit('compiling', settings), 0)

@ -1,11 +1,13 @@
const semver = require('semver') const semver = require('semver')
const minixhr = require('minixhr')
/* global Worker */ /* global Worker */
export const baseURLBin = 'https://solc-bin.ethereum.org/bin' export const baseURLBin = 'https://solc-bin.ethereum.org/bin'
export const baseURLWasm = 'https://solc-bin.ethereum.org/wasm' export const baseURLWasm = 'https://solc-bin.ethereum.org/wasm'
export const pathToURL = [] export const pathToURL = {}
// retrieves the URL of the given compiler version
export function urlFromVersion (version) { export function urlFromVersion (version) {
return `${pathToURL[version]}/${version}` return `${pathToURL[version]}/${version}`
} }
@ -15,45 +17,23 @@ export function urlFromVersion (version) {
* checks a compiler whitelist, browser support and OS. * checks a compiler whitelist, browser support and OS.
*/ */
export function canUseWorker (selectedVersion) { export function canUseWorker (selectedVersion) {
// Following restrictions should be deleted when Solidity will release fixed versions of compilers.
// See https://github.com/ethereum/remix-ide/issues/2461
/* const isChrome = !!window.chrome
const os = retrieveOS()
// define a whitelist for Linux
const linuxWL = ['0.4.26', '0.5.3', '0.5.4', '0.5.5']
const version = semver.coerce(selectedVersion)
// defining whitelist for chrome
let isFromWhiteList = false
switch (os) {
case 'Windows':
isFromWhiteList = semver.gt(version, '0.5.2') || version === '0.4.26'
break
case 'Linux':
isFromWhiteList = semver.gt(version, '0.5.13') || linuxWL.includes(version)
break
default :
isFromWhiteList = true
} */
const version = semver.coerce(selectedVersion) const version = semver.coerce(selectedVersion)
const isNightly = selectedVersion.includes('nightly') const isNightly = selectedVersion.includes('nightly')
return browserSupportWorker() && return browserSupportWorker() && (
( semver.gt(version, '0.6.3') ||
semver.gt(version, '0.6.3') || semver.gt(version, '0.3.6') && !isNightly
semver.gt(version, '0.3.5') && !isNightly )
)
// && (!isChrome || (isChrome && isFromWhiteList))
} }
function browserSupportWorker () { function browserSupportWorker () {
return document.location.protocol !== 'file:' && Worker !== undefined return document.location.protocol !== 'file:' && Worker !== undefined
} }
/* function retrieveOS () { // returns a promice for minixhr
let osName = 'Unknown OS' export function promisedMiniXhr (url) {
if (navigator.platform.indexOf('Win') !== -1) { return new Promise((resolve, reject) => {
osName = 'Windows' minixhr(url, (json, event) => {
} else if (navigator.platform.indexOf('Linux') !== -1) { resolve({ json, event })
osName = 'Linux' })
} })
return osName }
} */

@ -1,12 +1,11 @@
const yo = require('yo-yo') const yo = require('yo-yo')
const minixhr = require('minixhr')
const helper = require('../../../lib/helper') const helper = require('../../../lib/helper')
const addTooltip = require('../../ui/tooltip') const addTooltip = require('../../ui/tooltip')
const semver = require('semver') const semver = require('semver')
const modalDialogCustom = require('../../ui/modal-dialog-custom') const modalDialogCustom = require('../../ui/modal-dialog-custom')
const css = require('../styles/compile-tab-styles') const css = require('../styles/compile-tab-styles')
import { canUseWorker, baseURLBin, baseURLWasm, urlFromVersion, pathToURL } from '../../compiler/compiler-utils' import { canUseWorker, baseURLBin, baseURLWasm, urlFromVersion, pathToURL, promisedMiniXhr } from '../../compiler/compiler-utils'
class CompilerContainer { class CompilerContainer {
@ -414,61 +413,42 @@ class CompilerContainer {
if (this._view.version) this._view.version.innerText = text if (this._view.version) this._view.version.innerText = text
} }
// fetching both normal and wasm builds and creating an array [version, baseUrl] // fetching both normal and wasm builds and creating a [version, baseUrl] map
fetchAllVersion (callback) { async fetchAllVersion (callback) {
let allVersions, selectedVersion, allVersionsWasm, urls let allVersions, selectedVersion, allVersionsWasm
// fetch normal builds // fetch normal builds
minixhr(`${this.data.baseURLBin}/list.json`, (json, event) => { const binRes = await promisedMiniXhr(`${this.data.baseURLBin}/list.json`)
// @TODO: optimise and cache results to improve app loading times #2461 // fetch wasm builds
if (event.type !== 'error') { const wasmRes = await promisedMiniXhr(`${this.data.baseURLWasm}/list.json`)
try { if (binRes.event.type === 'error' && wasmRes.event.type === 'error') {
const data = JSON.parse(json) allVersions = [{ path: 'builtin', longVersion: 'latest local version' }]
allVersions = data.builds.slice().reverse() selectedVersion = 'builtin'
selectedVersion = this.data.defaultVersion callback(allVersions, selectedVersion)
if (this.queryParams.get().version) selectedVersion = this.queryParams.get().version }
// no fetching wasm builds try {
minixhr(`${this.data.baseURLWasm}/list.json`, (json, event) => { allVersions = JSON.parse(binRes.json).builds.slice().reverse()
// @TODO: optimise and cache results to improve app loading times #2461 selectedVersion = this.data.defaultVersion
if (event.type !== 'error') { if (this.queryParams.get().version) selectedVersion = this.queryParams.get().version
try { if (wasmRes.event.type !== 'error') {
const data = JSON.parse(json) allVersionsWasm = JSON.parse(wasmRes.json).builds.slice().reverse()
allVersionsWasm = data.builds.slice().reverse()
//selectedVersion = this.data.defaultVersion
if (this.queryParams.get().version) selectedVersion = this.queryParams.get().version
// rewriting all versions in allVersions which exist in allVersionsWasm
if (allVersionsWasm && allVersions)
allVersions.forEach((compiler, index) => {
const rewritten = allVersionsWasm.findIndex(oldCompiler => { return oldCompiler.longVersion === compiler.longVersion })
if (-1 !== rewritten) {
allVersions[index] = allVersionsWasm[rewritten]
pathToURL[compiler.path] = baseURLWasm
} else {
pathToURL[compiler.path] = baseURLBin
}
})
callback(allVersions, selectedVersion)
} catch (e) {
addTooltip('Cannot load compiler version list. It might have been blocked by an advertisement blocker. Please try deactivating any of them from this page and reload.')
}
} else {
allVersionsWasm = [{ path: 'builtin', longVersion: 'latest local version' }]
selectedVersion = 'builtin'
}
//callback(allVersions, selectedVersion)
})
} catch (e) {
addTooltip('Cannot load compiler version list. It might have been blocked by an advertisement blocker. Please try deactivating any of them from this page and reload.')
}
} else {
allVersions = [{ path: 'builtin', longVersion: 'latest local version' }]
selectedVersion = 'builtin'
} }
//callback(allVersions, selectedVersion) } catch (e) {
}) addTooltip('Cannot load compiler version list. It might have been blocked by an advertisement blocker. Please try deactivating any of them from this page and reload. Error: ' + e)
}
// replace in allVersions those compiler builds which exist in allVersionsWasm with new once
if (allVersionsWasm && allVersions) {
allVersions.forEach((compiler, index) => {
const wasmIndex = allVersionsWasm.findIndex(wasmCompiler => { return wasmCompiler.longVersion === compiler.longVersion })
if (wasmIndex !== -1) {
allVersions[index] = allVersionsWasm[wasmIndex]
pathToURL[compiler.path] = baseURLWasm
} else {
pathToURL[compiler.path] = baseURLBin
}
})
}
callback(allVersions, selectedVersion)
} }
scheduleCompilation () { scheduleCompilation () {
if (!this.config.get('autoCompile')) return if (!this.config.get('autoCompile')) return
if (this.data.compileTimeout) window.clearTimeout(this.data.compileTimeout) if (this.data.compileTimeout) window.clearTimeout(this.data.compileTimeout)

Loading…
Cancel
Save