Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge r228725 - Don't use JSFunction's allocation profile when gettin…
…g the prototype can be effectful https://bugs.webkit.org/show_bug.cgi?id=182942 <rdar://problem/37584764> Reviewed by Mark Lam. JSTests: * stress/get-prototype-create-this-effectful.js: Added. Source/JavaScriptCore: Prior to this patch, the create_this implementation assumed that anything that is a JSFunction can use the object allocation profile and go down the fast path to allocate the |this| object. Implied by this approach is that accessing the 'prototype' property of the incoming function is not an effectful operation. This is inherent to the ObjectAllocationProfile data structure: it caches the prototype field. However, getting the 'prototype' property might be an effectful operation, e.g, it could be a getter. Many variants of functions in JS have the 'prototype' property as non-configurable. However, some functions, like bound functions, do not have the 'prototype' field with these attributes. This patch adds the notion of 'canUseAllocationProfile' to JSFunction and threads it through so that we only go down the fast path and use the allocation profile when the prototype property is non-configurable. * bytecompiler/NodesCodegen.cpp: (JSC::ClassExprNode::emitBytecode): * dfg/DFGOperations.cpp: * runtime/CommonSlowPaths.cpp: (JSC::SLOW_PATH_DECL): * runtime/JSFunction.cpp: (JSC::JSFunction::prototypeForConstruction): (JSC::JSFunction::allocateAndInitializeRareData): (JSC::JSFunction::initializeRareData): (JSC::JSFunction::getOwnPropertySlot): (JSC::JSFunction::canUseAllocationProfileNonInline): * runtime/JSFunction.h: (JSC::JSFunction::ensureRareDataAndAllocationProfile): * runtime/JSFunctionInlines.h: (JSC::JSFunction::canUseAllocationProfile):
- Loading branch information
1 parent
d37752f
commit 9fa88d4
Showing
9 changed files
with
136 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
function assert(b) { | ||
if (!b) | ||
throw new Error("Bad assertion") | ||
} | ||
|
||
function test1() { | ||
let boundFunction = function () {}.bind(); | ||
Object.defineProperty(boundFunction, "prototype", { | ||
get() { | ||
throw Error("Hello"); | ||
} | ||
}); | ||
|
||
let threw = false; | ||
try { | ||
Reflect.construct(function() {}, [], boundFunction); | ||
} catch(e) { | ||
threw = true; | ||
assert(e.message === "Hello"); | ||
} | ||
assert(threw); | ||
} | ||
test1(); | ||
|
||
function test2() { | ||
let boundFunction = function () {}.bind(); | ||
let counter = 0; | ||
Object.defineProperty(boundFunction, "prototype", { | ||
get() { | ||
++counter; | ||
return {}; | ||
} | ||
}); | ||
|
||
const iters = 1000; | ||
for (let i = 0; i < iters; ++i) | ||
Reflect.construct(function() {}, [], boundFunction); | ||
assert(counter === iters); | ||
} | ||
test2(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters