JavaScript Feature Reference: Generator Object Web Browser Support Test

Last reviewed/updated: 03 Jan 2018 | Published: 01 Jan 2018 | Status: Active
Web browser support: Internet Explorer 10+, Edge 12+, Firefox 6+, Chrome 30+, Opera 17+

1. Introduction

In this web page there are two web browser JavaScript feature support tests; 1.) a feature implementation test, and 2.) a feature capability test. First, the implementation test is run. The implementation test determines if the web browser recognizes the JavaScript Generator object. The implementation test is a simple test for the presence of web browser support, and a definitive test for the absence of web browser support. If the web browser does not recognize the JavaScript Generator object, the testing is stopped and the implementation test reports: Fail (no support): The web browser does not recognize the JavaScript Generator object. The web browser does not support the JavaScript Generator object.

If the web browser recognizes the JavaScript Generator object, the capability test is run. The capability test determines if the web browser's implementation of the JavaScript Generator object includes support for at least one Generator object capability. The capability test is a more definitive, albeit not an all inclusive, test for the presence of web browser support. If the web browser's implementation of the JavaScript Generator object includes support for the tested capability, the capability test reports: Pass (at least partial/possibly full support): The web browser recognizes the JavaScript Generator object, and supports at least one Generator object capability. The web browser at least partially/possibly fully supports the JavaScript Generator object. Positive determination of full web browser support is beyond the scope of this test. If the web browser's implementation of the JavaScript Generator object does not include support for the tested capability, the capability test reports: Pass/Fail (partial support): The web browser recognizes the JavaScript Generator object, but does not support at least one Generator object capability. The web browser partially supports the JavaScript Generator object.

The web browser support test source code is shown in Section 2.1. The web browser support test source code is run in Section 2.2, which shows the web browser support test result.

1.1. Generator Object Web Browser Support

  • Pass (at least partial/possibly full support): ED13+, FF29+, CH39+, OP26+.
  • Fail (no support): IE11-, SF5.1.7-.

1.2. Abbreviations

  • IE = Internet Explorer.
  • ED = Edge = EdgeHTML rendering engine (ED12+) and/or Edge browser (ED20+).
  • FF = Firefox.
  • SF = Safari.
  • CH = Chrome.
  • OP = Opera.

2. Generator Object Web Browser Support Test

2.1. Web Browser Support Test Source Code

For the web browser test source code with additional comments, see Generator Object Web Browser Support Test With Additional Comments (learnwebcoding.com).
<p id='testId'><b>Fail</b> (no support): The web browser does not recognize the JavaScript <code>Generator</code> object. The web browser does not support the JavaScript <code>Generator</code> object.</p><!-- Hard code Fail because web browser no support error stops JavaScript execution. -->

<script>
function* generatorFunctionOne(){
 yield 1; // First call to next() returns Object {value: 1, done: false}.
 yield 2; // Second call to next() returns Object {value: 2, done: false}.
 yield 3; // Third call to next() returns Object {value: 3, done: false}. Subsequent calls to next() return Object {value: undefined, done: true}.
}
function* generatorFunctionTwo(param){
 yield param; // First call to next() returns Object {value: 1, done: false}. param = 1 throughout.
 yield param + 1; // Second call to next() returns Object {value: 2, done: false}. param = 1 throughout.
 yield param + 2; // Third call to next() returns Object {value: 3, done: false}. Subsequent calls to next() return Object {value: undefined, done: true}. param = 1 throughout.
}
function* generatorFunctionThree(param){
 yield param++; // param = 1. First call to next() returns Object {value: 1, done: false}. Then post increment param to 2.
 yield param++; // param = 2 from line above. Second call to next() returns Object {value: 2, done: false}. Then post increment param to 3.
 yield param++; // param = 3 from line above. Third call to next() returns Object {value: 3, done: false}. Then post increment param to 4. Subsequent calls to next() return Object {value: undefined, done: true}.
}
function* generatorFunctionFour(){
 yield 1; // First call to next() returns Object {value: 1, done: false}.
 return 2; // Second call to next() returns Object {value: 2, done: true}. Subsequent calls to next() return Object {value: undefined, done: true}.
 yield 3; // Unreachable code after return statement.
}
// Call generator functions. Each call returns a Generator object which inherits prototype from Object (window.Generator property does not exist) and is an iterator. Generator object has next() method property.
var generatorObjectOne = generatorFunctionOne();
var generatorObjectTwo = generatorFunctionTwo(1);
var generatorObjectThree = generatorFunctionThree(1);
var generatorObjectFour = generatorFunctionFour();
// For generatorObjectOne capability tests.
var generatorObjectOneFirstNext = generatorObjectOne.next(); // Object {value: 1, done: false}.
var generatorObjectOneFirstNextValue = generatorObjectOneFirstNext.value; // 1.
var generatorObjectOneFirstNextDone = generatorObjectOneFirstNext.done; // false.
var generatorObjectOneSecondNextValue = generatorObjectOne.next().value; // 2.
var generatorObjectOneThirdNext = generatorObjectOne.next(); // Object {value: 3, done: false}.
var generatorObjectOneThirdNextValue = generatorObjectOneThirdNext.value; // 3.
var generatorObjectOneThirdNextDone = generatorObjectOneThirdNext.done; // false.
var generatorObjectOneSubsequentNext = generatorObjectOne.next(); // Object {value: undefined, done: true}.
var generatorObjectOneSubsequentNextValue = generatorObjectOneSubsequentNext.value; // undefined.
var generatorObjectOneSubsequentNextDone = generatorObjectOneSubsequentNext.done; // true.
// For generatorObjectFour capability tests.
var generatorObjectFourFirstNext = generatorObjectFour.next(); // Object {value: 1, done: false}.
var generatorObjectFourFirstNextValue = generatorObjectFourFirstNext.value; // 1.
var generatorObjectFourFirstNextDone = generatorObjectFourFirstNext.done; // false.
var generatorObjectFourSecondNext = generatorObjectFour.next(); // Object {value: 2, done: true}.
var generatorObjectFourSecondNextValue = generatorObjectFourSecondNext.value; // 2.
var generatorObjectFourSecondNextDone = generatorObjectFourSecondNext.done; // true.
var generatorObjectFourSubsequentNext = generatorObjectFour.next(); // Object {value: undefined, done: true}.
var generatorObjectFourSubsequentNextValue = generatorObjectFourSubsequentNext.value; // undefined.
var generatorObjectFourSubsequentNextDone = generatorObjectFourSubsequentNext.done; // true.
if (window.generatorObjectOne){ // Identical to if (generatorObjectOne).
 var element = document.getElementById("testId");
 if ((typeof generatorObjectOne === "object") && generatorObjectOne instanceof Object && Object.prototype.isPrototypeOf(generatorObjectOne) && generatorObjectOne[Symbol.iterator] && (typeof generatorObjectOneFirstNext === "object") && (generatorObjectOneFirstNextValue === 1) && (generatorObjectOneFirstNextDone === false) && (generatorObjectOneSecondNextValue === 2) && (generatorObjectOneThirdNextValue === 3) && (generatorObjectOneThirdNextDone === false) && (typeof generatorObjectOneSubsequentNext === "object") && (generatorObjectOneSubsequentNextValue === undefined) && (generatorObjectOneSubsequentNextDone === true) && (generatorObjectTwo.next().value === 1) && (generatorObjectTwo.next().value === 2) && (generatorObjectTwo.next().value === 3) && (generatorObjectThree.next().value === 1) && (generatorObjectThree.next().value === 2) && (generatorObjectThree.next().value === 3) && (generatorObjectThree.next().value === undefined) && (generatorObjectThree.next().value === undefined) && (generatorObjectFourFirstNextValue === 1) && (generatorObjectFourFirstNextDone === false) && (generatorObjectFourSecondNextValue === 2) && (generatorObjectFourSecondNextDone === true) && (generatorObjectFourSubsequentNextValue === undefined) && (generatorObjectFourSubsequentNextDone === true)){
  element.innerHTML = "<b>Pass</b> (at least partial/possibly full support): The web browser recognizes the JavaScript <code>Generator</code> object, and supports at least one <code>Generator</code> object capability. The web browser at least partially/possibly fully supports the JavaScript <code>Generator</code> object. Positive determination of full web browser support is beyond the scope of this test.";
 } else {
  element.innerHTML = "<b>Pass/Fail</b> (partial support): The web browser recognizes the JavaScript <code>Generator</code> object, but does not support at least one <code>Generator</code> object capability. The web browser partially supports the JavaScript <code>Generator</code> object.";
 }
}
</script>

2.2. Web Browser Support Test Result

Fail (no support): The web browser does not recognize the JavaScript Generator object. The web browser does not support the JavaScript Generator object.


3. Resources And Additional Information