Skip to content

Commit d5407a9

Browse files
committed
We don't need special handle OwnKeys for CEO wrapper.
The code below will make sure to dispatch to CEO in proper way
1 parent 833c7f5 commit d5407a9

File tree

3 files changed

+0
-265
lines changed

3 files changed

+0
-265
lines changed

lib/Runtime/Language/JavascriptOperators.cpp

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,16 +1237,6 @@ using namespace Js;
12371237
{
12381238
return proxy->PropertyKeysTrap(JavascriptProxy::KeysTrapKind::GetOwnPropertyNamesKind, scriptContext);
12391239
}
1240-
#ifdef _CHAKRACOREBUILD
1241-
else
1242-
{
1243-
CustomExternalWrapperObject * wrapper = JavascriptOperators::TryFromVar<CustomExternalWrapperObject>(instance);
1244-
if (wrapper)
1245-
{
1246-
return wrapper->PropertyKeysTrap(CustomExternalWrapperObject::KeysTrapKind::GetOwnPropertyNamesKind, scriptContext);
1247-
}
1248-
}
1249-
#endif
12501240

12511241
return JavascriptObject::CreateOwnStringPropertiesHelper(object, scriptContext);
12521242
}
@@ -1262,16 +1252,6 @@ using namespace Js;
12621252
{
12631253
return proxy->PropertyKeysTrap(JavascriptProxy::KeysTrapKind::GetOwnPropertySymbolKind, scriptContext);
12641254
}
1265-
#ifdef _CHAKRACOREBUILD
1266-
else
1267-
{
1268-
CustomExternalWrapperObject * wrapper = JavascriptOperators::TryFromVar<CustomExternalWrapperObject>(instance);
1269-
if (wrapper)
1270-
{
1271-
return wrapper->PropertyKeysTrap(CustomExternalWrapperObject::KeysTrapKind::GetOwnPropertySymbolKind, scriptContext);
1272-
}
1273-
}
1274-
#endif
12751255

12761256
return JavascriptObject::CreateOwnSymbolPropertiesHelper(object, scriptContext);
12771257
}
@@ -1286,16 +1266,6 @@ using namespace Js;
12861266
{
12871267
return proxy->PropertyKeysTrap(JavascriptProxy::KeysTrapKind::KeysKind, scriptContext);
12881268
}
1289-
#ifdef _CHAKRACOREBUILD
1290-
else
1291-
{
1292-
CustomExternalWrapperObject * wrapper = JavascriptOperators::TryFromVar<CustomExternalWrapperObject>(instance);
1293-
if (wrapper)
1294-
{
1295-
return wrapper->PropertyKeysTrap(CustomExternalWrapperObject::KeysTrapKind::KeysKind, scriptContext);
1296-
}
1297-
}
1298-
#endif
12991269

13001270
return JavascriptObject::CreateOwnStringSymbolPropertiesHelper(object, scriptContext);
13011271
}
@@ -1331,43 +1301,6 @@ using namespace Js;
13311301
}
13321302
return proxyResultToReturn;
13331303
}
1334-
#ifdef _CHAKRACOREBUILD
1335-
else
1336-
{
1337-
CustomExternalWrapperObject * wrapper = JavascriptOperators::TryFromVar<CustomExternalWrapperObject>(object);
1338-
if (wrapper)
1339-
{
1340-
JavascriptArray* wrapperResult = wrapper->PropertyKeysTrap(CustomExternalWrapperObject::KeysTrapKind::GetOwnEnumerablePropertyNamesKind, scriptContext);
1341-
JavascriptArray* wrapperResultToReturn = scriptContext->GetLibrary()->CreateArray(0);
1342-
if (wrapperResult != nullptr)
1343-
{
1344-
// filter enumerable keys
1345-
uint32 resultLength = wrapperResult->GetLength();
1346-
Var element;
1347-
const Js::PropertyRecord *propertyRecord = nullptr;
1348-
uint32 index = 0;
1349-
for (uint32 i = 0; i < resultLength; i++)
1350-
{
1351-
element = wrapperResult->DirectGetItem(i);
1352-
1353-
Assert(!VarIs<JavascriptSymbol>(element));
1354-
1355-
PropertyDescriptor propertyDescriptor;
1356-
JavascriptConversion::ToPropertyKey(element, scriptContext, &propertyRecord, nullptr);
1357-
if (JavascriptOperators::GetOwnPropertyDescriptor(object, propertyRecord->GetPropertyId(), scriptContext, &propertyDescriptor))
1358-
{
1359-
if (propertyDescriptor.IsEnumerable())
1360-
{
1361-
wrapperResultToReturn->DirectSetItemAt(index++, CrossSite::MarshalVar(scriptContext, element));
1362-
}
1363-
}
1364-
}
1365-
}
1366-
1367-
return wrapperResultToReturn;
1368-
}
1369-
}
1370-
#endif
13711304

13721305
return JavascriptObject::CreateOwnEnumerableStringPropertiesHelper(object, scriptContext);
13731306
}
@@ -1379,16 +1312,6 @@ using namespace Js;
13791312
{
13801313
return proxy->PropertyKeysTrap(JavascriptProxy::KeysTrapKind::KeysKind, scriptContext);
13811314
}
1382-
#ifdef _CHAKRACOREBUILD
1383-
else
1384-
{
1385-
CustomExternalWrapperObject * wrapper = JavascriptOperators::TryFromVar<CustomExternalWrapperObject>(object);
1386-
if (wrapper)
1387-
{
1388-
return wrapper->PropertyKeysTrap(CustomExternalWrapperObject::KeysTrapKind::EnumerableKeysKind, scriptContext);
1389-
}
1390-
}
1391-
#endif
13921315

13931316
return JavascriptObject::CreateOwnEnumerableStringSymbolPropertiesHelper(object, scriptContext);
13941317
}

lib/Runtime/Library/CustomExternalWrapperObject.cpp

Lines changed: 0 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,192 +1184,6 @@ BOOL CustomExternalWrapperObject::DeleteProperty(Js::JavascriptString *propertyN
11841184
return TRUE;
11851185
}
11861186

1187-
Js::JavascriptArray * CustomExternalWrapperObject::PropertyKeysTrap(KeysTrapKind keysTrapKind, Js::ScriptContext * requestContext)
1188-
{
1189-
PROBE_STACK(GetScriptContext(), Js::Constants::MinStackDefault);
1190-
1191-
// Reject implicit call
1192-
ThreadContext* threadContext = requestContext->GetThreadContext();
1193-
if (threadContext->IsDisableImplicitCall())
1194-
{
1195-
threadContext->AddImplicitCallFlags(Js::ImplicitCall_External);
1196-
return nullptr;
1197-
}
1198-
1199-
if (!this->EnsureInitialized(requestContext))
1200-
{
1201-
return nullptr;
1202-
}
1203-
1204-
Js::RecyclableObject * targetObj = this;
1205-
CustomExternalWrapperType * type = this->GetExternalType();
1206-
Js::JavascriptFunction* ownKeysMethod = nullptr;
1207-
if (type->GetJsGetterSetterInterceptor()->ownKeysTrap != nullptr)
1208-
{
1209-
ownKeysMethod = Js::VarTo<JavascriptFunction>(type->GetJsGetterSetterInterceptor()->ownKeysTrap);
1210-
}
1211-
1212-
Assert(!GetScriptContext()->IsHeapEnumInProgress());
1213-
1214-
if (nullptr == ownKeysMethod)
1215-
{
1216-
switch (keysTrapKind)
1217-
{
1218-
case KeysTrapKind::GetOwnPropertyNamesKind:
1219-
return JavascriptObject::CreateOwnStringPropertiesHelper(this, requestContext);
1220-
case KeysTrapKind::GetOwnPropertySymbolKind:
1221-
return JavascriptObject::CreateOwnSymbolPropertiesHelper(this, requestContext);
1222-
case KeysTrapKind::KeysKind:
1223-
return JavascriptObject::CreateOwnStringSymbolPropertiesHelper(this, requestContext);
1224-
case KeysTrapKind::GetOwnEnumerablePropertyNamesKind:
1225-
return JavascriptObject::CreateOwnEnumerableStringPropertiesHelper(this, requestContext);
1226-
case KeysTrapKind::EnumerableKeysKind:
1227-
return JavascriptObject::CreateOwnEnumerableStringSymbolPropertiesHelper(this, requestContext);
1228-
default:
1229-
Assume(UNREACHED);
1230-
}
1231-
}
1232-
1233-
Js::Var ownKeysResult = threadContext->ExecuteImplicitCall(ownKeysMethod, Js::ImplicitCall_Accessor, [=]()->Js::Var
1234-
{
1235-
return CALL_FUNCTION(threadContext, ownKeysMethod, Js::CallInfo(Js::CallFlags_Value, 1), targetObj);
1236-
});
1237-
1238-
if (!Js::JavascriptOperators::IsObject(ownKeysResult))
1239-
{
1240-
Js::JavascriptError::ThrowTypeError(requestContext, JSERR_InconsistentTrapResult, _u("ownKeys"));
1241-
}
1242-
1243-
Js::RecyclableObject* trapResultArray = Js::VarTo<RecyclableObject>(ownKeysResult);
1244-
Js::JavascriptArray* trapResult = requestContext->GetLibrary()->CreateArray(0);
1245-
bool isConfigurableKeyMissingFromTrapResult = false;
1246-
bool isNonconfigurableKeyMissingFromTrapResult = false;
1247-
bool isKeyMissingFromTrapResult = false;
1248-
bool isKeyMissingFromTargetResult = false;
1249-
bool isAnyNonconfigurableKeyPresent = false;
1250-
Js::Var element;
1251-
Js::PropertyId propertyId;
1252-
const Js::PropertyRecord* propertyRecord = nullptr;
1253-
BOOL isTargetExtensible = FALSE;
1254-
1255-
BEGIN_TEMP_ALLOCATOR(tempAllocator, requestContext, _u("Runtime"))
1256-
{
1257-
// Dictionary containing intersection of keys present in targetKeys and trapResult
1258-
Js::Var lenValue = Js::JavascriptOperators::OP_GetLength(trapResultArray, requestContext);
1259-
uint32 len = (uint32)Js::JavascriptConversion::ToLength(lenValue, requestContext);
1260-
JsUtil::BaseDictionary<Js::PropertyId, bool, Memory::ArenaAllocator> targetToTrapResultMap(tempAllocator, len);
1261-
1262-
// Trap result to return.
1263-
// Note : This will not necessarily have all elements present in trapResultArray. E.g. If trap was called from GetOwnPropertySymbols()
1264-
// trapResult will only contain symbol elements from trapResultArray.
1265-
switch (keysTrapKind)
1266-
{
1267-
case GetOwnPropertyNamesKind:
1268-
case KeysTrapKind::GetOwnEnumerablePropertyNamesKind:
1269-
GetOwnPropertyKeysHelper(requestContext, trapResultArray, len, trapResult, targetToTrapResultMap,
1270-
[&](const Js::PropertyRecord *propertyRecord)->bool
1271-
{
1272-
return !propertyRecord->IsSymbol();
1273-
});
1274-
break;
1275-
case GetOwnPropertySymbolKind:
1276-
GetOwnPropertyKeysHelper(requestContext, trapResultArray, len, trapResult, targetToTrapResultMap,
1277-
[&](const Js::PropertyRecord *propertyRecord)->bool
1278-
{
1279-
return propertyRecord->IsSymbol();
1280-
});
1281-
break;
1282-
case KeysKind:
1283-
case EnumerableKeysKind:
1284-
GetOwnPropertyKeysHelper(requestContext, trapResultArray, len, trapResult, targetToTrapResultMap,
1285-
[&](const Js::PropertyRecord *propertyRecord)->bool
1286-
{
1287-
return true;
1288-
});
1289-
break;
1290-
}
1291-
1292-
isTargetExtensible = targetObj->IsExtensible();
1293-
Js::JavascriptArray * targetKeys = Js::JavascriptOperators::GetOwnPropertyKeys(targetObj, requestContext);
1294-
1295-
for (uint32 i = 0; i < targetKeys->GetLength(); i++)
1296-
{
1297-
element = targetKeys->DirectGetItem(i);
1298-
AssertMsg(Js::VarIs<JavascriptSymbol>(element) || Js::VarIs<JavascriptString>(element), "Invariant check during ownKeys wrapper trap should make sure we only get property key here. (symbol or string primitives)");
1299-
Js::JavascriptConversion::ToPropertyKey(element, requestContext, &propertyRecord, nullptr);
1300-
propertyId = propertyRecord->GetPropertyId();
1301-
1302-
if (propertyId == Js::Constants::NoProperty)
1303-
continue;
1304-
1305-
// If not present in intersection means either the property is not present in targetKeys or
1306-
// we have already visited the property in targetKeys
1307-
if (targetToTrapResultMap.ContainsKey(propertyId))
1308-
{
1309-
isKeyMissingFromTrapResult = false;
1310-
targetToTrapResultMap.Remove(propertyId);
1311-
}
1312-
else
1313-
{
1314-
isKeyMissingFromTrapResult = true;
1315-
}
1316-
1317-
Js::PropertyDescriptor targetKeyPropertyDescriptor;
1318-
if (Js::JavascriptOperators::GetOwnPropertyDescriptor(targetObj, propertyId, requestContext, &targetKeyPropertyDescriptor) && !targetKeyPropertyDescriptor.IsConfigurable())
1319-
{
1320-
isAnyNonconfigurableKeyPresent = true;
1321-
if (isKeyMissingFromTrapResult)
1322-
{
1323-
isNonconfigurableKeyMissingFromTrapResult = true;
1324-
}
1325-
}
1326-
else
1327-
{
1328-
if (isKeyMissingFromTrapResult)
1329-
{
1330-
isConfigurableKeyMissingFromTrapResult = true;
1331-
}
1332-
}
1333-
}
1334-
// Keys that were not found in targetKeys will continue to remain in the map
1335-
isKeyMissingFromTargetResult = targetToTrapResultMap.Count() != 0;
1336-
}
1337-
END_TEMP_ALLOCATOR(tempAllocator, requestContext)
1338-
1339-
1340-
// 19.
1341-
if (isTargetExtensible && !isAnyNonconfigurableKeyPresent)
1342-
{
1343-
return trapResult;
1344-
}
1345-
1346-
// 21.
1347-
if (isNonconfigurableKeyMissingFromTrapResult)
1348-
{
1349-
Js::JavascriptError::ThrowTypeError(requestContext, JSERR_InconsistentTrapResult, _u("ownKeys"));
1350-
}
1351-
1352-
// 22.
1353-
if (isTargetExtensible)
1354-
{
1355-
return trapResult;
1356-
}
1357-
1358-
// 23.
1359-
if (isConfigurableKeyMissingFromTrapResult)
1360-
{
1361-
Js::JavascriptError::ThrowTypeError(requestContext, JSERR_InconsistentTrapResult, _u("ownKeys"));
1362-
}
1363-
1364-
// 24.
1365-
if (isKeyMissingFromTargetResult)
1366-
{
1367-
Js::JavascriptError::ThrowTypeError(requestContext, JSERR_InconsistentTrapResult, _u("ownKeys"));
1368-
}
1369-
1370-
return trapResult;
1371-
}
1372-
13731187
#if ENABLE_TTD
13741188
TTD::NSSnapObjects::SnapObjectType CustomExternalWrapperObject::GetSnapTag_TTD() const
13751189
{

lib/Runtime/Library/CustomExternalWrapperObject.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ namespace Js
113113
BOOL SetPropertyTrap(Var receiver, SetPropertyTrapKind setPropertyTrapKind, GetPropertyNameFunc getPropertyName, Var newValue, ScriptContext * requestContext, PropertyOperationFlags propertyOperationFlags, BOOL skipPrototypeCheck, Fn fn);
114114
BOOL SetPropertyTrap(Var receiver, SetPropertyTrapKind setPropertyTrapKind, JavascriptString * propertyString, Var newValue, ScriptContext * requestContext, PropertyOperationFlags propertyOperationFlags);
115115

116-
JavascriptArray * PropertyKeysTrap(KeysTrapKind keysTrapKind, ScriptContext * requestContext);
117-
118116
void * GetSlotData() const;
119117
void SetSlotData(void * data);
120118
int GetInlineSlotSize() const;

0 commit comments

Comments
 (0)