Closed Bug 1288456 Opened 9 years ago Closed 9 years ago

Wrong evaluation order in Function.prototype.bind

Categories

(Core :: JavaScript: Standard Library, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla52
Tracking Status
firefox50 --- affected
firefox52 --- fixed

People

(Reporter: anba, Assigned: anba)

Details

Attachments

(1 file, 2 obsolete files)

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
Attached patch bug1288456.patch (obsolete) — Splinter Review
Simply moved the [[GetPrototypeOf]] called to self-hosted code, so it gets called at the correct time.
Assignee: nobody → andrebargull
Status: NEW → ASSIGNED
Attachment #8802258 - Flags: review?(till)
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)
Attached patch bug1288456.patch (obsolete) — Splinter Review
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 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+
Attached patch bug1288456.patchSplinter Review
Applied suggested review comments, carrying r+ from Till.
Attachment #8803412 - Attachment is obsolete: true
Attachment #8803911 - Flags: review+
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
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla52
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: