Closed Bug 1317389 Opened 8 years ago Closed 8 years ago

GeneratorFunction.prototype.constructor shouldn't be writable

Categories

(Core :: JavaScript: Standard Library, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla53
Tracking Status
firefox53 --- fixed

People

(Reporter: anba, Assigned: anba)

References

(Blocks 1 open bug)

Details

Attachments

(1 file, 1 obsolete file)

Test case:
---
var GeneratorFunctionPrototype = Object.getPrototypeOf(function*(){});
assertEq(Object.getOwnPropertyDescriptor(GeneratorFunctionPrototype, "constructor").writable, false);
---

Expected: Passes
Actual: Throws "Error: Assertion failed: got true, expected false"


ES2017 spec:
https://tc39.github.io/ecma262/#sec-generatorfunction.prototype.constructor
Attached patch bug1317389.patch (obsolete) — Splinter Review
The ECMAScript spec treats GeneratorFunction and AsyncFunction as subclasses of Function and therefore it uses different default property attributes for the "constructor" and "prototype" properties.
Assignee: nobody → andrebargull
Status: NEW → ASSIGNED
Attachment #8810950 - Flags: review?(jwalden+bmo)
Comment on attachment 8810950 [details] [diff] [review]
bug1317389.patch

Review of attachment 8810950 [details] [diff] [review]:
-----------------------------------------------------------------

::: js/src/tests/ecma_6/Generators/properties.js
@@ +12,5 @@
> +
> +assertEqArray(Object.getOwnPropertyNames(GeneratorFunction).sort(), ["length", "name", "prototype"]);
> +assertEqArray(Object.getOwnPropertySymbols(GeneratorFunction), []);
> +
> +assertDeepEq(Object.getOwnPropertyDescriptor(GeneratorFunction, "length"), {

Don't encourage use of assertDeepEq, which way overtests stuff and is much worse for debugging stacks and such.  Rather, add

function assertOwnDescriptor(obj, prop, expected)
{
  var desc = Object.getOwnPropertyDescriptor(obj, prop);
  if (desc === undefined)
  {
    assertEq(expected, undefined);
    return;
  }

  assertEq(desc.enumerable, expected.enumerable);
  assertEq(desc.configurable, expected.configurable);

  if (Object.hasOwnProperty(desc, "value"))
  {
    assertEq(desc.value, expected.value);
    assertEq(desc.writable, expected.writable);
  }
  else
  {
    assertEq(desc.get, expected.get);
    assertEq(desc.set, expected.set);
  }
}

and use that throughout these functions.
Attachment #8810950 - Flags: review?(jwalden+bmo) → review+
Attached patch bug1317389.patchSplinter Review
Updated per review comments, carrying r+ from Waldo.
Attachment #8810950 - Attachment is obsolete: true
Attachment #8811835 - Flags: review+
Pushed by cbook@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/1c66c26641ea
Change property attributes for generator and async functions to match ES2015/2017. r=Waldo
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/1c66c26641ea
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla53
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: