Closed
Bug 1288456
Opened 9 years ago
Closed 9 years ago
Wrong evaluation order in Function.prototype.bind
Categories
(Core :: JavaScript: Standard Library, defect)
Core
JavaScript: Standard Library
Tracking
()
RESOLVED
FIXED
mozilla52
People
(Reporter: anba, Assigned: anba)
Details
Attachments
(1 file, 2 obsolete files)
|
15.21 KB,
patch
|
anba
:
review+
|
Details | Diff | Splinter Review |
Test case:
---
var p = new Proxy(function(){}, new Proxy({}, {
get(t, pk, r) {
print("TRAP", pk);
}
}));
Function.prototype.bind.call(p);
---
Expected: "getPrototypeOf" trap is called first
Actual: "getPrototypeOf" trap is called last
| Assignee | ||
Comment 1•9 years ago
|
||
Simply moved the [[GetPrototypeOf]] called to self-hosted code, so it gets called at the correct time.
| Assignee | ||
Comment 2•9 years ago
|
||
Comment 3•9 years ago
|
||
Comment on attachment 8802258 [details] [diff] [review]
bug1288456.patch
Review of attachment 8802258 [details] [diff] [review]:
-----------------------------------------------------------------
This is rather unfortunate: the reason for having it in C++ was that it avoided the overhead of another native call in JS. Function#bind is pretty performance-critical, so making it slower (probably by tens of %), sucks.
That said, we do already have a C++ call in there, for `std_Object_hasOwnProperty`, so theoretically, we could add a new intrinsic that combines the two things. However, it'd need to return more than one thing.
Alternatively, we could try moving everything after step 4 to C++. I'm pretty sure I remember that that caused a slowdown, but I also don't know whether I tried everything possible to avoid that in C++.
Clearing the review for now, as I'd rather not land this with a perf regression: it's quite unlikely to cause issues in real-world code. If you feel strongly about it, we should discuss it some more.
Attachment #8802258 -
Flags: review?(till)
| Assignee | ||
Comment 4•9 years ago
|
||
New patch to avoid the 6-9% performance regression of the previous patch. Even provides better performance compared to tip, depending on the benchmark set-up:
```
function f() {} // Faster without patch.
// var f = function(){}; // Faster with patch.
function test() {
// var f = function(){}; // Faster with patch.
// function f() {} // Faster with patch.
var t = dateNow();
for (var i = 0; i < 1000000; ++i) f.bind();
return dateNow() - t;
}
for (var i = 0; i < 10; ++i) print(test());
```
Attachment #8802258 -
Attachment is obsolete: true
Attachment #8803412 -
Flags: review?(till)
Comment 5•9 years ago
|
||
Comment on attachment 8803412 [details] [diff] [review]
bug1288456.patch
Review of attachment 8803412 [details] [diff] [review]:
-----------------------------------------------------------------
Thank you, very nice!
::: js/src/vm/SelfHosting.cpp
@@ +546,5 @@
> + if (targetObj->is<JSFunction>() && !targetObj->as<JSFunction>().hasResolvedName())
> + name = targetObj->as<JSFunction>().getUnresolvedName(cx);
> +
> + RootedString rootedName(cx);
> + if (name != nullptr) {
Nit: this can just be `if (name)`
@@ +564,4 @@
> MOZ_ASSERT(!bound->hasGuessedAtom());
> + if (rootedName && !rootedName->empty()) {
> + StringBuffer sb(cx);
> + if (!sb.append("bound ") || !sb.append(rootedName))
You should be able to use `cx->names().boundWithSpace` here, too, I think? I'm pretty sure it won't have a meaningful impact on perf, but it won't hurt, either.
Attachment #8803412 -
Flags: review?(till) → review+
| Assignee | ||
Comment 6•9 years ago
|
||
Applied suggested review comments, carrying r+ from Till.
Attachment #8803412 -
Attachment is obsolete: true
Attachment #8803911 -
Flags: review+
| Assignee | ||
Updated•9 years ago
|
Keywords: checkin-needed
Pushed by cbook@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/84300334b59c
Resolve the target's prototype earlier in Function.prototype.bind. r=till
Keywords: checkin-needed
Comment 8•9 years ago
|
||
| bugherder | ||
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
status-firefox52:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla52
You need to log in
before you can comment on or make changes to this bug.
Description
•