Skip to content

Commit

Permalink
Cleanup and make ThenFinally anonymous
Browse files Browse the repository at this point in the history
  • Loading branch information
rhuanjl committed Feb 11, 2018
1 parent 1430bc2 commit 2884c00
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/Runtime/Library/JavascriptLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6939,10 +6939,10 @@ namespace Js

FunctionInfo* functionInfo = RecyclerNew(this->GetRecycler(), FunctionInfo, entryPoint);
DynamicType* type = CreateDeferredPrototypeFunctionType(entryPoint);
//set length and name here

JavascriptPromiseThenFinallyFunction* function = RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptPromiseThenFinallyFunction, type, functionInfo, OnFinally, Constructor, shouldThrow);
function->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable, nullptr);
function->SetPropertyWithAttributes(PropertyIds::name, scriptContext->GetLibrary()->CreateStringFromCppLiteral(_u("")), PropertyConfigurable, nullptr);

return function;
}
Expand Down
19 changes: 6 additions & 13 deletions lib/Runtime/Library/JavascriptPromise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ namespace Js
}

JavascriptLibrary* library = scriptContext->GetLibrary();
RecyclableObject* promise = RecyclableObject::FromVar(args[0]);
RecyclableObject* promise = RecyclableObject::UnsafeFromVar(args[0]);
//3. Let C be ? SpeciesConstructor(promise, %Promise%).
RecyclableObject* constructor = JavascriptOperators::SpeciesConstructor(promise, scriptContext->GetLibrary()->GetPromiseConstructor(), scriptContext);
//4. Assert IsConstructor(C)
Expand Down Expand Up @@ -621,7 +621,7 @@ namespace Js
{
JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_NeedFunction, _u("Promise.prototype.finally"));
}
RecyclableObject* func = RecyclableObject::FromVar(funcVar);
RecyclableObject* func = RecyclableObject::UnsafeFromVar(funcVar);

return CALL_FUNCTION(scriptContext->GetThreadContext(),
func, Js::CallInfo(CallFlags_Value, 3),
Expand All @@ -641,9 +641,7 @@ namespace Js

JavascriptLibrary* library = scriptContext->GetLibrary();

Assert(JavascriptPromiseThenFinallyFunction::Is(function));

JavascriptPromiseThenFinallyFunction* This = JavascriptPromiseThenFinallyFunction::UnsafeFromVar(function);
JavascriptPromiseThenFinallyFunction* This = JavascriptPromiseThenFinallyFunction::FromVar(function);

//1. Let onFinally be F.[[OnFinally]]
//2. Assert: IsCallabale(onFinally)=true
Expand All @@ -663,9 +661,8 @@ namespace Js
//OR 7. Let thrower be equivalent to a function that throws reason
JavascriptPromiseThunkFinallyFunction* Thunk = library->CreatePromiseThunkFinallyFunction(EntryThunkFinallyFunction, args[1], This->GetShouldThrow());


//8. Return ? Invoke(promise, "then", <<valueThink>>)
JavascriptPromise* promise = UnsafeFromVar(promiseVar);
//8. Return ? Invoke(promise, "then", <<valueThunk>>)
RecyclableObject* promise = RecyclableObject::UnsafeFromVar(promiseVar);
Var funcVar = JavascriptOperators::GetProperty(promise, Js::PropertyIds::then, scriptContext);

if (!JavascriptConversion::IsCallable(funcVar))
Expand All @@ -691,11 +688,7 @@ namespace Js
ARGUMENTS(args, callInfo);
Assert(!(callInfo.Flags & CallFlags_New));

Assert(args[0] != nullptr);

Assert(JavascriptPromiseThunkFinallyFunction::Is(function));

JavascriptPromiseThunkFinallyFunction* This = JavascriptPromiseThunkFinallyFunction::UnsafeFromVar(function);
JavascriptPromiseThunkFinallyFunction* This = JavascriptPromiseThunkFinallyFunction::FromVar(function);

if (!This->GetShouldThrow())
{
Expand Down
10 changes: 0 additions & 10 deletions lib/Runtime/Library/JavascriptPromise.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,6 @@ namespace Js
return static_cast<JavascriptPromiseThenFinallyFunction*>(var);
}

inline static JavascriptPromiseThenFinallyFunction* UnsafeFromVar(Var var)
{
return static_cast<JavascriptPromiseThenFinallyFunction*>(var);
}

inline bool GetShouldThrow() { return this->shouldThrow; }
inline RecyclableObject* GetOnFinally() { return this->OnFinally; }
inline RecyclableObject* GetConstructor() { return this->Constructor; }
Expand Down Expand Up @@ -308,11 +303,6 @@ namespace Js
return static_cast<JavascriptPromiseThunkFinallyFunction*>(var);
}

inline static JavascriptPromiseThunkFinallyFunction* UnsafeFromVar(Var var)
{
return static_cast<JavascriptPromiseThunkFinallyFunction*>(var);
}

inline bool GetShouldThrow() { return this->shouldThrow; }
inline Var GetValue() { return this->value; }

Expand Down

0 comments on commit 2884c00

Please sign in to comment.