Browse Source

Source compatibility fixes.

cl-refactor
Gav Wood 11 years ago
parent
commit
dde54bf383
  1. 4
      eth/BigInteger.js
  2. 15
      eth/eth.js
  3. 12
      eth/ethString.js

4
eth/BigInteger.js

@ -53,7 +53,7 @@
}
if (text === "-0") text = "0";
text = text.toUpperCase();
var isValid = (base == 16 ? /^[0-9A-F]+$/ : /^[0-9]+$/).test(text);
var isValid = (base == 16 ? /^[0-9A-F]*$/ : /^[0-9]+$/).test(text);
if (!isValid) throw new Error("Invalid integer");
if (base == 16) {
var val = bigInt(0);
@ -335,7 +335,7 @@
str = str.slice(1);
}
if (!str.length) str = "0";
var s = first.sign === sign.positive ? "" : "-";
var s = (first.sign === sign.positive || str == "0") ? "" : "-";
return s + str;
},
toHex: function (m) {

15
eth/eth.js

@ -1,7 +1,18 @@
if (typeof(window.eth) === "undefined")
{
if (typeof(require) !== "undefined")
require( ['ethString'], function() {} )
else if (typeof(String.prototype.pad) === "undefined")
alert("You need to have included ethString.js for eth to work.")
{
var scriptTag = document.getElementsByTagName('script');
scriptTag = scriptTag[scriptTag.length - 1];
var scriptPath = scriptTag.src;
var path = scriptPath.substr(0, scriptPath.lastIndexOf( '/' ));
var start = '<script src="' + path + '/';
var slash = '"><'+'/script>';
document.write(start + 'BigInteger.js' + slash);
document.write(start + 'ethString.js' + slash);
}
var spec = [
{ "method": "coinbase", "params": null, "returns" : "" },
@ -108,3 +119,5 @@ window.eth = (function ethScope() {
return ret;
}());
}

12
eth/ethString.js

@ -29,9 +29,9 @@ String.prototype.bin = function() {
bytes = []
var i = 2;
// Check if it's odd - pad with a zero if so.
if (s.length % 2)
if (this.length % 2)
bytes.push(parseInt(this.substr(i++, 1), 16))
for (; i < s.length - 1; i += 2)
for (; i < this.length - 1; i += 2)
bytes.push(parseInt(this.substr(i, 2), 16));
return String.fromCharCode.apply(String, bytes);
} else if (/^\d+$/.test(this))
@ -51,4 +51,12 @@ String.prototype.unbin = function() {
return "0x" + o;
}
String.prototype.dec = function() {
return bigInt(this.substr(0)).toString()
}
String.prototype.hex = function() {
return bigInt(this).toHex()
}

Loading…
Cancel
Save