-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JSC] Use cloning for Object.assign with empty object
https://bugs.webkit.org/show_bug.cgi?id=267239 rdar://120667395 Reviewed by Justin Michaud. This patch implements fast cloning path for `Object.assign({}, source)` case. When conditions are met, we clone Butterfly in source, set it to the empty target object, and use the source's Structure for target. This completely avoids iterating all object properties. * JSTests/stress/object-assign-clone.js: Added. (shouldBe): (shouldBeArray): (shouldBe.Reflect.getOwnPropertyDescriptor): (shouldBe.set get let): * Source/JavaScriptCore/dfg/DFGOperations.cpp: (JSC::DFG::JSC_DEFINE_JIT_OPERATION): * Source/JavaScriptCore/runtime/JSObject.h: * Source/JavaScriptCore/runtime/JSObjectInlines.h: (JSC::JSObject::fastForEachPropertyWithSideEffectFreeFunctor): Deleted. * Source/JavaScriptCore/runtime/ObjectConstructor.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): (JSC::toPropertyDescriptor): (JSC::defineProperties): * Source/JavaScriptCore/runtime/ObjectConstructorInlines.h: (JSC::objectCloneFast): (JSC::objectAssignFast): * Source/JavaScriptCore/runtime/Structure.cpp: (JSC::Structure::Structure): (JSC::Structure::nonPropertyTransitionSlow): * Source/JavaScriptCore/runtime/Structure.h: (JSC::Structure::seenProperties const): (JSC::Structure::bitFieldFlagsCantBeChangedWithoutTransition): (JSC::Structure::transitionPropertyAttributes const): (JSC::Structure::setTransitionPropertyAttributes): * Source/JavaScriptCore/runtime/StructureInlines.h: (JSC::Structure::add): (JSC::Structure::attributeChange): (JSC::Structure::addOrReplacePropertyWithoutTransition): Canonical link: https://commits.webkit.org/272794@main
- Loading branch information
1 parent
d34db4f
commit 11aee46
Showing
9 changed files
with
306 additions
and
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
function shouldBe(actual, expected) { | ||
if (actual !== expected) | ||
throw new Error('bad value: ' + actual); | ||
} | ||
|
||
function shouldBeArray(actual, expected) { | ||
shouldBe(actual.length, expected.length); | ||
for (var i = 0; i < expected.length; ++i) { | ||
try { | ||
shouldBe(actual[i], expected[i]); | ||
} catch(e) { | ||
print(JSON.stringify(actual)); | ||
throw e; | ||
} | ||
} | ||
} | ||
|
||
{ | ||
let source = {}; | ||
Reflect.defineProperty(source, "hello", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: 42, | ||
}); | ||
let result = Object.assign({}, source); | ||
shouldBe(Reflect.getOwnPropertyDescriptor(result, "hello"), undefined); | ||
} | ||
{ | ||
let source = {}; | ||
Reflect.defineProperty(source, "hello", { | ||
enumerable: true, | ||
configurable: false, | ||
writable: true, | ||
value: 42, | ||
}); | ||
let result = Object.assign({}, source); | ||
shouldBe(JSON.stringify(Reflect.getOwnPropertyDescriptor(result, "hello")), `{"value":42,"writable":true,"enumerable":true,"configurable":true}`); | ||
} | ||
{ | ||
let source = {}; | ||
Reflect.defineProperty(source, "hello", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: false, | ||
value: 42, | ||
}); | ||
let result = Object.assign({}, source); | ||
shouldBe(JSON.stringify(Reflect.getOwnPropertyDescriptor(result, "hello")), `{"value":42,"writable":true,"enumerable":true,"configurable":true}`); | ||
} | ||
{ | ||
let source = {}; | ||
Reflect.defineProperty(source, "hello", { | ||
enumerable: true, | ||
configurable: true, | ||
get() { return 42; }, | ||
set() { } | ||
}); | ||
let result = Object.assign({}, source); | ||
shouldBe(JSON.stringify(Reflect.getOwnPropertyDescriptor(result, "hello")), `{"value":42,"writable":true,"enumerable":true,"configurable":true}`); | ||
} |
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
Oops, something went wrong.