@@ -1507,53 +1507,63 @@ namespace Js
1507
1507
1508
1508
// 4. Let sources be the List of argument values starting with the second argument.
1509
1509
// 5. For each element nextSource of sources, in ascending index order,
1510
- for (unsigned int i = 2 ; i < args.Info .Count ; i++)
1510
+ AssignHelper<true >(args[2 ], to, scriptContext);
1511
+ for (unsigned int i = 3 ; i < args.Info .Count ; i++)
1511
1512
{
1512
- // a. If nextSource is undefined or null, let keys be an empty List.
1513
- // b. Else,
1514
- // i.Let from be ToObject(nextSource).
1515
- // ii.ReturnIfAbrupt(from).
1516
- // iii.Let keys be from.[[OwnPropertyKeys]]().
1517
- // iv.ReturnIfAbrupt(keys).
1513
+ AssignHelper<false >(args[2 ], to, scriptContext);
1514
+ }
1515
+
1516
+ // 6. Return to.
1517
+ return to;
1518
+ }
1519
+
1520
+ template <bool tryCopy>
1521
+ void JavascriptObject::AssignHelper (Var fromArg, RecyclableObject* to, ScriptContext* scriptContext)
1522
+ {
1523
+ // a. If nextSource is undefined or null, let keys be an empty List.
1524
+ // b. Else,
1525
+ // i.Let from be ToObject(nextSource).
1526
+ // ii.ReturnIfAbrupt(from).
1527
+ // iii.Let keys be from.[[OwnPropertyKeys]]().
1528
+ // iv.ReturnIfAbrupt(keys).
1518
1529
1519
- RecyclableObject* from = nullptr ;
1520
- if (!JavascriptConversion::ToObject (args[i], scriptContext, &from))
1530
+ RecyclableObject* from = nullptr ;
1531
+ if (!JavascriptConversion::ToObject (fromArg, scriptContext, &from))
1532
+ {
1533
+ if (JavascriptOperators::IsUndefinedOrNull (fromArg))
1521
1534
{
1522
- if (JavascriptOperators::IsUndefinedOrNull (args[i]))
1523
- {
1524
- continue ;
1525
- }
1526
- JavascriptError::ThrowTypeError (scriptContext, JSERR_FunctionArgument_NeedObject, _u (" Object.assign" ));
1535
+ return ;
1527
1536
}
1537
+ JavascriptError::ThrowTypeError (scriptContext, JSERR_FunctionArgument_NeedObject, _u (" Object.assign" ));
1538
+ }
1528
1539
1529
1540
#if ENABLE_COPYONACCESS_ARRAY
1530
- JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray<Var>(from);
1541
+ JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray<Var>(from);
1531
1542
#endif
1532
1543
1533
- // if proxy, take slow path by calling [[OwnPropertyKeys]] on source
1534
- if (JavascriptProxy::Is (from))
1535
- {
1536
- AssignForProxyObjects (from, to, scriptContext);
1537
- }
1538
- // else use enumerator to extract keys from source
1539
- else
1544
+ // if proxy, take slow path by calling [[OwnPropertyKeys]] on source
1545
+ if (JavascriptProxy::Is (from))
1546
+ {
1547
+ AssignForProxyObjects (from, to, scriptContext);
1548
+ }
1549
+ // else use enumerator to extract keys from source
1550
+ else
1551
+ {
1552
+ bool copied = false ;
1553
+ if (tryCopy)
1540
1554
{
1541
1555
DynamicObject* fromObj = JavascriptOperators::TryFromVar<DynamicObject>(from);
1542
1556
DynamicObject* toObj = JavascriptOperators::TryFromVar<DynamicObject>(to);
1543
- bool cloned = false ;
1544
1557
if (toObj && fromObj && toObj->GetType () == scriptContext->GetLibrary ()->GetObjectType ())
1545
1558
{
1546
- cloned = toObj->TryCopy (fromObj);
1547
- }
1548
- if (!cloned)
1549
- {
1550
- AssignForGenericObjects (from, to, scriptContext);
1559
+ copied = toObj->TryCopy (fromObj);
1551
1560
}
1552
1561
}
1562
+ if (!copied)
1563
+ {
1564
+ AssignForGenericObjects (from, to, scriptContext);
1565
+ }
1553
1566
}
1554
-
1555
- // 6. Return to.
1556
- return to;
1557
1567
}
1558
1568
1559
1569
void JavascriptObject::AssignForGenericObjects (RecyclableObject* from, RecyclableObject* to, ScriptContext* scriptContext)
0 commit comments