Last active
August 29, 2015 14:06
-
-
Save fwolff/4a82b9079c6f4a364d8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Spearal Offline Test</title> | |
<script src="traceur-runtime.js"></script> | |
<script src="spearal.js"></script> | |
<script type="text/javascript"> | |
var factory = new SpearalFactory(); | |
function encodeDecode(obj) { | |
var encoder = factory.newEncoder(); | |
encoder.writeAny(obj); | |
return factory.newDecoder(encoder.buffer).readAny(); | |
} | |
// Cyclic structure. | |
var selfish = {}; | |
selfish.friend = selfish; | |
console.log("Should be true: " + (selfish === selfish.friend)); | |
selfish = encodeDecode(selfish); | |
console.log("Should be true: " + (selfish === selfish.friend)); | |
// Shared instance. | |
var child = { age: 1 }; | |
var parents = [{ child: child }, { child: child }]; | |
parents[0].child.age = 2; | |
console.log("Should be 2: " + parents[1].child.age); | |
parents = encodeDecode(parents); | |
parents[0].child.age = 3; | |
console.log("Should be 3: " + parents[1].child.age); | |
// Class encoding. | |
function BourneIdentity(name) { | |
this.name = name; | |
} | |
var obj = new BourneIdentity("Jason"); | |
console.log("Should be a BourneIdentity: " + (obj instanceof BourneIdentity)); | |
obj = encodeDecode(obj); | |
console.log("Should be a BourneIdentity: " + (obj instanceof BourneIdentity)); | |
// Date encoding. | |
var date = new Date() | |
console.log("Should be a Date: " + (date instanceof Date)); | |
date = encodeDecode(date); | |
console.log("Should be a Date: " + (date instanceof Date)); | |
</script> | |
</head> | |
<body> | |
<h1>Spearal Offline Test</h1> | |
<p>Open your browser JavaScript console to see results.</p> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Spearal = function Spearal() { | |
"use strict"; | |
}; | |
($traceurRuntime.createClass)(Spearal, {}, { | |
get APPLICATION_SPEARAL() { | |
"use strict"; | |
return "application/spearal"; | |
}, | |
get PROPERTY_FILTER_HEADER() { | |
"use strict"; | |
return "Spearal-PropertyFilter"; | |
} | |
}); | |
var SpearalBigNumber = function SpearalBigNumber() { | |
"use strict"; | |
}; | |
($traceurRuntime.createClass)(SpearalBigNumber, {}, { | |
charAt: function(index) { | |
"use strict"; | |
var c = "0123456789+-.E".charAt(index); | |
if (c === "") | |
throw "Illegal big number digit index: " + index; | |
return c; | |
}, | |
indexOf: function(charCode) { | |
"use strict"; | |
switch (charCode) { | |
case 0x30: | |
return 0; | |
case 0x31: | |
return 1; | |
case 0x32: | |
return 2; | |
case 0x33: | |
return 3; | |
case 0x34: | |
return 4; | |
case 0x35: | |
return 5; | |
case 0x36: | |
return 6; | |
case 0x37: | |
return 7; | |
case 0x38: | |
return 8; | |
case 0x39: | |
return 9; | |
case 0x2b: | |
return 10; | |
case 0x2d: | |
return 11; | |
case 0x2e: | |
return 12; | |
case 0x45: | |
case 0x65: | |
return 13; | |
default: | |
throw "Illegal big number digit code: " + charCode; | |
} | |
} | |
}); | |
var SpearalType = function SpearalType() { | |
"use strict"; | |
}; | |
($traceurRuntime.createClass)(SpearalType, {}, { | |
get NULL() { | |
"use strict"; | |
return 0x00; | |
}, | |
get TRUE() { | |
"use strict"; | |
return 0x01; | |
}, | |
get FALSE() { | |
"use strict"; | |
return 0x02; | |
}, | |
get INTEGRAL() { | |
"use strict"; | |
return 0x10; | |
}, | |
get BIG_INTEGRAL() { | |
"use strict"; | |
return 0x20; | |
}, | |
get FLOATING() { | |
"use strict"; | |
return 0x30; | |
}, | |
get BIG_FLOATING() { | |
"use strict"; | |
return 0x40; | |
}, | |
get STRING() { | |
"use strict"; | |
return 0x50; | |
}, | |
get BYTE_ARRAY() { | |
"use strict"; | |
return 0x60; | |
}, | |
get DATE_TIME() { | |
"use strict"; | |
return 0x70; | |
}, | |
get COLLECTION() { | |
"use strict"; | |
return 0x80; | |
}, | |
get MAP() { | |
"use strict"; | |
return 0x90; | |
}, | |
get ENUM() { | |
"use strict"; | |
return 0xa0; | |
}, | |
get CLASS() { | |
"use strict"; | |
return 0xb0; | |
}, | |
get BEAN() { | |
"use strict"; | |
return 0xc0; | |
}, | |
typeOf: function(parameterizedType) { | |
"use strict"; | |
if (parameterizedType < 0x10) | |
return parameterizedType; | |
return (parameterizedType & 0xf0); | |
} | |
}); | |
var _SpearalClassDescriptor = function _SpearalClassDescriptor(className, propertyNames) { | |
"use strict"; | |
this.className = className; | |
this.propertyNames = propertyNames; | |
}; | |
var $_SpearalClassDescriptor = _SpearalClassDescriptor; | |
($traceurRuntime.createClass)(_SpearalClassDescriptor, {get description() { | |
"use strict"; | |
return this.className + '#' + this.propertyNames.join(','); | |
}}, {forDescription: function(description) { | |
"use strict"; | |
var classProperties = description.split('#'); | |
return new $_SpearalClassDescriptor(classProperties[0], classProperties[1].split(',')); | |
}}); | |
var SpearalContext = function SpearalContext() { | |
"use strict"; | |
this._configurables = []; | |
this._encodersCache = new Map(); | |
this._decodersCache = new Map(); | |
}; | |
($traceurRuntime.createClass)(SpearalContext, { | |
get configurables() { | |
"use strict"; | |
return this._configurables; | |
}, | |
normalize: function(value) { | |
"use strict"; | |
return value; | |
}, | |
_findConfigurable: function(name) { | |
"use strict"; | |
var param = arguments[1]; | |
for (var $__2 = this._configurables[$traceurRuntime.toProperty(Symbol.iterator)](), | |
$__3; !($__3 = $__2.next()).done; ) { | |
var configurable = $__3.value; | |
{ | |
var configurableFunction = configurable[$traceurRuntime.toProperty(name)]; | |
if (configurableFunction !== undefined) { | |
if (param !== undefined) | |
configurableFunction = configurableFunction(param); | |
if (configurableFunction !== undefined) | |
return configurableFunction; | |
} | |
} | |
} | |
}, | |
getDescriptor: function(value) { | |
"use strict"; | |
var filter = arguments[1] !== (void 0) ? arguments[1] : null; | |
if (this._descriptor == null) { | |
if ((this._descriptor = this._findConfigurable('descriptor')) == null) | |
throw "No descriptor for value: " + value; | |
} | |
return this._descriptor(value, filter); | |
}, | |
getEncoder: function(value) { | |
"use strict"; | |
var type = value.constructor, | |
encoder = this._encodersCache.get(type); | |
if (encoder == null) { | |
if ((encoder = this._findConfigurable('encoder', value)) == null) | |
throw "No encoder for type: " + value; | |
this._encodersCache.set(type, encoder); | |
} | |
return encoder; | |
}, | |
getInstance: function(descriptor) { | |
"use strict"; | |
if (this._instantiator == null) { | |
if ((this._instantiator = this._findConfigurable('instantiator')) == null) | |
throw "No instantiator for value: " + value; | |
} | |
return this._instantiator(descriptor); | |
}, | |
getDecoder: function(type) { | |
"use strict"; | |
var decoder = this._decodersCache.get(type); | |
if (decoder == null) { | |
if ((decoder = this._findConfigurable('decoder', type)) == null) | |
throw "No decoder for type: " + type; | |
this._decodersCache.set(type, decoder); | |
} | |
return decoder; | |
} | |
}, {}); | |
var _SpearalEncoderBuffer = function _SpearalEncoderBuffer() { | |
"use strict"; | |
var blockSize = arguments[0] !== (void 0) ? arguments[0] : 128; | |
this._view = new DataView(new ArrayBuffer(blockSize)); | |
this._blockSize = blockSize; | |
this._size = 0; | |
}; | |
($traceurRuntime.createClass)(_SpearalEncoderBuffer, { | |
get size() { | |
"use strict"; | |
return this._size; | |
}, | |
getBuffer: function() { | |
"use strict"; | |
var trim = arguments[0] !== (void 0) ? arguments[0] : true; | |
if (!trim || this._size === this._view.buffer.byteLength) | |
return this._view.buffer; | |
return this._view.buffer.slice(0, this._size); | |
}, | |
writeUint8: function(value) { | |
"use strict"; | |
this._ensureCapacity(1); | |
this._view.setUint8(this._size++, value); | |
}, | |
writeUintN: function(value, length0) { | |
"use strict"; | |
if (length0 < 0 || length0 > 3) | |
throw "Illegal length0: " + length0; | |
this._ensureCapacity(length0 + 1); | |
switch (length0) { | |
case 3: | |
this._view.setUint32(this._size, value); | |
this._size += 4; | |
break; | |
case 2: | |
this._view.setUint8(this._size++, value >>> 16); | |
case 1: | |
this._view.setUint16(this._size, value); | |
this._size += 2; | |
break; | |
case 0: | |
this._view.setUint8(this._size++, value); | |
break; | |
} | |
}, | |
writeFloat64: function(value) { | |
"use strict"; | |
this._ensureCapacity(8); | |
this._view.setFloat64(this._size, value); | |
this._size += 8; | |
}, | |
writeUTF: function(utf) { | |
"use strict"; | |
this._ensureCapacity(utf.length); | |
for (var i = 0; i < utf.length; i++) | |
this._view.setUint8(this._size++, utf.charCodeAt(i)); | |
}, | |
writeByteArray: function(buffer) { | |
"use strict"; | |
this._ensureCapacity(buffer.byteLength); | |
new Uint8Array(this._view.buffer, this._size).set(new Uint8Array(buffer)); | |
this._size += buffer.byteLength; | |
}, | |
_ensureCapacity: function(length) { | |
"use strict"; | |
if (this._view.buffer.byteLength - this._size < length) { | |
var newCapacity = (this._view.buffer.byteLength + (((length / this._blockSize) | 0) * this._blockSize) + this._blockSize); | |
var tmp = new Uint8Array(newCapacity); | |
tmp.set(new Uint8Array(this._view.buffer), 0, this._size); | |
this._view = new DataView(tmp.buffer); | |
} | |
} | |
}, {}); | |
var _IndexedMap = function _IndexedMap(iterable) { | |
"use strict"; | |
$traceurRuntime.superCall(this, $_IndexedMap.prototype, "constructor", [iterable]); | |
}; | |
var $_IndexedMap = _IndexedMap; | |
($traceurRuntime.createClass)(_IndexedMap, {setIfAbsent: function(key) { | |
"use strict"; | |
var index = this.get(key); | |
if (index !== undefined) | |
return index; | |
this.set(key, this.size); | |
}}, {}, Map); | |
var SpearalPropertyFilter = function SpearalPropertyFilter() { | |
"use strict"; | |
this._filters = new Map(); | |
}; | |
($traceurRuntime.createClass)(SpearalPropertyFilter, { | |
set: function(className) { | |
"use strict"; | |
for (var propertyNames = [], | |
$__7 = 1; $__7 < arguments.length; $__7++) | |
$traceurRuntime.setProperty(propertyNames, $__7 - 1, arguments[$traceurRuntime.toProperty($__7)]); | |
if (!(propertyNames instanceof Set)) | |
propertyNames = new Set(propertyNames); | |
this._filters.set(className, propertyNames); | |
}, | |
get: function(className) { | |
"use strict"; | |
return this._filters.get(className); | |
} | |
}, {}); | |
SpearalPropertyFilter.ACCEPT_ALL = {has: function(value) { | |
return true; | |
}}; | |
var SpearalEncoder = function SpearalEncoder(context, filter) { | |
"use strict"; | |
if (!(context instanceof SpearalContext)) | |
throw "Parameter 'context' must be a SpearalContext instance: " + context; | |
if (filter != null && !(filter instanceof SpearalPropertyFilter)) | |
throw "Parameter 'filter' must be a SpearalPropertyFilter instance: " + filter; | |
this._context = context; | |
this._filter = (filter != null ? filter : new SpearalPropertyFilter()); | |
this._buffer = new _SpearalEncoderBuffer(); | |
this._sharedStrings = new _IndexedMap(); | |
this._sharedObjects = new _IndexedMap(); | |
}; | |
var $SpearalEncoder = SpearalEncoder; | |
($traceurRuntime.createClass)(SpearalEncoder, { | |
get context() { | |
"use strict"; | |
return this._context; | |
}, | |
get filter() { | |
"use strict"; | |
return this._filter; | |
}, | |
get buffer() { | |
"use strict"; | |
return this._buffer.getBuffer(); | |
}, | |
writeAny: function(value) { | |
"use strict"; | |
value = this._context.normalize(value); | |
if (value == null) | |
this.writeNull(); | |
else | |
this._context.getEncoder(value)(this, value); | |
}, | |
writeNull: function() { | |
"use strict"; | |
this._buffer.writeUint8(SpearalType.NULL); | |
}, | |
writeBoolean: function(value) { | |
"use strict"; | |
this._buffer.writeUint8(value ? SpearalType.TRUE : SpearalType.FALSE); | |
}, | |
writeIntegral: function(value) { | |
"use strict"; | |
var inverse = 0x00; | |
if (value < 0) { | |
value = -value; | |
inverse = 0x08; | |
} | |
if (value <= 0xffffffff) | |
this._writeTypeUintN(SpearalType.INTEGRAL | inverse, value); | |
else { | |
var high32 = ((value / 0x100000000) | 0x00), | |
length0 = $SpearalEncoder._unsignedIntLength0(high32); | |
this._buffer.writeUint8(SpearalType.INTEGRAL | inverse | (length0 + 4)); | |
this._buffer.writeUintN(high32, length0); | |
this._buffer.writeUintN(value & 0xffffffff, 3); | |
} | |
}, | |
writeBigIntegral: function(value) { | |
"use strict"; | |
this._writeBigNumberData(SpearalType.BIG_INTEGRAL, this._exponentize(value)); | |
}, | |
writeFloating: function(value) { | |
"use strict"; | |
if (Number.isFinite(value) && !(value === 0 && (1 / value) === Number.NEGATIVE_INFINITY)) { | |
if (Number.isInteger(value)) { | |
if (value >= -0x00ffffffffffffff && value <= 0x00ffffffffffffff) { | |
this.writeIntegral(value); | |
return; | |
} | |
} else { | |
var value1K = value * 1000.0; | |
if (Number.isInteger(value1K) && (value === (value1K / 1000.0) || value === ((value1K += (value1K < 0 ? -1 : 1)) / 1000.0)) && value1K >= -0xffffffff && value1K <= 0xffffffff) { | |
var inverse = 0x00; | |
if (value1K < 0) { | |
value1K = -value1K; | |
inverse = 0x04; | |
} | |
this._writeTypeUintN(SpearalType.FLOATING | 0x08 | inverse, value1K); | |
return; | |
} | |
} | |
} | |
this._buffer.writeUint8(SpearalType.FLOATING); | |
this._buffer.writeFloat64(value); | |
}, | |
writeBigFloating: function(value) { | |
"use strict"; | |
this._writeBigNumberData(SpearalType.BIG_FLOATING, value); | |
}, | |
writeString: function(value) { | |
"use strict"; | |
this._writeStringData(SpearalType.STRING, value); | |
}, | |
writeByteArray: function(value) { | |
"use strict"; | |
if (!this._setAndWriteObjectReference(SpearalType.BYTE_ARRAY, value)) { | |
this._writeTypeUintN(SpearalType.BYTE_ARRAY, value.byteLength); | |
this._buffer.writeByteArray(value); | |
} | |
}, | |
writeDateTime: function(value) { | |
"use strict"; | |
if (Number.isNaN(value.getTime())) { | |
this.writeNull(); | |
return; | |
} | |
var year = value.getUTCFullYear() - 2000, | |
millis = value.getUTCMilliseconds(); | |
this._buffer.writeUint8(SpearalType.DATE_TIME | 0x0C | (millis !== 0 ? 0x03 : 0x00)); | |
var inverse = 0x00; | |
if (year < 0) { | |
inverse = 0x80; | |
year = -year; | |
} | |
var length0 = $SpearalEncoder._unsignedIntLength0(year); | |
this._buffer.writeUint8(inverse | (length0 << 4) | (value.getUTCMonth() + 1)); | |
this._buffer.writeUint8(value.getUTCDate()); | |
this._buffer.writeUintN(year, length0); | |
if (millis === 0) { | |
this._buffer.writeUint8(value.getUTCHours()); | |
this._buffer.writeUint8(value.getUTCMinutes()); | |
this._buffer.writeUint8(value.getUTCSeconds()); | |
} else { | |
length0 = $SpearalEncoder._unsignedIntLength0(millis); | |
this._buffer.writeUint8((length0 << 5) | value.getUTCHours()); | |
this._buffer.writeUint8(value.getUTCMinutes()); | |
this._buffer.writeUint8(value.getUTCSeconds()); | |
this._buffer.writeUintN(millis, length0); | |
} | |
}, | |
writeCollection: function(value) { | |
"use strict"; | |
if (!this._setAndWriteObjectReference(SpearalType.COLLECTION, value)) { | |
var size = (value instanceof Set ? value.size : value.length); | |
this._writeTypeUintN(SpearalType.COLLECTION, size); | |
for (var $__5 = value[$traceurRuntime.toProperty(Symbol.iterator)](), | |
$__6; !($__6 = $__5.next()).done; ) { | |
var item = $__6.value; | |
this.writeAny(item); | |
} | |
} | |
}, | |
writeMap: function(value) { | |
"use strict"; | |
if (!this._setAndWriteObjectReference(SpearalType.MAP, value)) { | |
this._writeTypeUintN(SpearalType.MAP, value.size); | |
for (var $__5 = value[$traceurRuntime.toProperty(Symbol.iterator)](), | |
$__6; !($__6 = $__5.next()).done; ) { | |
var $__8 = $__6.value, | |
key = $__8[0], | |
val = $__8[1]; | |
{ | |
this.writeAny(key); | |
this.writeAny(val); | |
} | |
} | |
} | |
}, | |
writeEnum: function(kind, name) { | |
"use strict"; | |
this._writeStringData(SpearalType.ENUM, kind); | |
this.writeString(name); | |
}, | |
writeClass: function(value) { | |
"use strict"; | |
this._writeStringData(SpearalType.CLASS, value.name); | |
}, | |
writeBean: function(value) { | |
"use strict"; | |
if (!this._setAndWriteObjectReference(SpearalType.BEAN, value)) { | |
var descriptor = this._context.getDescriptor(value, this._filter); | |
this._writeStringData(SpearalType.BEAN, descriptor.description); | |
for (var $__5 = descriptor.propertyNames[$traceurRuntime.toProperty(Symbol.iterator)](), | |
$__6; !($__6 = $__5.next()).done; ) { | |
var name = $__6.value; | |
this.writeAny(value[$traceurRuntime.toProperty(name)]); | |
} | |
} | |
}, | |
_writeStringData: function(type, value) { | |
"use strict"; | |
if (value.length === 0) { | |
this._buffer.writeUint8(type); | |
this._buffer.writeUint8(0); | |
return; | |
} | |
if (!this._setAndWriteStringReference(type, value)) { | |
value = unescape(encodeURIComponent(value)); | |
this._writeTypeUintN(type, value.length); | |
this._buffer.writeUTF(value); | |
} | |
}, | |
_exponentize: function(value) { | |
"use strict"; | |
var length = value.length; | |
if (length > 3) { | |
var trailingZeros = 0; | |
for (var i = length - 1; i > 0 && value.charAt(i) == '0'; i--) | |
trailingZeros++; | |
if (trailingZeros > 2) | |
value = value.substring(0, length - trailingZeros) + "E" + trailingZeros; | |
} | |
return value; | |
}, | |
_writeBigNumberData: function(type, value) { | |
"use strict"; | |
if (!this._setAndWriteStringReference(type, value)) { | |
var length = value.length; | |
this._writeTypeUintN(type, length); | |
for (var i = 0; i < length; ) { | |
var b = (SpearalBigNumber.indexOf(value.charCodeAt(i++)) << 4); | |
if (i < length) | |
b |= SpearalBigNumber.indexOf(value.charCodeAt(i++)); | |
this._buffer.writeUint8(b); | |
} | |
} | |
}, | |
_setAndWriteObjectReference: function(type, value) { | |
"use strict"; | |
var index = this._sharedObjects.setIfAbsent(value); | |
if (index !== undefined) { | |
this._writeTypeUintN(type | 0x08, index); | |
return true; | |
} | |
return false; | |
}, | |
_setAndWriteStringReference: function(type, value) { | |
"use strict"; | |
var index = this._sharedStrings.setIfAbsent(value); | |
if (index !== undefined) { | |
this._writeTypeUintN(type | 0x04, index); | |
return true; | |
} | |
return false; | |
}, | |
_writeTypeUintN: function(type, value) { | |
"use strict"; | |
var length0 = $SpearalEncoder._unsignedIntLength0(value); | |
this._buffer.writeUint8(type | length0); | |
this._buffer.writeUintN(value, length0); | |
} | |
}, {_unsignedIntLength0: function(value) { | |
"use strict"; | |
if (value <= 0xffff) | |
return (value <= 0xff ? 0 : 1); | |
return (value <= 0xffffff ? 2 : 3); | |
}}); | |
var _SpearalDecoderBuffer = function _SpearalDecoderBuffer(arrayBuffer) { | |
"use strict"; | |
this._view = new DataView(arrayBuffer); | |
this._pos = 0; | |
}; | |
($traceurRuntime.createClass)(_SpearalDecoderBuffer, { | |
readUint8: function() { | |
"use strict"; | |
try { | |
return this._view.getUint8(this._pos++); | |
} catch (e) { | |
throw "EOF: " + e; | |
} | |
}, | |
readUintN: function(length0) { | |
"use strict"; | |
if (length0 < 0 || length0 > 3) | |
throw "Illegal length0: " + length0; | |
try { | |
var value = 0; | |
switch (length0) { | |
case 3: | |
value = this._view.getUint32(this._pos); | |
this._pos += 4; | |
break; | |
case 2: | |
value = this._view.getUint8(this._pos++) << 16; | |
case 1: | |
value |= this._view.getUint16(this._pos); | |
this._pos += 2; | |
break; | |
case 0: | |
value = this._view.getUint8(this._pos++); | |
break; | |
} | |
return value; | |
} catch (e) { | |
throw "EOF: " + e; | |
} | |
}, | |
readFloat64: function() { | |
"use strict"; | |
try { | |
var value = this._view.getFloat64(this._pos); | |
this._pos += 8; | |
return value; | |
} catch (e) { | |
throw "EOF: " + e; | |
} | |
}, | |
readUTF: function(length) { | |
"use strict"; | |
try { | |
var utf = String.fromCharCode.apply(null, new Uint8Array(this._view.buffer, this._pos, length)); | |
this._pos += length; | |
return utf; | |
} catch (e) { | |
throw "EOF: " + e; | |
} | |
}, | |
readByteArray: function(length) { | |
"use strict"; | |
if (!length) | |
return new ArrayBuffer(0); | |
var end = this._pos + length; | |
if (end > this._view.buffer.byteLength) | |
throw "EOF: cannot read " + length + " bytes"; | |
var array = this._view.buffer.slice(this._pos, end); | |
this._pos = end; | |
return array; | |
} | |
}, {}); | |
var SpearalDecoder = function SpearalDecoder(context, buffer) { | |
"use strict"; | |
if (!(context instanceof SpearalContext)) | |
throw "Parameter 'context' must be a SpearalContext"; | |
if (!(buffer instanceof ArrayBuffer)) | |
throw "Parameter 'buffer' must be an ArrayBuffer"; | |
this._context = context; | |
this._buffer = new _SpearalDecoderBuffer(buffer); | |
this._sharedStrings = []; | |
this._sharedObjects = []; | |
}; | |
var $SpearalDecoder = SpearalDecoder; | |
($traceurRuntime.createClass)(SpearalDecoder, { | |
readAny: function() { | |
"use strict"; | |
return this._readAny(this._buffer.readUint8()); | |
}, | |
_readAny: function(parameterizedType) { | |
"use strict"; | |
var type = SpearalType.typeOf(parameterizedType), | |
value = null; | |
switch (type) { | |
case SpearalType.NULL: | |
value = null; | |
break; | |
case SpearalType.TRUE: | |
value = true; | |
break; | |
case SpearalType.FALSE: | |
value = false; | |
break; | |
case SpearalType.INTEGRAL: | |
value = this._readIntegral(parameterizedType); | |
break; | |
case SpearalType.BIG_INTEGRAL: | |
value = this._readBigIntegral(parameterizedType); | |
break; | |
case SpearalType.FLOATING: | |
value = this._readFloating(parameterizedType); | |
break; | |
case SpearalType.BIG_FLOATING: | |
value = this._readBigFloating(parameterizedType); | |
break; | |
case SpearalType.STRING: | |
value = this._readString(parameterizedType); | |
break; | |
case SpearalType.BYTE_ARRAY: | |
value = this._readByteArray(parameterizedType); | |
break; | |
case SpearalType.DATE_TIME: | |
value = this._readDateTime(parameterizedType); | |
break; | |
case SpearalType.COLLECTION: | |
value = this._readCollection(parameterizedType); | |
break; | |
case SpearalType.MAP: | |
value = this._readMap(parameterizedType); | |
break; | |
case SpearalType.ENUM: | |
value = this._readEnum(parameterizedType); | |
break; | |
case SpearalType.CLASS: | |
value = this._readClass(parameterizedType); | |
break; | |
case SpearalType.BEAN: | |
value = this._readBean(parameterizedType); | |
break; | |
default: | |
throw new "Unknown data type: " + parameterizedType + "/" + SpearalType.typeOf(parameterizedType); | |
} | |
return this._context.getDecoder(type)(value); | |
}, | |
_readIntegral: function(parameterizedType) { | |
"use strict"; | |
var length0 = (parameterizedType & 0x07), | |
value; | |
if (length0 <= 3) | |
value = this._buffer.readUintN(length0); | |
else | |
value = (this._buffer.readUintN(3) * Math.pow(256, length0 - 3)) + this._buffer.readUintN(length0 - 4); | |
return (((parameterizedType & 0x08) !== 0) ? -value : value); | |
}, | |
_readBigIntegral: function(parameterizedType) { | |
"use strict"; | |
var indexOrLength = this._readIndexOrLength(parameterizedType); | |
if ($SpearalDecoder._isStringReference(parameterizedType)) | |
return this._sharedStrings[$traceurRuntime.toProperty(indexOrLength)]; | |
var value = this._readBigNumberData(indexOrLength), | |
iExp = value.indexOf('E'); | |
if (iExp === -1) | |
return value; | |
var zeros = parseInt(value.substr(iExp + 1)); | |
value = value.substring(0, iExp); | |
for (var i = 0; i < zeros; i++) | |
value += '0'; | |
return value; | |
}, | |
_readFloating: function(parameterizedType) { | |
"use strict"; | |
if ((parameterizedType & 0x08) === 0) | |
return this._buffer.readFloat64(); | |
var v = this._buffer.readUintN(parameterizedType & 0x03); | |
if ((parameterizedType & 0x04) !== 0) | |
v = -v; | |
return (v / 1000.0); | |
}, | |
_readBigFloating: function(parameterizedType) { | |
"use strict"; | |
var indexOrLength = this._readIndexOrLength(parameterizedType); | |
if ($SpearalDecoder._isStringReference(parameterizedType)) | |
return this._sharedStrings[$traceurRuntime.toProperty(indexOrLength)]; | |
return this._readBigNumberData(indexOrLength); | |
}, | |
_readString: function(parameterizedType) { | |
"use strict"; | |
var indexOrLength = this._readIndexOrLength(parameterizedType); | |
return this._readStringData(parameterizedType, indexOrLength); | |
}, | |
_readByteArray: function(parameterizedType) { | |
"use strict"; | |
var indexOrLength = this._readIndexOrLength(parameterizedType); | |
if ($SpearalDecoder._isObjectReference(parameterizedType)) | |
return this._sharedObjects[$traceurRuntime.toProperty(indexOrLength)]; | |
var array = this._buffer.readByteArray(indexOrLength); | |
this._sharedObjects.push(array); | |
return array; | |
}, | |
_readDateTime: function(parameterizedType) { | |
"use strict"; | |
var hasDate = ((parameterizedType & 0x08) != 0), | |
hasTime = ((parameterizedType & 0x04) != 0), | |
year = 0, | |
month = 0, | |
date = 0, | |
hours = 0, | |
minutes = 0, | |
seconds = 0, | |
millis = 0, | |
subsecondsType; | |
if (hasDate) { | |
month = this._buffer.readUint8(); | |
date = this._buffer.readUint8(); | |
year = this._buffer.readUintN((month >>> 4) & 0x03); | |
if ((month & 0x80) != 0) | |
year = -year; | |
year += 2000; | |
month &= 0x0f; | |
month--; | |
} | |
if (hasTime) { | |
hours = this._buffer.readUint8(); | |
minutes = this._buffer.readUint8(); | |
seconds = this._buffer.readUint8(); | |
subsecondsType = (parameterizedType & 0x03); | |
if (subsecondsType !== 0) { | |
millis = this._buffer.readUintN(hours >>> 5); | |
if (subsecondsType === 1) | |
millis /= 1000000; | |
else if (subsecondsType === 2) | |
millis /= 1000; | |
} | |
hours &= 0x1f; | |
} | |
return new Date(Date.UTC(year, month, date, hours, minutes, seconds, millis)); | |
}, | |
_readCollection: function(parameterizedType) { | |
"use strict"; | |
var indexOrLength = this._readIndexOrLength(parameterizedType); | |
if ($SpearalDecoder._isObjectReference(parameterizedType)) | |
return this._sharedObjects[$traceurRuntime.toProperty(indexOrLength)]; | |
var value = new Array(indexOrLength); | |
this._sharedObjects.push(value); | |
for (var i = 0; i < indexOrLength; i++) | |
$traceurRuntime.setProperty(value, i, this.readAny()); | |
return value; | |
}, | |
_readMap: function(parameterizedType) { | |
"use strict"; | |
var indexOrLength = this._readIndexOrLength(parameterizedType); | |
if ($SpearalDecoder._isObjectReference(parameterizedType)) | |
return this._sharedObjects[$traceurRuntime.toProperty(indexOrLength)]; | |
var value = new Map(); | |
this._sharedObjects.push(value); | |
for (var i = 0; i < indexOrLength; i++) { | |
var key = this.readAny(); | |
var val = this.readAny(); | |
value.set(key, val); | |
} | |
return value; | |
}, | |
_readEnum: function(parameterizedType) { | |
"use strict"; | |
return { | |
kind: this._readString(parameterizedType), | |
name: this.readAny() | |
}; | |
}, | |
_readClass: function(parameterizedType) { | |
"use strict"; | |
var className = this._readString(parameterizedType), | |
cls = window[$traceurRuntime.toProperty(className)]; | |
return (cls != null ? cls : className); | |
}, | |
_readBean: function(parameterizedType) { | |
"use strict"; | |
var indexOrLength = this._readIndexOrLength(parameterizedType); | |
if ($SpearalDecoder._isObjectReference(parameterizedType)) | |
return this._sharedObjects[$traceurRuntime.toProperty(indexOrLength)]; | |
var description = this._readStringData(parameterizedType, indexOrLength), | |
descriptor = _SpearalClassDescriptor.forDescription(description), | |
value = this._context.getInstance(descriptor); | |
this._sharedObjects.push(value); | |
for (var $__10 = descriptor.propertyNames[$traceurRuntime.toProperty(Symbol.iterator)](), | |
$__11; !($__11 = $__10.next()).done; ) { | |
var name = $__11.value; | |
$traceurRuntime.setProperty(value, name, this.readAny()); | |
} | |
return value; | |
}, | |
_readBigNumberData: function(length) { | |
"use strict"; | |
var count = (length / 2) + (length % 2), | |
value = ""; | |
for (var i = 0; i < count; i++) { | |
var b = this._buffer.readUint8(); | |
value += SpearalBigNumber.charAt((b & 0xf0) >>> 4); | |
if (value.length === length) | |
break; | |
value += SpearalBigNumber.charAt(b & 0x0f); | |
} | |
this._sharedStrings.push(value); | |
return value; | |
}, | |
_readIndexOrLength: function(parameterizedType) { | |
"use strict"; | |
return this._buffer.readUintN(parameterizedType & 0x03); | |
}, | |
_readStringData: function(parameterizedType, indexOrLength) { | |
"use strict"; | |
if ($SpearalDecoder._isStringReference(parameterizedType)) | |
return this._sharedStrings[$traceurRuntime.toProperty(indexOrLength)]; | |
if (indexOrLength === 0) | |
return ""; | |
var value = decodeURIComponent(escape(this._buffer.readUTF(indexOrLength))); | |
this._sharedStrings.push(value); | |
return value; | |
} | |
}, { | |
_isObjectReference: function(parameterizedType) { | |
"use strict"; | |
return ((parameterizedType & 0x08) !== 0); | |
}, | |
_isStringReference: function(parameterizedType) { | |
"use strict"; | |
return ((parameterizedType & 0x04) !== 0); | |
} | |
}); | |
var SpearalFactory = function SpearalFactory() { | |
"use strict"; | |
this._context = new SpearalContext(); | |
this._context.configurables.push({ | |
descriptor: function(value, filter) { | |
var className = value._class; | |
if (className == null) | |
className = value.constructor.name; | |
if (className == null) | |
className = ''; | |
if (filter != null) | |
filter = filter.get(className); | |
if (filter == null) | |
filter = SpearalPropertyFilter.ACCEPT_ALL; | |
var propertyNames = []; | |
for (var property in value) { | |
if (property !== '_class' && value.hasOwnProperty(property) && filter.has(property)) | |
propertyNames.push(property); | |
} | |
return new _SpearalClassDescriptor(className, propertyNames); | |
}, | |
encoder: function(value) { | |
switch (value.constructor) { | |
case Boolean: | |
return function(encoder, value) { | |
encoder.writeBoolean(value); | |
}; | |
case Number: | |
return function(encoder, value) { | |
encoder.writeFloating(value); | |
}; | |
case String: | |
return function(encoder, value) { | |
encoder.writeString(value); | |
}; | |
case Function: | |
return function(encoder, value) { | |
encoder.writeClass(value); | |
}; | |
case Date: | |
return function(encoder, value) { | |
encoder.writeDateTime(value); | |
}; | |
case ArrayBuffer: | |
return function(encoder, value) { | |
encoder.writeByteArray(value); | |
}; | |
case Int8Array: | |
case Uint8Array: | |
case Int16Array: | |
case Uint16Array: | |
case Int32Array: | |
case Uint32Array: | |
case Float32Array: | |
case Float64Array: | |
case DataView: | |
return function(encoder, value) { | |
encoder.writeByteArray(value.buffer); | |
}; | |
case Array: | |
return function(encoder, value) { | |
encoder.writeCollection(value); | |
}; | |
case Set: | |
return function(encoder, value) { | |
encoder.writeCollection(value); | |
}; | |
case Map: | |
return function(encoder, value) { | |
encoder.writeMap(value); | |
}; | |
default: | |
return function(encoder, value) { | |
encoder.writeBean(value); | |
}; | |
} | |
}, | |
instantiator: function(descriptor) { | |
if (descriptor.className === '') | |
return {}; | |
if (window[$traceurRuntime.toProperty(descriptor.className)]) | |
return new window[$traceurRuntime.toProperty(descriptor.className)](); | |
return {_class: descriptor.className}; | |
}, | |
decoder: function(type) { | |
return function(value) { | |
return value; | |
}; | |
} | |
}); | |
}; | |
($traceurRuntime.createClass)(SpearalFactory, { | |
configure: function(configurable) { | |
"use strict"; | |
this._context.configurables.unshift(configurable); | |
}, | |
get context() { | |
"use strict"; | |
return this._context; | |
}, | |
newEncoder: function(filter) { | |
"use strict"; | |
return new SpearalEncoder(this._context, filter); | |
}, | |
newDecoder: function(buffer) { | |
"use strict"; | |
return new SpearalDecoder(this._context, buffer); | |
} | |
}, {}); | |
//# sourceMappingURL=spearal.map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(global) { | |
'use strict'; | |
if (global.$traceurRuntime) { | |
return; | |
} | |
var $Object = Object; | |
var $TypeError = TypeError; | |
var $create = $Object.create; | |
var $defineProperties = $Object.defineProperties; | |
var $defineProperty = $Object.defineProperty; | |
var $freeze = $Object.freeze; | |
var $getOwnPropertyDescriptor = $Object.getOwnPropertyDescriptor; | |
var $getOwnPropertyNames = $Object.getOwnPropertyNames; | |
var $keys = $Object.keys; | |
var $hasOwnProperty = $Object.prototype.hasOwnProperty; | |
var $toString = $Object.prototype.toString; | |
var $preventExtensions = Object.preventExtensions; | |
var $seal = Object.seal; | |
var $isExtensible = Object.isExtensible; | |
function nonEnum(value) { | |
return { | |
configurable: true, | |
enumerable: false, | |
value: value, | |
writable: true | |
}; | |
} | |
var types = { | |
void: function voidType() {}, | |
any: function any() {}, | |
string: function string() {}, | |
number: function number() {}, | |
boolean: function boolean() {} | |
}; | |
var method = nonEnum; | |
var counter = 0; | |
function newUniqueString() { | |
return '__$' + Math.floor(Math.random() * 1e9) + '$' + ++counter + '$__'; | |
} | |
var symbolInternalProperty = newUniqueString(); | |
var symbolDescriptionProperty = newUniqueString(); | |
var symbolDataProperty = newUniqueString(); | |
var symbolValues = $create(null); | |
var privateNames = $create(null); | |
function createPrivateName() { | |
var s = newUniqueString(); | |
privateNames[s] = true; | |
return s; | |
} | |
function isSymbol(symbol) { | |
return typeof symbol === 'object' && symbol instanceof SymbolValue; | |
} | |
function typeOf(v) { | |
if (isSymbol(v)) | |
return 'symbol'; | |
return typeof v; | |
} | |
function Symbol(description) { | |
var value = new SymbolValue(description); | |
if (!(this instanceof Symbol)) | |
return value; | |
throw new TypeError('Symbol cannot be new\'ed'); | |
} | |
$defineProperty(Symbol.prototype, 'constructor', nonEnum(Symbol)); | |
$defineProperty(Symbol.prototype, 'toString', method(function() { | |
var symbolValue = this[symbolDataProperty]; | |
if (!getOption('symbols')) | |
return symbolValue[symbolInternalProperty]; | |
if (!symbolValue) | |
throw TypeError('Conversion from symbol to string'); | |
var desc = symbolValue[symbolDescriptionProperty]; | |
if (desc === undefined) | |
desc = ''; | |
return 'Symbol(' + desc + ')'; | |
})); | |
$defineProperty(Symbol.prototype, 'valueOf', method(function() { | |
var symbolValue = this[symbolDataProperty]; | |
if (!symbolValue) | |
throw TypeError('Conversion from symbol to string'); | |
if (!getOption('symbols')) | |
return symbolValue[symbolInternalProperty]; | |
return symbolValue; | |
})); | |
function SymbolValue(description) { | |
var key = newUniqueString(); | |
$defineProperty(this, symbolDataProperty, {value: this}); | |
$defineProperty(this, symbolInternalProperty, {value: key}); | |
$defineProperty(this, symbolDescriptionProperty, {value: description}); | |
freeze(this); | |
symbolValues[key] = this; | |
} | |
$defineProperty(SymbolValue.prototype, 'constructor', nonEnum(Symbol)); | |
$defineProperty(SymbolValue.prototype, 'toString', { | |
value: Symbol.prototype.toString, | |
enumerable: false | |
}); | |
$defineProperty(SymbolValue.prototype, 'valueOf', { | |
value: Symbol.prototype.valueOf, | |
enumerable: false | |
}); | |
var hashProperty = createPrivateName(); | |
var hashPropertyDescriptor = {value: undefined}; | |
var hashObjectProperties = { | |
hash: {value: undefined}, | |
self: {value: undefined} | |
}; | |
var hashCounter = 0; | |
function getOwnHashObject(object) { | |
var hashObject = object[hashProperty]; | |
if (hashObject && hashObject.self === object) | |
return hashObject; | |
if ($isExtensible(object)) { | |
hashObjectProperties.hash.value = hashCounter++; | |
hashObjectProperties.self.value = object; | |
hashPropertyDescriptor.value = $create(null, hashObjectProperties); | |
$defineProperty(object, hashProperty, hashPropertyDescriptor); | |
return hashPropertyDescriptor.value; | |
} | |
return undefined; | |
} | |
function freeze(object) { | |
getOwnHashObject(object); | |
return $freeze.apply(this, arguments); | |
} | |
function preventExtensions(object) { | |
getOwnHashObject(object); | |
return $preventExtensions.apply(this, arguments); | |
} | |
function seal(object) { | |
getOwnHashObject(object); | |
return $seal.apply(this, arguments); | |
} | |
Symbol.iterator = Symbol(); | |
freeze(SymbolValue.prototype); | |
function toProperty(name) { | |
if (isSymbol(name)) | |
return name[symbolInternalProperty]; | |
return name; | |
} | |
function getOwnPropertyNames(object) { | |
var rv = []; | |
var names = $getOwnPropertyNames(object); | |
for (var i = 0; i < names.length; i++) { | |
var name = names[i]; | |
if (!symbolValues[name] && !privateNames[name]) | |
rv.push(name); | |
} | |
return rv; | |
} | |
function getOwnPropertyDescriptor(object, name) { | |
return $getOwnPropertyDescriptor(object, toProperty(name)); | |
} | |
function getOwnPropertySymbols(object) { | |
var rv = []; | |
var names = $getOwnPropertyNames(object); | |
for (var i = 0; i < names.length; i++) { | |
var symbol = symbolValues[names[i]]; | |
if (symbol) | |
rv.push(symbol); | |
} | |
return rv; | |
} | |
function hasOwnProperty(name) { | |
return $hasOwnProperty.call(this, toProperty(name)); | |
} | |
function getOption(name) { | |
return global.traceur && global.traceur.options[name]; | |
} | |
function setProperty(object, name, value) { | |
var sym, | |
desc; | |
if (isSymbol(name)) { | |
sym = name; | |
name = name[symbolInternalProperty]; | |
} | |
object[name] = value; | |
if (sym && (desc = $getOwnPropertyDescriptor(object, name))) | |
$defineProperty(object, name, {enumerable: false}); | |
return value; | |
} | |
function defineProperty(object, name, descriptor) { | |
if (isSymbol(name)) { | |
if (descriptor.enumerable) { | |
descriptor = $create(descriptor, {enumerable: {value: false}}); | |
} | |
name = name[symbolInternalProperty]; | |
} | |
$defineProperty(object, name, descriptor); | |
return object; | |
} | |
function polyfillObject(Object) { | |
$defineProperty(Object, 'defineProperty', {value: defineProperty}); | |
$defineProperty(Object, 'getOwnPropertyNames', {value: getOwnPropertyNames}); | |
$defineProperty(Object, 'getOwnPropertyDescriptor', {value: getOwnPropertyDescriptor}); | |
$defineProperty(Object.prototype, 'hasOwnProperty', {value: hasOwnProperty}); | |
$defineProperty(Object, 'freeze', {value: freeze}); | |
$defineProperty(Object, 'preventExtensions', {value: preventExtensions}); | |
$defineProperty(Object, 'seal', {value: seal}); | |
Object.getOwnPropertySymbols = getOwnPropertySymbols; | |
} | |
function exportStar(object) { | |
for (var i = 1; i < arguments.length; i++) { | |
var names = $getOwnPropertyNames(arguments[i]); | |
for (var j = 0; j < names.length; j++) { | |
var name = names[j]; | |
if (privateNames[name]) | |
continue; | |
(function(mod, name) { | |
$defineProperty(object, name, { | |
get: function() { | |
return mod[name]; | |
}, | |
enumerable: true | |
}); | |
})(arguments[i], names[j]); | |
} | |
} | |
return object; | |
} | |
function isObject(x) { | |
return x != null && (typeof x === 'object' || typeof x === 'function'); | |
} | |
function toObject(x) { | |
if (x == null) | |
throw $TypeError(); | |
return $Object(x); | |
} | |
function checkObjectCoercible(argument) { | |
if (argument == null) { | |
throw new TypeError('Value cannot be converted to an Object'); | |
} | |
return argument; | |
} | |
function setupGlobals(global) { | |
global.Symbol = Symbol; | |
global.Reflect = global.Reflect || {}; | |
global.Reflect.global = global.Reflect.global || global; | |
polyfillObject(global.Object); | |
} | |
setupGlobals(global); | |
global.$traceurRuntime = { | |
createPrivateName: createPrivateName, | |
exportStar: exportStar, | |
getOwnHashObject: getOwnHashObject, | |
privateNames: privateNames, | |
setProperty: setProperty, | |
setupGlobals: setupGlobals, | |
toObject: toObject, | |
isObject: isObject, | |
toProperty: toProperty, | |
type: types, | |
typeof: typeOf, | |
checkObjectCoercible: checkObjectCoercible, | |
hasOwnProperty: function(o, p) { | |
return hasOwnProperty.call(o, p); | |
}, | |
defineProperties: $defineProperties, | |
defineProperty: $defineProperty, | |
getOwnPropertyDescriptor: $getOwnPropertyDescriptor, | |
getOwnPropertyNames: $getOwnPropertyNames, | |
keys: $keys | |
}; | |
})(typeof global !== 'undefined' ? global : this); | |
(function() { | |
'use strict'; | |
function spread() { | |
var rv = [], | |
j = 0, | |
iterResult; | |
for (var i = 0; i < arguments.length; i++) { | |
var valueToSpread = $traceurRuntime.checkObjectCoercible(arguments[i]); | |
if (typeof valueToSpread[$traceurRuntime.toProperty(Symbol.iterator)] !== 'function') { | |
throw new TypeError('Cannot spread non-iterable object.'); | |
} | |
var iter = valueToSpread[$traceurRuntime.toProperty(Symbol.iterator)](); | |
while (!(iterResult = iter.next()).done) { | |
rv[j++] = iterResult.value; | |
} | |
} | |
return rv; | |
} | |
$traceurRuntime.spread = spread; | |
})(); | |
(function() { | |
'use strict'; | |
var $Object = Object; | |
var $TypeError = TypeError; | |
var $create = $Object.create; | |
var $defineProperties = $traceurRuntime.defineProperties; | |
var $defineProperty = $traceurRuntime.defineProperty; | |
var $getOwnPropertyDescriptor = $traceurRuntime.getOwnPropertyDescriptor; | |
var $getOwnPropertyNames = $traceurRuntime.getOwnPropertyNames; | |
var $getPrototypeOf = Object.getPrototypeOf; | |
function superDescriptor(homeObject, name) { | |
var proto = $getPrototypeOf(homeObject); | |
do { | |
var result = $getOwnPropertyDescriptor(proto, name); | |
if (result) | |
return result; | |
proto = $getPrototypeOf(proto); | |
} while (proto); | |
return undefined; | |
} | |
function superCall(self, homeObject, name, args) { | |
return superGet(self, homeObject, name).apply(self, args); | |
} | |
function superGet(self, homeObject, name) { | |
var descriptor = superDescriptor(homeObject, name); | |
if (descriptor) { | |
if (!descriptor.get) | |
return descriptor.value; | |
return descriptor.get.call(self); | |
} | |
return undefined; | |
} | |
function superSet(self, homeObject, name, value) { | |
var descriptor = superDescriptor(homeObject, name); | |
if (descriptor && descriptor.set) { | |
descriptor.set.call(self, value); | |
return value; | |
} | |
throw $TypeError("super has no setter '" + name + "'."); | |
} | |
function getDescriptors(object) { | |
var descriptors = {}, | |
name, | |
names = $getOwnPropertyNames(object); | |
for (var i = 0; i < names.length; i++) { | |
var name = names[i]; | |
descriptors[name] = $getOwnPropertyDescriptor(object, name); | |
} | |
return descriptors; | |
} | |
function createClass(ctor, object, staticObject, superClass) { | |
$defineProperty(object, 'constructor', { | |
value: ctor, | |
configurable: true, | |
enumerable: false, | |
writable: true | |
}); | |
if (arguments.length > 3) { | |
if (typeof superClass === 'function') | |
ctor.__proto__ = superClass; | |
ctor.prototype = $create(getProtoParent(superClass), getDescriptors(object)); | |
} else { | |
ctor.prototype = object; | |
} | |
$defineProperty(ctor, 'prototype', { | |
configurable: false, | |
writable: false | |
}); | |
return $defineProperties(ctor, getDescriptors(staticObject)); | |
} | |
function getProtoParent(superClass) { | |
if (typeof superClass === 'function') { | |
var prototype = superClass.prototype; | |
if ($Object(prototype) === prototype || prototype === null) | |
return superClass.prototype; | |
throw new $TypeError('super prototype must be an Object or null'); | |
} | |
if (superClass === null) | |
return null; | |
throw new $TypeError(("Super expression must either be null or a function, not " + typeof superClass + ".")); | |
} | |
function defaultSuperCall(self, homeObject, args) { | |
if ($getPrototypeOf(homeObject) !== null) | |
superCall(self, homeObject, 'constructor', args); | |
} | |
$traceurRuntime.createClass = createClass; | |
$traceurRuntime.defaultSuperCall = defaultSuperCall; | |
$traceurRuntime.superCall = superCall; | |
$traceurRuntime.superGet = superGet; | |
$traceurRuntime.superSet = superSet; | |
})(); | |
(function() { | |
'use strict'; | |
var createPrivateName = $traceurRuntime.createPrivateName; | |
var $defineProperties = $traceurRuntime.defineProperties; | |
var $defineProperty = $traceurRuntime.defineProperty; | |
var $create = Object.create; | |
var $TypeError = TypeError; | |
function nonEnum(value) { | |
return { | |
configurable: true, | |
enumerable: false, | |
value: value, | |
writable: true | |
}; | |
} | |
var ST_NEWBORN = 0; | |
var ST_EXECUTING = 1; | |
var ST_SUSPENDED = 2; | |
var ST_CLOSED = 3; | |
var END_STATE = -2; | |
var RETHROW_STATE = -3; | |
function getInternalError(state) { | |
return new Error('Traceur compiler bug: invalid state in state machine: ' + state); | |
} | |
function GeneratorContext() { | |
this.state = 0; | |
this.GState = ST_NEWBORN; | |
this.storedException = undefined; | |
this.finallyFallThrough = undefined; | |
this.sent_ = undefined; | |
this.returnValue = undefined; | |
this.tryStack_ = []; | |
} | |
GeneratorContext.prototype = { | |
pushTry: function(catchState, finallyState) { | |
if (finallyState !== null) { | |
var finallyFallThrough = null; | |
for (var i = this.tryStack_.length - 1; i >= 0; i--) { | |
if (this.tryStack_[i].catch !== undefined) { | |
finallyFallThrough = this.tryStack_[i].catch; | |
break; | |
} | |
} | |
if (finallyFallThrough === null) | |
finallyFallThrough = RETHROW_STATE; | |
this.tryStack_.push({ | |
finally: finallyState, | |
finallyFallThrough: finallyFallThrough | |
}); | |
} | |
if (catchState !== null) { | |
this.tryStack_.push({catch: catchState}); | |
} | |
}, | |
popTry: function() { | |
this.tryStack_.pop(); | |
}, | |
get sent() { | |
this.maybeThrow(); | |
return this.sent_; | |
}, | |
set sent(v) { | |
this.sent_ = v; | |
}, | |
get sentIgnoreThrow() { | |
return this.sent_; | |
}, | |
maybeThrow: function() { | |
if (this.action === 'throw') { | |
this.action = 'next'; | |
throw this.sent_; | |
} | |
}, | |
end: function() { | |
switch (this.state) { | |
case END_STATE: | |
return this; | |
case RETHROW_STATE: | |
throw this.storedException; | |
default: | |
throw getInternalError(this.state); | |
} | |
}, | |
handleException: function(ex) { | |
this.GState = ST_CLOSED; | |
this.state = END_STATE; | |
throw ex; | |
} | |
}; | |
function nextOrThrow(ctx, moveNext, action, x) { | |
switch (ctx.GState) { | |
case ST_EXECUTING: | |
throw new Error(("\"" + action + "\" on executing generator")); | |
case ST_CLOSED: | |
if (action == 'next') { | |
return { | |
value: undefined, | |
done: true | |
}; | |
} | |
throw x; | |
case ST_NEWBORN: | |
if (action === 'throw') { | |
ctx.GState = ST_CLOSED; | |
throw x; | |
} | |
if (x !== undefined) | |
throw $TypeError('Sent value to newborn generator'); | |
case ST_SUSPENDED: | |
ctx.GState = ST_EXECUTING; | |
ctx.action = action; | |
ctx.sent = x; | |
var value = moveNext(ctx); | |
var done = value === ctx; | |
if (done) | |
value = ctx.returnValue; | |
ctx.GState = done ? ST_CLOSED : ST_SUSPENDED; | |
return { | |
value: value, | |
done: done | |
}; | |
} | |
} | |
var ctxName = createPrivateName(); | |
var moveNextName = createPrivateName(); | |
function GeneratorFunction() {} | |
function GeneratorFunctionPrototype() {} | |
GeneratorFunction.prototype = GeneratorFunctionPrototype; | |
$defineProperty(GeneratorFunctionPrototype, 'constructor', nonEnum(GeneratorFunction)); | |
GeneratorFunctionPrototype.prototype = { | |
constructor: GeneratorFunctionPrototype, | |
next: function(v) { | |
return nextOrThrow(this[ctxName], this[moveNextName], 'next', v); | |
}, | |
throw: function(v) { | |
return nextOrThrow(this[ctxName], this[moveNextName], 'throw', v); | |
} | |
}; | |
$defineProperties(GeneratorFunctionPrototype.prototype, { | |
constructor: {enumerable: false}, | |
next: {enumerable: false}, | |
throw: {enumerable: false} | |
}); | |
Object.defineProperty(GeneratorFunctionPrototype.prototype, Symbol.iterator, nonEnum(function() { | |
return this; | |
})); | |
function createGeneratorInstance(innerFunction, functionObject, self) { | |
var moveNext = getMoveNext(innerFunction, self); | |
var ctx = new GeneratorContext(); | |
var object = $create(functionObject.prototype); | |
object[ctxName] = ctx; | |
object[moveNextName] = moveNext; | |
return object; | |
} | |
function initGeneratorFunction(functionObject) { | |
functionObject.prototype = $create(GeneratorFunctionPrototype.prototype); | |
functionObject.__proto__ = GeneratorFunctionPrototype; | |
return functionObject; | |
} | |
function AsyncFunctionContext() { | |
GeneratorContext.call(this); | |
this.err = undefined; | |
var ctx = this; | |
ctx.result = new Promise(function(resolve, reject) { | |
ctx.resolve = resolve; | |
ctx.reject = reject; | |
}); | |
} | |
AsyncFunctionContext.prototype = $create(GeneratorContext.prototype); | |
AsyncFunctionContext.prototype.end = function() { | |
switch (this.state) { | |
case END_STATE: | |
this.resolve(this.returnValue); | |
break; | |
case RETHROW_STATE: | |
this.reject(this.storedException); | |
break; | |
default: | |
this.reject(getInternalError(this.state)); | |
} | |
}; | |
AsyncFunctionContext.prototype.handleException = function() { | |
this.state = RETHROW_STATE; | |
}; | |
function asyncWrap(innerFunction, self) { | |
var moveNext = getMoveNext(innerFunction, self); | |
var ctx = new AsyncFunctionContext(); | |
ctx.createCallback = function(newState) { | |
return function(value) { | |
ctx.state = newState; | |
ctx.value = value; | |
moveNext(ctx); | |
}; | |
}; | |
ctx.errback = function(err) { | |
handleCatch(ctx, err); | |
moveNext(ctx); | |
}; | |
moveNext(ctx); | |
return ctx.result; | |
} | |
function getMoveNext(innerFunction, self) { | |
return function(ctx) { | |
while (true) { | |
try { | |
return innerFunction.call(self, ctx); | |
} catch (ex) { | |
handleCatch(ctx, ex); | |
} | |
} | |
}; | |
} | |
function handleCatch(ctx, ex) { | |
ctx.storedException = ex; | |
var last = ctx.tryStack_[ctx.tryStack_.length - 1]; | |
if (!last) { | |
ctx.handleException(ex); | |
return; | |
} | |
ctx.state = last.catch !== undefined ? last.catch : last.finally; | |
if (last.finallyFallThrough !== undefined) | |
ctx.finallyFallThrough = last.finallyFallThrough; | |
} | |
$traceurRuntime.asyncWrap = asyncWrap; | |
$traceurRuntime.initGeneratorFunction = initGeneratorFunction; | |
$traceurRuntime.createGeneratorInstance = createGeneratorInstance; | |
})(); | |
(function() { | |
function buildFromEncodedParts(opt_scheme, opt_userInfo, opt_domain, opt_port, opt_path, opt_queryData, opt_fragment) { | |
var out = []; | |
if (opt_scheme) { | |
out.push(opt_scheme, ':'); | |
} | |
if (opt_domain) { | |
out.push('//'); | |
if (opt_userInfo) { | |
out.push(opt_userInfo, '@'); | |
} | |
out.push(opt_domain); | |
if (opt_port) { | |
out.push(':', opt_port); | |
} | |
} | |
if (opt_path) { | |
out.push(opt_path); | |
} | |
if (opt_queryData) { | |
out.push('?', opt_queryData); | |
} | |
if (opt_fragment) { | |
out.push('#', opt_fragment); | |
} | |
return out.join(''); | |
} | |
; | |
var splitRe = new RegExp('^' + '(?:' + '([^:/?#.]+)' + ':)?' + '(?://' + '(?:([^/?#]*)@)?' + '([\\w\\d\\-\\u0100-\\uffff.%]*)' + '(?::([0-9]+))?' + ')?' + '([^?#]+)?' + '(?:\\?([^#]*))?' + '(?:#(.*))?' + '$'); | |
var ComponentIndex = { | |
SCHEME: 1, | |
USER_INFO: 2, | |
DOMAIN: 3, | |
PORT: 4, | |
PATH: 5, | |
QUERY_DATA: 6, | |
FRAGMENT: 7 | |
}; | |
function split(uri) { | |
return (uri.match(splitRe)); | |
} | |
function removeDotSegments(path) { | |
if (path === '/') | |
return '/'; | |
var leadingSlash = path[0] === '/' ? '/' : ''; | |
var trailingSlash = path.slice(-1) === '/' ? '/' : ''; | |
var segments = path.split('/'); | |
var out = []; | |
var up = 0; | |
for (var pos = 0; pos < segments.length; pos++) { | |
var segment = segments[pos]; | |
switch (segment) { | |
case '': | |
case '.': | |
break; | |
case '..': | |
if (out.length) | |
out.pop(); | |
else | |
up++; | |
break; | |
default: | |
out.push(segment); | |
} | |
} | |
if (!leadingSlash) { | |
while (up-- > 0) { | |
out.unshift('..'); | |
} | |
if (out.length === 0) | |
out.push('.'); | |
} | |
return leadingSlash + out.join('/') + trailingSlash; | |
} | |
function joinAndCanonicalizePath(parts) { | |
var path = parts[ComponentIndex.PATH] || ''; | |
path = removeDotSegments(path); | |
parts[ComponentIndex.PATH] = path; | |
return buildFromEncodedParts(parts[ComponentIndex.SCHEME], parts[ComponentIndex.USER_INFO], parts[ComponentIndex.DOMAIN], parts[ComponentIndex.PORT], parts[ComponentIndex.PATH], parts[ComponentIndex.QUERY_DATA], parts[ComponentIndex.FRAGMENT]); | |
} | |
function canonicalizeUrl(url) { | |
var parts = split(url); | |
return joinAndCanonicalizePath(parts); | |
} | |
function resolveUrl(base, url) { | |
var parts = split(url); | |
var baseParts = split(base); | |
if (parts[ComponentIndex.SCHEME]) { | |
return joinAndCanonicalizePath(parts); | |
} else { | |
parts[ComponentIndex.SCHEME] = baseParts[ComponentIndex.SCHEME]; | |
} | |
for (var i = ComponentIndex.SCHEME; i <= ComponentIndex.PORT; i++) { | |
if (!parts[i]) { | |
parts[i] = baseParts[i]; | |
} | |
} | |
if (parts[ComponentIndex.PATH][0] == '/') { | |
return joinAndCanonicalizePath(parts); | |
} | |
var path = baseParts[ComponentIndex.PATH]; | |
var index = path.lastIndexOf('/'); | |
path = path.slice(0, index + 1) + parts[ComponentIndex.PATH]; | |
parts[ComponentIndex.PATH] = path; | |
return joinAndCanonicalizePath(parts); | |
} | |
function isAbsolute(name) { | |
if (!name) | |
return false; | |
if (name[0] === '/') | |
return true; | |
var parts = split(name); | |
if (parts[ComponentIndex.SCHEME]) | |
return true; | |
return false; | |
} | |
$traceurRuntime.canonicalizeUrl = canonicalizeUrl; | |
$traceurRuntime.isAbsolute = isAbsolute; | |
$traceurRuntime.removeDotSegments = removeDotSegments; | |
$traceurRuntime.resolveUrl = resolveUrl; | |
})(); | |
(function(global) { | |
'use strict'; | |
var $__2 = $traceurRuntime, | |
canonicalizeUrl = $__2.canonicalizeUrl, | |
resolveUrl = $__2.resolveUrl, | |
isAbsolute = $__2.isAbsolute; | |
var moduleInstantiators = Object.create(null); | |
var baseURL; | |
if (global.location && global.location.href) | |
baseURL = resolveUrl(global.location.href, './'); | |
else | |
baseURL = ''; | |
var UncoatedModuleEntry = function UncoatedModuleEntry(url, uncoatedModule) { | |
this.url = url; | |
this.value_ = uncoatedModule; | |
}; | |
($traceurRuntime.createClass)(UncoatedModuleEntry, {}, {}); | |
var ModuleEvaluationError = function ModuleEvaluationError(erroneousModuleName, cause) { | |
this.message = this.constructor.name + (cause ? ': \'' + cause + '\'' : '') + ' in ' + erroneousModuleName; | |
}; | |
($traceurRuntime.createClass)(ModuleEvaluationError, {loadedBy: function(moduleName) { | |
this.message += '\n loaded by ' + moduleName; | |
}}, {}, Error); | |
var UncoatedModuleInstantiator = function UncoatedModuleInstantiator(url, func) { | |
$traceurRuntime.superCall(this, $UncoatedModuleInstantiator.prototype, "constructor", [url, null]); | |
this.func = func; | |
}; | |
var $UncoatedModuleInstantiator = UncoatedModuleInstantiator; | |
($traceurRuntime.createClass)(UncoatedModuleInstantiator, {getUncoatedModule: function() { | |
if (this.value_) | |
return this.value_; | |
try { | |
return this.value_ = this.func.call(global); | |
} catch (ex) { | |
if (ex instanceof ModuleEvaluationError) { | |
ex.loadedBy(this.url); | |
throw ex; | |
} | |
throw new ModuleEvaluationError(this.url, ex); | |
} | |
}}, {}, UncoatedModuleEntry); | |
function getUncoatedModuleInstantiator(name) { | |
if (!name) | |
return; | |
var url = ModuleStore.normalize(name); | |
return moduleInstantiators[url]; | |
} | |
; | |
var moduleInstances = Object.create(null); | |
var liveModuleSentinel = {}; | |
function Module(uncoatedModule) { | |
var isLive = arguments[1]; | |
var coatedModule = Object.create(null); | |
Object.getOwnPropertyNames(uncoatedModule).forEach((function(name) { | |
var getter, | |
value; | |
if (isLive === liveModuleSentinel) { | |
var descr = Object.getOwnPropertyDescriptor(uncoatedModule, name); | |
if (descr.get) | |
getter = descr.get; | |
} | |
if (!getter) { | |
value = uncoatedModule[name]; | |
getter = function() { | |
return value; | |
}; | |
} | |
Object.defineProperty(coatedModule, name, { | |
get: getter, | |
enumerable: true | |
}); | |
})); | |
Object.preventExtensions(coatedModule); | |
return coatedModule; | |
} | |
var ModuleStore = { | |
normalize: function(name, refererName, refererAddress) { | |
if (typeof name !== "string") | |
throw new TypeError("module name must be a string, not " + typeof name); | |
if (isAbsolute(name)) | |
return canonicalizeUrl(name); | |
if (/[^\.]\/\.\.\//.test(name)) { | |
throw new Error('module name embeds /../: ' + name); | |
} | |
if (name[0] === '.' && refererName) | |
return resolveUrl(refererName, name); | |
return canonicalizeUrl(name); | |
}, | |
get: function(normalizedName) { | |
var m = getUncoatedModuleInstantiator(normalizedName); | |
if (!m) | |
return undefined; | |
var moduleInstance = moduleInstances[m.url]; | |
if (moduleInstance) | |
return moduleInstance; | |
moduleInstance = Module(m.getUncoatedModule(), liveModuleSentinel); | |
return moduleInstances[m.url] = moduleInstance; | |
}, | |
set: function(normalizedName, module) { | |
normalizedName = String(normalizedName); | |
moduleInstantiators[normalizedName] = new UncoatedModuleInstantiator(normalizedName, (function() { | |
return module; | |
})); | |
moduleInstances[normalizedName] = module; | |
}, | |
get baseURL() { | |
return baseURL; | |
}, | |
set baseURL(v) { | |
baseURL = String(v); | |
}, | |
registerModule: function(name, func) { | |
var normalizedName = ModuleStore.normalize(name); | |
if (moduleInstantiators[normalizedName]) | |
throw new Error('duplicate module named ' + normalizedName); | |
moduleInstantiators[normalizedName] = new UncoatedModuleInstantiator(normalizedName, func); | |
}, | |
bundleStore: Object.create(null), | |
register: function(name, deps, func) { | |
if (!deps || !deps.length && !func.length) { | |
this.registerModule(name, func); | |
} else { | |
this.bundleStore[name] = { | |
deps: deps, | |
execute: function() { | |
var $__0 = arguments; | |
var depMap = {}; | |
deps.forEach((function(dep, index) { | |
return depMap[dep] = $__0[index]; | |
})); | |
var registryEntry = func.call(this, depMap); | |
registryEntry.execute.call(this); | |
return registryEntry.exports; | |
} | |
}; | |
} | |
}, | |
getAnonymousModule: function(func) { | |
return new Module(func.call(global), liveModuleSentinel); | |
}, | |
getForTesting: function(name) { | |
var $__0 = this; | |
if (!this.testingPrefix_) { | |
Object.keys(moduleInstances).some((function(key) { | |
var m = /(traceur@[^\/]*\/)/.exec(key); | |
if (m) { | |
$__0.testingPrefix_ = m[1]; | |
return true; | |
} | |
})); | |
} | |
return this.get(this.testingPrefix_ + name); | |
} | |
}; | |
ModuleStore.set('@traceur/src/runtime/ModuleStore', new Module({ModuleStore: ModuleStore})); | |
var setupGlobals = $traceurRuntime.setupGlobals; | |
$traceurRuntime.setupGlobals = function(global) { | |
setupGlobals(global); | |
}; | |
$traceurRuntime.ModuleStore = ModuleStore; | |
global.System = { | |
register: ModuleStore.register.bind(ModuleStore), | |
get: ModuleStore.get, | |
set: ModuleStore.set, | |
normalize: ModuleStore.normalize | |
}; | |
$traceurRuntime.getModuleImpl = function(name) { | |
var instantiator = getUncoatedModuleInstantiator(name); | |
return instantiator && instantiator.getUncoatedModule(); | |
}; | |
})(typeof global !== 'undefined' ? global : this); | |
System.register("traceur-runtime@0.0.60/src/runtime/polyfills/utils", [], function() { | |
"use strict"; | |
var __moduleName = "traceur-runtime@0.0.60/src/runtime/polyfills/utils"; | |
var $ceil = Math.ceil; | |
var $floor = Math.floor; | |
var $isFinite = isFinite; | |
var $isNaN = isNaN; | |
var $pow = Math.pow; | |
var $min = Math.min; | |
var toObject = $traceurRuntime.toObject; | |
function toUint32(x) { | |
return x >>> 0; | |
} | |
function isObject(x) { | |
return x && (typeof x === 'object' || typeof x === 'function'); | |
} | |
function isCallable(x) { | |
return typeof x === 'function'; | |
} | |
function isNumber(x) { | |
return typeof x === 'number'; | |
} | |
function toInteger(x) { | |
x = +x; | |
if ($isNaN(x)) | |
return 0; | |
if (x === 0 || !$isFinite(x)) | |
return x; | |
return x > 0 ? $floor(x) : $ceil(x); | |
} | |
var MAX_SAFE_LENGTH = $pow(2, 53) - 1; | |
function toLength(x) { | |
var len = toInteger(x); | |
return len < 0 ? 0 : $min(len, MAX_SAFE_LENGTH); | |
} | |
function checkIterable(x) { | |
return !isObject(x) ? undefined : x[Symbol.iterator]; | |
} | |
function isConstructor(x) { | |
return isCallable(x); | |
} | |
function createIteratorResultObject(value, done) { | |
return { | |
value: value, | |
done: done | |
}; | |
} | |
function maybeDefine(object, name, descr) { | |
if (!(name in object)) { | |
Object.defineProperty(object, name, descr); | |
} | |
} | |
function maybeDefineMethod(object, name, value) { | |
maybeDefine(object, name, { | |
value: value, | |
configurable: true, | |
enumerable: false, | |
writable: true | |
}); | |
} | |
function maybeDefineConst(object, name, value) { | |
maybeDefine(object, name, { | |
value: value, | |
configurable: false, | |
enumerable: false, | |
writable: false | |
}); | |
} | |
function maybeAddFunctions(object, functions) { | |
for (var i = 0; i < functions.length; i += 2) { | |
var name = functions[i]; | |
var value = functions[i + 1]; | |
maybeDefineMethod(object, name, value); | |
} | |
} | |
function maybeAddConsts(object, consts) { | |
for (var i = 0; i < consts.length; i += 2) { | |
var name = consts[i]; | |
var value = consts[i + 1]; | |
maybeDefineConst(object, name, value); | |
} | |
} | |
function maybeAddIterator(object, func, Symbol) { | |
if (!Symbol || !Symbol.iterator || object[Symbol.iterator]) | |
return; | |
if (object['@@iterator']) | |
func = object['@@iterator']; | |
Object.defineProperty(object, Symbol.iterator, { | |
value: func, | |
configurable: true, | |
enumerable: false, | |
writable: true | |
}); | |
} | |
var polyfills = []; | |
function registerPolyfill(func) { | |
polyfills.push(func); | |
} | |
function polyfillAll(global) { | |
polyfills.forEach((function(f) { | |
return f(global); | |
})); | |
} | |
return { | |
get toObject() { | |
return toObject; | |
}, | |
get toUint32() { | |
return toUint32; | |
}, | |
get isObject() { | |
return isObject; | |
}, | |
get isCallable() { | |
return isCallable; | |
}, | |
get isNumber() { | |
return isNumber; | |
}, | |
get toInteger() { | |
return toInteger; | |
}, | |
get toLength() { | |
return toLength; | |
}, | |
get checkIterable() { | |
return checkIterable; | |
}, | |
get isConstructor() { | |
return isConstructor; | |
}, | |
get createIteratorResultObject() { | |
return createIteratorResultObject; | |
}, | |
get maybeDefine() { | |
return maybeDefine; | |
}, | |
get maybeDefineMethod() { | |
return maybeDefineMethod; | |
}, | |
get maybeDefineConst() { | |
return maybeDefineConst; | |
}, | |
get maybeAddFunctions() { | |
return maybeAddFunctions; | |
}, | |
get maybeAddConsts() { | |
return maybeAddConsts; | |
}, | |
get maybeAddIterator() { | |
return maybeAddIterator; | |
}, | |
get registerPolyfill() { | |
return registerPolyfill; | |
}, | |
get polyfillAll() { | |
return polyfillAll; | |
} | |
}; | |
}); | |
System.register("traceur-runtime@0.0.60/src/runtime/polyfills/Map", [], function() { | |
"use strict"; | |
var __moduleName = "traceur-runtime@0.0.60/src/runtime/polyfills/Map"; | |
var $__3 = System.get("traceur-runtime@0.0.60/src/runtime/polyfills/utils"), | |
isObject = $__3.isObject, | |
maybeAddIterator = $__3.maybeAddIterator, | |
registerPolyfill = $__3.registerPolyfill; | |
var getOwnHashObject = $traceurRuntime.getOwnHashObject; | |
var $hasOwnProperty = Object.prototype.hasOwnProperty; | |
var deletedSentinel = {}; | |
function lookupIndex(map, key) { | |
if (isObject(key)) { | |
var hashObject = getOwnHashObject(key); | |
return hashObject && map.objectIndex_[hashObject.hash]; | |
} | |
if (typeof key === 'string') | |
return map.stringIndex_[key]; | |
return map.primitiveIndex_[key]; | |
} | |
function initMap(map) { | |
map.entries_ = []; | |
map.objectIndex_ = Object.create(null); | |
map.stringIndex_ = Object.create(null); | |
map.primitiveIndex_ = Object.create(null); | |
map.deletedCount_ = 0; | |
} | |
var Map = function Map() { | |
var iterable = arguments[0]; | |
if (!isObject(this)) | |
throw new TypeError('Map called on incompatible type'); | |
if ($hasOwnProperty.call(this, 'entries_')) { | |
throw new TypeError('Map can not be reentrantly initialised'); | |
} | |
initMap(this); | |
if (iterable !== null && iterable !== undefined) { | |
for (var $__5 = iterable[Symbol.iterator](), | |
$__6; !($__6 = $__5.next()).done; ) { | |
var $__7 = $__6.value, | |
key = $__7[0], | |
value = $__7[1]; | |
{ | |
this.set(key, value); | |
} | |
} | |
} | |
}; | |
($traceurRuntime.createClass)(Map, { | |
get size() { | |
return this.entries_.length / 2 - this.deletedCount_; | |
}, | |
get: function(key) { | |
var index = lookupIndex(this, key); | |
if (index !== undefined) | |
return this.entries_[index + 1]; | |
}, | |
set: function(key, value) { | |
var objectMode = isObject(key); | |
var stringMode = typeof key === 'string'; | |
var index = lookupIndex(this, key); | |
if (index !== undefined) { | |
this.entries_[index + 1] = value; | |
} else { | |
index = this.entries_.length; | |
this.entries_[index] = key; | |
this.entries_[index + 1] = value; | |
if (objectMode) { | |
var hashObject = getOwnHashObject(key); | |
var hash = hashObject.hash; | |
this.objectIndex_[hash] = index; | |
} else if (stringMode) { | |
this.stringIndex_[key] = index; | |
} else { | |
this.primitiveIndex_[key] = index; | |
} | |
} | |
return this; | |
}, | |
has: function(key) { | |
return lookupIndex(this, key) !== undefined; | |
}, | |
delete: function(key) { | |
var objectMode = isObject(key); | |
var stringMode = typeof key === 'string'; | |
var index; | |
var hash; | |
if (objectMode) { | |
var hashObject = getOwnHashObject(key); | |
if (hashObject) { | |
index = this.objectIndex_[hash = hashObject.hash]; | |
delete this.objectIndex_[hash]; | |
} | |
} else if (stringMode) { | |
index = this.stringIndex_[key]; | |
delete this.stringIndex_[key]; | |
} else { | |
index = this.primitiveIndex_[key]; | |
delete this.primitiveIndex_[key]; | |
} | |
if (index !== undefined) { | |
this.entries_[index] = deletedSentinel; | |
this.entries_[index + 1] = undefined; | |
this.deletedCount_++; | |
return true; | |
} | |
return false; | |
}, | |
clear: function() { | |
initMap(this); | |
}, | |
forEach: function(callbackFn) { | |
var thisArg = arguments[1]; | |
for (var i = 0, | |
len = this.entries_.length; i < len; i += 2) { | |
var key = this.entries_[i]; | |
var value = this.entries_[i + 1]; | |
if (key === deletedSentinel) | |
continue; | |
callbackFn.call(thisArg, value, key, this); | |
} | |
}, | |
entries: $traceurRuntime.initGeneratorFunction(function $__8() { | |
var i, | |
len, | |
key, | |
value; | |
return $traceurRuntime.createGeneratorInstance(function($ctx) { | |
while (true) | |
switch ($ctx.state) { | |
case 0: | |
i = 0, len = this.entries_.length; | |
$ctx.state = 12; | |
break; | |
case 12: | |
$ctx.state = (i < len) ? 8 : -2; | |
break; | |
case 4: | |
i += 2; | |
$ctx.state = 12; | |
break; | |
case 8: | |
key = this.entries_[i]; | |
value = this.entries_[i + 1]; | |
$ctx.state = 9; | |
break; | |
case 9: | |
$ctx.state = (key === deletedSentinel) ? 4 : 6; | |
break; | |
case 6: | |
$ctx.state = 2; | |
return [key, value]; | |
case 2: | |
$ctx.maybeThrow(); | |
$ctx.state = 4; | |
break; | |
default: | |
return $ctx.end(); | |
} | |
}, $__8, this); | |
}), | |
keys: $traceurRuntime.initGeneratorFunction(function $__9() { | |
var i, | |
len, | |
key, | |
value; | |
return $traceurRuntime.createGeneratorInstance(function($ctx) { | |
while (true) | |
switch ($ctx.state) { | |
case 0: | |
i = 0, len = this.entries_.length; | |
$ctx.state = 12; | |
break; | |
case 12: | |
$ctx.state = (i < len) ? 8 : -2; | |
break; | |
case 4: | |
i += 2; | |
$ctx.state = 12; | |
break; | |
case 8: | |
key = this.entries_[i]; | |
value = this.entries_[i + 1]; | |
$ctx.state = 9; | |
break; | |
case 9: | |
$ctx.state = (key === deletedSentinel) ? 4 : 6; | |
break; | |
case 6: | |
$ctx.state = 2; | |
return key; | |
case 2: | |
$ctx.maybeThrow(); | |
$ctx.state = 4; | |
break; | |
default: | |
return $ctx.end(); | |
} | |
}, $__9, this); | |
}), | |
values: $traceurRuntime.initGeneratorFunction(function $__10() { | |
var i, | |
len, | |
key, | |
value; | |
return $traceurRuntime.createGeneratorInstance(function($ctx) { | |
while (true) | |
switch ($ctx.state) { | |
case 0: | |
i = 0, len = this.entries_.length; | |
$ctx.state = 12; | |
break; | |
case 12: | |
$ctx.state = (i < len) ? 8 : -2; | |
break; | |
case 4: | |
i += 2; | |
$ctx.state = 12; | |
break; | |
case 8: | |
key = this.entries_[i]; | |
value = this.entries_[i + 1]; | |
$ctx.state = 9; | |
break; | |
case 9: | |
$ctx.state = (key === deletedSentinel) ? 4 : 6; | |
break; | |
case 6: | |
$ctx.state = 2; | |
return value; | |
case 2: | |
$ctx.maybeThrow(); | |
$ctx.state = 4; | |
break; | |
default: | |
return $ctx.end(); | |
} | |
}, $__10, this); | |
}) | |
}, {}); | |
Object.defineProperty(Map.prototype, Symbol.iterator, { | |
configurable: true, | |
writable: true, | |
value: Map.prototype.entries | |
}); | |
function polyfillMap(global) { | |
var $__7 = global, | |
Object = $__7.Object, | |
Symbol = $__7.Symbol; | |
if (!global.Map) | |
global.Map = Map; | |
var mapPrototype = global.Map.prototype; | |
if (mapPrototype.entries) { | |
maybeAddIterator(mapPrototype, mapPrototype.entries, Symbol); | |
maybeAddIterator(Object.getPrototypeOf(new global.Map().entries()), function() { | |
return this; | |
}, Symbol); | |
} | |
} | |
registerPolyfill(polyfillMap); | |
return { | |
get Map() { | |
return Map; | |
}, | |
get polyfillMap() { | |
return polyfillMap; | |
} | |
}; | |
}); | |
System.get("traceur-runtime@0.0.60/src/runtime/polyfills/Map" + ''); | |
System.register("traceur-runtime@0.0.60/src/runtime/polyfills/Set", [], function() { | |
"use strict"; | |
var __moduleName = "traceur-runtime@0.0.60/src/runtime/polyfills/Set"; | |
var $__11 = System.get("traceur-runtime@0.0.60/src/runtime/polyfills/utils"), | |
isObject = $__11.isObject, | |
maybeAddIterator = $__11.maybeAddIterator, | |
registerPolyfill = $__11.registerPolyfill; | |
var Map = System.get("traceur-runtime@0.0.60/src/runtime/polyfills/Map").Map; | |
var getOwnHashObject = $traceurRuntime.getOwnHashObject; | |
var $hasOwnProperty = Object.prototype.hasOwnProperty; | |
function initSet(set) { | |
set.map_ = new Map(); | |
} | |
var Set = function Set() { | |
var iterable = arguments[0]; | |
if (!isObject(this)) | |
throw new TypeError('Set called on incompatible type'); | |
if ($hasOwnProperty.call(this, 'map_')) { | |
throw new TypeError('Set can not be reentrantly initialised'); | |
} | |
initSet(this); | |
if (iterable !== null && iterable !== undefined) { | |
for (var $__15 = iterable[Symbol.iterator](), | |
$__16; !($__16 = $__15.next()).done; ) { | |
var item = $__16.value; | |
{ | |
this.add(item); | |
} | |
} | |
} | |
}; | |
($traceurRuntime.createClass)(Set, { | |
get size() { | |
return this.map_.size; | |
}, | |
has: function(key) { | |
return this.map_.has(key); | |
}, | |
add: function(key) { | |
this.map_.set(key, key); | |
return this; | |
}, | |
delete: function(key) { | |
return this.map_.delete(key); | |
}, | |
clear: function() { | |
return this.map_.clear(); | |
}, | |
forEach: function(callbackFn) { | |
var thisArg = arguments[1]; | |
var $__13 = this; | |
return this.map_.forEach((function(value, key) { | |
callbackFn.call(thisArg, key, key, $__13); | |
})); | |
}, | |
values: $traceurRuntime.initGeneratorFunction(function $__18() { | |
var $__19, | |
$__20; | |
return $traceurRuntime.createGeneratorInstance(function($ctx) { | |
while (true) | |
switch ($ctx.state) { | |
case 0: | |
$__19 = this.map_.keys()[Symbol.iterator](); | |
$ctx.sent = void 0; | |
$ctx.action = 'next'; | |
$ctx.state = 12; | |
break; | |
case 12: | |
$__20 = $__19[$ctx.action]($ctx.sentIgnoreThrow); | |
$ctx.state = 9; | |
break; | |
case 9: | |
$ctx.state = ($__20.done) ? 3 : 2; | |
break; | |
case 3: | |
$ctx.sent = $__20.value; | |
$ctx.state = -2; | |
break; | |
case 2: | |
$ctx.state = 12; | |
return $__20.value; | |
default: | |
return $ctx.end(); | |
} | |
}, $__18, this); | |
}), | |
entries: $traceurRuntime.initGeneratorFunction(function $__21() { | |
var $__22, | |
$__23; | |
return $traceurRuntime.createGeneratorInstance(function($ctx) { | |
while (true) | |
switch ($ctx.state) { | |
case 0: | |
$__22 = this.map_.entries()[Symbol.iterator](); | |
$ctx.sent = void 0; | |
$ctx.action = 'next'; | |
$ctx.state = 12; | |
break; | |
case 12: | |
$__23 = $__22[$ctx.action]($ctx.sentIgnoreThrow); | |
$ctx.state = 9; | |
break; | |
case 9: | |
$ctx.state = ($__23.done) ? 3 : 2; | |
break; | |
case 3: | |
$ctx.sent = $__23.value; | |
$ctx.state = -2; | |
break; | |
case 2: | |
$ctx.state = 12; | |
return $__23.value; | |
default: | |
return $ctx.end(); | |
} | |
}, $__21, this); | |
}) | |
}, {}); | |
Object.defineProperty(Set.prototype, Symbol.iterator, { | |
configurable: true, | |
writable: true, | |
value: Set.prototype.values | |
}); | |
Object.defineProperty(Set.prototype, 'keys', { | |
configurable: true, | |
writable: true, | |
value: Set.prototype.values | |
}); | |
function polyfillSet(global) { | |
var $__17 = global, | |
Object = $__17.Object, | |
Symbol = $__17.Symbol; | |
if (!global.Set) | |
global.Set = Set; | |
var setPrototype = global.Set.prototype; | |
if (setPrototype.values) { | |
maybeAddIterator(setPrototype, setPrototype.values, Symbol); | |
maybeAddIterator(Object.getPrototypeOf(new global.Set().values()), function() { | |
return this; | |
}, Symbol); | |
} | |
} | |
registerPolyfill(polyfillSet); | |
return { | |
get Set() { | |
return Set; | |
}, | |
get polyfillSet() { | |
return polyfillSet; | |
} | |
}; | |
}); | |
System.get("traceur-runtime@0.0.60/src/runtime/polyfills/Set" + ''); | |
System.register("traceur-runtime@0.0.60/node_modules/rsvp/lib/rsvp/asap", [], function() { | |
"use strict"; | |
var __moduleName = "traceur-runtime@0.0.60/node_modules/rsvp/lib/rsvp/asap"; | |
var len = 0; | |
function asap(callback, arg) { | |
queue[len] = callback; | |
queue[len + 1] = arg; | |
len += 2; | |
if (len === 2) { | |
scheduleFlush(); | |
} | |
} | |
var $__default = asap; | |
var browserGlobal = (typeof window !== 'undefined') ? window : {}; | |
var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver; | |
var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined'; | |
function useNextTick() { | |
return function() { | |
process.nextTick(flush); | |
}; | |
} | |
function useMutationObserver() { | |
var iterations = 0; | |
var observer = new BrowserMutationObserver(flush); | |
var node = document.createTextNode(''); | |
observer.observe(node, {characterData: true}); | |
return function() { | |
node.data = (iterations = ++iterations % 2); | |
}; | |
} | |
function useMessageChannel() { | |
var channel = new MessageChannel(); | |
channel.port1.onmessage = flush; | |
return function() { | |
channel.port2.postMessage(0); | |
}; | |
} | |
function useSetTimeout() { | |
return function() { | |
setTimeout(flush, 1); | |
}; | |
} | |
var queue = new Array(1000); | |
function flush() { | |
for (var i = 0; i < len; i += 2) { | |
var callback = queue[i]; | |
var arg = queue[i + 1]; | |
callback(arg); | |
queue[i] = undefined; | |
queue[i + 1] = undefined; | |
} | |
len = 0; | |
} | |
var scheduleFlush; | |
if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') { | |
scheduleFlush = useNextTick(); | |
} else if (BrowserMutationObserver) { | |
scheduleFlush = useMutationObserver(); | |
} else if (isWorker) { | |
scheduleFlush = useMessageChannel(); | |
} else { | |
scheduleFlush = useSetTimeout(); | |
} | |
return {get default() { | |
return $__default; | |
}}; | |
}); | |
System.register("traceur-runtime@0.0.60/src/runtime/polyfills/Promise", [], function() { | |
"use strict"; | |
var __moduleName = "traceur-runtime@0.0.60/src/runtime/polyfills/Promise"; | |
var async = System.get("traceur-runtime@0.0.60/node_modules/rsvp/lib/rsvp/asap").default; | |
var registerPolyfill = System.get("traceur-runtime@0.0.60/src/runtime/polyfills/utils").registerPolyfill; | |
var promiseRaw = {}; | |
function isPromise(x) { | |
return x && typeof x === 'object' && x.status_ !== undefined; | |
} | |
function idResolveHandler(x) { | |
return x; | |
} | |
function idRejectHandler(x) { | |
throw x; | |
} | |
function chain(promise) { | |
var onResolve = arguments[1] !== (void 0) ? arguments[1] : idResolveHandler; | |
var onReject = arguments[2] !== (void 0) ? arguments[2] : idRejectHandler; | |
var deferred = getDeferred(promise.constructor); | |
switch (promise.status_) { | |
case undefined: | |
throw TypeError; | |
case 0: | |
promise.onResolve_.push(onResolve, deferred); | |
promise.onReject_.push(onReject, deferred); | |
break; | |
case +1: | |
promiseEnqueue(promise.value_, [onResolve, deferred]); | |
break; | |
case -1: | |
promiseEnqueue(promise.value_, [onReject, deferred]); | |
break; | |
} | |
return deferred.promise; | |
} | |
function getDeferred(C) { | |
if (this === $Promise) { | |
var promise = promiseInit(new $Promise(promiseRaw)); | |
return { | |
promise: promise, | |
resolve: (function(x) { | |
promiseResolve(promise, x); | |
}), | |
reject: (function(r) { | |
promiseReject(promise, r); | |
}) | |
}; | |
} else { | |
var result = {}; | |
result.promise = new C((function(resolve, reject) { | |
result.resolve = resolve; | |
result.reject = reject; | |
})); | |
return result; | |
} | |
} | |
function promiseSet(promise, status, value, onResolve, onReject) { | |
promise.status_ = status; | |
promise.value_ = value; | |
promise.onResolve_ = onResolve; | |
promise.onReject_ = onReject; | |
return promise; | |
} | |
function promiseInit(promise) { | |
return promiseSet(promise, 0, undefined, [], []); | |
} | |
var Promise = function Promise(resolver) { | |
if (resolver === promiseRaw) | |
return; | |
if (typeof resolver !== 'function') | |
throw new TypeError; | |
var promise = promiseInit(this); | |
try { | |
resolver((function(x) { | |
promiseResolve(promise, x); | |
}), (function(r) { | |
promiseReject(promise, r); | |
})); | |
} catch (e) { | |
promiseReject(promise, e); | |
} | |
}; | |
($traceurRuntime.createClass)(Promise, { | |
catch: function(onReject) { | |
return this.then(undefined, onReject); | |
}, | |
then: function(onResolve, onReject) { | |
if (typeof onResolve !== 'function') | |
onResolve = idResolveHandler; | |
if (typeof onReject !== 'function') | |
onReject = idRejectHandler; | |
var that = this; | |
var constructor = this.constructor; | |
return chain(this, function(x) { | |
x = promiseCoerce(constructor, x); | |
return x === that ? onReject(new TypeError) : isPromise(x) ? x.then(onResolve, onReject) : onResolve(x); | |
}, onReject); | |
} | |
}, { | |
resolve: function(x) { | |
if (this === $Promise) { | |
if (isPromise(x)) { | |
return x; | |
} | |
return promiseSet(new $Promise(promiseRaw), +1, x); | |
} else { | |
return new this(function(resolve, reject) { | |
resolve(x); | |
}); | |
} | |
}, | |
reject: function(r) { | |
if (this === $Promise) { | |
return promiseSet(new $Promise(promiseRaw), -1, r); | |
} else { | |
return new this((function(resolve, reject) { | |
reject(r); | |
})); | |
} | |
}, | |
all: function(values) { | |
var deferred = getDeferred(this); | |
var resolutions = []; | |
try { | |
var count = values.length; | |
if (count === 0) { | |
deferred.resolve(resolutions); | |
} else { | |
for (var i = 0; i < values.length; i++) { | |
this.resolve(values[i]).then(function(i, x) { | |
resolutions[i] = x; | |
if (--count === 0) | |
deferred.resolve(resolutions); | |
}.bind(undefined, i), (function(r) { | |
deferred.reject(r); | |
})); | |
} | |
} | |
} catch (e) { | |
deferred.reject(e); | |
} | |
return deferred.promise; | |
}, | |
race: function(values) { | |
var deferred = getDeferred(this); | |
try { | |
for (var i = 0; i < values.length; i++) { | |
this.resolve(values[i]).then((function(x) { | |
deferred.resolve(x); | |
}), (function(r) { | |
deferred.reject(r); | |
})); | |
} | |
} catch (e) { | |
deferred.reject(e); | |
} | |
return deferred.promise; | |
} | |
}); | |
var $Promise = Promise; | |
var $PromiseReject = $Promise.reject; | |
function promiseResolve(promise, x) { | |
promiseDone(promise, +1, x, promise.onResolve_); | |
} | |
function promiseReject(promise, r) { | |
promiseDone(promise, -1, r, promise.onReject_); | |
} | |
function promiseDone(promise, status, value, reactions) { | |
if (promise.status_ !== 0) | |
return; | |
promiseEnqueue(value, reactions); | |
promiseSet(promise, status, value); | |
} | |
function promiseEnqueue(value, tasks) { | |
async((function() { | |
for (var i = 0; i < tasks.length; i += 2) { | |
promiseHandle(value, tasks[i], tasks[i + 1]); | |
} | |
})); | |
} | |
function promiseHandle(value, handler, deferred) { | |
try { | |
var result = handler(value); | |
if (result === deferred.promise) | |
throw new TypeError; | |
else if (isPromise(result)) | |
chain(result, deferred.resolve, deferred.reject); | |
else | |
deferred.resolve(result); | |
} catch (e) { | |
try { | |
deferred.reject(e); | |
} catch (e) {} | |
} | |
} | |
var thenableSymbol = '@@thenable'; | |
function isObject(x) { | |
return x && (typeof x === 'object' || typeof x === 'function'); | |
} | |
function promiseCoerce(constructor, x) { | |
if (!isPromise(x) && isObject(x)) { | |
var then; | |
try { | |
then = x.then; | |
} catch (r) { | |
var promise = $PromiseReject.call(constructor, r); | |
x[thenableSymbol] = promise; | |
return promise; | |
} | |
if (typeof then === 'function') { | |
var p = x[thenableSymbol]; | |
if (p) { | |
return p; | |
} else { | |
var deferred = getDeferred(constructor); | |
x[thenableSymbol] = deferred.promise; | |
try { | |
then.call(x, deferred.resolve, deferred.reject); | |
} catch (r) { | |
deferred.reject(r); | |
} | |
return deferred.promise; | |
} | |
} | |
} | |
return x; | |
} | |
function polyfillPromise(global) { | |
if (!global.Promise) | |
global.Promise = Promise; | |
} | |
registerPolyfill(polyfillPromise); | |
return { | |
get Promise() { | |
return Promise; | |
}, | |
get polyfillPromise() { | |
return polyfillPromise; | |
} | |
}; | |
}); | |
System.get("traceur-runtime@0.0.60/src/runtime/polyfills/Promise" + ''); | |
System.register("traceur-runtime@0.0.60/src/runtime/polyfills/StringIterator", [], function() { | |
"use strict"; | |
var $__29; | |
var __moduleName = "traceur-runtime@0.0.60/src/runtime/polyfills/StringIterator"; | |
var $__27 = System.get("traceur-runtime@0.0.60/src/runtime/polyfills/utils"), | |
createIteratorResultObject = $__27.createIteratorResultObject, | |
isObject = $__27.isObject; | |
var $__30 = $traceurRuntime, | |
hasOwnProperty = $__30.hasOwnProperty, | |
toProperty = $__30.toProperty; | |
var iteratedString = Symbol('iteratedString'); | |
var stringIteratorNextIndex = Symbol('stringIteratorNextIndex'); | |
var StringIterator = function StringIterator() {}; | |
($traceurRuntime.createClass)(StringIterator, ($__29 = {}, Object.defineProperty($__29, "next", { | |
value: function() { | |
var o = this; | |
if (!isObject(o) || !hasOwnProperty(o, iteratedString)) { | |
throw new TypeError('this must be a StringIterator object'); | |
} | |
var s = o[toProperty(iteratedString)]; | |
if (s === undefined) { | |
return createIteratorResultObject(undefined, true); | |
} | |
var position = o[toProperty(stringIteratorNextIndex)]; | |
var len = s.length; | |
if (position >= len) { | |
o[toProperty(iteratedString)] = undefined; | |
return createIteratorResultObject(undefined, true); | |
} | |
var first = s.charCodeAt(position); | |
var resultString; | |
if (first < 0xD800 || first > 0xDBFF || position + 1 === len) { | |
resultString = String.fromCharCode(first); | |
} else { | |
var second = s.charCodeAt(position + 1); | |
if (second < 0xDC00 || second > 0xDFFF) { | |
resultString = String.fromCharCode(first); | |
} else { | |
resultString = String.fromCharCode(first) + String.fromCharCode(second); | |
} | |
} | |
o[toProperty(stringIteratorNextIndex)] = position + resultString.length; | |
return createIteratorResultObject(resultString, false); | |
}, | |
configurable: true, | |
enumerable: true, | |
writable: true | |
}), Object.defineProperty($__29, Symbol.iterator, { | |
value: function() { | |
return this; | |
}, | |
configurable: true, | |
enumerable: true, | |
writable: true | |
}), $__29), {}); | |
function createStringIterator(string) { | |
var s = String(string); | |
var iterator = Object.create(StringIterator.prototype); | |
iterator[toProperty(iteratedString)] = s; | |
iterator[toProperty(stringIteratorNextIndex)] = 0; | |
return iterator; | |
} | |
return {get createStringIterator() { | |
return createStringIterator; | |
}}; | |
}); | |
System.register("traceur-runtime@0.0.60/src/runtime/polyfills/String", [], function() { | |
"use strict"; | |
var __moduleName = "traceur-runtime@0.0.60/src/runtime/polyfills/String"; | |
var createStringIterator = System.get("traceur-runtime@0.0.60/src/runtime/polyfills/StringIterator").createStringIterator; | |
var $__32 = System.get("traceur-runtime@0.0.60/src/runtime/polyfills/utils"), | |
maybeAddFunctions = $__32.maybeAddFunctions, | |
maybeAddIterator = $__32.maybeAddIterator, | |
registerPolyfill = $__32.registerPolyfill; | |
var $toString = Object.prototype.toString; | |
var $indexOf = String.prototype.indexOf; | |
var $lastIndexOf = String.prototype.lastIndexOf; | |
function startsWith(search) { | |
var string = String(this); | |
if (this == null || $toString.call(search) == '[object RegExp]') { | |
throw TypeError(); | |
} | |
var stringLength = string.length; | |
var searchString = String(search); | |
var searchLength = searchString.length; | |
var position = arguments.length > 1 ? arguments[1] : undefined; | |
var pos = position ? Number(position) : 0; | |
if (isNaN(pos)) { | |
pos = 0; | |
} | |
var start = Math.min(Math.max(pos, 0), stringLength); | |
return $indexOf.call(string, searchString, pos) == start; | |
} | |
function endsWith(search) { | |
var string = String(this); | |
if (this == null || $toString.call(search) == '[object RegExp]') { | |
throw TypeError(); | |
} | |
var stringLength = string.length; | |
var searchString = String(search); | |
var searchLength = searchString.length; | |
var pos = stringLength; | |
if (arguments.length > 1) { | |
var position = arguments[1]; | |
if (position !== undefined) { | |
pos = position ? Number(position) : 0; | |
if (isNaN(pos)) { | |
pos = 0; | |
} | |
} | |
} | |
var end = Math.min(Math.max(pos, 0), stringLength); | |
var start = end - searchLength; | |
if (start < 0) { | |
return false; | |
} | |
return $lastIndexOf.call(string, searchString, start) == start; | |
} | |
function contains(search) { | |
if (this == null) { | |
throw TypeError(); | |
} | |
var string = String(this); | |
var stringLength = string.length; | |
var searchString = String(search); | |
var searchLength = searchString.length; | |
var position = arguments.length > 1 ? arguments[1] : undefined; | |
var pos = position ? Number(position) : 0; | |
if (isNaN(pos)) { | |
pos = 0; | |
} | |
var start = Math.min(Math.max(pos, 0), stringLength); | |
return $indexOf.call(string, searchString, pos) != -1; | |
} | |
function repeat(count) { | |
if (this == null) { | |
throw TypeError(); | |
} | |
var string = String(this); | |
var n = count ? Number(count) : 0; | |
if (isNaN(n)) { | |
n = 0; | |
} | |
if (n < 0 || n == Infinity) { | |
throw RangeError(); | |
} | |
if (n == 0) { | |
return ''; | |
} | |
var result = ''; | |
while (n--) { | |
result += string; | |
} | |
return result; | |
} | |
function codePointAt(position) { | |
if (this == null) { | |
throw TypeError(); | |
} | |
var string = String(this); | |
var size = string.length; | |
var index = position ? Number(position) : 0; | |
if (isNaN(index)) { | |
index = 0; | |
} | |
if (index < 0 || index >= size) { | |
return undefined; | |
} | |
var first = string.charCodeAt(index); | |
var second; | |
if (first >= 0xD800 && first <= 0xDBFF && size > index + 1) { | |
second = string.charCodeAt(index + 1); | |
if (second >= 0xDC00 && second <= 0xDFFF) { | |
return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000; | |
} | |
} | |
return first; | |
} | |
function raw(callsite) { | |
var raw = callsite.raw; | |
var len = raw.length >>> 0; | |
if (len === 0) | |
return ''; | |
var s = ''; | |
var i = 0; | |
while (true) { | |
s += raw[i]; | |
if (i + 1 === len) | |
return s; | |
s += arguments[++i]; | |
} | |
} | |
function fromCodePoint() { | |
var codeUnits = []; | |
var floor = Math.floor; | |
var highSurrogate; | |
var lowSurrogate; | |
var index = -1; | |
var length = arguments.length; | |
if (!length) { | |
return ''; | |
} | |
while (++index < length) { | |
var codePoint = Number(arguments[index]); | |
if (!isFinite(codePoint) || codePoint < 0 || codePoint > 0x10FFFF || floor(codePoint) != codePoint) { | |
throw RangeError('Invalid code point: ' + codePoint); | |
} | |
if (codePoint <= 0xFFFF) { | |
codeUnits.push(codePoint); | |
} else { | |
codePoint -= 0x10000; | |
highSurrogate = (codePoint >> 10) + 0xD800; | |
lowSurrogate = (codePoint % 0x400) + 0xDC00; | |
codeUnits.push(highSurrogate, lowSurrogate); | |
} | |
} | |
return String.fromCharCode.apply(null, codeUnits); | |
} | |
function stringPrototypeIterator() { | |
var o = $traceurRuntime.checkObjectCoercible(this); | |
var s = String(o); | |
return createStringIterator(s); | |
} | |
function polyfillString(global) { | |
var String = global.String; | |
maybeAddFunctions(String.prototype, ['codePointAt', codePointAt, 'contains', contains, 'endsWith', endsWith, 'startsWith', startsWith, 'repeat', repeat]); | |
maybeAddFunctions(String, ['fromCodePoint', fromCodePoint, 'raw', raw]); | |
maybeAddIterator(String.prototype, stringPrototypeIterator, Symbol); | |
} | |
registerPolyfill(polyfillString); | |
return { | |
get startsWith() { | |
return startsWith; | |
}, | |
get endsWith() { | |
return endsWith; | |
}, | |
get contains() { | |
return contains; | |
}, | |
get repeat() { | |
return repeat; | |
}, | |
get codePointAt() { | |
return codePointAt; | |
}, | |
get raw() { | |
return raw; | |
}, | |
get fromCodePoint() { | |
return fromCodePoint; | |
}, | |
get stringPrototypeIterator() { | |
return stringPrototypeIterator; | |
}, | |
get polyfillString() { | |
return polyfillString; | |
} | |
}; | |
}); | |
System.get("traceur-runtime@0.0.60/src/runtime/polyfills/String" + ''); | |
System.register("traceur-runtime@0.0.60/src/runtime/polyfills/ArrayIterator", [], function() { | |
"use strict"; | |
var $__36; | |
var __moduleName = "traceur-runtime@0.0.60/src/runtime/polyfills/ArrayIterator"; | |
var $__34 = System.get("traceur-runtime@0.0.60/src/runtime/polyfills/utils"), | |
toObject = $__34.toObject, | |
toUint32 = $__34.toUint32, | |
createIteratorResultObject = $__34.createIteratorResultObject; | |
var ARRAY_ITERATOR_KIND_KEYS = 1; | |
var ARRAY_ITERATOR_KIND_VALUES = 2; | |
var ARRAY_ITERATOR_KIND_ENTRIES = 3; | |
var ArrayIterator = function ArrayIterator() {}; | |
($traceurRuntime.createClass)(ArrayIterator, ($__36 = {}, Object.defineProperty($__36, "next", { | |
value: function() { | |
var iterator = toObject(this); | |
var array = iterator.iteratorObject_; | |
if (!array) { | |
throw new TypeError('Object is not an ArrayIterator'); | |
} | |
var index = iterator.arrayIteratorNextIndex_; | |
var itemKind = iterator.arrayIterationKind_; | |
var length = toUint32(array.length); | |
if (index >= length) { | |
iterator.arrayIteratorNextIndex_ = Infinity; | |
return createIteratorResultObject(undefined, true); | |
} | |
iterator.arrayIteratorNextIndex_ = index + 1; | |
if (itemKind == ARRAY_ITERATOR_KIND_VALUES) | |
return createIteratorResultObject(array[index], false); | |
if (itemKind == ARRAY_ITERATOR_KIND_ENTRIES) | |
return createIteratorResultObject([index, array[index]], false); | |
return createIteratorResultObject(index, false); | |
}, | |
configurable: true, | |
enumerable: true, | |
writable: true | |
}), Object.defineProperty($__36, Symbol.iterator, { | |
value: function() { | |
return this; | |
}, | |
configurable: true, | |
enumerable: true, | |
writable: true | |
}), $__36), {}); | |
function createArrayIterator(array, kind) { | |
var object = toObject(array); | |
var iterator = new ArrayIterator; | |
iterator.iteratorObject_ = object; | |
iterator.arrayIteratorNextIndex_ = 0; | |
iterator.arrayIterationKind_ = kind; | |
return iterator; | |
} | |
function entries() { | |
return createArrayIterator(this, ARRAY_ITERATOR_KIND_ENTRIES); | |
} | |
function keys() { | |
return createArrayIterator(this, ARRAY_ITERATOR_KIND_KEYS); | |
} | |
function values() { | |
return createArrayIterator(this, ARRAY_ITERATOR_KIND_VALUES); | |
} | |
return { | |
get entries() { | |
return entries; | |
}, | |
get keys() { | |
return keys; | |
}, | |
get values() { | |
return values; | |
} | |
}; | |
}); | |
System.register("traceur-runtime@0.0.60/src/runtime/polyfills/Array", [], function() { | |
"use strict"; | |
var __moduleName = "traceur-runtime@0.0.60/src/runtime/polyfills/Array"; | |
var $__37 = System.get("traceur-runtime@0.0.60/src/runtime/polyfills/ArrayIterator"), | |
entries = $__37.entries, | |
keys = $__37.keys, | |
values = $__37.values; | |
var $__38 = System.get("traceur-runtime@0.0.60/src/runtime/polyfills/utils"), | |
checkIterable = $__38.checkIterable, | |
isCallable = $__38.isCallable, | |
isConstructor = $__38.isConstructor, | |
maybeAddFunctions = $__38.maybeAddFunctions, | |
maybeAddIterator = $__38.maybeAddIterator, | |
registerPolyfill = $__38.registerPolyfill, | |
toInteger = $__38.toInteger, | |
toLength = $__38.toLength, | |
toObject = $__38.toObject; | |
function from(arrLike) { | |
var mapFn = arguments[1]; | |
var thisArg = arguments[2]; | |
var C = this; | |
var items = toObject(arrLike); | |
var mapping = mapFn !== undefined; | |
var k = 0; | |
var arr, | |
len; | |
if (mapping && !isCallable(mapFn)) { | |
throw TypeError(); | |
} | |
if (checkIterable(items)) { | |
arr = isConstructor(C) ? new C() : []; | |
for (var $__39 = items[Symbol.iterator](), | |
$__40; !($__40 = $__39.next()).done; ) { | |
var item = $__40.value; | |
{ | |
if (mapping) { | |
arr[k] = mapFn.call(thisArg, item, k); | |
} else { | |
arr[k] = item; | |
} | |
k++; | |
} | |
} | |
arr.length = k; | |
return arr; | |
} | |
len = toLength(items.length); | |
arr = isConstructor(C) ? new C(len) : new Array(len); | |
for (; k < len; k++) { | |
if (mapping) { | |
arr[k] = typeof thisArg === 'undefined' ? mapFn(items[k], k) : mapFn.call(thisArg, items[k], k); | |
} else { | |
arr[k] = items[k]; | |
} | |
} | |
arr.length = len; | |
return arr; | |
} | |
function of() { | |
for (var items = [], | |
$__41 = 0; $__41 < arguments.length; $__41++) | |
items[$__41] = arguments[$__41]; | |
var C = this; | |
var len = items.length; | |
var arr = isConstructor(C) ? new C(len) : new Array(len); | |
for (var k = 0; k < len; k++) { | |
arr[k] = items[k]; | |
} | |
arr.length = len; | |
return arr; | |
} | |
function fill(value) { | |
var start = arguments[1] !== (void 0) ? arguments[1] : 0; | |
var end = arguments[2]; | |
var object = toObject(this); | |
var len = toLength(object.length); | |
var fillStart = toInteger(start); | |
var fillEnd = end !== undefined ? toInteger(end) : len; | |
fillStart = fillStart < 0 ? Math.max(len + fillStart, 0) : Math.min(fillStart, len); | |
fillEnd = fillEnd < 0 ? Math.max(len + fillEnd, 0) : Math.min(fillEnd, len); | |
while (fillStart < fillEnd) { | |
object[fillStart] = value; | |
fillStart++; | |
} | |
return object; | |
} | |
function find(predicate) { | |
var thisArg = arguments[1]; | |
return findHelper(this, predicate, thisArg); | |
} | |
function findIndex(predicate) { | |
var thisArg = arguments[1]; | |
return findHelper(this, predicate, thisArg, true); | |
} | |
function findHelper(self, predicate) { | |
var thisArg = arguments[2]; | |
var returnIndex = arguments[3] !== (void 0) ? arguments[3] : false; | |
var object = toObject(self); | |
var len = toLength(object.length); | |
if (!isCallable(predicate)) { | |
throw TypeError(); | |
} | |
for (var i = 0; i < len; i++) { | |
if (i in object) { | |
var value = object[i]; | |
if (predicate.call(thisArg, value, i, object)) { | |
return returnIndex ? i : value; | |
} | |
} | |
} | |
return returnIndex ? -1 : undefined; | |
} | |
function polyfillArray(global) { | |
var $__42 = global, | |
Array = $__42.Array, | |
Object = $__42.Object, | |
Symbol = $__42.Symbol; | |
maybeAddFunctions(Array.prototype, ['entries', entries, 'keys', keys, 'values', values, 'fill', fill, 'find', find, 'findIndex', findIndex]); | |
maybeAddFunctions(Array, ['from', from, 'of', of]); | |
maybeAddIterator(Array.prototype, values, Symbol); | |
maybeAddIterator(Object.getPrototypeOf([].values()), function() { | |
return this; | |
}, Symbol); | |
} | |
registerPolyfill(polyfillArray); | |
return { | |
get from() { | |
return from; | |
}, | |
get of() { | |
return of; | |
}, | |
get fill() { | |
return fill; | |
}, | |
get find() { | |
return find; | |
}, | |
get findIndex() { | |
return findIndex; | |
}, | |
get polyfillArray() { | |
return polyfillArray; | |
} | |
}; | |
}); | |
System.get("traceur-runtime@0.0.60/src/runtime/polyfills/Array" + ''); | |
System.register("traceur-runtime@0.0.60/src/runtime/polyfills/Object", [], function() { | |
"use strict"; | |
var __moduleName = "traceur-runtime@0.0.60/src/runtime/polyfills/Object"; | |
var $__43 = System.get("traceur-runtime@0.0.60/src/runtime/polyfills/utils"), | |
maybeAddFunctions = $__43.maybeAddFunctions, | |
registerPolyfill = $__43.registerPolyfill; | |
var $__44 = $traceurRuntime, | |
defineProperty = $__44.defineProperty, | |
getOwnPropertyDescriptor = $__44.getOwnPropertyDescriptor, | |
getOwnPropertyNames = $__44.getOwnPropertyNames, | |
keys = $__44.keys, | |
privateNames = $__44.privateNames; | |
function is(left, right) { | |
if (left === right) | |
return left !== 0 || 1 / left === 1 / right; | |
return left !== left && right !== right; | |
} | |
function assign(target) { | |
for (var i = 1; i < arguments.length; i++) { | |
var source = arguments[i]; | |
var props = keys(source); | |
var p, | |
length = props.length; | |
for (p = 0; p < length; p++) { | |
var name = props[p]; | |
if (privateNames[name]) | |
continue; | |
target[name] = source[name]; | |
} | |
} | |
return target; | |
} | |
function mixin(target, source) { | |
var props = getOwnPropertyNames(source); | |
var p, | |
descriptor, | |
length = props.length; | |
for (p = 0; p < length; p++) { | |
var name = props[p]; | |
if (privateNames[name]) | |
continue; | |
descriptor = getOwnPropertyDescriptor(source, props[p]); | |
defineProperty(target, props[p], descriptor); | |
} | |
return target; | |
} | |
function polyfillObject(global) { | |
var Object = global.Object; | |
maybeAddFunctions(Object, ['assign', assign, 'is', is, 'mixin', mixin]); | |
} | |
registerPolyfill(polyfillObject); | |
return { | |
get is() { | |
return is; | |
}, | |
get assign() { | |
return assign; | |
}, | |
get mixin() { | |
return mixin; | |
}, | |
get polyfillObject() { | |
return polyfillObject; | |
} | |
}; | |
}); | |
System.get("traceur-runtime@0.0.60/src/runtime/polyfills/Object" + ''); | |
System.register("traceur-runtime@0.0.60/src/runtime/polyfills/Number", [], function() { | |
"use strict"; | |
var __moduleName = "traceur-runtime@0.0.60/src/runtime/polyfills/Number"; | |
var $__46 = System.get("traceur-runtime@0.0.60/src/runtime/polyfills/utils"), | |
isNumber = $__46.isNumber, | |
maybeAddConsts = $__46.maybeAddConsts, | |
maybeAddFunctions = $__46.maybeAddFunctions, | |
registerPolyfill = $__46.registerPolyfill, | |
toInteger = $__46.toInteger; | |
var $abs = Math.abs; | |
var $isFinite = isFinite; | |
var $isNaN = isNaN; | |
var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1; | |
var MIN_SAFE_INTEGER = -Math.pow(2, 53) + 1; | |
var EPSILON = Math.pow(2, -52); | |
function NumberIsFinite(number) { | |
return isNumber(number) && $isFinite(number); | |
} | |
; | |
function isInteger(number) { | |
return NumberIsFinite(number) && toInteger(number) === number; | |
} | |
function NumberIsNaN(number) { | |
return isNumber(number) && $isNaN(number); | |
} | |
; | |
function isSafeInteger(number) { | |
if (NumberIsFinite(number)) { | |
var integral = toInteger(number); | |
if (integral === number) | |
return $abs(integral) <= MAX_SAFE_INTEGER; | |
} | |
return false; | |
} | |
function polyfillNumber(global) { | |
var Number = global.Number; | |
maybeAddConsts(Number, ['MAX_SAFE_INTEGER', MAX_SAFE_INTEGER, 'MIN_SAFE_INTEGER', MIN_SAFE_INTEGER, 'EPSILON', EPSILON]); | |
maybeAddFunctions(Number, ['isFinite', NumberIsFinite, 'isInteger', isInteger, 'isNaN', NumberIsNaN, 'isSafeInteger', isSafeInteger]); | |
} | |
registerPolyfill(polyfillNumber); | |
return { | |
get MAX_SAFE_INTEGER() { | |
return MAX_SAFE_INTEGER; | |
}, | |
get MIN_SAFE_INTEGER() { | |
return MIN_SAFE_INTEGER; | |
}, | |
get EPSILON() { | |
return EPSILON; | |
}, | |
get isFinite() { | |
return NumberIsFinite; | |
}, | |
get isInteger() { | |
return isInteger; | |
}, | |
get isNaN() { | |
return NumberIsNaN; | |
}, | |
get isSafeInteger() { | |
return isSafeInteger; | |
}, | |
get polyfillNumber() { | |
return polyfillNumber; | |
} | |
}; | |
}); | |
System.get("traceur-runtime@0.0.60/src/runtime/polyfills/Number" + ''); | |
System.register("traceur-runtime@0.0.60/src/runtime/polyfills/polyfills", [], function() { | |
"use strict"; | |
var __moduleName = "traceur-runtime@0.0.60/src/runtime/polyfills/polyfills"; | |
var polyfillAll = System.get("traceur-runtime@0.0.60/src/runtime/polyfills/utils").polyfillAll; | |
polyfillAll(this); | |
var setupGlobals = $traceurRuntime.setupGlobals; | |
$traceurRuntime.setupGlobals = function(global) { | |
setupGlobals(global); | |
polyfillAll(global); | |
}; | |
return {}; | |
}); | |
System.get("traceur-runtime@0.0.60/src/runtime/polyfills/polyfills" + ''); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment