Skip to content

Commit

Permalink
chakra-core#274 Remove [[Enumerate]] and associated reflective capabi…
Browse files Browse the repository at this point in the history
…lities
  • Loading branch information
leirocks committed Jun 6, 2016
1 parent 05bbe22 commit fc4ad53
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 58 deletions.
1 change: 0 additions & 1 deletion lib/Runtime/Library/JavascriptBuiltInFunctionList.h
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,6 @@ BUILTIN(JavascriptPromise, AllResolveElementFunction, EntryAllResolveElementFunc
BUILTIN(JavascriptPromise, GetterSymbolSpecies, EntryGetterSymbolSpecies, FunctionInfo::ErrorOnNew)
BUILTIN(JavascriptReflect, DefineProperty, EntryDefineProperty, FunctionInfo::ErrorOnNew | FunctionInfo::DoNotProfile)
BUILTIN(JavascriptReflect, DeleteProperty, EntryDeleteProperty, FunctionInfo::ErrorOnNew | FunctionInfo::DoNotProfile)
BUILTIN(JavascriptReflect, Enumerate, EntryEnumerate, FunctionInfo::ErrorOnNew | FunctionInfo::DoNotProfile)
BUILTIN(JavascriptReflect, Get, EntryGet, FunctionInfo::ErrorOnNew | FunctionInfo::DoNotProfile)
BUILTIN(JavascriptReflect, GetOwnPropertyDescriptor, EntryGetOwnPropertyDescriptor, FunctionInfo::ErrorOnNew | FunctionInfo::DoNotProfile)
BUILTIN(JavascriptReflect, GetPrototypeOf, EntryGetPrototypeOf, FunctionInfo::ErrorOnNew | FunctionInfo::DoNotProfile)
Expand Down
3 changes: 0 additions & 3 deletions lib/Runtime/Library/JavascriptLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3152,8 +3152,6 @@ namespace Js
library->AddFunctionToLibraryObject(reflectObject, PropertyIds::defineProperty, &JavascriptReflect::EntryInfo::DefineProperty, 3));
scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::DeleteProperty.GetOriginalEntryPoint(),
library->AddFunctionToLibraryObject(reflectObject, PropertyIds::deleteProperty, &JavascriptReflect::EntryInfo::DeleteProperty, 2));
scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::Enumerate.GetOriginalEntryPoint(),
library->AddFunctionToLibraryObject(reflectObject, PropertyIds::enumerate, &JavascriptReflect::EntryInfo::Enumerate, 1));
scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::Get.GetOriginalEntryPoint(),
library->AddFunctionToLibraryObject(reflectObject, PropertyIds::get, &JavascriptReflect::EntryInfo::Get, 2));
scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::GetOwnPropertyDescriptor.GetOriginalEntryPoint(),
Expand Down Expand Up @@ -7111,7 +7109,6 @@ namespace Js

REG_OBJECTS_LIB_FUNC(defineProperty, JavascriptReflect::EntryDefineProperty);
REG_OBJECTS_LIB_FUNC(deleteProperty, JavascriptReflect::EntryDeleteProperty);
REG_OBJECTS_LIB_FUNC(enumerate, JavascriptReflect::EntryEnumerate);
REG_OBJECTS_LIB_FUNC(get, JavascriptReflect::EntryGet);
REG_OBJECTS_LIB_FUNC(getOwnPropertyDescriptor, JavascriptReflect::EntryGetOwnPropertyDescriptor);
REG_OBJECTS_LIB_FUNC(getPrototypeOf, JavascriptReflect::EntryGetPrototypeOf);
Expand Down
13 changes: 8 additions & 5 deletions lib/Runtime/Library/JavascriptProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ namespace Js
// the proxy has been revoked; TypeError.
if (!threadContext->RecordImplicitException())
return FALSE;
JavascriptError::ThrowTypeError(GetScriptContext(), JSERR_ErrorOnRevokedProxy, _u("enumerate"));
JavascriptError::ThrowTypeError(GetScriptContext(), JSERR_ErrorOnRevokedProxy, _u("ownKeys"));
}

//4. Let trap be the result of GetMethod(handler, "enumerate").
Expand All @@ -902,7 +902,7 @@ namespace Js
//8. ReturnIfAbrupt(trapResult).
//9. If Type(trapResult) is not Object, then throw a TypeError exception.
//10. Return trapResult.
JavascriptFunction* getEnumeratorMethod = GetMethodHelper(PropertyIds::enumerate, scriptContext);
JavascriptFunction* getEnumeratorMethod = GetMethodHelper(PropertyIds::ownKeys, scriptContext);
Assert(!GetScriptContext()->IsHeapEnumInProgress());
if (nullptr == getEnumeratorMethod)
{
Expand All @@ -919,11 +919,14 @@ namespace Js
Var trapResult = getEnumeratorMethod->CallFunction(arguments);
threadContext->SetImplicitCallFlags((Js::ImplicitCallFlags)(saveImplicitCallFlags | ImplicitCall_Accessor));

if (!JavascriptOperators::IsObject(trapResult))
if (!JavascriptOperators::IsArray(trapResult))
{
JavascriptError::ThrowTypeError(scriptContext, JSERR_InconsistentTrapResult, _u("enumerate"));
JavascriptError::ThrowTypeError(scriptContext, JSERR_InconsistentTrapResult, _u("ownKeys"));
}
*enumerator = IteratorObjectEnumerator::Create(scriptContext, trapResult);

Var arrayIterator = JavascriptOperators::GetIterator(RecyclableObject::FromVar(trapResult), scriptContext);
*enumerator = IteratorObjectEnumerator::Create(scriptContext, arrayIterator);

return TRUE;
}

Expand Down
27 changes: 0 additions & 27 deletions lib/Runtime/Library/JavascriptReflect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,33 +83,6 @@ namespace Js
return JavascriptOperators::OP_DeleteElementI(target, propertyKey, scriptContext);
}

Var JavascriptReflect::EntryEnumerate(RecyclableObject* function, CallInfo callInfo, ...)
{
PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault);

ARGUMENTS(args, callInfo);
ScriptContext* scriptContext = function->GetScriptContext();
AUTO_TAG_NATIVE_LIBRARY_ENTRY(function, callInfo, _u("Reflect.enumerate"));

AssertMsg(args.Info.Count > 0, "Should always have implicit 'this'");
if (args.Info.Flags & CallFlags_New)
{
JavascriptError::ThrowTypeError(scriptContext, JSERR_ErrorOnNew, _u("Reflect.enumerate"));
}

if (args.Info.Count < 2 || !JavascriptOperators::IsObject(args[1]))
{
JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_NeedObject, _u("Reflect.enumerate"));
}
Var target = args[1];

Var iterator = nullptr;
Recycler* recycler = scriptContext->GetRecycler();
ForInObjectEnumeratorWrapper* forinEnumerator = RecyclerNew(recycler, Js::ForInObjectEnumeratorWrapper, RecyclableObject::FromVar(target), scriptContext);
iterator = JavascriptEnumeratorIterator::Create(forinEnumerator, nullptr, scriptContext);
return iterator;
}

Var JavascriptReflect::EntryGet(RecyclableObject* function, CallInfo callInfo, ...)
{
PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault);
Expand Down
1 change: 0 additions & 1 deletion lib/Runtime/Library/JavascriptReflect.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ namespace Js

static Var EntryDefineProperty(RecyclableObject* function, CallInfo callInfo, ...);
static Var EntryDeleteProperty(RecyclableObject* function, CallInfo callInfo, ...);
static Var EntryEnumerate(RecyclableObject* function, CallInfo callInfo, ...);
static Var EntryGet(RecyclableObject* function, CallInfo callInfo, ...);
static Var EntryGetOwnPropertyDescriptor(RecyclableObject* function, CallInfo callInfo, ...);
static Var EntryGetPrototypeOf(RecyclableObject* function, CallInfo callInfo, ...);
Expand Down
20 changes: 0 additions & 20 deletions test/es6/proxyenumbug.js

This file was deleted.

28 changes: 28 additions & 0 deletions test/es6/proxyenumremoval.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------

var passed = 1;
passed &= typeof Reflect.enumerate === 'undefined';

var proxy = new Proxy({}, {
enumerate: function() {
passed = 0;
}
});
for(var key in proxy);

var proxy = new Proxy({x:1}, {
ownKeys: function() {
return ['a','b'];
}
});

var keys=""
for(var key in proxy){ keys += key;}
passed &= keys==="ab";

if (passed) {
WScript.Echo("PASS");
}
2 changes: 1 addition & 1 deletion test/es6/rlexe.xml
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@
</test>
<test>
<default>
<files>proxyenumbug.js</files>
<files>proxyenumremoval.js</files>
</default>
</test>
<test>
Expand Down

0 comments on commit fc4ad53

Please sign in to comment.