mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-02-11 09:24:58 +00:00
Update std.js
This commit is contained in:
parent
401cb4296e
commit
6abe48ba5a
106
lib/std.js
106
lib/std.js
|
@ -449,6 +449,112 @@ AsyncFunction.bind = function(exports, args) {
|
|||
return result;
|
||||
};
|
||||
|
||||
function GeneratorFunction(f, callback) {
|
||||
this._f = f;
|
||||
this._callback = callback;
|
||||
this._nextState = 0;
|
||||
this._state = 0;
|
||||
this._value = undefined;
|
||||
this._done = false;
|
||||
this._yield = function(value) {
|
||||
if (this._nextState < this._state) {
|
||||
throw new ReferenceError("CONTINUE");
|
||||
} else {
|
||||
this._value = value;
|
||||
this._state++;
|
||||
throw new ReferenceError("BREAK");
|
||||
}
|
||||
throw new RangeError("OUT OF RANGE");
|
||||
};
|
||||
|
||||
this.next = function() {
|
||||
this._nextState = 0;
|
||||
|
||||
var go = true;
|
||||
while (go) {
|
||||
try {
|
||||
this._f(this._yield);
|
||||
} catch (e) {
|
||||
go = (e.message == "CONTINUE");
|
||||
this._nextState++;
|
||||
}
|
||||
}
|
||||
|
||||
this._done = (typeof this._callback !== "undefined" ? this._callback(this) : false);
|
||||
|
||||
return {
|
||||
value: this._value,
|
||||
done: this._done
|
||||
};
|
||||
};
|
||||
|
||||
this['return'] = function() {
|
||||
// Not implemented
|
||||
};
|
||||
|
||||
this['throw'] = function() {
|
||||
// Not implemented
|
||||
};
|
||||
}
|
||||
|
||||
function GeneratorFunction(f, callback) {
|
||||
this._f = f;
|
||||
this._callback = callback;
|
||||
this._nextState = 0;
|
||||
this._state = 0;
|
||||
this._value = undefined;
|
||||
this._done = false;
|
||||
this._yield = function(value) {
|
||||
if (this._nextState < this._state) {
|
||||
throw new ReferenceError("CONTINUE");
|
||||
} else {
|
||||
this._value = value;
|
||||
this._state++;
|
||||
throw new ReferenceError("BREAK");
|
||||
}
|
||||
throw new RangeError("OUT OF RANGE");
|
||||
};
|
||||
|
||||
this.next = function() {
|
||||
this._nextState = 0;
|
||||
|
||||
var go = true;
|
||||
while (go) {
|
||||
try {
|
||||
this._f(this._yield);
|
||||
} catch (e) {
|
||||
go = (e.message == "CONTINUE");
|
||||
this._nextState++;
|
||||
}
|
||||
}
|
||||
|
||||
this._done = (typeof this._callback !== "undefined" ? this._callback(this) : false);
|
||||
|
||||
return {
|
||||
value: this._value,
|
||||
done: this._done
|
||||
};
|
||||
};
|
||||
|
||||
this['return'] = function() {
|
||||
// Not implemented
|
||||
};
|
||||
|
||||
this['throw'] = function() {
|
||||
// Not implemented
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
new GeneratorFunction(function(yield) {
|
||||
yield(1);
|
||||
yield(2);
|
||||
yield(3);
|
||||
}, function(generator) {
|
||||
return generator._value == 3;
|
||||
});
|
||||
*/
|
||||
|
||||
global.GetResource = GetResource;
|
||||
global.sleep = sleep;
|
||||
global.repeat = repeat;
|
||||
|
|
Loading…
Reference in New Issue
Block a user