Update std.js

This commit is contained in:
Namhyeon Go 2023-03-10 17:46:50 +09:00 committed by GitHub
parent 401cb4296e
commit 6abe48ba5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;