Closed
Bug 648355
Opened 14 years ago
Closed 14 years ago
Function.prototype.isGenerator
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
FIXED
People
(Reporter: dherman, Assigned: dherman)
References
()
Details
(Keywords: dev-doc-complete, Whiteboard: fixed-in-tracemonkey)
Attachments
(1 file, 1 obsolete file)
3.43 KB,
patch
|
brendan
:
review+
|
Details | Diff | Splinter Review |
Function.isGenerator(f) -> boolean
Indicates whether a given function is a generator function. As specified on the attached TC39 wiki page.
Should be easy -- I'll try to do today.
Dave
Assignee | ||
Comment 1•14 years ago
|
||
This version tests for generator functions by testing whether a function a) is interpreted and b) starts its script with JSOP_GENERATOR. This seems a bit brittle. Is it worth nabbing a JSFUN_XXX bit and setting that on the JSScript flags?
Dave
Assignee | ||
Comment 2•14 years ago
|
||
Brendan: what was the reason we couldn't put isGenerator on Function.prototype as a (non-enumerable) zero-argument self-test? Does it create web incompatibilities?
Dave
Assignee | ||
Comment 3•14 years ago
|
||
Ready for review.
Dave
Assignee: general → dherman
Attachment #524551 -
Attachment is obsolete: true
Attachment #524713 -
Flags: review?(brendan)
Assignee | ||
Updated•14 years ago
|
Summary: Function.isGenerator → Function.prototype.isGenerator
Comment 4•14 years ago
|
||
Comment on attachment 524713 [details] [diff] [review]
moved to Function.prototype, added tests
>From: Dave Herman <dherman@mozilla.com>
>Function.isGenerator (bug 648355, r=?)
>
>diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp
>--- a/js/src/jsfun.cpp
>+++ b/js/src/jsfun.cpp
>@@ -2331,16 +2331,39 @@ CallOrConstructBoundFunction(JSContext *
> return false;
>
> *vp = args.rval();
> return true;
> }
>
> }
>
>+ bool rval = false;
Nit: rval is a canonical name for a jsval or js::Value local. Suggest result or answer instead.
>+ if (fun->isInterpreted()) {
>+ JSScript *script = fun->u.i.script;
>+ rval = script->length > 0 && script->code[0] == JSOP_GENERATOR;
Nit: prevailing style prefers != 0 for unsigned tests, not > 0, but:
Non-nit: we don't need a length check here, scripts by definition have at least JSOP_STOP as a bytecode. So you could get rid of the script local, or keep it and assert that length != 0.
>+script regress-648355.js
I'm glad to have a regression test but this space in the suite is for actual bugs we don't want to reopen, not features being added and covered. IIRC from discussion with Waldo, something like tests/js1_8_5/extensions/is-generator.js would be better.
Best to update the strawman at the bug's URL to match what this patch implements.
r=me with these addressed; happy to look again if you like.
/be
Attachment #524713 -
Flags: review?(brendan) → review+
Assignee | ||
Comment 5•14 years ago
|
||
Whiteboard: fixed-in-tracemonkey
Assignee | ||
Comment 6•14 years ago
|
||
Waldo caught a missing #if/#endif. Pushed here:
http://hg.mozilla.org/tracemonkey/rev/dbecfa435101
Comment 7•14 years ago
|
||
http://hg.mozilla.org/mozilla-central/rev/90fa43dcb844
http://hg.mozilla.org/mozilla-central/rev/dbecfa435101
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Updated•14 years ago
|
Keywords: dev-doc-needed
Comment 8•14 years ago
|
||
Now documented:
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/isGenerator
With a link from the Function page here:
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function#Methods_2
And mentioned on Firefox 5 for developers.
Keywords: dev-doc-needed → dev-doc-complete
You need to log in
before you can comment on or make changes to this bug.
Description
•