From fe14f94510422d2f6fe5857f74ce945fa51c8ea4 Mon Sep 17 00:00:00 2001 From: Seth Brenith Date: Tue, 10 Jul 2018 11:53:14 -0700 Subject: [PATCH] nicer dynamic casts I recently came across the following code: ```C++ // JsParseSerialized only accepts ArrayBuffer (incl. ExternalArrayBuffer) if (!Js::ExternalArrayBuffer::Is(bufferVal)) { return JsErrorInvalidArgument; } ``` I thought the comment was out of date, and was about to update it, when I realized that `ExternalArrayBuffer::Is` actually invokes `ArrayBuffer::Is`, because static methods are inherited and `ExternalArrayBuffer` doesn't provide an `Is` method. I don't want to live in a world where `ExternalArrayBuffer::Is(bufferVal)` can return something other than whether `bufferVal` is an `ExternalArrayBuffer`, so this change is my proposed solution. It introduces a new template method `VarIs` (in RecyclableObject.h) and uses it consistently for all type-checks and conversions of `RecyclableObject` subclasses. Benefits are: * Avoid the confusing case above (it would be a linker error) * Less boilerplate code (this is a net removal of about 1500 lines) * Every type gets by default an optimization for when the compiler knows the input is `RecyclableObject*` (previously only a few types implemented this) Most of the change is purely mechanical, and anybody who's willing to review it is a hero. However, a few cases are interesting: * `DynamicObject`, `JavascriptArray`, and `JavascriptGeneratorFunction` had asymmetrical behavior between `Is` and `(Unsafe)?FromVar`. I have attempted to avoid any behavior changes in this review by updating callers to `Is` to use a new uniquely-named method, and making `VarIs` respect the behavior from `(Unsafe)?FromVar`. * A few calls have been updated to refer to the thing they were actually calling, not some subclass: * `JavascriptObject` -> `DynamicObject` * `ExternalArrayBuffer` -> `ArrayBuffer` * `JavascriptArrayBuffer` -> `ArrayBuffer` * `RuntimeFunction` -> `JavascriptFunction` --- lib/Backend/BackendApi.cpp | 6 +- lib/Backend/BailOut.cpp | 22 +- lib/Backend/FixedFieldInfo.cpp | 8 +- lib/Backend/GlobOptFields.cpp | 10 +- lib/Backend/Inline.cpp | 14 +- lib/Backend/InlineeFrameInfo.cpp | 6 +- lib/Backend/Lower.cpp | 26 +- lib/Backend/NativeCodeGenerator.cpp | 36 +- lib/Backend/ObjTypeSpecFldInfo.cpp | 6 +- lib/Backend/ObjTypeSpecFldInfo.h | 4 +- lib/Backend/Opnd.cpp | 16 +- lib/Backend/SimpleJitProfilingHelpers.cpp | 2 +- lib/Common/Exceptions/Throw.h | 4 +- lib/Jsrt/Core/JsrtCore.cpp | 4 +- lib/Jsrt/Jsrt.cpp | 186 ++--- lib/Jsrt/JsrtDebugUtils.cpp | 8 +- lib/Jsrt/JsrtDiag.cpp | 22 +- lib/Jsrt/JsrtExternalObject.cpp | 23 - lib/Jsrt/JsrtExternalObject.h | 9 +- lib/Jsrt/JsrtInternal.h | 8 +- lib/Jsrt/JsrtSourceHolder.cpp | 4 +- lib/Runtime/Base/CrossSite.cpp | 54 +- lib/Runtime/Base/FunctionBody.cpp | 14 +- lib/Runtime/Base/FunctionInfo.cpp | 4 +- lib/Runtime/Base/ScriptContext.cpp | 20 +- lib/Runtime/Base/ThreadContext.cpp | 4 +- lib/Runtime/ByteCode/ByteCodeDumper.cpp | 4 +- lib/Runtime/ByteCode/ByteCodeSerializer.cpp | 22 +- lib/Runtime/Debug/DiagObjectModel.cpp | 182 ++--- lib/Runtime/Debug/DiagStackFrame.cpp | 6 +- lib/Runtime/Debug/MutationBreakpoint.cpp | 8 +- lib/Runtime/Debug/ProbeContainer.cpp | 12 +- lib/Runtime/Debug/TTActionEvents.cpp | 50 +- lib/Runtime/Debug/TTEventLog.cpp | 14 +- lib/Runtime/Debug/TTEvents.cpp | 2 +- lib/Runtime/Debug/TTEvents.h | 8 +- lib/Runtime/Debug/TTRuntimeInfoTracker.cpp | 28 +- lib/Runtime/Debug/TTSerialize.cpp | 18 +- lib/Runtime/Debug/TTSnapObjects.cpp | 24 +- lib/Runtime/Debug/TTSnapObjects.h | 38 +- lib/Runtime/Debug/TTSnapValues.cpp | 20 +- lib/Runtime/Debug/TTSnapshot.cpp | 8 +- lib/Runtime/Debug/TTSnapshotExtractor.cpp | 12 +- lib/Runtime/Language/AsmJsLink.cpp | 18 +- lib/Runtime/Language/AsmJsModule.cpp | 8 +- lib/Runtime/Language/AsmJsUtils.cpp | 14 +- lib/Runtime/Language/CacheOperators.cpp | 18 +- lib/Runtime/Language/CacheOperators.inl | 10 +- lib/Runtime/Language/DynamicProfileInfo.cpp | 8 +- lib/Runtime/Language/InlineCache.cpp | 22 +- lib/Runtime/Language/InlineCache.h | 6 +- lib/Runtime/Language/InlineCache.inl | 38 +- lib/Runtime/Language/InterpreterLoop.inl | 2 +- .../Language/InterpreterStackFrame.cpp | 92 +-- lib/Runtime/Language/JavascriptConversion.cpp | 201 ++--- lib/Runtime/Language/JavascriptConversion.inl | 4 +- .../Language/JavascriptExceptionObject.cpp | 6 +- .../Language/JavascriptExceptionObject.h | 8 +- .../Language/JavascriptExceptionOperators.cpp | 34 +- lib/Runtime/Language/JavascriptOperators.cpp | 696 +++++++++--------- lib/Runtime/Language/JavascriptOperators.h | 19 +- lib/Runtime/Language/JavascriptOperators.inl | 4 +- .../Language/JavascriptStackWalker.cpp | 24 +- lib/Runtime/Language/ModuleNamespace.h | 7 +- .../Language/ModuleNamespaceEnumerator.cpp | 4 +- lib/Runtime/Language/ProfilingHelpers.cpp | 72 +- .../Language/SourceTextModuleRecord.cpp | 2 +- lib/Runtime/Language/SourceTextModuleRecord.h | 4 +- lib/Runtime/Language/TaggedInt.h | 5 + lib/Runtime/Language/TaggedInt.inl | 2 +- lib/Runtime/Language/ValueType.cpp | 8 +- lib/Runtime/Language/WebAssemblySource.cpp | 8 +- .../Language/i386/AsmJsJitTemplate.cpp | 19 +- lib/Runtime/Library/ArgumentsObject.cpp | 11 +- lib/Runtime/Library/ArgumentsObject.h | 9 +- lib/Runtime/Library/ArrayBuffer.cpp | 109 ++- lib/Runtime/Library/ArrayBuffer.h | 15 +- lib/Runtime/Library/AtomicsObject.cpp | 14 +- lib/Runtime/Library/BoundFunction.cpp | 26 +- lib/Runtime/Library/BoundFunction.h | 6 +- .../Library/Chakra.Runtime.Library.vcxproj | 1 - .../Chakra.Runtime.Library.vcxproj.filters | 3 +- lib/Runtime/Library/CompoundString.cpp | 61 +- lib/Runtime/Library/CompoundString.h | 8 +- lib/Runtime/Library/ConcatString.cpp | 28 +- lib/Runtime/Library/ConcatString.h | 20 +- .../Library/CustomExternalIterator.cpp | 25 +- lib/Runtime/Library/CustomExternalIterator.h | 5 +- lib/Runtime/Library/DataView.cpp | 87 ++- lib/Runtime/Library/DataView.h | 19 +- lib/Runtime/Library/ES5Array.cpp | 17 - lib/Runtime/Library/ES5Array.h | 8 +- lib/Runtime/Library/ES5ArrayIndexEnumerator.h | 2 +- lib/Runtime/Library/EngineInterfaceObject.cpp | 62 +- lib/Runtime/Library/EngineInterfaceObject.h | 8 +- lib/Runtime/Library/ForInObjectEnumerator.cpp | 2 +- lib/Runtime/Library/GlobalObject.cpp | 47 +- lib/Runtime/Library/GlobalObject.h | 9 +- .../IntlEngineInterfaceExtensionObject.cpp | 178 ++--- lib/Runtime/Library/JSON.cpp | 11 +- lib/Runtime/Library/JSONParser.cpp | 18 +- lib/Runtime/Library/JSONStringifier.cpp | 24 +- lib/Runtime/Library/JavascriptArray.cpp | 599 +++++++-------- lib/Runtime/Library/JavascriptArray.h | 110 ++- .../Library/JavascriptArrayIterator.cpp | 32 +- lib/Runtime/Library/JavascriptArrayIterator.h | 9 +- lib/Runtime/Library/JavascriptBoolean.cpp | 24 +- lib/Runtime/Library/JavascriptBoolean.h | 8 +- lib/Runtime/Library/JavascriptBoolean.inl | 29 - .../Library/JavascriptBooleanObject.cpp | 21 +- lib/Runtime/Library/JavascriptBooleanObject.h | 8 +- lib/Runtime/Library/JavascriptDate.cpp | 222 +++--- lib/Runtime/Library/JavascriptDate.h | 10 +- lib/Runtime/Library/JavascriptError.cpp | 18 +- lib/Runtime/Library/JavascriptError.h | 20 +- .../Library/JavascriptExternalFunction.cpp | 10 +- lib/Runtime/Library/JavascriptFunction.cpp | 124 ++-- lib/Runtime/Library/JavascriptFunction.h | 6 +- lib/Runtime/Library/JavascriptGenerator.cpp | 32 +- lib/Runtime/Library/JavascriptGenerator.h | 6 +- .../Library/JavascriptGeneratorFunction.cpp | 43 +- .../Library/JavascriptGeneratorFunction.h | 14 +- lib/Runtime/Library/JavascriptLibrary.cpp | 70 +- .../Library/JavascriptListIterator.cpp | 25 +- lib/Runtime/Library/JavascriptListIterator.h | 9 +- lib/Runtime/Library/JavascriptMap.cpp | 27 +- lib/Runtime/Library/JavascriptMap.h | 9 +- lib/Runtime/Library/JavascriptMapIterator.cpp | 24 +- lib/Runtime/Library/JavascriptMapIterator.h | 9 +- lib/Runtime/Library/JavascriptNumber.cpp | 36 +- lib/Runtime/Library/JavascriptNumber.inl | 2 +- .../Library/JavascriptNumberObject.cpp | 19 - lib/Runtime/Library/JavascriptNumberObject.h | 8 +- lib/Runtime/Library/JavascriptObject.cpp | 88 +-- lib/Runtime/Library/JavascriptPromise.cpp | 275 +++---- lib/Runtime/Library/JavascriptPromise.h | 130 +--- lib/Runtime/Library/JavascriptProxy.cpp | 94 ++- lib/Runtime/Library/JavascriptProxy.h | 11 +- lib/Runtime/Library/JavascriptReflect.cpp | 30 +- .../Library/JavascriptRegularExpression.cpp | 69 +- .../Library/JavascriptRegularExpression.h | 8 +- lib/Runtime/Library/JavascriptSet.cpp | 25 +- lib/Runtime/Library/JavascriptSet.h | 9 +- lib/Runtime/Library/JavascriptSetIterator.cpp | 24 +- lib/Runtime/Library/JavascriptSetIterator.h | 9 +- lib/Runtime/Library/JavascriptString.cpp | 78 +- lib/Runtime/Library/JavascriptString.h | 5 +- .../Library/JavascriptStringIterator.cpp | 24 +- .../Library/JavascriptStringIterator.h | 9 +- .../Library/JavascriptStringObject.cpp | 25 +- lib/Runtime/Library/JavascriptStringObject.h | 8 +- lib/Runtime/Library/JavascriptSymbol.cpp | 53 +- lib/Runtime/Library/JavascriptSymbol.h | 8 +- .../Library/JavascriptSymbolObject.cpp | 21 +- lib/Runtime/Library/JavascriptSymbolObject.h | 8 +- lib/Runtime/Library/JavascriptTypedNumber.cpp | 4 +- lib/Runtime/Library/JavascriptTypedNumber.h | 29 +- ...ascriptTypedObjectSlotAccessorFunction.cpp | 67 -- lib/Runtime/Library/JavascriptVariantDate.cpp | 19 - lib/Runtime/Library/JavascriptVariantDate.h | 9 +- lib/Runtime/Library/JavascriptWeakMap.cpp | 49 +- lib/Runtime/Library/JavascriptWeakMap.h | 9 +- lib/Runtime/Library/JavascriptWeakSet.cpp | 41 +- lib/Runtime/Library/JavascriptWeakSet.h | 9 +- ...sBuiltInEngineInterfaceExtensionObject.cpp | 26 +- lib/Runtime/Library/LazyJSONString.cpp | 17 +- lib/Runtime/Library/LazyJSONString.h | 6 +- lib/Runtime/Library/ModuleRoot.h | 1 - lib/Runtime/Library/ObjectPrototypeObject.cpp | 4 +- lib/Runtime/Library/PropertyString.cpp | 16 +- lib/Runtime/Library/PropertyString.h | 17 +- lib/Runtime/Library/RegexHelper.cpp | 8 +- lib/Runtime/Library/RootObjectBase.cpp | 23 - lib/Runtime/Library/RootObjectBase.h | 11 +- lib/Runtime/Library/RuntimeFunction.cpp | 4 +- lib/Runtime/Library/SameValueComparer.h | 4 +- lib/Runtime/Library/ScriptFunction.cpp | 94 +-- lib/Runtime/Library/ScriptFunction.h | 46 +- lib/Runtime/Library/SharedArrayBuffer.cpp | 55 +- lib/Runtime/Library/SharedArrayBuffer.h | 19 +- lib/Runtime/Library/StackScriptFunction.cpp | 36 +- lib/Runtime/Library/StackScriptFunction.h | 14 +- lib/Runtime/Library/ThrowErrorObject.cpp | 19 +- lib/Runtime/Library/ThrowErrorObject.h | 8 +- lib/Runtime/Library/TypedArray.cpp | 572 ++++---------- lib/Runtime/Library/TypedArray.h | 15 +- lib/Runtime/Library/UriHelper.cpp | 8 +- lib/Runtime/Library/WabtInterface.cpp | 4 +- lib/Runtime/Library/WebAssembly.cpp | 16 +- .../Library/WebAssemblyEnvironment.cpp | 6 +- lib/Runtime/Library/WebAssemblyInstance.cpp | 49 +- lib/Runtime/Library/WebAssemblyInstance.h | 8 +- lib/Runtime/Library/WebAssemblyMemory.cpp | 39 +- lib/Runtime/Library/WebAssemblyMemory.h | 8 +- lib/Runtime/Library/WebAssemblyModule.cpp | 39 +- lib/Runtime/Library/WebAssemblyModule.h | 9 +- lib/Runtime/Library/WebAssemblyTable.cpp | 49 +- lib/Runtime/Library/WebAssemblyTable.h | 9 +- lib/Runtime/Math/JavascriptMath.cpp | 28 +- lib/Runtime/Math/JavascriptMath.inl | 4 +- lib/Runtime/Runtime.h | 1 - lib/Runtime/Types/ActivationObject.cpp | 24 +- lib/Runtime/Types/ActivationObject.h | 42 +- lib/Runtime/Types/DeferredTypeHandler.cpp | 2 +- lib/Runtime/Types/DictionaryTypeHandler.cpp | 46 +- lib/Runtime/Types/DynamicObject.cpp | 37 +- lib/Runtime/Types/DynamicObject.h | 11 +- .../Types/DynamicObjectPropertyEnumerator.cpp | 2 +- lib/Runtime/Types/DynamicType.cpp | 2 +- lib/Runtime/Types/ES5ArrayTypeHandler.cpp | 46 +- lib/Runtime/Types/JavascriptEnumerator.cpp | 18 +- lib/Runtime/Types/JavascriptEnumerator.h | 7 +- lib/Runtime/Types/NullTypeHandler.cpp | 2 +- lib/Runtime/Types/PathTypeHandler.cpp | 13 +- lib/Runtime/Types/RecyclableObject.cpp | 60 +- lib/Runtime/Types/RecyclableObject.h | 79 +- lib/Runtime/Types/RecyclableObject.inl | 33 - .../Types/SimpleDictionaryTypeHandler.cpp | 26 +- lib/Runtime/Types/SimpleTypeHandler.cpp | 22 +- lib/Runtime/Types/SpreadArgument.cpp | 29 +- lib/Runtime/Types/SpreadArgument.h | 8 +- lib/Runtime/Types/StaticType.cpp | 4 +- lib/Runtime/Types/TypeHandler.cpp | 4 +- lib/Runtime/Types/TypePropertyCache.cpp | 18 +- lib/Runtime/Types/WithScopeObject.cpp | 17 - lib/Runtime/Types/WithScopeObject.h | 8 +- 226 files changed, 3200 insertions(+), 4654 deletions(-) delete mode 100644 lib/Runtime/Library/JavascriptBoolean.inl delete mode 100644 lib/Runtime/Library/JavascriptTypedObjectSlotAccessorFunction.cpp diff --git a/lib/Backend/BackendApi.cpp b/lib/Backend/BackendApi.cpp index 134555f1a08..075f8edaa7d 100644 --- a/lib/Backend/BackendApi.cpp +++ b/lib/Backend/BackendApi.cpp @@ -142,10 +142,10 @@ void CheckIsExecutable(Js::RecyclableObject * function, Js::JavascriptMethod ent { Js::ScriptContext * scriptContext = function->GetScriptContext(); // it's easy to call the default entry point from RecyclableObject. - AssertMsg((Js::JavascriptFunction::Is(function) && Js::JavascriptFunction::FromVar(function)->IsExternalFunction()) + AssertMsg((Js::VarIs(function) && Js::VarTo(function)->IsExternalFunction()) || Js::CrossSite::IsThunk(entrypoint) // External object with entrypoint - || (!Js::JavascriptFunction::Is(function) + || (!Js::VarIs(function) && function->IsExternal() && Js::JavascriptConversion::IsCallable(function)) || !scriptContext->IsActuallyClosed() @@ -160,7 +160,7 @@ void CheckIsExecutable(Js::RecyclableObject * function, Js::JavascriptMethod ent { return; } - + Js::TypeId typeId = Js::JavascriptOperators::GetTypeId(function); if (typeId == Js::TypeIds_HostDispatch) { diff --git a/lib/Backend/BailOut.cpp b/lib/Backend/BailOut.cpp index 28475844ec5..b8109532fdb 100644 --- a/lib/Backend/BailOut.cpp +++ b/lib/Backend/BailOut.cpp @@ -576,10 +576,10 @@ BailOutRecord::RestoreValues(IR::BailOutKind bailOutKind, Js::JavascriptCallStac Assert(RegTypes[LinearScanMD::GetRegisterFromSaveIndex(offset)] != TyFloat64); value = registerSaveSpace[offset - 1]; } - Assert(Js::DynamicObject::Is(value)); + Assert(Js::DynamicObject::IsBaseDynamicObject(value)); Assert(ThreadContext::IsOnStack(value)); - Js::DynamicObject * obj = Js::DynamicObject::FromVar(value); + Js::DynamicObject * obj = Js::VarTo(value); uint propertyCount = obj->GetPropertyCount(); for (uint j = record.initFldCount; j < propertyCount; j++) { @@ -656,7 +656,7 @@ BailOutRecord::RestoreValues(IR::BailOutKind bailOutKind, Js::JavascriptCallStac if (branchValueRegSlot != Js::Constants::NoRegister) { // Used when a t1 = CmCC is optimize to BrCC, and the branch bails out. T1 needs to be restored - Assert(branchValue && Js::JavascriptBoolean::Is(branchValue)); + Assert(branchValue && Js::VarIs(branchValue)); Assert(branchValueRegSlot < newInstance->GetJavascriptFunction()->GetFunctionBody()->GetLocalsCount()); newInstance->m_localSlots[branchValueRegSlot] = branchValue; } @@ -1004,7 +1004,7 @@ BailOutRecord::BailOutCommonNoCodeGen(Js::JavascriptCallStackLayout * layout, Ba BailOutReturnValue * bailOutReturnValue, void * argoutRestoreAddress) { Assert(bailOutRecord->parent == nullptr); - Assert(Js::ScriptFunction::Is(layout->functionObject)); + Assert(Js::VarIs(layout->functionObject)); Js::ScriptFunction ** functionRef = (Js::ScriptFunction **)&layout->functionObject; Js::ArgumentReader args(&layout->callInfo, layout->args); Js::Var result = BailOutHelper(layout, functionRef, args, false, bailOutRecord, bailOutOffset, returnAddress, bailOutKind, registerSaves, bailOutReturnValue, layout->GetArgumentsObjectLocation(), branchValue, argoutRestoreAddress); @@ -1031,7 +1031,7 @@ uint32 bailOutOffset, void * returnAddress, IR::BailOutKind bailOutKind, Js::Imp sizeof(registerSaves)); Js::Var result = BailOutCommonNoCodeGen(layout, bailOutRecord, bailOutOffset, returnAddress, bailOutKind, branchValue, registerSaves, bailOutReturnValue, argoutRestoreAddress); - ScheduleFunctionCodeGen(Js::ScriptFunction::FromVar(layout->functionObject), nullptr, bailOutRecord, bailOutKind, bailOutOffset, savedImplicitCallFlags, returnAddress); + ScheduleFunctionCodeGen(Js::VarTo(layout->functionObject), nullptr, bailOutRecord, bailOutKind, bailOutOffset, savedImplicitCallFlags, returnAddress); return result; } @@ -1060,7 +1060,7 @@ BailOutRecord::BailOutInlinedCommon(Js::JavascriptCallStackLayout * layout, Bail } Js::Var result = BailOutCommonNoCodeGen(layout, currentBailOutRecord, currentBailOutRecord->bailOutOffset, returnAddress, bailOutKind, branchValue, registerSaves, &bailOutReturnValue); - ScheduleFunctionCodeGen(Js::ScriptFunction::FromVar(layout->functionObject), innerMostInlinee, currentBailOutRecord, bailOutKind, bailOutOffset, savedImplicitCallFlags, returnAddress); + ScheduleFunctionCodeGen(Js::VarTo(layout->functionObject), innerMostInlinee, currentBailOutRecord, bailOutKind, bailOutOffset, savedImplicitCallFlags, returnAddress); return result; } @@ -1076,7 +1076,7 @@ BailOutRecord::BailOutFromLoopBodyCommon(Js::JavascriptCallStackLayout * layout, js_memcpy_s(registerSaves, sizeof(registerSaves), (Js::Var *)layout->functionObject->GetScriptContext()->GetThreadContext()->GetBailOutRegisterSaveSpace(), sizeof(registerSaves)); uint32 result = BailOutFromLoopBodyHelper(layout, bailOutRecord, bailOutOffset, bailOutKind, branchValue, registerSaves); - ScheduleLoopBodyCodeGen(Js::ScriptFunction::FromVar(layout->functionObject), nullptr, bailOutRecord, bailOutKind); + ScheduleLoopBodyCodeGen(Js::VarTo(layout->functionObject), nullptr, bailOutRecord, bailOutKind); return result; } @@ -1106,7 +1106,7 @@ BailOutRecord::BailOutFromLoopBodyInlinedCommon(Js::JavascriptCallStackLayout * uint32 result = BailOutFromLoopBodyHelper(layout, currentBailOutRecord, currentBailOutRecord->bailOutOffset, bailOutKind, nullptr, registerSaves, &bailOutReturnValue); - ScheduleLoopBodyCodeGen(Js::ScriptFunction::FromVar(layout->functionObject), innerMostInlinee, currentBailOutRecord, bailOutKind); + ScheduleLoopBodyCodeGen(Js::VarTo(layout->functionObject), innerMostInlinee, currentBailOutRecord, bailOutKind); return result; } @@ -1118,7 +1118,7 @@ BailOutRecord::BailOutInlinedHelper(Js::JavascriptCallStackLayout * layout, Bail BailOutReturnValue * lastBailOutReturnValue = nullptr; *innerMostInlinee = nullptr; - Js::FunctionBody* functionBody = Js::ScriptFunction::FromVar(layout->functionObject)->GetFunctionBody(); + Js::FunctionBody* functionBody = Js::VarTo(layout->functionObject)->GetFunctionBody(); Js::EntryPointInfo *entryPointInfo; if(isInLoopBody) @@ -1162,7 +1162,7 @@ BailOutRecord::BailOutInlinedHelper(Js::JavascriptCallStackLayout * layout, Bail Js::ScriptFunction ** functionRef = (Js::ScriptFunction **)&(inlinedFrame->function); AnalysisAssert(*functionRef); - Assert(Js::ScriptFunction::Is(inlinedFrame->function)); + Assert(Js::VarIs(inlinedFrame->function)); if (*innerMostInlinee == nullptr) { @@ -1381,7 +1381,7 @@ BailOutRecord::BailOutHelper(Js::JavascriptCallStackLayout * layout, Js::ScriptF // when resuming a generator and not needed when yielding from a generator, as is occurring // here. AssertMsg(args.Info.Count == 2, "Generator ScriptFunctions should only be invoked by generator APIs with the pair of arguments they pass in -- the generator object and a ResumeYieldData pointer"); - Js::JavascriptGenerator* generator = Js::JavascriptGenerator::FromVar(args[0]); + Js::JavascriptGenerator* generator = Js::VarTo(args[0]); newInstance = generator->GetFrame(); if (newInstance != nullptr) diff --git a/lib/Backend/FixedFieldInfo.cpp b/lib/Backend/FixedFieldInfo.cpp index b3f04c2f2de..947fbb226d8 100644 --- a/lib/Backend/FixedFieldInfo.cpp +++ b/lib/Backend/FixedFieldInfo.cpp @@ -14,16 +14,16 @@ FixedFieldInfo::PopulateFixedField(_In_opt_ Js::Type * type, _In_opt_ Js::Var va FixedFieldIDL * rawFF = fixed->GetRaw(); rawFF->fieldValue = var; rawFF->nextHasSameFixedField = false; - if (var != nullptr && Js::JavascriptFunction::Is(var)) + if (var != nullptr && Js::VarIs(var)) { - Js::JavascriptFunction * funcObj = Js::JavascriptFunction::FromVar(var); + Js::JavascriptFunction * funcObj = Js::VarTo(var); rawFF->valueType = ValueType::FromObject(funcObj).GetRawData(); rawFF->funcInfoAddr = (void*)funcObj->GetFunctionInfo(); rawFF->isClassCtor = funcObj->GetFunctionInfo()->IsClassConstructor(); rawFF->localFuncId = funcObj->GetFunctionInfo()->GetLocalFunctionId(); - if (Js::ScriptFunction::Is(var)) + if (Js::VarIs(var)) { - rawFF->environmentAddr = (void*)Js::ScriptFunction::FromVar(funcObj)->GetEnvironment(); + rawFF->environmentAddr = (void*)Js::VarTo(funcObj)->GetEnvironment(); } } if (type != nullptr) diff --git a/lib/Backend/GlobOptFields.cpp b/lib/Backend/GlobOptFields.cpp index 3a24f6eeb31..5efe1c8989c 100644 --- a/lib/Backend/GlobOptFields.cpp +++ b/lib/Backend/GlobOptFields.cpp @@ -400,7 +400,7 @@ GlobOpt::ProcessFieldKills(IR::Instr *instr, BVSparse *bv, bo case Js::OpCode::InlineeEnd: Assert(!instr->UsesAllFields()); - // Kill all live 'arguments' and 'caller' fields, as 'inlineeFunction.arguments' and 'inlineeFunction.caller' + // Kill all live 'arguments' and 'caller' fields, as 'inlineeFunction.arguments' and 'inlineeFunction.caller' // cannot be copy-propped across different instances of the same inlined function. KillLiveFields(argumentsEquivBv, bv); KillLiveFields(callerEquivBv, bv); @@ -493,7 +493,7 @@ GlobOpt::CreateFieldSrcValue(PropertySym * sym, PropertySym * originalSym, IR::O } Assert((*ppOpnd)->AsSymOpnd()->m_sym == sym || this->IsLoopPrePass()); - + // We don't use the sym store to do copy prop on hoisted fields, but create a value // in case it can be copy prop out of the loop. return this->NewGenericValue(ValueType::Uninitialized, *ppOpnd); @@ -1284,8 +1284,8 @@ GlobOpt::ProcessPropOpInTypeCheckSeq(IR::Instr* instr, IR::PropertySymOpnd *opnd } } else if (valueInfo->GetJsTypeSet() && - (opnd->IsMono() ? - valueInfo->GetJsTypeSet()->Contains(opnd->GetFirstEquivalentType()) : + (opnd->IsMono() ? + valueInfo->GetJsTypeSet()->Contains(opnd->GetFirstEquivalentType()) : IsSubsetOf(opndTypeSet, valueInfo->GetJsTypeSet()) ) ) @@ -1473,7 +1473,7 @@ GlobOpt::OptNewScObject(IR::Instr** instrPtr, Value* srcVal) instr->m_func->GetConstructorCache(static_cast(instr->AsProfiledInstr()->u.profileId)) : nullptr; // TODO: OOP JIT, enable assert - //Assert(ctorCache == nullptr || srcVal->GetValueInfo()->IsVarConstant() && Js::JavascriptFunction::Is(srcVal->GetValueInfo()->AsVarConstant()->VarValue())); + //Assert(ctorCache == nullptr || srcVal->GetValueInfo()->IsVarConstant() && Js::VarIs(srcVal->GetValueInfo()->AsVarConstant()->VarValue())); Assert(ctorCache == nullptr || !ctorCache->IsTypeFinal() || ctorCache->CtorHasNoExplicitReturnValue()); if (ctorCache != nullptr && !ctorCache->SkipNewScObject() && (isCtorInlined || ctorCache->IsTypeFinal())) diff --git a/lib/Backend/Inline.cpp b/lib/Backend/Inline.cpp index ca6f1416b7a..8905482c70d 100644 --- a/lib/Backend/Inline.cpp +++ b/lib/Backend/Inline.cpp @@ -2549,7 +2549,7 @@ IR::Instr * Inline::InlineApplyWithArgumentsObject(IR::Instr * callInstr, IR::In IR::Instr * argumentsObjArgOut = nullptr; uint argOutCount = 0; this->GetArgInstrsForCallAndApply(callInstr, &implicitThisArgOut, &explicitThisArgOut, &argumentsObjArgOut, argOutCount); - + Assert(implicitThisArgOut); Assert(explicitThisArgOut); Assert(argumentsObjArgOut); @@ -2725,7 +2725,7 @@ IR::Instr * Inline::InlineApplyWithoutArrayArgument(IR::Instr *callInstr, const Assert(implicitThisArgOut); Assert(explicitThisArgOut); - + EmitFixedMethodOrFunctionObjectChecksForBuiltIns(callInstr, callInstr, applyInfo, false /*isPolymorphic*/, true /*isBuiltIn*/, false /*isCtor*/, true /*isInlined*/); InsertInlineeBuiltInStartEndTags(callInstr, 2); // 2 args (implicit this + explicit this) @@ -2898,7 +2898,7 @@ bool Inline::InlineApplyScriptTarget(IR::Instr *callInstr, const FunctionJITTime { return false; } - + const FunctionJITTimeInfo * inlineeData = nullptr; Js::InlineCacheIndex inlineCacheIndex = 0; IR::Instr * callbackDefInstr = nullptr; @@ -2955,7 +2955,7 @@ bool Inline::InlineApplyScriptTarget(IR::Instr *callInstr, const FunctionJITTime }); // If the arguments object was passed in as the first argument to apply, - // 'arguments' access continues to exist even after apply target inlining + // 'arguments' access continues to exist even after apply target inlining if (!HasArgumentsAccess(explicitThisArgOut)) { callInstr->m_func->SetApplyTargetInliningRemovedArgumentsAccess(); @@ -3023,7 +3023,7 @@ Inline::InlineCallApplyTarget_Shared(IR::Instr *callInstr, bool originalCallTarg if (isCallback) { char16 debugStringBuffer[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE]; - INLINE_CALLBACKS_TRACE(_u("INLINING CALLBACK : Inlining callback for call/apply target : \t%s (%s)\n"), inlineeData->GetBody()->GetDisplayName(), + INLINE_CALLBACKS_TRACE(_u("INLINING CALLBACK : Inlining callback for call/apply target : \t%s (%s)\n"), inlineeData->GetBody()->GetDisplayName(), inlineeData->GetDebugNumberSet(debugStringBuffer)); } #endif @@ -4067,7 +4067,7 @@ void Inline::InlineDOMGetterSetterFunction(IR::Instr *ldFldInstr, const Function // type-specific optimizations. Otherwise, this optimization to reduce calls into the host will also // result in relatively more expensive calls in the runtime. tmpDst->SetValueType(ldFldInstr->GetDst()->GetValueType()); - + IR::Opnd * callInstrDst = ldFldInstr->UnlinkDst(); ldFldInstr->SetDst(tmpDst); @@ -4491,7 +4491,7 @@ Inline::InsertJsFunctionCheck(IR::Instr * callInstr, IR::Instr *insertBeforeInst void Inline::InsertFunctionInfoCheck(IR::RegOpnd * funcOpnd, IR::Instr *insertBeforeInstr, IR::Instr* bailoutInstr, const FunctionJITTimeInfo *funcInfo) { - // if (JavascriptFunction::FromVar(r1)->functionInfo != funcInfo) goto noInlineLabel + // if (VarTo(r1)->functionInfo != funcInfo) goto noInlineLabel // BrNeq_I4 noInlineLabel, r1->functionInfo, funcInfo IR::IndirOpnd* opndFuncInfo = IR::IndirOpnd::New(funcOpnd, Js::JavascriptFunction::GetOffsetOfFunctionInfo(), TyMachPtr, insertBeforeInstr->m_func); IR::AddrOpnd* inlinedFuncInfo = IR::AddrOpnd::New(funcInfo->GetFunctionInfoAddr(), IR::AddrOpndKindDynamicFunctionInfo, insertBeforeInstr->m_func); diff --git a/lib/Backend/InlineeFrameInfo.cpp b/lib/Backend/InlineeFrameInfo.cpp index 4ac71f94bc3..706f5cae942 100644 --- a/lib/Backend/InlineeFrameInfo.cpp +++ b/lib/Backend/InlineeFrameInfo.cpp @@ -211,9 +211,9 @@ void InlineeFrameRecord::Restore(Js::FunctionBody* functionBody, InlinedFrameLay BAILOUT_VERBOSE_TRACE(functionBody, _u("Restore function object: ")); // No deepCopy needed for just the function Js::Var varFunction = this->Restore(this->functionOffset, /*isFloat64*/ false, /*isInt32*/ false, layout, functionBody, boxValues); - Assert(Js::ScriptFunction::Is(varFunction)); + Assert(Js::VarIs(varFunction)); - Js::ScriptFunction* function = Js::ScriptFunction::FromVar(varFunction); + Js::ScriptFunction* function = Js::VarTo(varFunction); BAILOUT_VERBOSE_TRACE(functionBody, _u("Inlinee: %s [%d.%d] \n"), function->GetFunctionBody()->GetDisplayName(), function->GetFunctionBody()->GetSourceContextId(), function->GetFunctionBody()->GetLocalFunctionId()); inlinedFrame->function = function; @@ -230,7 +230,7 @@ void InlineeFrameRecord::Restore(Js::FunctionBody* functionBody, InlinedFrameLay #if DBG if (boxValues && !Js::TaggedNumber::Is(var)) { - Js::RecyclableObject *const recyclableObject = Js::RecyclableObject::FromVar(var); + Js::RecyclableObject *const recyclableObject = Js::VarTo(var); Assert(!ThreadContext::IsOnStack(recyclableObject)); } #endif diff --git a/lib/Backend/Lower.cpp b/lib/Backend/Lower.cpp index b29b1bf0401..e03294d9e26 100644 --- a/lib/Backend/Lower.cpp +++ b/lib/Backend/Lower.cpp @@ -247,7 +247,7 @@ Lowerer::LowerRange(IR::Instr *instrStart, IR::Instr *instrEnd, bool defaultDoFa { this->helperCallCheckState = (HelperCallCheckState)(this->helperCallCheckState | HelperCallCheckState_ImplicitCallsBailout); } - + if ((bailoutKind & IR::BailOutOnArrayAccessHelperCall) != 0 && instr->m_opcode != Js::OpCode::Memcopy && instr->m_opcode != Js::OpCode::Memset) @@ -6881,7 +6881,7 @@ Lowerer::LowerNewScFuncHomeObj(IR::Instr * newScFuncInstr) IR::Opnd * src1 = newScFuncInstr->UnlinkSrc1(); newScFuncInstr->SetSrc1(helperOpnd); newScFuncInstr->SetSrc2(src1); - + return newScFuncInstr; } @@ -6906,7 +6906,7 @@ Lowerer::LowerNewScGenFuncHomeObj(IR::Instr * newScFuncInstr) IR::Opnd * src1 = newScFuncInstr->UnlinkSrc1(); newScFuncInstr->SetSrc1(helperOpnd); newScFuncInstr->SetSrc2(src1); - + return newScFuncInstr; } @@ -7867,7 +7867,7 @@ Lowerer::CreateEquivalentTypeGuardAndLinkToGuardedProperties(IR::PropertySymOpnd if (propertySymOpnd->ShouldUsePolyEquivTypeGuard(this->m_func)) { Js::JitPolyEquivalentTypeGuard *polyGuard = this->m_func->CreatePolyEquivalentTypeGuard(propertySymOpnd->GetObjTypeSpecFldId()); - + // Copy types from the type set to the guard's value locations Js::EquivalentTypeSet* typeSet = propertySymOpnd->GetEquivalentTypeSet(); for (uint16 ti = 0; ti < typeSet->GetCount(); ti++) @@ -9771,7 +9771,7 @@ Lowerer::LowerStArrViewElem(IR::Instr * instr) instr->FreeSrc2(); } } - // wasm memory buffer is not recycler allocated, so we shouldn't generate write barrier + // wasm memory buffer is not recycler allocated, so we shouldn't generate write barrier InsertMaskableMove(true, false, dst, src1, src2, indexOpnd, done, this); instr->Remove(); @@ -14811,7 +14811,7 @@ IR::RegOpnd *Lowerer::GenerateArrayTest( { // Only DynamicObject is allowed (DynamicObject vtable is ensured) because some object types have special handling for // index properties - arguments object, string object, external object, etc. - // If other object types are also allowed in the future, corresponding changes will have to made to + // If other object types are also allowed in the future, corresponding changes will have to made to // JavascriptArray::Jit_TryGetArrayForObjectWithArray as well. GenerateObjectTypeTest(baseOpnd, insertBeforeInstr, isNotObjectLabel); GenerateObjectHeaderInliningTest(baseOpnd, isNotArrayLabel, insertBeforeInstr); @@ -24834,7 +24834,7 @@ void Lowerer::GenerateJavascriptOperatorsIsConstructorGotoElse(IR::Instr *instrInsert, IR::RegOpnd *instanceRegOpnd, IR::LabelInstr *labelReturnTrue, IR::LabelInstr *labelReturnFalse) { // $ProxyLoop: - // // if (!RecyclableObject::Is(instance)) { goto $ReturnFalse }; // omitted: RecyclableObject::Is(instance) always true + // // if (!VarIs(instance)) { goto $ReturnFalse }; // omitted: VarIs(instance) always true // MOV s0, instance->type // MOV s1, s0->typeId // CMP s1, TypeIds_Proxy @@ -24994,7 +24994,7 @@ Lowerer::GenerateLdHomeObj(IR::Instr* instr) } else { - // Even if the function does not have home object in eval cases we still have the LdHomeObj opcode + // Even if the function does not have home object in eval cases we still have the LdHomeObj opcode InsertBranch(Js::OpCode::Br, labelDone, instr); } @@ -25015,7 +25015,7 @@ Lowerer::GenerateLdHomeObjProto(IR::Instr* instr) // TEST instance, instance // JZ $Done // - // if (!RecyclableObject::Is(instance)) goto $Done + // if (!VarIs(instance)) goto $Done // MOV type, [instance+Offset(type)] // MOV typeId, [type+Offset(typeId)] // CMP typeId, TypeIds_Null @@ -25030,7 +25030,7 @@ Lowerer::GenerateLdHomeObjProto(IR::Instr* instr) // instance = ((RecyclableObject*)instance)->GetPrototype(); // if (instance == nullptr) goto $Done; // - // if (!RecyclableObject::Is(instance)) goto $Done + // if (!VarIs(instance)) goto $Done // // MOV dst, instance // $Done: @@ -28267,7 +28267,7 @@ Lowerer::AddBailoutToHelperCallInstr(IR::Instr * helperCallInstr, BailOutInfo * return helperCallInstr; } -void +void Lowerer::GenerateAuxSlotPtrLoad(IR::PropertySymOpnd *propertySymOpnd, IR::Instr * instrInsert) { StackSym * auxSlotPtrSym = propertySymOpnd->GetAuxSlotPtrSym(); @@ -28359,7 +28359,7 @@ Lowerer::LowerCheckLowerIntBound(IR::Instr * instr) m_lowererMD.ChangeToHelperCall(helperCallInstr, IR::HelperIntRangeCheckFailure); instr->InsertAfter(continueLabel); - + instr->Remove(); return instrPrev; @@ -28375,7 +28375,7 @@ Lowerer::LowerCheckUpperIntBound(IR::Instr * instr) IR::LabelInstr * continueLabel = IR::LabelInstr::New(Js::OpCode::Label, instr->m_func, false /*isOpHelper*/); IR::LabelInstr * helperLabel = IR::LabelInstr::New(Js::OpCode::Label, instr->m_func, true /*isOpHelper*/); - + Assert(instr->GetSrc1()->IsInt32() || instr->GetSrc1()->IsUInt32()); if (lowerBoundCheckInstr) { diff --git a/lib/Backend/NativeCodeGenerator.cpp b/lib/Backend/NativeCodeGenerator.cpp index 53b3e746501..62a65e6f1e3 100644 --- a/lib/Backend/NativeCodeGenerator.cpp +++ b/lib/Backend/NativeCodeGenerator.cpp @@ -401,7 +401,7 @@ void NativeCodeGenerator::Jit_TransitionFromSimpleJit(void *const framePointer) { JIT_HELPER_NOT_REENTRANT_NOLOCK_HEADER(TransitionFromSimpleJit); TransitionFromSimpleJit( - Js::ScriptFunction::FromVar(Js::JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject)); + Js::VarTo(Js::JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject)); JIT_HELPER_END(TransitionFromSimpleJit); } @@ -740,7 +740,7 @@ NativeCodeGenerator::IsValidVar(const Js::Var var, Recycler *const recycler) } #endif - RecyclableObject *const recyclableObject = RecyclableObject::UnsafeFromVar(var); + RecyclableObject *const recyclableObject = UnsafeVarTo(var); if(!recycler->IsValidObject(recyclableObject, sizeof(*recyclableObject))) { return false; @@ -968,7 +968,7 @@ NativeCodeGenerator::CodeGen(PageAllocator * pageAllocator, CodeGenWorkItem* wor throw Js::OperationAbortedException(); } - + #if ENABLE_OOP_NATIVE_CODEGEN if (JITManager::GetJITManager()->IsOOPJITEnabled()) { @@ -1024,7 +1024,7 @@ NativeCodeGenerator::CodeGen(PageAllocator * pageAllocator, CodeGenWorkItem* wor Output::Flush(); } - epInfo->GetNativeEntryPointData()->SetFrameHeight(jitWriteData.frameHeight); + epInfo->GetNativeEntryPointData()->SetFrameHeight(jitWriteData.frameHeight); if (workItem->Type() == JsFunctionType) { @@ -2305,7 +2305,7 @@ NativeCodeGenerator::GatherCodeGenData( { // TODO: For now, we create the native entry point data and the jit transfer data when we queue up // the entry point for code gen, but not clear/free then then the work item got knocked off the queue - // without code gen happening. + // without code gen happening. nativeEntryPointData = entryPoint->EnsureNativeEntryPointData(); nativeEntryPointData->EnsureJitTransferData(recycler); @@ -2425,11 +2425,11 @@ NativeCodeGenerator::GatherCodeGenData( { Js::InlineCache *inlineCache = nullptr; - if(function && Js::ScriptFunctionWithInlineCache::Is(function)) + if(function && Js::VarIs(function)) { - if (Js::ScriptFunctionWithInlineCache::FromVar(function)->GetInlineCaches() != nullptr) + if (Js::VarTo(function)->GetInlineCaches() != nullptr) { - inlineCache = Js::ScriptFunctionWithInlineCache::FromVar(function)->GetInlineCache(i); + inlineCache = Js::VarTo(function)->GetInlineCache(i); } } else @@ -2561,11 +2561,11 @@ NativeCodeGenerator::GatherCodeGenData( } } // Even if the FldInfo says that the field access may be polymorphic, be optimistic that if the function object has inline caches, they'll be monomorphic - else if(function && Js::ScriptFunctionWithInlineCache::Is(function) && (cacheType & Js::FldInfo_InlineCandidate || !polymorphicCacheOnFunctionBody)) + else if(function && Js::VarIs(function) && (cacheType & Js::FldInfo_InlineCandidate || !polymorphicCacheOnFunctionBody)) { - if (Js::ScriptFunctionWithInlineCache::FromVar(function)->GetInlineCaches() != nullptr) + if (Js::VarTo(function)->GetInlineCaches() != nullptr) { - Js::InlineCache *inlineCache = Js::ScriptFunctionWithInlineCache::FromVar(function)->GetInlineCache(i); + Js::InlineCache *inlineCache = Js::VarTo(function)->GetInlineCache(i); ObjTypeSpecFldInfo* objTypeSpecFldInfo = nullptr; if(!PHASE_OFF(Js::ObjTypeSpecPhase, functionBody) || !PHASE_OFF(Js::FixedMethodsPhase, functionBody)) @@ -2698,8 +2698,8 @@ NativeCodeGenerator::GatherCodeGenData( // Clone polymorphic inline caches for runtime usage in this inlinee. The JIT should only use the pointers to // the inline caches, as their cached data is not guaranteed to be stable while jitting. Js::InlineCache *const inlineCache = - function && Js::ScriptFunctionWithInlineCache::Is(function) - ? (Js::ScriptFunctionWithInlineCache::FromVar(function)->GetInlineCaches() != nullptr ? Js::ScriptFunctionWithInlineCache::FromVar(function)->GetInlineCache(i) : nullptr) + function && Js::VarIs(function) + ? (Js::VarTo(function)->GetInlineCaches() != nullptr ? Js::VarTo(function)->GetInlineCache(i) : nullptr) : functionBody->GetInlineCache(i); if (inlineCache != nullptr) @@ -2828,11 +2828,11 @@ NativeCodeGenerator::GatherCodeGenData( Js::InlineCache * inlineCache = nullptr; if ((ldFldInlineCacheIndex != Js::Constants::NoInlineCacheIndex) && (ldFldInlineCacheIndex < functionBody->GetInlineCacheCount())) { - if(function && Js::ScriptFunctionWithInlineCache::Is(function)) + if(function && Js::VarIs(function)) { - if (Js::ScriptFunctionWithInlineCache::FromVar(function)->GetInlineCaches() != nullptr) + if (Js::VarTo(function)->GetInlineCaches() != nullptr) { - inlineCache = Js::ScriptFunctionWithInlineCache::FromVar(function)->GetInlineCache(ldFldInlineCacheIndex); + inlineCache = Js::VarTo(function)->GetInlineCache(ldFldInlineCacheIndex); } } else @@ -3129,7 +3129,7 @@ NativeCodeGenerator::GatherCodeGenData(Js::FunctionBody *const topFunctionBody, topFunctionBody->GetDisplayName(), topFunctionBody->GetDebugNumberSet(debugStringBuffer), functionBody->GetDisplayName(), functionBody->GetDebugNumberSet(debugStringBuffer2)); } #endif - GatherCodeGenData(recycler, topFunctionBody, functionBody, entryPoint, inliningDecider, objTypeSpecFldInfoList, jitTimeData, nullptr, function ? Js::JavascriptFunction::FromVar(function) : nullptr, 0); + GatherCodeGenData(recycler, topFunctionBody, functionBody, entryPoint, inliningDecider, objTypeSpecFldInfoList, jitTimeData, nullptr, function ? Js::VarTo(function) : nullptr, 0); jitTimeData->sharedPropertyGuards = entryPoint->GetNativeEntryPointData()->GetSharedPropertyGuards(recycler, jitTimeData->sharedPropertyGuardCount); @@ -3279,7 +3279,7 @@ void FreeNativeCodeGenAllocation(Js::ScriptContext *scriptContext, Js::JavascriptMethod codeAddress, Js::JavascriptMethod thunkAddress) { if (!scriptContext->GetNativeCodeGenerator()) - { + { return; } diff --git a/lib/Backend/ObjTypeSpecFldInfo.cpp b/lib/Backend/ObjTypeSpecFldInfo.cpp index 95dc9458c54..a4436fb4b97 100644 --- a/lib/Backend/ObjTypeSpecFldInfo.cpp +++ b/lib/Backend/ObjTypeSpecFldInfo.cpp @@ -45,7 +45,7 @@ ObjTypeSpecFldInfo::NeedsDepolymorphication() const return m_data.polymorphicInfoArray != nullptr; } -void +void ObjTypeSpecFldInfo::TryDepolymorphication(JITTypeHolder type, uint16 slotIndex, bool usesAuxSlot, uint16 * pNewSlotIndex, bool * pNewUsesAuxSlot, uint16 * checkedTypeSetIndex) const { Assert(NeedsDepolymorphication()); @@ -505,7 +505,7 @@ ObjTypeSpecFldInfo* ObjTypeSpecFldInfo::CreateFrom(uint id, Js::InlineCache* cac propertyGuard = entryPoint->GetNativeEntryPointData()->RegisterSharedPropertyGuard(propertyId, scriptContext); } - if (fixedProperty != nullptr && Js::JavascriptFunction::Is(fixedProperty)) + if (fixedProperty != nullptr && Js::VarIs(fixedProperty)) { functionObject = (Js::JavascriptFunction *)fixedProperty; if (PHASE_VERBOSE_TRACE(Js::FixedMethodsPhase, functionBody)) @@ -860,7 +860,7 @@ ObjTypeSpecFldInfo* ObjTypeSpecFldInfo::CreateFrom(uint id, Js::PolymorphicInlin { areEquivalent = false; } - if (!isAccessor || isGetterAccessor != inlineCache.IsGetterAccessor() || !isAccessorOnProto || !inlineCache.u.accessor.isOnProto || + if (!isAccessor || isGetterAccessor != inlineCache.IsGetterAccessor() || !isAccessorOnProto || !inlineCache.u.accessor.isOnProto || accessorOwnerObject != inlineCache.u.accessor.object || typeId != TypeWithoutAuxSlotTag(inlineCache.u.accessor.type)->GetTypeId()) { areEquivalent = false; diff --git a/lib/Backend/ObjTypeSpecFldInfo.h b/lib/Backend/ObjTypeSpecFldInfo.h index 6e7d99935b4..df130e6117e 100644 --- a/lib/Backend/ObjTypeSpecFldInfo.h +++ b/lib/Backend/ObjTypeSpecFldInfo.h @@ -191,8 +191,8 @@ class ObjTypeSpecFldInfo if (PHASE_OFF1(Js::ObjTypeSpecPhase)) return nullptr; // TODO: (lei)remove this after obj type spec for OOPJIT implemented - return m_data.fixedFieldInfoArray[0].fieldValue != 0 && Js::JavascriptFunction::Is((Js::Var)m_data.fixedFieldInfoArray[0].fieldValue) ? - Js::JavascriptFunction::FromVar((Js::Var)m_data.fixedFieldInfoArray[0].fieldValue) : nullptr; + return m_data.fixedFieldInfoArray[0].fieldValue != 0 && Js::VarIs((Js::Var)m_data.fixedFieldInfoArray[0].fieldValue) ? + Js::VarTo((Js::Var)m_data.fixedFieldInfoArray[0].fieldValue) : nullptr; } Js::TypeId GetTypeId() const; diff --git a/lib/Backend/Opnd.cpp b/lib/Backend/Opnd.cpp index 8f6a92f725a..d56410e41b8 100644 --- a/lib/Backend/Opnd.cpp +++ b/lib/Backend/Opnd.cpp @@ -1016,7 +1016,7 @@ PropertySymOpnd::UpdateSlotForFinalType() return; } - // TODO: OOP JIT: should assert about runtime type handler addr + // TODO: OOP JIT: should assert about runtime type handler addr Assert(cachedType->GetTypeHandler() != finalType->GetTypeHandler()); if (cachedType->GetTypeHandler()->GetInlineSlotCapacity() == finalType->GetTypeHandler()->GetInlineSlotCapacity() && @@ -1068,7 +1068,7 @@ PropertySymOpnd::CloneUseInternalSub(Func *func) return this->CopyInternalSub(func); } -bool +bool PropertySymOpnd::ShouldUsePolyEquivTypeGuard(Func *const func) const { return this->IsPoly() && this->m_polyCacheUtil >= PolymorphicInlineCacheUtilizationThreshold && !PHASE_OFF(Js::PolyEquivTypeGuardPhase, func); @@ -3232,7 +3232,7 @@ Opnd::Dump(IRDumpFlags flags, Func *func) Output::Print(_u("%s"), func->GetInProcThreadContext()->GetPropertyRecord(propertyOpInfo->GetPropertyId())->GetBuffer(), propertyOpId); } Output::Print(_u("(%u)"), propertyOpId); - + if (propertyOpInfo->IsLoadedFromProto()) { Output::Print(_u("~")); @@ -3627,13 +3627,13 @@ Opnd::GetAddrDescription(__out_ecount(count) char16 *const description, const si } else { - switch (Js::RecyclableObject::FromVar(address)->GetTypeId()) + switch (Js::VarTo(address)->GetTypeId()) { case Js::TypeIds_Boolean: - WriteToBuffer(&buffer, &n, Js::JavascriptBoolean::FromVar(address)->GetValue() ? _u(" (true)") : _u(" (false)")); + WriteToBuffer(&buffer, &n, Js::VarTo(address)->GetValue() ? _u(" (true)") : _u(" (false)")); break; case Js::TypeIds_String: - WriteToBuffer(&buffer, &n, _u(" (\"%s\")"), Js::JavascriptString::FromVar(address)->GetSz()); + WriteToBuffer(&buffer, &n, _u(" (\"%s\")"), Js::VarTo(address)->GetSz()); break; case Js::TypeIds_Number: WriteToBuffer(&buffer, &n, _u(" (value: %f)"), Js::JavascriptNumber::GetValue(address)); @@ -3830,9 +3830,9 @@ Opnd::GetAddrDescription(__out_ecount(count) char16 *const description, const si DumpAddress(address, printToConsole, skipMaskedAddress); { Js::RecyclableObject * dynamicObject = (Js::RecyclableObject *)((intptr_t)address - Js::RecyclableObject::GetOffsetOfType()); - if (!func->IsOOPJIT() && Js::JavascriptFunction::Is(dynamicObject)) + if (!func->IsOOPJIT() && Js::VarIs(dynamicObject)) { - DumpFunctionInfo(&buffer, &n, Js::JavascriptFunction::FromVar((void *)((intptr_t)address - Js::RecyclableObject::GetOffsetOfType()))->GetFunctionInfo(), + DumpFunctionInfo(&buffer, &n, Js::VarTo((void *)((intptr_t)address - Js::RecyclableObject::GetOffsetOfType()))->GetFunctionInfo(), printToConsole, _u("FunctionObjectTypeRef")); } else diff --git a/lib/Backend/SimpleJitProfilingHelpers.cpp b/lib/Backend/SimpleJitProfilingHelpers.cpp index 6a1fa9ca66f..756cdff2de0 100644 --- a/lib/Backend/SimpleJitProfilingHelpers.cpp +++ b/lib/Backend/SimpleJitProfilingHelpers.cpp @@ -69,7 +69,7 @@ using namespace Js; DynamicProfileInfo * dynamicProfileInfo = callerFunctionBody->GetDynamicProfileInfo(); JavascriptFunction *const calleeFunction = - JavascriptFunction::Is(callee) ? JavascriptFunction::FromVar(callee) : nullptr; + VarIs(callee) ? VarTo(callee) : nullptr; FunctionInfo* calleeFunctionInfo = calleeFunction ? calleeFunction->GetFunctionInfo() : nullptr; auto const ctor = !!(info.Flags & CallFlags_New); diff --git a/lib/Common/Exceptions/Throw.h b/lib/Common/Exceptions/Throw.h index 72c1bbfa7dd..d92cfcdae8d 100644 --- a/lib/Common/Exceptions/Throw.h +++ b/lib/Common/Exceptions/Throw.h @@ -210,10 +210,10 @@ namespace Js { #define GET_RUNTIME_ERROR_IMPL(hr, GetRuntimeErrorFunc, exceptionObject) \ { \ Js::Var errorObject = exceptionObject->GetThrownObject(nullptr); \ - if (errorObject != nullptr && (Js::JavascriptError::Is(errorObject) || \ + if (errorObject != nullptr && (Js::VarIs(errorObject) || \ Js::JavascriptError::IsRemoteError(errorObject))) \ { \ - hr = GetRuntimeErrorFunc(Js::RecyclableObject::FromVar(errorObject), nullptr); \ + hr = GetRuntimeErrorFunc(Js::VarTo(errorObject), nullptr); \ } \ else if (errorObject != nullptr) \ { \ diff --git a/lib/Jsrt/Core/JsrtCore.cpp b/lib/Jsrt/Core/JsrtCore.cpp index 77dd538139b..47107cec3c8 100644 --- a/lib/Jsrt/Core/JsrtCore.cpp +++ b/lib/Jsrt/Core/JsrtCore.cpp @@ -77,7 +77,7 @@ JsParseModuleSource( size_t moduleUrlLen = 0; if (moduleRecord->GetModuleUrl()) { - Js::JavascriptString *moduleUrl = Js::JavascriptString::FromVar(moduleRecord->GetModuleUrl()); + Js::JavascriptString *moduleUrl = Js::VarTo(moduleRecord->GetModuleUrl()); moduleUrlSz = moduleUrl->GetSz(); moduleUrlLen = moduleUrl->GetLength(); } @@ -171,7 +171,7 @@ JsSetModuleHostInfo( currentContext->GetHostScriptContext()->SetNotifyModuleReadyCallback(reinterpret_cast(hostInfo)); break; case JsModuleHostInfo_Url: - moduleRecord->SetModuleUrl(hostInfo); + moduleRecord->SetModuleUrl(hostInfo); break; default: return JsInvalidModuleHostInfoKind; diff --git a/lib/Jsrt/Jsrt.cpp b/lib/Jsrt/Jsrt.cpp index 9a9e1e084e4..317d198cf48 100644 --- a/lib/Jsrt/Jsrt.cpp +++ b/lib/Jsrt/Jsrt.cpp @@ -220,7 +220,7 @@ void CALLBACK CreateExternalObject_TTDCallback(Js::ScriptContext* ctx, Js::Var p Js::RecyclableObject * prototypeObject = nullptr; if (prototype != JS_INVALID_REFERENCE) { - prototypeObject = Js::RecyclableObject::FromVar(prototype); + prototypeObject = Js::VarTo(prototype); } *object = JsrtExternalObject::Create(nullptr, nullptr, prototypeObject, ctx); @@ -641,7 +641,7 @@ CHAKRA_API JsAddRef(_In_ JsRef ref, _Out_opt_ unsigned int *count) if((lCount == 1) && (threadContext->IsRuntimeInTTDMode()) && (!threadContext->TTDLog->IsPropertyRecordRef(ref))) { - Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(ref); + Js::RecyclableObject* obj = Js::VarTo(ref); if(obj->GetScriptContext()->IsTTDRecordModeEnabled()) { if(obj->GetScriptContext()->ShouldPerformRecordAction()) @@ -861,11 +861,11 @@ CHAKRA_API JsGetContextOfObject(_In_ JsValueRef object, _Out_ JsContextRef *cont BEGIN_JSRT_NO_EXCEPTION { - if (!Js::RecyclableObject::Is(object)) + if (!Js::VarIs(object)) { RETURN_NO_EXCEPTION(JsErrorArgumentNotObject); } - Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(object); + Js::RecyclableObject* obj = Js::VarTo(object); *context = (JsContextRef)obj->GetScriptContext()->GetLibrary()->GetJsrtContext(); } END_JSRT_NO_EXCEPTION @@ -995,12 +995,12 @@ CHAKRA_API JsBooleanToBool(_In_ JsValueRef value, _Out_ bool *boolValue) BEGIN_JSRT_NO_EXCEPTION { - if (!Js::JavascriptBoolean::Is(value)) + if (!Js::VarIs(value)) { RETURN_NO_EXCEPTION(JsErrorInvalidArgument); } - *boolValue = Js::JavascriptBoolean::FromVar(value)->GetValue() ? true : false; + *boolValue = Js::VarTo(value)->GetValue() ? true : false; } END_JSRT_NO_EXCEPTION } @@ -1210,12 +1210,12 @@ CHAKRA_API JsGetStringLength(_In_ JsValueRef value, _Out_ int *length) BEGIN_JSRT_NO_EXCEPTION { - if (!Js::JavascriptString::Is(value)) + if (!Js::VarIs(value)) { RETURN_NO_EXCEPTION(JsErrorInvalidArgument); } - *length = Js::JavascriptString::FromVar(value)->GetLengthAsSignedInt(); + *length = Js::VarTo(value)->GetLengthAsSignedInt(); } END_JSRT_NO_EXCEPTION } @@ -1252,13 +1252,13 @@ CHAKRA_API JsStringToPointer(_In_ JsValueRef stringValue, _Outptr_result_buffer_ PARAM_NOT_NULL(stringLength); *stringLength = 0; - if (!Js::JavascriptString::Is(stringValue)) + if (!Js::VarIs(stringValue)) { return JsErrorInvalidArgument; } return GlobalAPIWrapper_NoRecord([&]() -> JsErrorCode { - Js::JavascriptString *jsString = Js::JavascriptString::FromVar(stringValue); + Js::JavascriptString *jsString = Js::VarTo(stringValue); *stringPtr = jsString->GetSz(); *stringLength = jsString->GetLength(); @@ -1271,7 +1271,7 @@ CHAKRA_API JsConvertValueToString(_In_ JsValueRef value, _Out_ JsValueRef *resul PARAM_NOT_NULL(result); *result = nullptr; - if (value != nullptr && Js::JavascriptString::Is(value)) + if (value != nullptr && Js::VarIs(value)) { return ContextAPINoScriptWrapper([&](Js::ScriptContext *scriptContext, TTDRecorder& _actionEntryPopper) -> JsErrorCode { PERFORM_JSRT_TTD_RECORD_ACTION(scriptContext, RecordJsRTVarToStringConversion, (Js::Var)value); @@ -1337,7 +1337,7 @@ CHAKRA_API JsCreateExternalObjectWithPrototype(_In_opt_ void *data, if (prototype != JS_INVALID_REFERENCE) { VALIDATE_INCOMING_OBJECT(prototype, scriptContext); - prototypeObject = Js::RecyclableObject::FromVar(prototype); + prototypeObject = Js::VarTo(prototype); } *object = JsrtExternalObject::Create(data, finalizeCallback, prototypeObject, scriptContext); @@ -1401,7 +1401,7 @@ CHAKRA_API JsSetPrototype(_In_ JsValueRef object, _In_ JsValueRef prototypeObjec return JsErrorInvalidArgument; } - Js::JavascriptObject::ChangePrototype(Js::RecyclableObject::FromVar(object), Js::RecyclableObject::FromVar(prototypeObject), true, scriptContext); + Js::JavascriptObject::ChangePrototype(Js::VarTo(object), Js::VarTo(prototypeObject), true, scriptContext); return JsNoError; }); @@ -1416,7 +1416,7 @@ CHAKRA_API JsInstanceOf(_In_ JsValueRef object, _In_ JsValueRef constructor, _Ou PARAM_NOT_NULL(result); Js::Var value = Js::JavascriptOperators::OP_IsInst(object, constructor, scriptContext, nullptr); - *result = !!Js::JavascriptBoolean::FromVar(value)->GetValue(); + *result = !!Js::VarTo(value)->GetValue(); return JsNoError; }); @@ -1431,7 +1431,7 @@ CHAKRA_API JsGetExtensionAllowed(_In_ JsValueRef object, _Out_ bool *value) PARAM_NOT_NULL(value); *value = false; - *value = Js::RecyclableObject::FromVar(object)->IsExtensible() != 0; + *value = Js::VarTo(object)->IsExtensible() != 0; return JsNoError; }); @@ -1444,7 +1444,7 @@ CHAKRA_API JsPreventExtension(_In_ JsValueRef object) VALIDATE_INCOMING_OBJECT(object, scriptContext); - Js::RecyclableObject::FromVar(object)->PreventExtensions(); + Js::VarTo(object)->PreventExtensions(); return JsNoError; }); @@ -1486,11 +1486,11 @@ static JsErrorCode InternalGetPropertyRecord(Js::ScriptContext * scriptContext, switch(key->GetTypeId()) { case Js::TypeIds_String: - scriptContext->GetOrAddPropertyRecord(Js::JavascriptString::FromVar(key), + scriptContext->GetOrAddPropertyRecord(Js::VarTo(key), (Js::PropertyRecord const **)propertyRecord); break; case Js::TypeIds_Symbol: - *propertyRecord = Js::JavascriptSymbol::FromVar(key)->GetValue(); + *propertyRecord = Js::VarTo(key)->GetValue(); break; default: return JsErrorInvalidArgument; @@ -1512,7 +1512,7 @@ CHAKRA_API JsObjectHasOwnProperty(_In_ JsValueRef object, _In_ JsValueRef proper const Js::PropertyRecord *propertyRecord = nullptr; JsErrorCode errorValue = InternalGetPropertyRecord(scriptContext, - Js::RecyclableObject::FromVar(propertyId), &propertyRecord); + Js::VarTo(propertyId), &propertyRecord); if (errorValue != JsNoError) { @@ -1547,7 +1547,7 @@ CHAKRA_API JsGetProperty(_In_ JsValueRef object, _In_ JsPropertyIdRef propertyId PARAM_NOT_NULL(value); *value = nullptr; - Js::RecyclableObject * instance = Js::RecyclableObject::FromVar(object); + Js::RecyclableObject * instance = Js::VarTo(object); JsErrorCode err = JsGetPropertyCommon(scriptContext, instance, (const Js::PropertyRecord *)propertyId, value); @@ -1571,7 +1571,7 @@ CHAKRA_API JsObjectGetProperty(_In_ JsValueRef object, _In_ JsValueRef propertyI const Js::PropertyRecord *propertyRecord = nullptr; JsErrorCode errorValue = InternalGetPropertyRecord(scriptContext, - Js::RecyclableObject::FromVar(propertyId), &propertyRecord); + Js::VarTo(propertyId), &propertyRecord); if (errorValue != JsNoError) { @@ -1580,7 +1580,7 @@ CHAKRA_API JsObjectGetProperty(_In_ JsValueRef object, _In_ JsValueRef propertyI Assert(propertyRecord != nullptr); - Js::RecyclableObject * instance = Js::RecyclableObject::FromVar(object); + Js::RecyclableObject * instance = Js::VarTo(object); return JsGetPropertyCommon(scriptContext, instance, propertyRecord, value); }); } @@ -1592,7 +1592,7 @@ static JsErrorCode JsGetOwnPropertyDescriptorCommon(Js::ScriptContext * scriptCo AssertMsg(scriptContext->GetThreadContext()->IsScriptActive(), "Caller is expected to be under ContextAPIWrapper!"); Js::PropertyDescriptor propertyDescriptorValue; - if (Js::JavascriptOperators::GetOwnPropertyDescriptor(Js::RecyclableObject::FromVar(object), + if (Js::JavascriptOperators::GetOwnPropertyDescriptor(Js::VarTo(object), propertyRecord->GetPropertyId(), scriptContext, &propertyDescriptorValue)) { *propertyDescriptor = Js::JavascriptOperators::FromPropertyDescriptor(propertyDescriptorValue, scriptContext); @@ -1639,7 +1639,7 @@ CHAKRA_API JsObjectGetOwnPropertyDescriptor(_In_ JsValueRef object, _In_ JsValue const Js::PropertyRecord *propertyRecord = nullptr; JsErrorCode errorValue = InternalGetPropertyRecord(scriptContext, - Js::RecyclableObject::FromVar(propertyId), &propertyRecord); + Js::VarTo(propertyId), &propertyRecord); if (errorValue != JsNoError) { @@ -1692,7 +1692,7 @@ CHAKRA_API JsObjectSetProperty(_In_ JsValueRef object, _In_ JsValueRef propertyI const Js::PropertyRecord *propertyRecord = nullptr; JsErrorCode errorValue = InternalGetPropertyRecord(scriptContext, - Js::RecyclableObject::FromVar(propertyId), &propertyRecord); + Js::VarTo(propertyId), &propertyRecord); if (errorValue != JsNoError) { @@ -1719,13 +1719,13 @@ CHAKRA_API JsHasProperty(_In_ JsValueRef object, _In_ JsPropertyIdRef propertyId PARAM_NOT_NULL(hasProperty); *hasProperty = false; - Js::RecyclableObject * instance = Js::RecyclableObject::FromVar(object); + Js::RecyclableObject * instance = Js::VarTo(object); *hasProperty = Js::JavascriptOperators::HasProperty(instance, ((Js::PropertyRecord *)propertyId)->GetPropertyId()) != 0; return JsNoError; }; - Js::RecyclableObject* robject = Js::RecyclableObject::FromVar(object); + Js::RecyclableObject* robject = Js::VarTo(object); Js::TypeId typeId = Js::JavascriptOperators::GetTypeId(robject); while (typeId != Js::TypeIds_Null && typeId != Js::TypeIds_Proxy) { @@ -1758,20 +1758,20 @@ CHAKRA_API JsObjectHasProperty(_In_ JsValueRef object, _In_ JsValueRef propertyI const Js::PropertyRecord *propertyRecord = nullptr; JsErrorCode errorValue = InternalGetPropertyRecord(scriptContext, - Js::RecyclableObject::FromVar(propertyId), &propertyRecord); + Js::VarTo(propertyId), &propertyRecord); if (errorValue != JsNoError) { return errorValue; } - Js::RecyclableObject * instance = Js::RecyclableObject::FromVar(object); + Js::RecyclableObject * instance = Js::VarTo(object); *hasProperty = Js::JavascriptOperators::HasProperty(instance, propertyRecord->GetPropertyId()) != 0; return JsNoError; }; - Js::RecyclableObject* robject = Js::RecyclableObject::FromVar(object); + Js::RecyclableObject* robject = Js::VarTo(object); Js::TypeId typeId = Js::JavascriptOperators::GetTypeId(robject); while (typeId != Js::TypeIds_Null && typeId != Js::TypeIds_Proxy) { @@ -1840,7 +1840,7 @@ CHAKRA_API JsObjectDeleteProperty(_In_ JsValueRef object, _In_ JsValueRef proper const Js::PropertyRecord *propertyRecord = nullptr; JsErrorCode errorValue = InternalGetPropertyRecord(scriptContext, - Js::RecyclableObject::FromVar(propertyId), &propertyRecord); + Js::VarTo(propertyId), &propertyRecord); if (errorValue != JsNoError) { @@ -1868,7 +1868,7 @@ static JsErrorCode JsDefinePropertyCommon(Js::ScriptContext * scriptContext, _In } *result = Js::JavascriptOperators::DefineOwnPropertyDescriptor( - Js::RecyclableObject::FromVar(object), propertyRecord->GetPropertyId(), + Js::VarTo(object), propertyRecord->GetPropertyId(), propertyDescriptorValue, true, scriptContext) != 0; return JsNoError; @@ -1908,7 +1908,7 @@ CHAKRA_API JsObjectDefineProperty(_In_ JsValueRef object, _In_ JsValueRef proper const Js::PropertyRecord *propertyRecord = nullptr; JsErrorCode errorValue = InternalGetPropertyRecord(scriptContext, - Js::RecyclableObject::FromVar(propertyId), &propertyRecord); + Js::VarTo(propertyId), &propertyRecord); if (errorValue != JsNoError) { @@ -2011,13 +2011,13 @@ CHAKRA_API JsGetSharedArrayBufferContent(_In_ JsValueRef sharedArrayBuffer, _Out PARAM_NOT_NULL(sharedContents); - if (!Js::SharedArrayBuffer::Is(sharedArrayBuffer)) + if (!Js::VarIs(sharedArrayBuffer)) { return JsErrorInvalidArgument; } Js::SharedContents**& content = (Js::SharedContents**&)sharedContents; - *content = Js::SharedArrayBuffer::FromVar(sharedArrayBuffer)->GetSharedContents(); + *content = Js::VarTo(sharedArrayBuffer)->GetSharedContents(); if (*content == nullptr) { @@ -2081,7 +2081,7 @@ CHAKRA_API JsCreateTypedArray(_In_ JsTypedArrayType arrayType, _In_ JsValueRef b Js::JavascriptLibrary* library = scriptContext->GetLibrary(); - const bool fromArrayBuffer = (baseArray != JS_INVALID_REFERENCE && Js::ArrayBuffer::Is(baseArray)); + const bool fromArrayBuffer = (baseArray != JS_INVALID_REFERENCE && Js::VarIs(baseArray)); if (byteOffset != 0 && !fromArrayBuffer) { @@ -2160,13 +2160,13 @@ CHAKRA_API JsCreateDataView(_In_ JsValueRef arrayBuffer, _In_ unsigned int byteO VALIDATE_INCOMING_REFERENCE(arrayBuffer, scriptContext); PARAM_NOT_NULL(result); - if (!Js::ArrayBuffer::Is(arrayBuffer)) + if (!Js::VarIs(arrayBuffer)) { return JsErrorInvalidArgument; } Js::JavascriptLibrary* library = scriptContext->GetLibrary(); - *result = library->CreateDataView(Js::ArrayBuffer::FromVar(arrayBuffer), byteOffset, byteLength); + *result = library->CreateDataView(Js::VarTo(arrayBuffer), byteOffset, byteLength); JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_OBJECT(*result)); return JsNoError; @@ -2207,7 +2207,7 @@ CHAKRA_API JsGetTypedArrayInfo(_In_ JsValueRef typedArray, _Out_opt_ JsTypedArra *arrayType = GetTypedArrayType(typeId); } - Js::TypedArrayBase* typedArrayBase = Js::TypedArrayBase::FromVar(typedArray); + Js::TypedArrayBase* typedArrayBase = Js::VarTo(typedArray); if (arrayBuffer != nullptr) { *arrayBuffer = typedArrayBase->GetArrayBuffer(); } @@ -2222,7 +2222,7 @@ CHAKRA_API JsGetTypedArrayInfo(_In_ JsValueRef typedArray, _Out_opt_ JsTypedArra } #if ENABLE_TTD - Js::ScriptContext* scriptContext = Js::RecyclableObject::FromVar(typedArray)->GetScriptContext(); + Js::ScriptContext* scriptContext = Js::VarTo(typedArray)->GetScriptContext(); if(PERFORM_JSRT_TTD_RECORD_ACTION_CHECK(scriptContext) && arrayBuffer != nullptr) { scriptContext->GetThreadContext()->TTDLog->RecordJsRTGetTypedArrayInfo(typedArray, *arrayBuffer); @@ -2241,12 +2241,12 @@ CHAKRA_API JsGetArrayBufferStorage(_In_ JsValueRef instance, _Outptr_result_byte BEGIN_JSRT_NO_EXCEPTION { - if (!Js::ArrayBuffer::Is(instance)) + if (!Js::VarIs(instance)) { RETURN_NO_EXCEPTION(JsErrorInvalidArgument); } - Js::ArrayBuffer* arrayBuffer = Js::ArrayBuffer::FromVar(instance); + Js::ArrayBuffer* arrayBuffer = Js::VarTo(instance); *buffer = arrayBuffer->GetBuffer(); *bufferLength = arrayBuffer->GetByteLength(); } @@ -2268,7 +2268,7 @@ CHAKRA_API JsGetTypedArrayStorage(_In_ JsValueRef instance, _Outptr_result_byteb RETURN_NO_EXCEPTION(JsErrorInvalidArgument); } - Js::TypedArrayBase* typedArrayBase = Js::TypedArrayBase::FromVar(instance); + Js::TypedArrayBase* typedArrayBase = Js::VarTo(instance); *buffer = typedArrayBase->GetByteBuffer(); *bufferLength = typedArrayBase->GetByteLength(); @@ -2326,12 +2326,12 @@ CHAKRA_API JsGetDataViewStorage(_In_ JsValueRef instance, _Outptr_result_bytebuf BEGIN_JSRT_NO_EXCEPTION { - if (!Js::DataView::Is(instance)) + if (!Js::VarIs(instance)) { RETURN_NO_EXCEPTION(JsErrorInvalidArgument); } - Js::DataView* dataView = Js::DataView::FromVar(instance); + Js::DataView* dataView = Js::VarTo(instance); *buffer = dataView->GetArrayBuffer()->GetBuffer() + dataView->GetByteOffset(); *bufferLength = dataView->GetLength(); } @@ -2459,7 +2459,7 @@ Js::ArrayObject* CreateTypedArray(Js::ScriptContext *scriptContext, void* data, template void GetObjectArrayData(Js::ArrayObject* objectArray, void** data, JsTypedArrayType* arrayType, uint* length) { - Js::TypedArray* typedArray = Js::TypedArray::FromVar(objectArray); + Js::TypedArray* typedArray = Js::VarTo>(objectArray); *data = typedArray->GetArrayBuffer()->GetBuffer(); *arrayType = TypedArrayTypeTraits::cTypedArrayType; *length = typedArray->GetLength(); @@ -2483,7 +2483,7 @@ CHAKRA_API JsSetIndexedPropertiesToExternalData( || (typeId >= Js::TypeIds_TypedArrayMin && typeId <= Js::TypeIds_TypedArrayMax) || typeId == Js::TypeIds_ArrayBuffer || typeId == Js::TypeIds_DataView - || Js::RecyclableObject::FromVar(object)->IsExternal() + || Js::VarTo(object)->IsExternal() ) { return JsErrorInvalidArgument; @@ -2528,7 +2528,7 @@ CHAKRA_API JsSetIndexedPropertiesToExternalData( return JsErrorInvalidArgument; } - Js::DynamicObject* dynamicObject = Js::DynamicObject::FromVar(object); + Js::DynamicObject* dynamicObject = Js::VarTo(object); dynamicObject->SetObjectArray(newTypedArray); return JsNoError; @@ -2546,7 +2546,7 @@ CHAKRA_API JsHasIndexedPropertiesExternalData(_In_ JsValueRef object, _Out_ bool if (Js::DynamicType::Is(Js::JavascriptOperators::GetTypeId(object))) { - Js::DynamicObject* dynamicObject = Js::DynamicObject::UnsafeFromVar(object); + Js::DynamicObject* dynamicObject = Js::UnsafeVarTo(object); Js::ArrayObject* objectArray = dynamicObject->GetObjectArray(); *value = (objectArray && !Js::DynamicObject::IsAnyArray(objectArray)); } @@ -2576,7 +2576,7 @@ CHAKRA_API JsGetIndexedPropertiesExternalData( *arrayType = JsTypedArrayType(); *elementLength = 0; - Js::DynamicObject* dynamicObject = Js::DynamicObject::UnsafeFromVar(object); + Js::DynamicObject* dynamicObject = Js::UnsafeVarTo(object); Js::ArrayObject* objectArray = dynamicObject->GetObjectArray(); if (!objectArray) { @@ -2684,7 +2684,7 @@ CHAKRA_API JsHasExternalData(_In_ JsValueRef object, _Out_ bool *value) BEGIN_JSRT_NO_EXCEPTION { - *value = JsrtExternalObject::Is(object); + *value = Js::VarIs(object); } END_JSRT_NO_EXCEPTION } @@ -2696,9 +2696,9 @@ CHAKRA_API JsGetExternalData(_In_ JsValueRef object, _Out_ void **data) BEGIN_JSRT_NO_EXCEPTION { - if (JsrtExternalObject::Is(object)) + if (Js::VarIs(object)) { - *data = JsrtExternalObject::FromVar(object)->GetSlotData(); + *data = Js::VarTo(object)->GetSlotData(); } else { @@ -2715,9 +2715,9 @@ CHAKRA_API JsSetExternalData(_In_ JsValueRef object, _In_opt_ void *data) BEGIN_JSRT_NO_EXCEPTION { - if (JsrtExternalObject::Is(object)) + if (Js::VarIs(object)) { - JsrtExternalObject::FromVar(object)->SetSlotData(data); + Js::VarTo(object)->SetSlotData(data); } else { @@ -2768,7 +2768,7 @@ CHAKRA_API JsCallFunction(_In_ JsValueRef function, _In_reads_(cargs) JsValueRef VALIDATE_INCOMING_REFERENCE(args[index], scriptContext); } - Js::JavascriptFunction *jsFunction = Js::JavascriptFunction::FromVar(function); + Js::JavascriptFunction *jsFunction = Js::VarTo(function); Js::CallInfo callInfo(cargs); Js::Arguments jsArgs(callInfo, reinterpret_cast(args)); @@ -2809,13 +2809,13 @@ CHAKRA_API JsConstructObject(_In_ JsValueRef function, _In_reads_(cargs) JsValue VALIDATE_INCOMING_REFERENCE(args[index], scriptContext); } - Js::JavascriptFunction *jsFunction = Js::JavascriptFunction::FromVar(function); + Js::JavascriptFunction *jsFunction = Js::VarTo(function); Js::CallInfo callInfo(Js::CallFlags::CallFlags_New, cargs); Js::Arguments jsArgs(callInfo, reinterpret_cast(args)); // //TODO: we will want to look at this at some point -- either treat as "top-level" call or maybe constructors are fast so we can just jump back to previous "real" code - //TTDAssert(!Js::ScriptFunction::Is(jsFunction) || execContext->GetThreadContext()->TTDRootNestingCount != 0, "This will cause user code to execute and we need to add support for that as a top-level call source!!!!"); + //TTDAssert(!Js::VarIs(jsFunction) || execContext->GetThreadContext()->TTDRootNestingCount != 0, "This will cause user code to execute and we need to add support for that as a top-level call source!!!!"); // BEGIN_SAFE_REENTRANT_CALL(scriptContext->GetThreadContext()) @@ -2919,9 +2919,9 @@ void SetErrorMessage(Js::ScriptContext *scriptContext, Js::JavascriptError *newE if (!Js::JavascriptOperators::IsUndefined(message)) { Js::JavascriptString *messageStr = nullptr; - if (Js::JavascriptString::Is(message)) + if (Js::VarIs(message)) { - messageStr = Js::JavascriptString::FromVar(message); + messageStr = Js::VarTo(message); } else { @@ -3348,12 +3348,12 @@ CHAKRA_API JsGetPropertyIdFromSymbol(_In_ JsValueRef symbol, _Out_ JsPropertyIdR PARAM_NOT_NULL(propertyId); *propertyId = nullptr; - if (!Js::JavascriptSymbol::Is(symbol)) + if (!Js::VarIs(symbol)) { return JsErrorPropertyNotSymbol; } - *propertyId = (JsPropertyIdRef)Js::JavascriptSymbol::FromVar(symbol)->GetValue(); + *propertyId = (JsPropertyIdRef)Js::VarTo(symbol)->GetValue(); return JsNoError; }, /*allowInObjectBeforeCollectCallback*/true); @@ -3722,8 +3722,8 @@ JsErrorCode GetScriptBufferDetails( *cb = 0; *script = nullptr; - const bool isExternalArray = Js::ExternalArrayBuffer::Is(scriptVal); - const bool isString = !isExternalArray && Js::JavascriptString::Is(scriptVal); + const bool isExternalArray = Js::VarIs(scriptVal); + const bool isString = !isExternalArray && Js::VarIs(scriptVal); if (!isExternalArray && !isString) { return JsErrorInvalidArgument; @@ -4254,9 +4254,9 @@ CHAKRA_API JsTTDNotifyLongLivedReferenceAdd(_In_ JsValueRef value) return JsErrorNoCurrentContext; } - if (Js::RecyclableObject::Is(value)) + if (Js::VarIs(value)) { - Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(value); + Js::RecyclableObject* obj = Js::VarTo(value); if (obj->GetScriptContext()->IsTTDRecordModeEnabled()) { if (obj->GetScriptContext()->ShouldPerformRecordAction()) @@ -4331,13 +4331,13 @@ CHAKRA_API JsTTDRawBufferAsyncModificationRegister(_In_ JsValueRef instance, _In JsErrorCode addRefResult = ContextAPIWrapper([&](Js::ScriptContext *scriptContext, TTDRecorder& _actionEntryPopper) -> JsErrorCode { if (scriptContext->IsTTDRecordModeEnabled()) { - TTDAssert(Js::ArrayBuffer::Is(instance), "Not array buffer object!!!"); - Js::ArrayBuffer* dstBuff = Js::ArrayBuffer::FromVar(instance); + TTDAssert(Js::VarIs(instance), "Not array buffer object!!!"); + Js::ArrayBuffer* dstBuff = Js::VarTo(instance); addRefObj = dstBuff; TTDAssert(dstBuff->GetBuffer() <= initialModPos && initialModPos < dstBuff->GetBuffer() + dstBuff->GetByteLength(), "Not array buffer object!!!"); TTDAssert(initialModPos - dstBuff->GetBuffer() < UINT32_MAX, "This is really big!!!"); - ptrdiff_t index = initialModPos - Js::ArrayBuffer::FromVar(instance)->GetBuffer(); + ptrdiff_t index = initialModPos - Js::VarTo(instance)->GetBuffer(); scriptContext->TTDContextInfo->AddToAsyncPendingList(dstBuff, (uint32)index); @@ -4376,7 +4376,7 @@ CHAKRA_API JsTTDRawBufferAsyncModifyComplete(_In_ byte* finalModPos) TTD::TTDPendingAsyncBufferModification pendingAsyncInfo = { 0 }; scriptContext->TTDContextInfo->GetFromAsyncPendingList(&pendingAsyncInfo, finalModPos); - Js::ArrayBuffer* dstBuff = Js::ArrayBuffer::FromVar(pendingAsyncInfo.ArrayBufferVar); + Js::ArrayBuffer* dstBuff = Js::VarTo(pendingAsyncInfo.ArrayBufferVar); releaseObj = dstBuff; PERFORM_JSRT_TTD_RECORD_ACTION(scriptContext, RecordJsRTRawBufferAsyncModifyComplete, pendingAsyncInfo, finalModPos); @@ -4935,7 +4935,7 @@ _ALWAYSINLINE JsErrorCode CompileRun( VALIDATE_JSREF(scriptVal); PARAM_NOT_NULL(sourceUrl); - bool isExternalArray = Js::ExternalArrayBuffer::Is(scriptVal), + bool isExternalArray = Js::VarIs(scriptVal), isString = false; bool isUtf8 = !(parseAttributes & JsParseScriptAttributeArrayBufferIsUtf16Encoded); @@ -4956,7 +4956,7 @@ _ALWAYSINLINE JsErrorCode CompileRun( } else { - isString = Js::JavascriptString::Is(scriptVal); + isString = Js::VarIs(scriptVal); if (!isString) { return JsErrorInvalidArgument; @@ -4966,19 +4966,19 @@ _ALWAYSINLINE JsErrorCode CompileRun( JsErrorCode error = GlobalAPIWrapper_NoRecord([&]() -> JsErrorCode { if (isString) { - Js::JavascriptString* jsString = Js::JavascriptString::FromVar(scriptVal); + Js::JavascriptString* jsString = Js::VarTo(scriptVal); script = (const byte*)jsString->GetSz(); // JavascriptString is 2 bytes (WCHAR/char16) cb = jsString->GetLength() * sizeof(WCHAR); } - if (!Js::JavascriptString::Is(sourceUrl)) + if (!Js::VarIs(sourceUrl)) { return JsErrorInvalidArgument; } - url = Js::JavascriptString::FromVar(sourceUrl)->GetSz(); + url = Js::VarTo(sourceUrl)->GetSz(); return JsNoError; @@ -5133,7 +5133,7 @@ CHAKRA_API JsParseSerialized( const WCHAR *url; - if (Js::JavascriptString::Is(sourceUrl)) + if (Js::VarIs(sourceUrl)) { url = ((Js::JavascriptString*)(sourceUrl))->GetSz(); } @@ -5143,12 +5143,12 @@ CHAKRA_API JsParseSerialized( } // JsParseSerialized only accepts ArrayBuffer (incl. ExternalArrayBuffer) - if (!Js::ExternalArrayBuffer::Is(bufferVal)) + if (!Js::VarIs(bufferVal)) { return JsErrorInvalidArgument; } - Js::ArrayBuffer* arrayBuffer = Js::ArrayBuffer::FromVar(bufferVal); + Js::ArrayBuffer* arrayBuffer = Js::VarTo(bufferVal); byte* buffer = arrayBuffer->GetBuffer(); return RunSerializedScriptCore( @@ -5167,7 +5167,7 @@ CHAKRA_API JsRunSerialized( PARAM_NOT_NULL(bufferVal); const WCHAR *url; - if (sourceUrl && Js::JavascriptString::Is(sourceUrl)) + if (sourceUrl && Js::VarIs(sourceUrl)) { url = ((Js::JavascriptString*)(sourceUrl))->GetSz(); } @@ -5177,12 +5177,12 @@ CHAKRA_API JsRunSerialized( } // JsParseSerialized only accepts ArrayBuffer (incl. ExternalArrayBuffer) - if (!Js::ExternalArrayBuffer::Is(bufferVal)) + if (!Js::VarIs(bufferVal)) { return JsErrorInvalidArgument; } - Js::ArrayBuffer* arrayBuffer = Js::ArrayBuffer::FromVar(bufferVal); + Js::ArrayBuffer* arrayBuffer = Js::VarTo(bufferVal); byte* buffer = arrayBuffer->GetBuffer(); return RunSerializedScriptCore( @@ -5227,12 +5227,12 @@ CHAKRA_API JsGetPromiseState(_In_ JsValueRef promise, _Out_ JsPromiseState *stat *state = JsPromiseStatePending; - if (!Js::JavascriptPromise::Is(promise)) + if (!Js::VarIs(promise)) { return JsErrorInvalidArgument; } - Js::JavascriptPromise *jsPromise = Js::JavascriptPromise::FromVar(promise); + Js::JavascriptPromise *jsPromise = Js::VarTo(promise); Js::JavascriptPromise::PromiseStatus status = jsPromise->GetStatus(); switch (status) @@ -5260,12 +5260,12 @@ CHAKRA_API JsGetPromiseResult(_In_ JsValueRef promise, _Out_ JsValueRef *result) *result = JS_INVALID_REFERENCE; - if (!Js::JavascriptPromise::Is(promise)) + if (!Js::VarIs(promise)) { return JsErrorInvalidArgument; } - Js::JavascriptPromise *jsPromise = Js::JavascriptPromise::FromVar(promise); + Js::JavascriptPromise *jsPromise = Js::VarTo(promise); Js::Var jsResult = jsPromise->GetResult(); if (jsResult == nullptr) @@ -5456,12 +5456,12 @@ CHAKRA_API JsGetDataViewInfo( BEGIN_JSRT_NO_EXCEPTION { - if (!Js::DataView::Is(dataView)) + if (!Js::VarIs(dataView)) { RETURN_NO_EXCEPTION(JsErrorInvalidArgument); } - Js::DataView* dv = Js::DataView::FromVar(dataView); + Js::DataView* dv = Js::VarTo(dataView); if (arrayBuffer != nullptr) { *arrayBuffer = dv->GetArrayBuffer(); } @@ -5476,7 +5476,7 @@ CHAKRA_API JsGetDataViewInfo( } #if ENABLE_TTD - Js::ScriptContext* scriptContext = Js::RecyclableObject::FromVar(dataView)->GetScriptContext(); + Js::ScriptContext* scriptContext = Js::VarTo(dataView)->GetScriptContext(); if(PERFORM_JSRT_TTD_RECORD_ACTION_CHECK(scriptContext) && arrayBuffer != nullptr) { scriptContext->GetThreadContext()->TTDLog->RecordJsRTGetDataViewInfo(dataView, *arrayBuffer); @@ -5511,14 +5511,14 @@ CHAKRA_API JsGetProxyProperties (_In_ JsValueRef object, _Out_ bool* isProxy, _O *handler = JS_INVALID_REFERENCE; } - *isProxy = Js::JavascriptProxy::Is(object); + *isProxy = Js::VarIs(object); if (!*isProxy) { return JsNoError; } - Js::JavascriptProxy* proxy = Js::JavascriptProxy::UnsafeFromVar(object); + Js::JavascriptProxy* proxy = Js::UnsafeVarTo(object); bool revoked = proxy->IsRevoked(); if (target != nullptr && !revoked) @@ -5697,7 +5697,7 @@ CHAKRA_API JsRunScriptWithParserState( JsErrorCode errorCode = GetScriptBufferDetails(script, parseAttributes, &loadScriptFlag, &cb, &bytes); - if (sourceUrl && Js::JavascriptString::Is(sourceUrl)) + if (sourceUrl && Js::VarIs(sourceUrl)) { url = ((Js::JavascriptString*)(sourceUrl))->GetSz(); } @@ -5762,12 +5762,12 @@ CHAKRA_API JsRunScriptWithParserState( return errorCode; } - if (!Js::ExternalArrayBuffer::Is(parserState)) + if (!Js::VarIs(parserState)) { return JsErrorInvalidArgument; } - Js::ArrayBuffer* arrayBuffer = Js::ArrayBuffer::FromVar(parserState); + Js::ArrayBuffer* arrayBuffer = Js::VarTo(parserState); byte* buffer = arrayBuffer->GetBuffer(); JsSerializedLoadScriptCallback dummy = DummyScriptLoadSourceCallbackForRunScriptWithParserState; diff --git a/lib/Jsrt/JsrtDebugUtils.cpp b/lib/Jsrt/JsrtDebugUtils.cpp index 1d0b54f9d2b..209e890cf31 100644 --- a/lib/Jsrt/JsrtDebugUtils.cpp +++ b/lib/Jsrt/JsrtDebugUtils.cpp @@ -167,7 +167,7 @@ void JsrtDebugUtils::AddPropertyType(Js::DynamicObject * object, Js::IDiagObject case Js::TypeIds_Boolean: JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::type, scriptContext->GetLibrary()->GetBooleanTypeDisplayString(), scriptContext); - JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::value, Js::JavascriptBoolean::FromVar(varValue)->GetValue() == TRUE ? true : false, scriptContext); + JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::value, Js::VarTo(varValue)->GetValue() == TRUE ? true : false, scriptContext); break; case Js::TypeIds_Integer: @@ -192,17 +192,17 @@ void JsrtDebugUtils::AddPropertyType(Js::DynamicObject * object, Js::IDiagObject } case Js::TypeIds_Int64Number: JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::type, scriptContext->GetLibrary()->GetNumberTypeDisplayString(), scriptContext); - JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::value, (double)Js::JavascriptInt64Number::FromVar(varValue)->GetValue(), scriptContext); + JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::value, (double)Js::VarTo(varValue)->GetValue(), scriptContext); break; case Js::TypeIds_UInt64Number: JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::type, scriptContext->GetLibrary()->GetNumberTypeDisplayString(), scriptContext); - JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::value, (double)Js::JavascriptUInt64Number::FromVar(varValue)->GetValue(), scriptContext); + JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::value, (double)Js::VarTo(varValue)->GetValue(), scriptContext); break; case Js::TypeIds_String: JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::type, scriptContext->GetLibrary()->GetStringTypeDisplayString(), scriptContext); - JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::value, Js::JavascriptString::FromVar(varValue), scriptContext); + JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::value, Js::VarTo(varValue), scriptContext); break; case Js::TypeIds_Symbol: diff --git a/lib/Jsrt/JsrtDiag.cpp b/lib/Jsrt/JsrtDiag.cpp index a1f9ef649c2..2c4daebfb39 100644 --- a/lib/Jsrt/JsrtDiag.cpp +++ b/lib/Jsrt/JsrtDiag.cpp @@ -479,7 +479,7 @@ CHAKRA_API JsDiagSetStepType( ThreadContext* threadContext = runtime->GetThreadContext(); if(!threadContext->IsRuntimeInTTDMode()) { - //Don't want to fail hard when user accidentally clicks this so pring message and step forward + //Don't want to fail hard when user accidentally clicks this so pring message and step forward fprintf(stderr, "Must be in replay mode to use reverse-step - launch with \"--replay-debug\" flag in Node."); jsrtDebugManager->SetResumeType(BREAKRESUMEACTION_STEP_OVER); } @@ -500,7 +500,7 @@ CHAKRA_API JsDiagSetStepType( ThreadContext* threadContext = runtime->GetThreadContext(); if(!threadContext->IsRuntimeInTTDMode()) { - //Don't want to fail hard when user accidentally clicks this so pring message and step forward + //Don't want to fail hard when user accidentally clicks this so pring message and step forward fprintf(stderr, "Must be in replay mode to use reverse-continue - launch with \"--replay-debug\" flag in Node."); jsrtDebugManager->SetResumeType(BREAKRESUMEACTION_CONTINUE); } @@ -566,12 +566,12 @@ CHAKRA_API JsDiagGetFunctionPosition( *functionPosition = JS_INVALID_REFERENCE; - if (!Js::RecyclableObject::Is(function) || !Js::ScriptFunction::Is(function)) + if (!Js::VarIs(function) || !Js::VarIs(function)) { return JsErrorInvalidArgument; } - Js::ScriptFunction* jsFunction = Js::ScriptFunction::FromVar(function); + Js::ScriptFunction* jsFunction = Js::VarTo(function); BOOL fParsed = jsFunction->GetParseableFunctionInfo()->IsFunctionParsed(); if (!fParsed) @@ -788,13 +788,13 @@ CHAKRA_API JsDiagEvaluate( PARAM_NOT_NULL(expressionVal); PARAM_NOT_NULL(evalResult); - bool isArrayBuffer = Js::ArrayBuffer::Is(expressionVal), + bool isArrayBuffer = Js::VarIs(expressionVal), isString = false; bool isUtf8 = !(parseAttributes & JsParseScriptAttributeArrayBufferIsUtf16Encoded); if (!isArrayBuffer) { - isString = Js::JavascriptString::Is(expressionVal); + isString = Js::VarIs(expressionVal); if (!isString) { return JsErrorInvalidArgument; @@ -802,8 +802,8 @@ CHAKRA_API JsDiagEvaluate( } const size_t len = isArrayBuffer ? - Js::ArrayBuffer::FromVar(expressionVal)->GetByteLength() : - Js::JavascriptString::FromVar(expressionVal)->GetLength(); + Js::VarTo(expressionVal)->GetByteLength() : + Js::VarTo(expressionVal)->GetLength(); if (len > INT_MAX) { @@ -815,7 +815,7 @@ CHAKRA_API JsDiagEvaluate( if (isArrayBuffer && isUtf8) { wide_expression.Initialize( - (const char*)Js::ArrayBuffer::FromVar(expressionVal)->GetBuffer(), len); + (const char*)Js::VarTo(expressionVal)->GetBuffer(), len); if (!wide_expression) { return JsErrorOutOfMemory; @@ -825,9 +825,9 @@ CHAKRA_API JsDiagEvaluate( else { expression = !isArrayBuffer ? - Js::JavascriptString::FromVar(expressionVal)->GetSz() // String + Js::VarTo(expressionVal)->GetSz() // String : - (const WCHAR*)Js::ArrayBuffer::FromVar(expressionVal)->GetBuffer(); // ArrayBuffer; + (const WCHAR*)Js::VarTo(expressionVal)->GetBuffer(); // ArrayBuffer; } *evalResult = JS_INVALID_REFERENCE; diff --git a/lib/Jsrt/JsrtExternalObject.cpp b/lib/Jsrt/JsrtExternalObject.cpp index 0e8e60650f6..20944a48658 100644 --- a/lib/Jsrt/JsrtExternalObject.cpp +++ b/lib/Jsrt/JsrtExternalObject.cpp @@ -51,29 +51,6 @@ JsrtExternalObject* JsrtExternalObject::Create(void *data, JsFinalizeCallback fi return externalObject; } -bool JsrtExternalObject::Is(Js::Var value) -{ - if (Js::TaggedNumber::Is(value)) - { - return false; - } - - return (VirtualTableInfo::HasVirtualTable(value)) || - (VirtualTableInfo>::HasVirtualTable(value)); -} - -JsrtExternalObject * JsrtExternalObject::FromVar(Js::Var value) -{ - AssertOrFailFast(Is(value)); - return static_cast(value); -} - -JsrtExternalObject * JsrtExternalObject::UnsafeFromVar(Js::Var value) -{ - Assert(Is(value)); - return static_cast(value); -} - void JsrtExternalObject::Finalize(bool isShutdown) { JsFinalizeCallback finalizeCallback = this->GetExternalType()->GetJsFinalizeCallback(); diff --git a/lib/Jsrt/JsrtExternalObject.h b/lib/Jsrt/JsrtExternalObject.h index 0f648bbb6be..2dcc0264424 100644 --- a/lib/Jsrt/JsrtExternalObject.h +++ b/lib/Jsrt/JsrtExternalObject.h @@ -47,9 +47,6 @@ class JsrtExternalObject : public Js::DynamicObject public: JsrtExternalObject(JsrtExternalType * type, void *data); - static bool Is(Js::Var value); - static JsrtExternalObject * FromVar(Js::Var value); - static JsrtExternalObject * UnsafeFromVar(Js::Var value); static JsrtExternalObject * Create(void *data, JsFinalizeCallback finalizeCallback, Js::RecyclableObject * prototype, Js::ScriptContext *scriptContext); JsrtExternalType * GetExternalType() const { return (JsrtExternalType *)this->GetType(); } @@ -74,3 +71,9 @@ class JsrtExternalObject : public Js::DynamicObject #endif }; AUTO_REGISTER_RECYCLER_OBJECT_DUMPER(JsrtExternalObject, &Js::RecyclableObject::DumpObjectFunction); + +template <> inline bool Js::VarIsImpl(Js::RecyclableObject* obj) +{ + return (VirtualTableInfo::HasVirtualTable(obj)) || + (VirtualTableInfo>::HasVirtualTable(obj)); +} diff --git a/lib/Jsrt/JsrtInternal.h b/lib/Jsrt/JsrtInternal.h index 95de950046a..13c96a00561 100644 --- a/lib/Jsrt/JsrtInternal.h +++ b/lib/Jsrt/JsrtInternal.h @@ -38,7 +38,7 @@ typedef struct {} TTDRecorder; } \ #define MARSHAL_OBJECT(p, scriptContext) \ - Js::RecyclableObject* __obj = Js::RecyclableObject::FromVar(p); \ + Js::RecyclableObject* __obj = Js::VarTo(p); \ if (__obj->GetScriptContext() != scriptContext) \ { \ if(__obj->GetScriptContext()->GetThreadContext() != scriptContext->GetThreadContext()) \ @@ -68,7 +68,7 @@ typedef struct {} TTDRecorder; #define VALIDATE_INCOMING_REFERENCE(p, scriptContext) \ { \ VALIDATE_JSREF(p); \ - if (Js::RecyclableObject::Is(p)) \ + if (Js::VarIs(p)) \ { \ MARSHAL_OBJECT(p, scriptContext) \ } \ @@ -87,7 +87,7 @@ typedef struct {} TTDRecorder; #define VALIDATE_INCOMING_RECYCLABLE(p, scriptContext) \ { \ VALIDATE_JSREF(p); \ - if (!Js::RecyclableObject::Is(p)) \ + if (!Js::VarIs(p)) \ { \ return JsErrorInvalidArgument; \ } \ @@ -107,7 +107,7 @@ typedef struct {} TTDRecorder; #define VALIDATE_INCOMING_FUNCTION(p, scriptContext) \ { \ VALIDATE_JSREF(p); \ - if (!Js::JavascriptFunction::Is(p)) \ + if (!Js::VarIs(p)) \ { \ return JsErrorInvalidArgument; \ } \ diff --git a/lib/Jsrt/JsrtSourceHolder.cpp b/lib/Jsrt/JsrtSourceHolder.cpp index 8e60c6e0e6b..4d76dee4bc1 100644 --- a/lib/Jsrt/JsrtSourceHolder.cpp +++ b/lib/Jsrt/JsrtSourceHolder.cpp @@ -251,13 +251,13 @@ namespace Js } END_LEAVE_SCRIPT(scriptContext); - bool isExternalArray = Js::ExternalArrayBuffer::Is(scriptVal), + bool isExternalArray = Js::VarIs(scriptVal), isString = false; bool isUtf8 = !(attributes & JsParseScriptAttributeArrayBufferIsUtf16Encoded); if (!isExternalArray) { - isString = Js::JavascriptString::Is(scriptVal); + isString = Js::VarIs(scriptVal); if (!isString) { Js::JavascriptError::ThrowOutOfMemoryError(nullptr); diff --git a/lib/Runtime/Base/CrossSite.cpp b/lib/Runtime/Base/CrossSite.cpp index 2792a7877c2..6cc84314fb9 100644 --- a/lib/Runtime/Base/CrossSite.cpp +++ b/lib/Runtime/Base/CrossSite.cpp @@ -28,14 +28,14 @@ namespace Js { return FALSE; } - RecyclableObject * object = RecyclableObject::UnsafeFromVar(instance); + RecyclableObject * object = UnsafeVarTo(instance); if (object->GetScriptContext() == requestContext) { return FALSE; } if (DynamicType::Is(object->GetTypeId())) { - return !DynamicObject::UnsafeFromVar(object)->IsCrossSiteObject() && !object->IsExternal(); + return !UnsafeVarTo(object)->IsCrossSiteObject() && !object->IsExternal(); } return TRUE; } @@ -50,7 +50,7 @@ namespace Js if (object->GetTypeId() == TypeIds_Function) { AssertMsg(object != object->GetScriptContext()->GetLibrary()->GetDefaultAccessorFunction(), "default accessor marshalled"); - JavascriptFunction * function = JavascriptFunction::FromVar(object); + JavascriptFunction * function = VarTo(object); //TODO: this may be too aggressive and create x-site thunks that are't technically needed -- see uglify-2js test. @@ -74,7 +74,7 @@ namespace Js } else if (object->GetTypeId() == TypeIds_Proxy) { - RecyclableObject * target = JavascriptProxy::FromVar(object)->GetTarget(); + RecyclableObject * target = VarTo(object)->GetTarget(); if (JavascriptConversion::IsCallable(target)) { Assert(JavascriptProxy::FunctionCallTrap == object->GetEntryPoint()); @@ -90,7 +90,7 @@ namespace Js while (prototype->GetTypeId() != TypeIds_Null && prototype->GetTypeId() != TypeIds_HostDispatch) { // We should not see any static type or host dispatch here - DynamicObject * prototypeObject = DynamicObject::FromVar(prototype); + DynamicObject * prototypeObject = VarTo(prototype); if (prototypeObject->IsCrossSiteObject()) { break; @@ -99,7 +99,7 @@ namespace Js { MarshalDynamicObject(scriptContext, prototypeObject); } - if (JavascriptProxy::Is(prototypeObject)) + if (VarIs(prototypeObject)) { // Fetching prototype of proxy can invoke trap - which we don't want during the marshalling time. break; @@ -124,10 +124,10 @@ namespace Js for (uint16 i = 0; i < length; i++) { Var value = display->GetItem(i); - if (WithScopeObject::Is(value)) + if (VarIs(value)) { // Here we are marshalling the wrappedObject and then ReWrapping th object in the new context. - RecyclableObject* wrappedObject = WithScopeObject::FromVar(value)->GetWrappedObject(); + RecyclableObject* wrappedObject = VarTo(value)->GetWrappedObject(); ScriptContext* wrappedObjectScriptContext = wrappedObject->GetScriptContext(); value = JavascriptOperators::ToWithObject(CrossSite::MarshalVar(scriptContext, wrappedObject, wrappedObjectScriptContext), scriptContext); @@ -151,7 +151,7 @@ namespace Js { return value; } - return MarshalVarInner(scriptContext, RecyclableObject::FromVar(value), false); + return MarshalVarInner(scriptContext, VarTo(value), false); } return value; } @@ -164,7 +164,7 @@ namespace Js { return value; } - Js::RecyclableObject* object = RecyclableObject::UnsafeFromVar(value); + Js::RecyclableObject* object = UnsafeVarTo(value); if (fRequestWrapper || scriptContext != object->GetScriptContext()) { return MarshalVarInner(scriptContext, object, fRequestWrapper); @@ -174,7 +174,7 @@ namespace Js bool CrossSite::DoRequestWrapper(Js::RecyclableObject* object, bool fRequestWrapper) { - return fRequestWrapper && JavascriptFunction::Is(object) && JavascriptFunction::FromVar(object)->IsExternalFunction(); + return fRequestWrapper && VarIs(object) && VarTo(object)->IsExternalFunction(); } #if ENABLE_TTD @@ -185,7 +185,7 @@ namespace Js if(obj->GetTypeId() == TypeIds_Function) { AssertMsg(obj != obj->GetScriptContext()->GetLibrary()->GetDefaultAccessorFunction(), "default accessor marshalled -- I don't think this should ever happen as it is marshalled in a special case?"); - JavascriptFunction * function = JavascriptFunction::FromVar(obj); + JavascriptFunction * function = VarTo(obj); // //TODO: what happens if the gaurd in marshal (MarshalDynamicObject) isn't true? @@ -300,12 +300,12 @@ namespace Js // so optimization overrides can be updated as a group scriptContext->optimizationOverrides.Merge(&object->GetScriptContext()->optimizationOverrides); - DynamicObject * dynamicObject = DynamicObject::FromVar(object); + DynamicObject * dynamicObject = VarTo(object); if (!dynamicObject->IsExternal()) { if (!dynamicObject->IsCrossSiteObject()) { - if (JavascriptProxy::Is(dynamicObject)) + if (VarIs(dynamicObject)) { // We don't need to marshal the prototype chain in the case of Proxy. Otherwise we will go to the user code. TTD_XSITE_LOG(object->GetScriptContext(), "MarshalDynamicObject", object); @@ -345,7 +345,7 @@ namespace Js #if defined(ENABLE_SCRIPT_PROFILING) || defined(ENABLE_SCRIPT_DEBUGGING) Var CrossSite::ProfileThunk(RecyclableObject* callable, CallInfo callInfo, ...) { - JavascriptFunction* function = JavascriptFunction::FromVar(callable); + JavascriptFunction* function = VarTo(callable); Assert(function->GetTypeId() == TypeIds_Function); Assert(function->GetEntryPoint() == CrossSite::ProfileThunk); RUNTIME_ARGUMENTS(args, callInfo); @@ -360,7 +360,7 @@ namespace Js TTD_XSITE_LOG(callable->GetScriptContext(), "DefaultOrProfileThunk", callable); #ifdef ENABLE_WASM - if (WasmScriptFunction::Is(function)) + if (VarIs(function)) { entryPoint = Js::AsmJsExternalEntryPoint; } else @@ -370,7 +370,7 @@ namespace Js #if ENABLE_DEBUG_CONFIG_OPTIONS char16 debugStringBuffer[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE]; #endif - entryPoint = ScriptFunction::FromVar(function)->GetEntryPointInfo()->jsMethod; + entryPoint = VarTo(function)->GetEntryPointInfo()->jsMethod; if (funcInfo->IsDeferred() && scriptContext->IsProfiling()) { // if the current entrypoint is deferred parse we need to update it appropriately for the profiler mode. @@ -390,7 +390,7 @@ namespace Js Var CrossSite::DefaultThunk(RecyclableObject* callable, CallInfo callInfo, ...) { - JavascriptFunction* function = JavascriptFunction::FromVar(callable); + JavascriptFunction* function = VarTo(callable); Assert(function->GetTypeId() == TypeIds_Function); Assert(function->GetEntryPoint() == CrossSite::DefaultThunk); RUNTIME_ARGUMENTS(args, callInfo); @@ -415,7 +415,7 @@ namespace Js else #endif { - entryPoint = ScriptFunction::FromVar(function)->GetEntryPointInfo()->jsMethod; + entryPoint = VarTo(function)->GetEntryPointInfo()->jsMethod; } } else @@ -428,16 +428,16 @@ namespace Js Var CrossSite::CrossSiteProxyCallTrap(RecyclableObject* function, CallInfo callInfo, ...) { RUNTIME_ARGUMENTS(args, callInfo); - Assert(JavascriptProxy::Is(function)); + Assert(VarIs(function)); return CrossSite::CommonThunk(function, JavascriptProxy::FunctionCallTrap, args); } Var CrossSite::CommonThunk(RecyclableObject* recyclableObject, JavascriptMethod entryPoint, Arguments args) { - DynamicObject* function = DynamicObject::FromVar(recyclableObject); + DynamicObject* function = VarTo(recyclableObject); - FunctionInfo * functionInfo = (JavascriptFunction::Is(function) ? JavascriptFunction::FromVar(function)->GetFunctionInfo() : nullptr); + FunctionInfo * functionInfo = (VarIs(function) ? VarTo(function)->GetFunctionInfo() : nullptr); AutoDisableRedeferral autoDisableRedeferral(functionInfo); ScriptContext* targetScriptContext = function->GetScriptContext(); @@ -468,7 +468,7 @@ namespace Js { i = 1; Assert(args.IsNewCall()); - Assert(JavascriptProxy::Is(function) || (JavascriptFunction::Is(function) && JavascriptFunction::FromVar(function)->GetFunctionInfo()->GetAttributes() & FunctionInfo::SkipDefaultNewObject)); + Assert(VarIs(function) || (VarIs(function) && VarTo(function)->GetFunctionInfo()->GetAttributes() & FunctionInfo::SkipDefaultNewObject)); } uint count = args.Info.Count; for (; i < count; i++) @@ -485,13 +485,13 @@ namespace Js // The final eval arg is a frame display that needs to be marshaled specially. args.Values[count] = CrossSite::MarshalFrameDisplay(targetScriptContext, args.GetFrameDisplay()); } - + #if ENABLE_NATIVE_CODEGEN CheckCodeGenFunction checkCodeGenFunction = GetCheckCodeGenFunction(entryPoint); if (checkCodeGenFunction != nullptr) { - ScriptFunction* callFunc = ScriptFunction::FromVar(function); + ScriptFunction* callFunc = VarTo(function); entryPoint = checkCodeGenFunction(callFunc); Assert(CrossSite::IsThunk(function->GetEntryPoint())); } @@ -579,9 +579,9 @@ namespace Js { return; } - while (DynamicType::Is(object->GetTypeId()) && !JavascriptProxy::Is(object)) + while (DynamicType::Is(object->GetTypeId()) && !VarIs(object)) { - DynamicObject* dynamicObject = DynamicObject::UnsafeFromVar(object); + DynamicObject* dynamicObject = UnsafeVarTo(object); if (!dynamicObject->IsCrossSiteObject() && !dynamicObject->IsExternal()) { // force to install cross-site thunk on prototype objects. diff --git a/lib/Runtime/Base/FunctionBody.cpp b/lib/Runtime/Base/FunctionBody.cpp index 4d3330ea49f..f6df073e02d 100644 --- a/lib/Runtime/Base/FunctionBody.cpp +++ b/lib/Runtime/Base/FunctionBody.cpp @@ -5562,7 +5562,7 @@ namespace Js ScopeType FrameDisplay::GetScopeType(void* scope) { - if(Js::ActivationObject::Is(scope)) + if(Js::VarIs(scope)) { return ScopeType_ActivationObject; } @@ -5574,7 +5574,7 @@ namespace Js } // ScopeSlots - bool ScopeSlots::IsDebuggerScopeSlotArray() + bool ScopeSlots::IsDebuggerScopeSlotArray() { return DebuggerScope::Is(slotArray[ScopeMetadataSlotIndex]); } @@ -8217,7 +8217,7 @@ namespace Js void EntryPointInfo::OnNativeCodeInstallFailure() { // If more data is transferred from the background thread to the main thread in ProcessJitTransferData, - // corresponding fields on the entryPointInfo should be rolled back here. + // corresponding fields on the entryPointInfo should be rolled back here. this->nativeEntryPointData->ClearTypeRefsAndGuards(GetScriptContext()); this->ResetOnNativeCodeInstallFailure(); } @@ -8233,7 +8233,7 @@ namespace Js } #endif - + void EntryPointInfo::PinTypeRefs(ScriptContext* scriptContext) { NativeEntryPointData * nativeEntryPointData = this->GetNativeEntryPointData(); @@ -8324,7 +8324,7 @@ namespace Js if (jitTransferData->equivalentTypeGuardOffsets) { // InstallGuards - int guardCount = jitTransferData->equivalentTypeGuardOffsets->count; + int guardCount = jitTransferData->equivalentTypeGuardOffsets->count; EquivalentTypeCache* cache = this->nativeEntryPointData->EnsureEquivalentTypeCache(guardCount, scriptContext, this); char * nativeDataBuffer = this->GetOOPNativeEntryPointData()->GetNativeDataBuffer(); for (int i = 0; i < guardCount; i++) @@ -8833,7 +8833,7 @@ namespace Js this->OnCleanup(isShutdown); if (this->nativeEntryPointData) - { + { this->nativeEntryPointData->Cleanup(GetScriptContext(), isShutdown, false); this->nativeEntryPointData = nullptr; } @@ -8913,7 +8913,7 @@ namespace Js void EntryPointInfo::SetTJCodeSize(ptrdiff_t size) { Assert(isAsmJsFunction); - // TODO: We don't need the whole NativeEntryPointData to just hold just the code and size for TJ mode + // TODO: We don't need the whole NativeEntryPointData to just hold just the code and size for TJ mode this->EnsureNativeEntryPointData()->SetTJCodeSize(size); } diff --git a/lib/Runtime/Base/FunctionInfo.cpp b/lib/Runtime/Base/FunctionInfo.cpp index e75bd00c5a9..359244df823 100644 --- a/lib/Runtime/Base/FunctionInfo.cpp +++ b/lib/Runtime/Base/FunctionInfo.cpp @@ -23,7 +23,7 @@ namespace Js } FunctionInfo::FunctionInfo(FunctionInfo& that) - : originalEntryPoint(that.originalEntryPoint), attributes(that.attributes), + : originalEntryPoint(that.originalEntryPoint), attributes(that.attributes), functionBodyImpl(FORCE_NO_WRITE_BARRIER_TAG(that.functionBodyImpl)), functionId(that.functionId), compileCount(that.compileCount) { @@ -61,6 +61,6 @@ namespace Js FunctionInfo::Attributes FunctionInfo::GetAttributes(Js::RecyclableObject * function) { return function->GetTypeId() == Js::TypeIds_Function ? - Js::JavascriptFunction::UnsafeFromVar(function)->GetFunctionInfo()->GetAttributes() : Js::FunctionInfo::None; + Js::UnsafeVarTo(function)->GetFunctionInfo()->GetAttributes() : Js::FunctionInfo::None; } } diff --git a/lib/Runtime/Base/ScriptContext.cpp b/lib/Runtime/Base/ScriptContext.cpp index a14c250fc5f..67fa5c399dd 100644 --- a/lib/Runtime/Base/ScriptContext.cpp +++ b/lib/Runtime/Base/ScriptContext.cpp @@ -2455,7 +2455,7 @@ namespace Js hr = ps.ParseCesu8Source(&parseTree, pszSrc, cbLength, grfscr, pse, &sourceContextInfo->nextLocalFunctionId, sourceContextInfo); } - + utf8SourceInfo->SetParseFlags(grfscr); srcLength = ps.GetSourceLength(); @@ -4063,7 +4063,7 @@ namespace Js scriptFunction->GetFunctionBody()->GetAsmJsFunctionInfo() != nullptr && scriptFunction->GetFunctionBody()->GetAsmJsFunctionInfo()->GetModuleFunctionBody() != nullptr) { - AsmJsScriptFunction* asmFunc = AsmJsScriptFunction::FromVar(scriptFunction); + AsmJsScriptFunction* asmFunc = VarTo(scriptFunction); void* env = (void*)asmFunc->GetModuleEnvironment(); SList * funcList = nullptr; if (asmJsEnvironmentMap->TryGetValue(env, &funcList)) @@ -4151,9 +4151,9 @@ namespace Js pFunction->ResetConstructorCacheToDefault(); } - if (ScriptFunctionWithInlineCache::Is(pFunction)) + if (VarIs(pFunction)) { - ScriptFunctionWithInlineCache::FromVar(pFunction)->ClearInlineCacheOnFunctionObject(); + VarTo(pFunction)->ClearInlineCacheOnFunctionObject(); } // We should have force parsed the function, and have a function body @@ -4173,7 +4173,7 @@ namespace Js #endif #ifdef ASMJS_PLAT - ScriptFunction * scriptFunction = ScriptFunction::FromVar(pFunction); + ScriptFunction * scriptFunction = VarTo(pFunction); scriptContext->TransitionEnvironmentForDebugger(scriptFunction); #endif } @@ -4237,7 +4237,7 @@ namespace Js { OUTPUT_TRACE(Js::ScriptProfilerPhase, _u("\t\tJs::ScriptContext::GetProfileModeThunk : 0x%08X\n"), (DWORD_PTR)Js::ScriptContext::GetProfileModeThunk(entryPoint)); - ScriptFunction * scriptFunction = ScriptFunction::FromVar(pFunction); + ScriptFunction * scriptFunction = VarTo(pFunction); scriptFunction->ChangeEntryPoint(proxy->GetDefaultEntryPointInfo(), Js::ScriptContext::GetProfileModeThunk(entryPoint)); #if ENABLE_NATIVE_CODEGEN && defined(ENABLE_SCRIPT_PROFILING) @@ -4508,8 +4508,8 @@ namespace Js #if defined(ENABLE_SCRIPT_DEBUGGING) || defined(ENABLE_SCRIPT_PROFILING) RUNTIME_ARGUMENTS(args, callInfo); - Assert(!WasmScriptFunction::Is(callable)); - JavascriptFunction* function = JavascriptFunction::FromVar(callable); + Assert(!VarIs(callable)); + JavascriptFunction* function = VarTo(callable); ScriptContext* scriptContext = function->GetScriptContext(); // We can come here when profiling is not on @@ -4568,7 +4568,7 @@ namespace Js else { // it is string because user had called in toString extract name from it - Assert(JavascriptString::Is(sourceString)); + Assert(VarIs(sourceString)); const char16 *pwszToString = ((JavascriptString *)sourceString)->GetSz(); const char16 *pwszNameStart = wcsstr(pwszToString, _u(" ")); const char16 *pwszNameEnd = wcsstr(pwszToString, _u("(")); @@ -5022,7 +5022,7 @@ namespace Js void ScriptContext::RegisterIsInstInlineCache(Js::IsInstInlineCache * cache, Js::Var function) { - Assert(JavascriptFunction::FromVar(function)->GetScriptContext() == this); + Assert(VarTo(function)->GetScriptContext() == this); hasIsInstInlineCache = true; #if DBG this->isInstInlineCacheAllocator.Unlock(); diff --git a/lib/Runtime/Base/ThreadContext.cpp b/lib/Runtime/Base/ThreadContext.cpp index 0496e0625ae..22f1f5aad6b 100644 --- a/lib/Runtime/Base/ThreadContext.cpp +++ b/lib/Runtime/Base/ThreadContext.cpp @@ -1746,7 +1746,7 @@ ThreadContext::ProbeStack(size_t size, Js::RecyclableObject * obj, Js::ScriptCon { AssertCanHandleStackOverflowCall(obj->IsExternal() || (Js::JavascriptOperators::GetTypeId(obj) == Js::TypeIds_Function && - Js::JavascriptFunction::FromVar(obj)->IsExternalFunction())); + Js::VarTo(obj)->IsExternalFunction())); if (!this->IsStackAvailable(size)) { if (this->IsExecutionDisabled()) @@ -1758,7 +1758,7 @@ ThreadContext::ProbeStack(size_t size, Js::RecyclableObject * obj, Js::ScriptCon if (obj->IsExternal() || (Js::JavascriptOperators::GetTypeId(obj) == Js::TypeIds_Function && - Js::JavascriptFunction::FromVar(obj)->IsExternalFunction())) + Js::VarTo(obj)->IsExternalFunction())) { Js::JavascriptError::ThrowStackOverflowError(scriptContext); } diff --git a/lib/Runtime/ByteCode/ByteCodeDumper.cpp b/lib/Runtime/ByteCode/ByteCodeDumper.cpp index a9bbcaa2bef..631689ed3f5 100644 --- a/lib/Runtime/ByteCode/ByteCodeDumper.cpp +++ b/lib/Runtime/ByteCode/ByteCodeDumper.cpp @@ -181,7 +181,7 @@ namespace Js break; case Js::TypeIds_Boolean: Output::Print(_u("%-10s"), OpCodeUtil::GetOpCodeName( - JavascriptBoolean::FromVar(varConst)->GetValue() ? OpCode::LdTrue : OpCode::LdFalse)); + VarTo(varConst)->GetValue() ? OpCode::LdTrue : OpCode::LdFalse)); break; case Js::TypeIds_Number: #if ENABLE_NATIVE_CODEGEN @@ -197,7 +197,7 @@ namespace Js #else Output::Print(_u("%-10s"), OpCodeUtil::GetOpCodeName(OpCode::Ld_A)); #endif - Output::Print(_u(" (\"%s\")%s"), JavascriptString::FromVar(varConst)->GetSz(), Js::PropertyString::Is(varConst) ? _u(" [prop]") : _u("")); + Output::Print(_u(" (\"%s\")%s"), VarTo(varConst)->GetSz(), Js::VarIs(varConst) ? _u(" [prop]") : _u("")); break; case Js::TypeIds_GlobalObject: #if ENABLE_NATIVE_CODEGEN diff --git a/lib/Runtime/ByteCode/ByteCodeSerializer.cpp b/lib/Runtime/ByteCode/ByteCodeSerializer.cpp index eaef1ae29b2..1fbaa9814a1 100644 --- a/lib/Runtime/ByteCode/ByteCodeSerializer.cpp +++ b/lib/Runtime/ByteCode/ByteCodeSerializer.cpp @@ -1459,7 +1459,7 @@ class ByteCodeBufferBuilder uint32 PrependStringConstant(BufferBuilderList & builder, Var var) { - auto str = JavascriptString::FromVar(var); + auto str = VarTo(var); uint32 size = 0; #ifdef BYTE_CODE_MAGIC_CONSTANTS @@ -1477,7 +1477,7 @@ class ByteCodeBufferBuilder uint32 PrependStringTemplateCallsiteConstant(BufferBuilderList & builder, Var var) { - ES5Array* callsite = ES5Array::FromVar(var); + ES5Array* callsite = VarTo(var); Var element = nullptr; auto size = PrependInt32(builder, _u("String Template Callsite Constant String Count"), (int)callsite->GetLength()); @@ -1488,7 +1488,7 @@ class ByteCodeBufferBuilder } Var rawVar = JavascriptOperators::OP_GetProperty(callsite, Js::PropertyIds::raw, callsite->GetScriptContext()); - ES5Array* rawArray = ES5Array::FromVar(rawVar); + ES5Array* rawArray = VarTo(rawVar); for (uint32 i = 0; i < rawArray->GetLength(); i++) { @@ -1520,7 +1520,7 @@ class ByteCodeBufferBuilder return PrependByte(builder, _u("Null Constant"), ctNull); case TypeIds_Boolean: - return PrependByte(builder, _u("Boolean Constant"), JavascriptBoolean::FromVar(var)->GetValue()? ctTrue : ctFalse); + return PrependByte(builder, _u("Boolean Constant"), VarTo(var)->GetValue()? ctTrue : ctFalse); case TypeIds_Number: { @@ -1550,8 +1550,8 @@ class ByteCodeBufferBuilder case TypeIds_String: { - auto size = PrependByte(builder, _u("String Constant 16"), - Js::PropertyString::Is(var)? ctPropertyString16 : ctString16); + auto size = PrependByte(builder, _u("String Constant 16"), + Js::VarIs(var)? ctPropertyString16 : ctString16); return size + PrependStringConstant(builder, var); } @@ -2294,7 +2294,7 @@ class ByteCodeBufferBuilder definedFields.has_attributes = true; PrependInt32(builder, _u("Attributes"), attributes); } - + PrependInt32(builder, _u("Offset Into Source"), sourceDiff); PrependInt32(builder, _u("Offset Into Source for toString"), function->PrintableStartOffset()); if (function->GetNestedCount() > 0) @@ -2896,7 +2896,7 @@ class ByteCodeBufferReader uint32 countOfAuxiliaryStructure; current = ReadUInt32(current, &countOfAuxiliaryStructure); Assert(countOfAuxiliaryStructure != 0); - + uint32 sizeOfAuxiliaryBlock; uint32 sizeOfAuxiliaryContextBlock; current = ReadUInt32(current, &sizeOfAuxiliaryBlock); @@ -3419,7 +3419,7 @@ class ByteCodeBufferReader current = ReadUInt32(current, &count); Js::AuxArray * slotIdInCachedScopeToNestedIndexArray = functionBody->AllocateSlotIdInCachedScopeToNestedIndexArray(count); - + uint32 value; for (uint i = 0; i < count; i++) { @@ -3475,7 +3475,7 @@ class ByteCodeBufferReader { Assert(function); Assert(debuggerScopeCount != 0); - + #ifdef BYTE_CODE_MAGIC_CONSTANTS int constant; current = ReadInt32(current, &constant); @@ -4870,7 +4870,7 @@ HRESULT ByteCodeSerializer::SerializeToBuffer(ScriptContext * scriptContext, Are int32 sourceCharLength = utf8SourceInfo->GetCchLength(); ByteCodeBufferBuilder builder(sourceByteLength, sourceCharLength, utf8Source, utf8SourceInfo, scriptContext, alloc, dwFlags, builtInPropertyCount); - + hr = builder.AddTopFunctionBody(function, srcInfo, cache); if (SUCCEEDED(hr)) diff --git a/lib/Runtime/Debug/DiagObjectModel.cpp b/lib/Runtime/Debug/DiagObjectModel.cpp index ba17a095df2..5bccc5a2038 100644 --- a/lib/Runtime/Debug/DiagObjectModel.cpp +++ b/lib/Runtime/Debug/DiagObjectModel.cpp @@ -71,15 +71,15 @@ namespace Js IDiagObjectModelDisplay* pOMDisplay = nullptr; ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena(); - if (Js::TypedArrayBase::Is(obj)) + if (Js::VarIs(obj)) { pOMDisplay = Anew(pRefArena->Arena(), RecyclableTypedArrayDisplay, this); } - else if (Js::ES5Array::Is(obj)) + else if (Js::VarIs(obj)) { pOMDisplay = Anew(pRefArena->Arena(), RecyclableES5ArrayDisplay, this); } - else if (Js::JavascriptArray::Is(obj)) + else if (Js::JavascriptArray::IsNonES5Array(obj)) { // DisableJIT-TODO: Review- is this correct? #if ENABLE_COPYONACCESS_ARRAY @@ -426,7 +426,7 @@ namespace Js // This is fake [Methods] object. pResolvedObject->name = groupType == UIGroupType_Scope ? _u("[Scope]") : _u("[Globals]"); - pResolvedObject->obj = Js::RecyclableObject::FromVar(instance); + pResolvedObject->obj = Js::VarTo(instance); pResolvedObject->typeId = TypeIds_Function; pResolvedObject->address = nullptr; // Scope object should not be editable @@ -780,7 +780,7 @@ namespace Js if (displayInfo->IsInDeadZone()) { // The uninitialized string is already set in the var for the dead zone display. - Assert(JavascriptString::Is(displayInfo->aVar)); + Assert(VarIs(displayInfo->aVar)); returnedVar = displayInfo->aVar; } else @@ -820,9 +820,9 @@ namespace Js ScriptContext * scriptContext = pFrame->GetScriptContext(); ArenaAllocator *arena = GetArenaFromContext(scriptContext); - Assert(Js::RecyclableObject::Is(instance)); + Assert(Js::VarIs(instance)); - Js::RecyclableObject* object = Js::RecyclableObject::FromVar(instance); + Js::RecyclableObject* object = Js::VarTo(instance); Assert(JavascriptOperators::IsObject(object)); int count = object->GetPropertyCount(); @@ -861,7 +861,7 @@ namespace Js itemObj = scriptContext->GetLibrary()->GetUndefined(); } - AssertMsg(!RootObjectBase::Is(object) || !isConst, "root object shouldn't produce const properties through IsPropertyValid"); + AssertMsg(!VarIs(object) || !isConst, "root object shouldn't produce const properties through IsPropertyValid"); DebuggerPropertyDisplayInfo *info = AllocateNewPropertyDisplayInfo( propertyId, @@ -892,8 +892,8 @@ namespace Js ScriptContext * scriptContext = pFrame->GetScriptContext(); ArenaAllocator *arena = GetArenaFromContext(scriptContext); - Assert(Js::RootObjectBase::Is(instance)); - Js::RootObjectBase* object = Js::RootObjectBase::FromVar(instance); + Assert(Js::VarIs(instance)); + Js::RootObjectBase* object = Js::VarTo(instance); int count = object->GetPropertyCount(); pMembersList = JsUtil::List::New(arena, count); @@ -1634,7 +1634,7 @@ namespace Js { // If we're in a dead zone, the value will be the // [Uninitialized block variable] string. - Assert(JavascriptString::Is(value)); + Assert(VarIs(value)); } #endif // DBG @@ -1647,12 +1647,12 @@ namespace Js BOOL LocalObjectAddressForSlot::IsInDeadZone() const { Var value = slotArray.Get(slotIndex); - if (!RecyclableObject::Is(value)) + if (!VarIs(value)) { return FALSE; } - RecyclableObject* obj = RecyclableObject::FromVar(value); + RecyclableObject* obj = VarTo(value); ScriptContext* scriptContext = obj->GetScriptContext(); return scriptContext->IsUndeclBlockVar(obj) ? TRUE : FALSE; } @@ -1697,7 +1697,7 @@ namespace Js { // If we're in a dead zone, the value will be the // [Uninitialized block variable] string. - Assert(JavascriptString::Is(value)); + Assert(VarIs(value)); } #endif // DBG @@ -1754,9 +1754,9 @@ namespace Js if (debuggerScope->scopeType == Js::DiagCatchScopeInObject) { Var obj = pFrame->GetInnerScopeFromRegSlot(debuggerScope->GetLocation()); - Assert(RecyclableObject::Is(obj)); + Assert(VarIs(obj)); - outValue = RecyclableObjectWalker::GetObject(RecyclableObject::FromVar(obj), RecyclableObject::FromVar(obj), scopeProperty.propId, scriptContext); + outValue = RecyclableObjectWalker::GetObject(VarTo(obj), VarTo(obj), scopeProperty.propId, scriptContext); bool isInDeadZone = scriptContext->IsUndeclBlockVar(outValue); if (isInDeadZone) { @@ -1824,9 +1824,9 @@ namespace Js BOOL RecyclableObjectAddress::Set(Var updateObject) { - if (Js::RecyclableObject::Is(parentObj)) + if (Js::VarIs(parentObj)) { - Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(parentObj); + Js::RecyclableObject* obj = Js::VarTo(parentObj); ScriptContext* requestContext = obj->GetScriptContext(); //TODO: real requestContext return Js::JavascriptOperators::SetProperty(obj, obj, propId, updateObject, requestContext); @@ -1836,9 +1836,9 @@ namespace Js BOOL RecyclableObjectAddress::IsWritable() { - if (Js::RecyclableObject::Is(parentObj)) + if (Js::VarIs(parentObj)) { - Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(parentObj); + Js::RecyclableObject* obj = Js::VarTo(parentObj); return obj->IsWritable(propId); } @@ -1853,9 +1853,9 @@ namespace Js return value; } - if (Js::RecyclableObject::Is(parentObj)) + if (Js::VarIs(parentObj)) { - Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(parentObj); + Js::RecyclableObject* obj = Js::VarTo(parentObj); ScriptContext* requestContext = obj->GetScriptContext(); Var objValue = nullptr; @@ -1938,7 +1938,7 @@ namespace Js } else { - Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(instance); + Js::RecyclableObject* obj = Js::VarTo(instance); StringBuilder* builder = scriptContext->GetThreadContext()->GetDebugManager()->pCurrentInterpreterLocation->stringBuilder; builder->Reset(); @@ -1951,9 +1951,9 @@ namespace Js if (typeId == TypeIds_Object && GetPropertyWithScriptEnter(obj, obj, PropertyIds::constructor, &value, scriptContext)) { builder->AppendCppLiteral(_u("Object")); - if (Js::JavascriptFunction::Is(value)) + if (Js::VarIs(value)) { - Js::JavascriptFunction *pfunction = Js::JavascriptFunction::FromVar(value); + Js::JavascriptFunction *pfunction = Js::VarTo(value); // For an odd chance that the constructor wasn't called to create the object. Js::ParseableFunctionInfo *pFuncBody = pfunction->GetFunctionProxy() != nullptr ? pfunction->GetFunctionProxy()->EnsureDeserialized() : nullptr; if (pFuncBody) @@ -1997,7 +1997,7 @@ namespace Js if(Js::TaggedInt::Is(instance) || Js::JavascriptNumber::Is(instance) - || Js::JavascriptNumberObject::Is(instance) + || Js::VarIs(instance) || Js::JavascriptOperators::GetTypeId(instance) == TypeIds_Int64Number || Js::JavascriptOperators::GetTypeId(instance) == TypeIds_UInt64Number) { @@ -2012,15 +2012,15 @@ namespace Js } else if (Js::JavascriptOperators::GetTypeId(instance) == TypeIds_Int64Number) { - value = (double)JavascriptInt64Number::FromVar(instance)->GetValue(); + value = (double)VarTo(instance)->GetValue(); } else if (Js::JavascriptOperators::GetTypeId(instance) == TypeIds_UInt64Number) { - value = (double)JavascriptUInt64Number::FromVar(instance)->GetValue(); + value = (double)VarTo(instance)->GetValue(); } else { - Js::JavascriptNumberObject* numobj = Js::JavascriptNumberObject::FromVar(instance); + Js::JavascriptNumberObject* numobj = Js::VarTo(instance); value = numobj->GetValue(); } @@ -2061,7 +2061,7 @@ namespace Js } else { - Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(instance); + Js::RecyclableObject* obj = Js::VarTo(instance); StringBuilder* builder = scriptContext->GetThreadContext()->GetDebugManager()->pCurrentInterpreterLocation->stringBuilder; builder->Reset(); @@ -2081,9 +2081,9 @@ namespace Js BOOL RecyclableObjectDisplay::HasChildren() { - if (Js::RecyclableObject::Is(instance)) + if (Js::VarIs(instance)) { - Js::RecyclableObject* object = Js::RecyclableObject::FromVar(instance); + Js::RecyclableObject* object = Js::VarTo(instance); if (JavascriptOperators::IsObject(object)) { @@ -2139,7 +2139,7 @@ namespace Js { // The For in enumerator can throw an exception and we will use the error object as a child in that case. Var error = err.GetAndClear()->GetThrownObject(scriptContext); - if (error != nullptr && Js::JavascriptError::Is(error)) + if (error != nullptr && Js::VarIs(error)) { return TRUE; } @@ -2164,7 +2164,7 @@ namespace Js { DBGPROP_ATTRIB_FLAGS flag = defaultAttributes; - if (Js::RecyclableObject::Is(instance)) + if (Js::VarIs(instance)) { if (instance == scriptContext->GetLibrary()->GetDebuggerDeadZoneBlockVariableString()) { @@ -2289,7 +2289,7 @@ namespace Js return FALSE; } - int nonArrayElementCount = Js::RecyclableObject::Is(instance) ? pMembersList->Count() : 0; + int nonArrayElementCount = Js::VarIs(instance) ? pMembersList->Count() : 0; // First the virtual groups if (index < fakeObjCount) @@ -2302,7 +2302,7 @@ namespace Js if (index < nonArrayElementCount) { - Assert(Js::RecyclableObject::Is(instance)); + Assert(Js::VarIs(instance)); pResolvedObject->propId = pMembersList->Item(index)->propId; @@ -2407,11 +2407,11 @@ namespace Js RecyclableMethodsGroupWalker *pMethodsGroupWalker = nullptr; - if (Js::RecyclableObject::Is(instance)) + if (Js::VarIs(instance)) { - Js::RecyclableObject* object = Js::RecyclableObject::FromVar(instance); + Js::RecyclableObject* object = Js::VarTo(instance); // If we are walking a prototype, we'll use its instance for property names enumeration, but originalInstance to get values - Js::RecyclableObject* originalObject = (originalInstance != nullptr) ? Js::RecyclableObject::FromVar(originalInstance) : object; + Js::RecyclableObject* originalObject = (originalInstance != nullptr) ? Js::VarTo(originalInstance) : object; const Js::TypeId typeId = JavascriptOperators::GetTypeId(instance); if (JavascriptOperators::IsObject(object)) @@ -2454,7 +2454,7 @@ namespace Js catch (const JavascriptException& err) { Var error = err.GetAndClear()->GetThrownObject(scriptContext); - if (error != nullptr && Js::JavascriptError::Is(error)) + if (error != nullptr && Js::VarIs(error)) { Js::PropertyId propertyId = scriptContext->GetOrAddPropertyIdTracked(_u("{error}")); InsertItem(propertyId, false /*isConst*/, false /*isUnscoped*/, error, &pMethodsGroupWalker); @@ -2466,7 +2466,7 @@ namespace Js // Provide [Proxy] group object EnsureFakeGroupObjectWalkerList(); - JavascriptProxy* proxy = JavascriptProxy::FromVar(object); + JavascriptProxy* proxy = VarTo(object); RecyclableProxyObjectWalker* proxyWalker = Anew(arena, RecyclableProxyObjectWalker, scriptContext, proxy); fakeGroupObjectWalkerList->Add(proxyWalker); } @@ -2520,14 +2520,14 @@ namespace Js if (propertyId != Js::Constants::NoProperty) { bool isConst = true; - if (propertyId == PropertyIds::length && Js::JavascriptArray::Is(object)) + if (propertyId == PropertyIds::length && Js::JavascriptArray::IsNonES5Array(object)) { // For JavascriptArrays, we allow resetting the length special property. isConst = false; } auto containsPredicate = [&](Js::DebuggerPropertyDisplayInfo* info) { return info->propId == propertyId; }; - if (Js::BoundFunction::Is(object) + if (Js::VarIs(object) && this->pMembersList->Any(containsPredicate)) { // Bound functions can already contain their special properties, @@ -2542,7 +2542,7 @@ namespace Js InsertItem(originalObject, object, propertyId, isConst, isUnscoped, &pMethodsGroupWalker); } } - if (Js::JavascriptFunction::Is(object)) + if (Js::VarIs(object)) { // We need to special-case RegExp constructor here because it has some special properties (above) and some // special enumerable properties which should all show up in the debugger. @@ -2594,7 +2594,7 @@ namespace Js // Provide [Map] group object. EnsureFakeGroupObjectWalkerList(); - JavascriptMap* map = JavascriptMap::FromVar(object); + JavascriptMap* map = VarTo(object); RecyclableMapObjectWalker *pMapWalker = Anew(arena, RecyclableMapObjectWalker, scriptContext, map); fakeGroupObjectWalkerList->Add(pMapWalker); } @@ -2603,7 +2603,7 @@ namespace Js // Provide [Set] group object. EnsureFakeGroupObjectWalkerList(); - JavascriptSet* set = JavascriptSet::FromVar(object); + JavascriptSet* set = VarTo(object); RecyclableSetObjectWalker *pSetWalker = Anew(arena, RecyclableSetObjectWalker, scriptContext, set); fakeGroupObjectWalkerList->Add(pSetWalker); } @@ -2612,7 +2612,7 @@ namespace Js // Provide [WeakMap] group object. EnsureFakeGroupObjectWalkerList(); - JavascriptWeakMap* weakMap = JavascriptWeakMap::FromVar(object); + JavascriptWeakMap* weakMap = VarTo(object); RecyclableWeakMapObjectWalker *pWeakMapWalker = Anew(arena, RecyclableWeakMapObjectWalker, scriptContext, weakMap); fakeGroupObjectWalkerList->Add(pWeakMapWalker); } @@ -2621,7 +2621,7 @@ namespace Js // Provide [WeakSet] group object. EnsureFakeGroupObjectWalkerList(); - JavascriptWeakSet* weakSet = JavascriptWeakSet::FromVar(object); + JavascriptWeakSet* weakSet = VarTo(object); RecyclableWeakSetObjectWalker *pWeakSetWalker = Anew(arena, RecyclableWeakSetObjectWalker, scriptContext, weakSet); fakeGroupObjectWalkerList->Add(pWeakSetWalker); } @@ -2630,21 +2630,21 @@ namespace Js // Provide [Promise] group object. EnsureFakeGroupObjectWalkerList(); - JavascriptPromise* promise = JavascriptPromise::FromVar(object); + JavascriptPromise* promise = VarTo(object); RecyclablePromiseObjectWalker *pPromiseWalker = Anew(arena, RecyclablePromiseObjectWalker, scriptContext, promise); fakeGroupObjectWalkerList->Add(pPromiseWalker); } else if (Js::DynamicType::Is(typeId)) { - DynamicObject *const dynamicObject = Js::DynamicObject::FromVar(instance); + DynamicObject *const dynamicObject = Js::VarTo(instance); if (dynamicObject->HasNonEmptyObjectArray()) { ArrayObject* objectArray = dynamicObject->GetObjectArray(); - if (Js::ES5Array::Is(objectArray)) + if (Js::VarIs(objectArray)) { innerArrayObjectWalker = Anew(arena, RecyclableES5ArrayWalker, scriptContext, objectArray, originalInstance); } - else if (Js::JavascriptArray::Is(objectArray)) + else if (Js::JavascriptArray::IsNonES5Array(objectArray)) { innerArrayObjectWalker = Anew(arena, RecyclableArrayWalker, scriptContext, objectArray, originalInstance); } @@ -2781,7 +2781,7 @@ namespace Js catch(const JavascriptException& err) { Var error = err.GetAndClear()->GetThrownObject(instance->GetScriptContext()); - if (error != nullptr && Js::JavascriptError::Is(error)) + if (error != nullptr && Js::VarIs(error)) { obj = error; } @@ -2803,9 +2803,9 @@ namespace Js BOOL RecyclableArrayAddress::Set(Var updateObject) { - if (Js::JavascriptArray::Is(parentArray)) + if (Js::JavascriptArray::IsNonES5Array(parentArray)) { - Js::JavascriptArray* jsArray = Js::JavascriptArray::FromVar(parentArray); + Js::JavascriptArray* jsArray = Js::VarTo(parentArray); return jsArray->SetItem(index, updateObject, PropertyOperation_None); } return FALSE; @@ -2835,9 +2835,9 @@ namespace Js BOOL RecyclableArrayDisplay::HasChildren() { - if (Js::JavascriptArray::Is(instance)) + if (Js::JavascriptArray::IsNonES5Array(instance)) { - Js::JavascriptArray* arrayObj = Js::JavascriptArray::FromVar(instance); + Js::JavascriptArray* arrayObj = Js::VarTo(instance); if (HasChildrenInternal(arrayObj)) { return TRUE; @@ -2958,7 +2958,7 @@ namespace Js { AssertMsg(pResolvedObject, "Bad usage of RecyclableArrayWalker::Get"); - if (Js::JavascriptArray::Is(instance) || Js::ES5Array::Is(instance)) + if (Js::JavascriptArray::IsNonES5Array(instance) || Js::VarIs(instance)) { Js::JavascriptArray* arrayObj = GetArrayObject(); @@ -2987,15 +2987,15 @@ namespace Js Js::JavascriptArray* RecyclableArrayWalker::GetArrayObject() { - Assert(Js::JavascriptArray::Is(instance) || Js::ES5Array::Is(instance)); - return Js::ES5Array::Is(instance) ? - static_cast(RecyclableObject::FromVar(instance)) : - Js::JavascriptArray::FromVar(instance); + Assert(Js::JavascriptArray::IsNonES5Array(instance) || Js::VarIs(instance)); + return Js::VarIs(instance) ? + static_cast(VarTo(instance)) : + Js::VarTo(instance); } uint32 RecyclableArrayWalker::GetChildrenCount() { - if (Js::JavascriptArray::Is(instance) || Js::ES5Array::Is(instance)) + if (Js::JavascriptArray::IsNonES5Array(instance) || Js::VarIs(instance)) { uint32 count = (!fOnlyOwnProperties ? RecyclableObjectWalker::GetChildrenCount() : 0); @@ -3023,7 +3023,7 @@ namespace Js BOOL RecyclableArgumentsArrayAddress::Set(Var updateObject) { - if (Js::ArgumentsObject::Is(parentArray)) + if (Js::VarIs(parentArray)) { Js::ArgumentsObject* argObj = static_cast(parentArray); return argObj->SetItem(index, updateObject, PropertyOperation_None); @@ -3095,7 +3095,7 @@ namespace Js { if (pMembersList == nullptr) { - Assert(Js::ArgumentsObject::Is(instance)); + Assert(Js::VarIs(instance)); Js::ArgumentsObject * argObj = static_cast(instance); pMembersList = JsUtil::List::New(GetArenaFromContext(scriptContext)); @@ -3158,7 +3158,7 @@ namespace Js AssertMsg(pResolvedObject, "Bad usage of RecyclableArgumentsArrayWalker::Get"); Assert(i >= 0); - Assert(Js::ArgumentsObject::Is(instance)); + Assert(Js::VarIs(instance)); if (pMembersList && i < pMembersList->Count()) { @@ -3268,9 +3268,9 @@ namespace Js { if (!indexedItemCount) { - Assert(Js::TypedArrayBase::Is(instance)); + Assert(Js::VarIs(instance)); - Js::TypedArrayBase * typedArrayObj = Js::TypedArrayBase::FromVar(instance); + Js::TypedArrayBase * typedArrayObj = Js::VarTo(instance); indexedItemCount = typedArrayObj->GetLength() + (!fOnlyOwnProperties ? RecyclableObjectWalker::GetChildrenCount() : 0); } @@ -3282,9 +3282,9 @@ namespace Js { AssertMsg(pResolvedObject, "Bad usage of RecyclableTypedArrayWalker::Get"); - Assert(Js::TypedArrayBase::Is(instance)); + Assert(Js::VarIs(instance)); - Js::TypedArrayBase * typedArrayObj = Js::TypedArrayBase::FromVar(instance); + Js::TypedArrayBase * typedArrayObj = Js::VarTo(instance); int nonArrayElementCount = (!fOnlyOwnProperties ? RecyclableObjectWalker::GetChildrenCount() : 0); @@ -3326,9 +3326,9 @@ namespace Js BOOL RecyclableES5ArrayAddress::Set(Var updateObject) { - if (Js::ES5Array::Is(parentArray)) + if (Js::VarIs(parentArray)) { - Js::ES5Array* arrayObj = Js::ES5Array::FromVar(parentArray); + Js::ES5Array* arrayObj = Js::VarTo(parentArray); return arrayObj->SetItem(index, updateObject, PropertyOperation_None); } @@ -3346,9 +3346,9 @@ namespace Js BOOL RecyclableES5ArrayDisplay::HasChildren() { - if (Js::ES5Array::Is(instance)) + if (Js::VarIs(instance)) { - Js::JavascriptArray* arrayObj = static_cast(RecyclableObject::FromVar(instance)); + Js::JavascriptArray* arrayObj = static_cast(VarTo(instance)); if (HasChildrenInternal(arrayObj)) { return TRUE; @@ -3372,7 +3372,7 @@ namespace Js uint32 RecyclableES5ArrayWalker::GetNextDescriptor(uint32 currentDescriptor) { - Js::ES5Array *es5Array = static_cast(RecyclableObject::FromVar(instance)); + Js::ES5Array *es5Array = static_cast(VarTo(instance)); IndexPropertyDescriptor* descriptor = nullptr; void * descriptorValidationToken = nullptr; return es5Array->GetNextDescriptor(currentDescriptor, &descriptor, &descriptorValidationToken); @@ -3424,14 +3424,14 @@ namespace Js defaultAttributes = DBGPROP_ATTRIB_VALUE_IS_FAKE; } - RecyclableObject *obj = Js::RecyclableObject::FromVar(instance); + RecyclableObject *obj = Js::VarTo(instance); Assert(obj->GetPrototype() != nullptr); //withscopeObjects prototype is null Assert(obj->GetPrototype()->GetTypeId() != TypeIds_Null || (obj->GetPrototype()->GetTypeId() == TypeIds_Null && obj->GetTypeId() == TypeIds_WithScopeObject)); pResolvedObject->obj = obj->GetPrototype(); - pResolvedObject->originalObj = (originalInstance != nullptr) ? Js::RecyclableObject::FromVar(originalInstance) : pResolvedObject->obj; + pResolvedObject->originalObj = (originalInstance != nullptr) ? Js::VarTo(originalInstance) : pResolvedObject->obj; pResolvedObject->scriptContext = scriptContext; pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj); @@ -3556,7 +3556,7 @@ namespace Js template uint32 RecyclableCollectionObjectWalker::GetChildrenCount() { - TData* data = TData::FromVar(instance); + TData* data = VarTo(instance); if (data->Size() > 0 && propertyList == nullptr) { propertyList = JsUtil::List, ArenaAllocator>::New(GetArenaFromContext(scriptContext)); @@ -3569,7 +3569,7 @@ namespace Js template <> void RecyclableCollectionObjectWalker::GetChildren() { - JavascriptMap* data = JavascriptMap::FromVar(instance); + JavascriptMap* data = VarTo(instance); auto iterator = data->GetIterator(); while (iterator.Next()) { @@ -3582,7 +3582,7 @@ namespace Js template <> void RecyclableCollectionObjectWalker::GetChildren() { - JavascriptSet* data = JavascriptSet::FromVar(instance); + JavascriptSet* data = VarTo(instance); auto iterator = data->GetIterator(); while (iterator.Next()) { @@ -3594,7 +3594,7 @@ namespace Js template <> void RecyclableCollectionObjectWalker::GetChildren() { - JavascriptWeakMap* data = JavascriptWeakMap::FromVar(instance); + JavascriptWeakMap* data = VarTo(instance); data->Map([&](Var key, Var value) { propertyList->Add(RecyclableCollectionObjectWalkerPropertyData(key, value)); @@ -3604,7 +3604,7 @@ namespace Js template <> void RecyclableCollectionObjectWalker::GetChildren() { - JavascriptWeakSet* data = JavascriptWeakSet::FromVar(instance); + JavascriptWeakSet* data = VarTo(instance); data->Map([&](Var value) { propertyList->Add(RecyclableCollectionObjectWalkerPropertyData(value)); @@ -3753,7 +3753,7 @@ namespace Js BOOL RecyclableProxyObjectWalker::Get(int i, ResolvedObject* pResolvedObject) { - JavascriptProxy* proxy = JavascriptProxy::FromVar(instance); + JavascriptProxy* proxy = VarTo(instance); if (proxy->GetTarget() == nullptr || proxy->GetHandler() == nullptr) { return FALSE; @@ -3832,7 +3832,7 @@ namespace Js BOOL RecyclablePromiseObjectWalker::Get(int i, ResolvedObject* pResolvedObject) { - JavascriptPromise* promise = JavascriptPromise::FromVar(instance); + JavascriptPromise* promise = VarTo(instance); if (i == 0) { @@ -3919,7 +3919,7 @@ namespace Js // This is fake [Methods] object. pResolvedObject->name = _u("[Methods]"); - pResolvedObject->obj = Js::RecyclableObject::FromVar(instance); + pResolvedObject->obj = Js::VarTo(instance); pResolvedObject->scriptContext = scriptContext; pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj); pResolvedObject->address = nullptr; // Methods object will not be editable @@ -3991,23 +3991,23 @@ namespace Js LPCWSTR ScopeVariablesGroupDisplay::Value(int radix) { - if (ActivationObject::Is(instance)) + if (VarIs(instance)) { // The scope is defined by the activation object. - Js::RecyclableObject *object = Js::RecyclableObject::FromVar(instance); + Js::RecyclableObject *object = Js::VarTo(instance); try { // Trying to find out the JavascriptFunction from the scope. Var value = nullptr; if (object->GetTypeId() == TypeIds_ActivationObject && GetPropertyWithScriptEnter(object, object, PropertyIds::arguments, &value, scriptContext)) { - if (Js::RecyclableObject::Is(value)) + if (Js::VarIs(value)) { - Js::RecyclableObject *argObject = Js::RecyclableObject::FromVar(value); + Js::RecyclableObject *argObject = Js::VarTo(value); Var calleeFunc = nullptr; - if (GetPropertyWithScriptEnter(argObject, argObject, PropertyIds::callee, &calleeFunc, scriptContext) && Js::JavascriptFunction::Is(calleeFunc)) + if (GetPropertyWithScriptEnter(argObject, argObject, PropertyIds::callee, &calleeFunc, scriptContext) && Js::VarIs(calleeFunc)) { - Js::JavascriptFunction *calleeFunction = Js::JavascriptFunction::FromVar(calleeFunc); + Js::JavascriptFunction *calleeFunction = Js::VarTo(calleeFunc); Js::FunctionBody *pFuncBody = calleeFunction->GetFunctionBody(); if (pFuncBody) diff --git a/lib/Runtime/Debug/DiagStackFrame.cpp b/lib/Runtime/Debug/DiagStackFrame.cpp index e28b0cc3e7e..0887d231fdd 100644 --- a/lib/Runtime/Debug/DiagStackFrame.cpp +++ b/lib/Runtime/Debug/DiagStackFrame.cpp @@ -29,7 +29,7 @@ namespace Js ScriptFunction* DiagStackFrame::GetScriptFunction() { - return ScriptFunction::FromVar(GetJavascriptFunction()); + return VarTo(GetJavascriptFunction()); } FunctionBody* DiagStackFrame::GetFunction() @@ -79,7 +79,7 @@ namespace Js { display = this->GetScriptFunction()->GetEnvironment(); } - + return display; } @@ -298,7 +298,7 @@ namespace Js Js::ScriptContext* scriptContext = this->GetScriptContext(); ArenaAllocator *arena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena()->Arena(); - Js::LocalsWalker *localsWalker = Anew(arena, Js::LocalsWalker, this, + Js::LocalsWalker *localsWalker = Anew(arena, Js::LocalsWalker, this, Js::FrameWalkerFlags::FW_EnumWithScopeAlso | Js::FrameWalkerFlags::FW_AllowLexicalThis | Js::FrameWalkerFlags::FW_AllowSuperReference | Js::FrameWalkerFlags::FW_DontAddGlobalsDirectly); // Store the diag address of a var to the map so that it will be used for editing the value. diff --git a/lib/Runtime/Debug/MutationBreakpoint.cpp b/lib/Runtime/Debug/MutationBreakpoint.cpp index 850880cb991..8f6b0e9d2d4 100644 --- a/lib/Runtime/Debug/MutationBreakpoint.cpp +++ b/lib/Runtime/Debug/MutationBreakpoint.cpp @@ -42,7 +42,7 @@ bool Js::MutationBreakpoint::HandleSetProperty(Js::ScriptContext *scriptContext, && objectContext->HasMutationBreakpoints()) { MutationBreakpoint *bp = nullptr; - DynamicObject *dynObj = DynamicObject::FromVar(object); + DynamicObject *dynObj = VarTo(object); if (dynObj->GetInternalProperty(object, InternalPropertyIds::MutationBp, reinterpret_cast(&bp), nullptr, objectContext) && bp) @@ -83,7 +83,7 @@ void Js::MutationBreakpoint::HandleDeleteProperty(ScriptContext *scriptContext, Assert(instance); if (MutationBreakpoint::CanSet(instance)) { - DynamicObject *obj = DynamicObject::FromVar(instance); + DynamicObject *obj = VarTo(instance); if (obj->GetScriptContext()->HasMutationBreakpoints()) { MutationBreakpoint *bp = nullptr; @@ -107,8 +107,8 @@ void Js::MutationBreakpoint::HandleDeleteProperty(ScriptContext *scriptContext, void Js::MutationBreakpoint::HandleDeleteProperty(ScriptContext *scriptContext, Var instance, Js::JavascriptString *propertyNameString) { PropertyRecord const *propertyRecord = nullptr; - DynamicObject *obj = DynamicObject::FromVar(instance); - + DynamicObject *obj = VarTo(instance); + if (JavascriptOperators::ShouldTryDeleteProperty(obj, propertyNameString, &propertyRecord)) { Assert(propertyRecord); diff --git a/lib/Runtime/Debug/ProbeContainer.cpp b/lib/Runtime/Debug/ProbeContainer.cpp index f99b538e49a..0cb1b466b43 100644 --- a/lib/Runtime/Debug/ProbeContainer.cpp +++ b/lib/Runtime/Debug/ProbeContainer.cpp @@ -143,7 +143,7 @@ namespace Js if (func->IsScriptFunction()) { frm = Anew(pDiagArena, DiagNativeStackFrame, - ScriptFunction::FromVar(walker.GetCurrentFunction()), walker.GetByteCodeOffset(), stackAddress, walker.GetCurrentCodeAddr()); + VarTo(walker.GetCurrentFunction()), walker.GetByteCodeOffset(), stackAddress, walker.GetCurrentCodeAddr()); } else #else @@ -298,7 +298,7 @@ namespace Js } } }, - [&](bool) + [&](bool) { DestroyLocation(); }); @@ -383,7 +383,7 @@ namespace Js { DestroyLocation(); }); - + OUTPUT_TRACE(Js::DebuggerPhase, _u("ProbeContainer::DispatchInlineBreakpoint: end: pHaltState=%p\n"), pHaltState); } @@ -405,7 +405,7 @@ namespace Js // Will store current offset of the bytecode block. int currentOffset = -1; - TryFinally([&]() + TryFinally([&]() { InitializeLocation(pHaltState, false); OUTPUT_TRACE(Js::DebuggerPhase, _u("ProbeContainer::DispatchExceptionBreakpoint: initialized location: pHaltState=%p, IsInterpreterFrame=%d\n"), @@ -533,7 +533,7 @@ namespace Js // will store Current offset of the bytecode block. int currentOffset = -1; - TryFinally([&]() + TryFinally([&]() { InitializeLocation(pHaltState); OUTPUT_TRACE(Js::DebuggerPhase, _u("ProbeContainer::DispatchMutationBreakpoint: initialized location: pHaltState=%p, pHaltState->IsValid()=%d\n"), @@ -580,7 +580,7 @@ namespace Js return; } - TryFinally([&]() + TryFinally([&]() { InitializeLocation(pHaltState); diff --git a/lib/Runtime/Debug/TTActionEvents.cpp b/lib/Runtime/Debug/TTActionEvents.cpp index 9d87d656b45..d1321587989 100644 --- a/lib/Runtime/Debug/TTActionEvents.cpp +++ b/lib/Runtime/Debug/TTActionEvents.cpp @@ -126,7 +126,7 @@ namespace TTD { const JsRTSingleVarArgumentAction* action = GetInlineEventDataAs(evt); Js::Var gvar = InflateVarInReplay(executeContext, GetVarItem_0(action)); - TTDAssert(gvar == nullptr || Js::GlobalObject::Is(gvar), "Something is not right here!"); + TTDAssert(gvar == nullptr || Js::VarIs(gvar), "Something is not right here!"); Js::GlobalObject* gobj = static_cast(gvar); Js::ScriptContext* newCtx = (gobj != nullptr) ? gobj->GetScriptContext() : nullptr; @@ -286,7 +286,7 @@ namespace TTD TTD_LOG_PTR_ID origId = reinterpret_cast(GetVarItem_0(action)); Js::Var var = InflateVarInReplay(executeContext, GetVarItem_0(action)); - Js::RecyclableObject* newObj = Js::RecyclableObject::FromVar(var); + Js::RecyclableObject* newObj = Js::VarTo(var); executeContext->AddRootRef_Replay(origId, newObj); } @@ -298,7 +298,7 @@ namespace TTD TTD_LOG_PTR_ID origId = reinterpret_cast(GetVarItem_0(action)); Js::Var var = InflateVarInReplay(executeContext, GetVarItem_0(action)); - Js::RecyclableObject* newObj = Js::RecyclableObject::FromVar(var); + Js::RecyclableObject* newObj = Js::VarTo(var); executeContext->AddRootRef_Replay(origId, newObj); } @@ -559,12 +559,12 @@ namespace TTD //These really don't have any effect, we need the marshal in validate, so just skip since Js::JavascriptSymbol has strange declaration order // - //if(!Js::JavascriptSymbol::Is(sym)) + //if(!Js::VarIs(sym)) //{ // return JsErrorPropertyNotSymbol; //} // - //Js::JavascriptSymbol::FromVar(symbol)->GetValue(); + //Js::VarTo(symbol)->GetValue(); } void GetPrototypeAction_Execute(const EventLogEntry* evt, ThreadContextTTD* executeContext) @@ -616,7 +616,7 @@ namespace TTD Js::Var res = nullptr; Js::PropertyDescriptor propertyDescriptorValue; - if(Js::JavascriptOperators::GetOwnPropertyDescriptor(Js::RecyclableObject::FromVar(var), GetPropertyIdItem(action), ctx, &propertyDescriptorValue)) + if(Js::JavascriptOperators::GetOwnPropertyDescriptor(Js::VarTo(var), GetPropertyIdItem(action), ctx, &propertyDescriptorValue)) { res = Js::JavascriptOperators::FromPropertyDescriptor(propertyDescriptorValue, ctx); } @@ -667,7 +667,7 @@ namespace TTD Js::PropertyDescriptor propertyDescriptorValue; Js::JavascriptOperators::ToPropertyDescriptor(propertyDescriptor, &propertyDescriptorValue, ctx); - Js::JavascriptOperators::DefineOwnPropertyDescriptor(Js::RecyclableObject::FromVar(object), GetPropertyIdItem(action), propertyDescriptorValue, true, ctx); + Js::JavascriptOperators::DefineOwnPropertyDescriptor(Js::VarTo(object), GetPropertyIdItem(action), propertyDescriptorValue, true, ctx); } void DeletePropertyAction_Execute(const EventLogEntry* evt, ThreadContextTTD* executeContext) @@ -692,7 +692,7 @@ namespace TTD Js::Var proto = InflateVarInReplay(executeContext, GetVarItem_1(action)); TTD_REPLAY_VALIDATE_INCOMING_OBJECT_OR_NULL(proto, ctx); - Js::JavascriptObject::ChangePrototype(Js::RecyclableObject::FromVar(var), Js::RecyclableObject::FromVar(proto), true, ctx); + Js::JavascriptObject::ChangePrototype(Js::VarTo(var), Js::VarTo(proto), true, ctx); } void SetPropertyAction_Execute(const EventLogEntry* evt, ThreadContextTTD* executeContext) @@ -726,7 +726,7 @@ namespace TTD const JsRTSingleVarArgumentAction* action = GetInlineEventDataAs(evt); Js::Var var = InflateVarInReplay(executeContext, GetVarItem_0(action)); - Js::TypedArrayBase* typedArrayBase = Js::TypedArrayBase::FromVar(var); + Js::TypedArrayBase* typedArrayBase = Js::VarTo(var); Js::Var res = typedArrayBase->GetArrayBuffer(); //Need additional notify since JsRTActionHandleResultForReplay may allocate but GetTypedArrayInfo does not enter runtime @@ -740,7 +740,7 @@ namespace TTD const JsRTSingleVarArgumentAction* action = GetInlineEventDataAs(evt); Js::Var var = InflateVarInReplay(executeContext, GetVarItem_0(action)); - Js::DataView* dataView = Js::DataView::FromVar(var); + Js::DataView* dataView = Js::VarTo(var); Js::Var res = dataView->GetArrayBuffer(); //Need additional notify since JsRTActionHandleResultForReplay may allocate but GetDataViewInfo does not enter runtime @@ -787,12 +787,12 @@ namespace TTD Js::Var dst = InflateVarInReplay(executeContext, action->Dst); //never cross context Js::Var src = InflateVarInReplay(executeContext, action->Src); //never cross context - TTDAssert(Js::ArrayBuffer::Is(dst) && Js::ArrayBuffer::Is(src), "Not array buffer objects!!!"); - TTDAssert(action->DstIndx + action->Count <= Js::ArrayBuffer::FromVar(dst)->GetByteLength(), "Copy off end of buffer!!!"); - TTDAssert(action->SrcIndx + action->Count <= Js::ArrayBuffer::FromVar(src)->GetByteLength(), "Copy off end of buffer!!!"); + TTDAssert(Js::VarIs(dst) && Js::VarIs(src), "Not array buffer objects!!!"); + TTDAssert(action->DstIndx + action->Count <= Js::VarTo(dst)->GetByteLength(), "Copy off end of buffer!!!"); + TTDAssert(action->SrcIndx + action->Count <= Js::VarTo(src)->GetByteLength(), "Copy off end of buffer!!!"); - byte* dstBuff = Js::ArrayBuffer::FromVar(dst)->GetBuffer() + action->DstIndx; - byte* srcBuff = Js::ArrayBuffer::FromVar(src)->GetBuffer() + action->SrcIndx; + byte* dstBuff = Js::VarTo(dst)->GetBuffer() + action->DstIndx; + byte* srcBuff = Js::VarTo(src)->GetBuffer() + action->SrcIndx; //node uses mmove so we do too memmove(dstBuff, srcBuff, action->Count); @@ -803,10 +803,10 @@ namespace TTD const JsRTRawBufferModifyAction* action = GetInlineEventDataAs(evt); Js::Var trgt = InflateVarInReplay(executeContext, action->Trgt); //never cross context - TTDAssert(Js::ArrayBuffer::Is(trgt), "Not array buffer object!!!"); - TTDAssert(action->Index + action->Length <= Js::ArrayBuffer::FromVar(trgt)->GetByteLength(), "Copy off end of buffer!!!"); + TTDAssert(Js::VarIs(trgt), "Not array buffer object!!!"); + TTDAssert(action->Index + action->Length <= Js::VarTo(trgt)->GetByteLength(), "Copy off end of buffer!!!"); - byte* trgtBuff = Js::ArrayBuffer::FromVar(trgt)->GetBuffer() + action->Index; + byte* trgtBuff = Js::VarTo(trgt)->GetBuffer() + action->Index; js_memcpy_s(trgtBuff, action->Length, action->Data, action->Length); } @@ -816,7 +816,7 @@ namespace TTD const JsRTRawBufferModifyAction* action = GetInlineEventDataAs(evt); Js::Var trgt = InflateVarInReplay(executeContext, action->Trgt); //never cross context - ctx->TTDContextInfo->AddToAsyncPendingList(Js::ArrayBuffer::FromVar(trgt), action->Index); + ctx->TTDContextInfo->AddToAsyncPendingList(Js::VarTo(trgt), action->Index); } void RawBufferAsyncModifyComplete_Execute(const EventLogEntry* evt, ThreadContextTTD* executeContext) @@ -825,7 +825,7 @@ namespace TTD const JsRTRawBufferModifyAction* action = GetInlineEventDataAs(evt); Js::Var trgt = InflateVarInReplay(executeContext, action->Trgt); //never cross context - const Js::ArrayBuffer* dstBuff = Js::ArrayBuffer::FromVar(trgt); + const Js::ArrayBuffer* dstBuff = Js::VarTo(trgt); byte* copyBuff = dstBuff->GetBuffer() + action->Index; byte* finalModPos = dstBuff->GetBuffer() + action->Index + action->Length; @@ -855,13 +855,13 @@ namespace TTD ccAction->ExecArgs[i - 1] = argi; } - Js::JavascriptFunction* jsFunction = Js::JavascriptFunction::FromVar(jsFunctionVar); + Js::JavascriptFunction* jsFunction = Js::VarTo(jsFunctionVar); Js::CallInfo callInfo(Js::CallFlags::CallFlags_New, (ushort)(ccAction->ArgCount - 1)); Js::Arguments jsArgs(callInfo, ccAction->ExecArgs); // //TODO: we will want to look at this at some point -- either treat as "top-level" call or maybe constructors are fast so we can just jump back to previous "real" code - //TTDAssert(!Js::ScriptFunction::Is(jsFunction) || execContext->GetThreadContext()->TTDRootNestingCount != 0, "This will cause user code to execute and we need to add support for that as a top-level call source!!!!"); + //TTDAssert(!Js::VarIs(jsFunction) || execContext->GetThreadContext()->TTDRootNestingCount != 0, "This will cause user code to execute and we need to add support for that as a top-level call source!!!!"); // Js::Var res = nullptr; @@ -1064,9 +1064,9 @@ namespace TTD { JsRTCallFunctionAction* cfAction = GetInlineEventDataAs(evt); - if(Js::JavascriptFunction::Is(funcVar)) + if(Js::VarIs(funcVar)) { - Js::JavascriptString* displayName = Js::JavascriptFunction::FromVar(funcVar)->GetDisplayName(); + Js::JavascriptString* displayName = Js::VarTo(funcVar)->GetDisplayName(); alloc.CopyStringIntoWLength(displayName->GetString(), displayName->GetLength(), cfAction->FunctionName); } else @@ -1119,7 +1119,7 @@ namespace TTD Js::Var jsFunctionVar = InflateVarInReplay(executeContext, cfAction->ArgArray[0]); TTD_REPLAY_VALIDATE_INCOMING_FUNCTION(jsFunctionVar, ctx); - Js::JavascriptFunction *jsFunction = Js::JavascriptFunction::FromVar(jsFunctionVar); + Js::JavascriptFunction *jsFunction = Js::VarTo(jsFunctionVar); //remove implicit constructor function as first arg in callInfo and argument loop below Js::CallInfo callInfo((ushort)(cfAction->ArgCount - 1)); diff --git a/lib/Runtime/Debug/TTEventLog.cpp b/lib/Runtime/Debug/TTEventLog.cpp index bed5f8b54ed..185e69ba975 100644 --- a/lib/Runtime/Debug/TTEventLog.cpp +++ b/lib/Runtime/Debug/TTEventLog.cpp @@ -2420,9 +2420,9 @@ namespace TTD void EventLog::RecordJsRTRawBufferCopySync(TTDJsRTActionResultAutoRecorder& actionPopper, Js::Var dst, uint32 dstIndex, Js::Var src, uint32 srcIndex, uint32 length) { - TTDAssert(Js::ArrayBuffer::Is(dst) && Js::ArrayBuffer::Is(src), "Not array buffer objects!!!"); - TTDAssert(dstIndex + length <= Js::ArrayBuffer::FromVar(dst)->GetByteLength(), "Copy off end of buffer!!!"); - TTDAssert(srcIndex + length <= Js::ArrayBuffer::FromVar(src)->GetByteLength(), "Copy off end of buffer!!!"); + TTDAssert(Js::VarIs(dst) && Js::VarIs(src), "Not array buffer objects!!!"); + TTDAssert(dstIndex + length <= Js::VarTo(dst)->GetByteLength(), "Copy off end of buffer!!!"); + TTDAssert(srcIndex + length <= Js::VarTo(src)->GetByteLength(), "Copy off end of buffer!!!"); NSLogEvents::JsRTRawBufferCopyAction* rbcAction = nullptr; NSLogEvents::EventLogEntry* evt = this->RecordGetInitializedEvent(&rbcAction); @@ -2437,8 +2437,8 @@ namespace TTD void EventLog::RecordJsRTRawBufferModifySync(TTDJsRTActionResultAutoRecorder& actionPopper, Js::Var dst, uint32 index, uint32 count) { - TTDAssert(Js::ArrayBuffer::Is(dst), "Not array buffer object!!!"); - TTDAssert(index + count <= Js::ArrayBuffer::FromVar(dst)->GetByteLength(), "Copy off end of buffer!!!"); + TTDAssert(Js::VarIs(dst), "Not array buffer object!!!"); + TTDAssert(index + count <= Js::VarTo(dst)->GetByteLength(), "Copy off end of buffer!!!"); NSLogEvents::JsRTRawBufferModifyAction* rbmAction = nullptr; NSLogEvents::EventLogEntry* evt = this->RecordGetInitializedEvent(&rbmAction); @@ -2447,7 +2447,7 @@ namespace TTD rbmAction->Length = count; rbmAction->Data = (rbmAction->Length != 0) ? this->m_eventSlabAllocator.SlabAllocateArray(rbmAction->Length) : nullptr; - byte* copyBuff = Js::ArrayBuffer::FromVar(dst)->GetBuffer() + index; + byte* copyBuff = Js::VarTo(dst)->GetBuffer() + index; js_memcpy_s(rbmAction->Data, rbmAction->Length, copyBuff, count); actionPopper.InitializeWithEventAndEnter(evt); @@ -2465,7 +2465,7 @@ namespace TTD void EventLog::RecordJsRTRawBufferAsyncModifyComplete(TTDJsRTActionResultAutoRecorder& actionPopper, TTDPendingAsyncBufferModification& pendingAsyncInfo, byte* finalModPos) { - Js::ArrayBuffer* dstBuff = Js::ArrayBuffer::FromVar(pendingAsyncInfo.ArrayBufferVar); + Js::ArrayBuffer* dstBuff = Js::VarTo(pendingAsyncInfo.ArrayBufferVar); byte* copyBuff = dstBuff->GetBuffer() + pendingAsyncInfo.Index; NSLogEvents::JsRTRawBufferModifyAction* rbrAction = nullptr; diff --git a/lib/Runtime/Debug/TTEvents.cpp b/lib/Runtime/Debug/TTEvents.cpp index f823dfcf2d1..8d75f8e5d1d 100644 --- a/lib/Runtime/Debug/TTEvents.cpp +++ b/lib/Runtime/Debug/TTEvents.cpp @@ -23,7 +23,7 @@ namespace TTD if(replayVar != nullptr && TTD::JsSupport::IsVarPtrValued(replayVar)) { - Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(replayVar); + Js::RecyclableObject* obj = Js::VarTo(replayVar); executeContext->AddLocalRoot(TTD_CONVERT_OBJ_TO_LOG_PTR_ID(origVar), obj); } } diff --git a/lib/Runtime/Debug/TTEvents.h b/lib/Runtime/Debug/TTEvents.h index 8621221c27d..15777a15797 100644 --- a/lib/Runtime/Debug/TTEvents.h +++ b/lib/Runtime/Debug/TTEvents.h @@ -28,7 +28,7 @@ } #define TTD_REPLAY_MARSHAL_OBJECT(p, scriptContext) \ - Js::RecyclableObject* __obj = Js::RecyclableObject::FromVar(p); \ + Js::RecyclableObject* __obj = Js::VarTo(p); \ if (__obj->GetScriptContext() != scriptContext) \ { \ p = Js::CrossSite::MarshalVar(scriptContext, __obj); \ @@ -36,7 +36,7 @@ #define TTD_REPLAY_VALIDATE_INCOMING_REFERENCE(p, scriptContext) \ TTD_REPLAY_VALIDATE_JSREF(p); \ - if (Js::RecyclableObject::Is(p)) \ + if (Js::VarIs(p)) \ { \ TTD_REPLAY_MARSHAL_OBJECT(p, scriptContext) \ } @@ -64,7 +64,7 @@ #define TTD_REPLAY_VALIDATE_INCOMING_FUNCTION(p, scriptContext) \ { \ TTD_REPLAY_VALIDATE_JSREF(p); \ - if(!Js::JavascriptFunction::Is(p)) \ + if(!Js::VarIs(p)) \ { \ return; \ } \ @@ -272,7 +272,7 @@ namespace TTD //A struct that represents snapshot events struct SnapshotEventLogEntry { - //The timestamp we should restore to + //The timestamp we should restore to int64 RestoreTimestamp; //The snapshot (we many persist this to disk and inflate back in later) diff --git a/lib/Runtime/Debug/TTRuntimeInfoTracker.cpp b/lib/Runtime/Debug/TTRuntimeInfoTracker.cpp index a3f70e91e13..d7b4c3a66b9 100644 --- a/lib/Runtime/Debug/TTRuntimeInfoTracker.cpp +++ b/lib/Runtime/Debug/TTRuntimeInfoTracker.cpp @@ -24,7 +24,7 @@ namespace TTD ctx->InitializeDebugging(); #else // - //TODO: x-plat does not like some parts of initiallize debugging so just set the flag we need + //TODO: x-plat does not like some parts of initiallize debugging so just set the flag we need // ctx->GetDebugContext()->SetDebuggerMode(Js::DebuggerMode::Debugging); #endif @@ -48,7 +48,7 @@ namespace TTD : m_threadCtx(threadContext), m_runtimeHandle(runtimeHandle), m_contextCreatedOrDestoyedInReplay(false), SnapInterval(snapInterval), SnapHistoryLength(snapHistoryLength), m_activeContext(nullptr), m_contextList(&HeapAllocator::Instance), m_ttdContextToExternalRefMap(&HeapAllocator::Instance), - m_ttdRootTagToObjectMap(&HeapAllocator::Instance), m_ttdMayBeLongLivedRoot(&HeapAllocator::Instance), + m_ttdRootTagToObjectMap(&HeapAllocator::Instance), m_ttdMayBeLongLivedRoot(&HeapAllocator::Instance), m_ttdRecordRootWeakMap(),m_ttdReplayRootPinSet(), TTDataIOInfo({ 0 }), TTDExternalObjectFunctions({ 0 }) { @@ -274,7 +274,7 @@ namespace TTD } } - //Now sync up the root list wrt. long lived roots that we recorded + //Now sync up the root list wrt. long lived roots that we recorded JsUtil::BaseHashSet refInfoMap(&HeapAllocator::Instance); for(uint32 i = 0; i < liveRootCount; ++i) { @@ -351,7 +351,7 @@ namespace TTD for(int32 i = 0; i < this->m_ttdPendingAsyncModList.Count(); ++i) { const TTDPendingAsyncBufferModification& pi = this->m_ttdPendingAsyncModList.Item(i); - const Js::ArrayBuffer* pbuff = Js::ArrayBuffer::FromVar(pi.ArrayBufferVar); + const Js::ArrayBuffer* pbuff = Js::VarTo(pi.ArrayBufferVar); const byte* pbuffBegin = pbuff->GetBuffer() + pi.Index; const byte* pbuffMax = pbuff->GetBuffer() + pbuff->GetByteLength(); @@ -675,7 +675,7 @@ namespace TTD return wcscmp(p1->GetBuffer(), p2->GetBuffer()) > 0; } } - + RuntimeContextInfo::RuntimeContextInfo() : m_worklist(&HeapAllocator::Instance), m_nullString(), m_coreObjToPathMap(&HeapAllocator::Instance, TTD_CORE_OBJECT_COUNT), m_coreBodyToPathMap(&HeapAllocator::Instance, TTD_CORE_FUNCTION_BODY_COUNT), m_coreDbgScopeToPathMap(&HeapAllocator::Instance, TTD_CORE_FUNCTION_BODY_COUNT), @@ -774,7 +774,7 @@ namespace TTD this->EnqueueRootPathObject(_u("global"), ctx->GetGlobalObject()); this->EnqueueRootPathObject(_u("null"), ctx->GetLibrary()->GetNull()); - this->EnqueueRootPathObject(_u("undeclBlockVar"), Js::RecyclableObject::FromVar(ctx->GetLibrary()->GetUndeclBlockVar())); + this->EnqueueRootPathObject(_u("undeclBlockVar"), Js::VarTo(ctx->GetLibrary()->GetUndeclBlockVar())); this->EnqueueRootPathObject(_u("_defaultAccessor"), ctx->GetLibrary()->GetDefaultAccessorFunction()); @@ -833,14 +833,14 @@ namespace TTD { if(getter != nullptr && !Js::JavascriptOperators::IsUndefinedObject(getter)) { - TTDAssert(Js::JavascriptFunction::Is(getter), "The getter is not a function?"); + TTDAssert(Js::VarIs(getter), "The getter is not a function?"); this->EnqueueNewPathVarAsNeeded(curr, getter, precord, _u(">")); } if(setter != nullptr && !Js::JavascriptOperators::IsUndefinedObject(setter)) { - TTDAssert(Js::JavascriptFunction::Is(setter), "The setter is not a function?"); - this->EnqueueNewPathVarAsNeeded(curr, Js::RecyclableObject::FromVar(setter), precord, _u("<")); + TTDAssert(Js::VarIs(setter), "The setter is not a function?"); + this->EnqueueNewPathVarAsNeeded(curr, Js::VarTo(setter), precord, _u("<")); } } else @@ -854,9 +854,9 @@ namespace TTD } //shouldn't have any dynamic array valued properties - if(Js::DynamicType::Is(curr->GetTypeId())) + if(Js::DynamicType::Is(curr->GetTypeId())) { - Js::ArrayObject* parray = Js::DynamicObject::FromVar(curr)->GetObjectArray(); + Js::ArrayObject* parray = Js::VarTo(curr)->GetObjectArray(); if(parray != nullptr) { this->EnqueueNewPathVarAsNeeded(curr, parray, _u("_object_array_")); @@ -902,14 +902,14 @@ namespace TTD return; } - if(JsSupport::IsVarPrimitiveKind(val) && !Js::GlobalObject::Is(parent)) + if(JsSupport::IsVarPrimitiveKind(val) && !Js::VarIs(parent)) { return; //we keep primitives from global object only -- may need others but this is a simple way to start to get undefined, null, infy, etc. } - Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(val); + Js::RecyclableObject* obj = Js::VarTo(val); if(!this->m_coreObjToPathMap.ContainsKey(obj)) - { + { const UtilSupport::TTAutoString* ppath = this->m_coreObjToPathMap.Item(parent); this->m_worklist.Enqueue(obj); diff --git a/lib/Runtime/Debug/TTSerialize.cpp b/lib/Runtime/Debug/TTSerialize.cpp index a667fbc02ea..e1ae02577a1 100644 --- a/lib/Runtime/Debug/TTSerialize.cpp +++ b/lib/Runtime/Debug/TTSerialize.cpp @@ -1906,7 +1906,7 @@ namespace TTD this->AppendLiteral("null"); break; case Js::TypeIds_Boolean: - this->AppendBool(!!Js::JavascriptBoolean::FromVar(var)->GetValue()); + this->AppendBool(!!Js::VarTo(var)->GetValue()); break; case Js::TypeIds_Integer: this->AppendInteger(Js::TaggedInt::ToInt64(var)); @@ -1915,30 +1915,30 @@ namespace TTD this->AppendDouble(Js::JavascriptNumber::GetValue(var)); break; case Js::TypeIds_Int64Number: - this->AppendInteger(Js::JavascriptInt64Number::FromVar(var)->GetValue()); + this->AppendInteger(Js::VarTo(var)->GetValue()); break; case Js::TypeIds_UInt64Number: - this->AppendUnsignedInteger(Js::JavascriptUInt64Number::FromVar(var)->GetValue()); + this->AppendUnsignedInteger(Js::VarTo(var)->GetValue()); break; case Js::TypeIds_String: this->AppendLiteral("'"); if(!skipStringContents) { - if(Js::JavascriptString::FromVar(var)->GetLength() <= 40) + if(Js::VarTo(var)->GetLength() <= 40) { - this->AppendText(Js::JavascriptString::FromVar(var)->GetString(), Js::JavascriptString::FromVar(var)->GetLength()); + this->AppendText(Js::VarTo(var)->GetString(), Js::VarTo(var)->GetLength()); } else { - this->AppendText(Js::JavascriptString::FromVar(var)->GetString(), 40); + this->AppendText(Js::VarTo(var)->GetString(), 40); this->AppendLiteral("..."); - this->AppendInteger(Js::JavascriptString::FromVar(var)->GetLength()); + this->AppendInteger(Js::VarTo(var)->GetLength()); } } else { this->AppendLiteral("string@length="); - this->AppendInteger(Js::JavascriptString::FromVar(var)->GetLength()); + this->AppendInteger(Js::VarTo(var)->GetLength()); this->AppendLiteral("..."); } this->AppendLiteral("'"); @@ -1948,7 +1948,7 @@ namespace TTD #if ENABLE_OBJECT_SOURCE_TRACKING if(tid > Js::TypeIds_LastStaticType) { - const Js::DynamicObject* dynObj = Js::DynamicObject::FromVar(var); + const Js::DynamicObject* dynObj = Js::VarTo(var); if(!IsDiagnosticOriginInformationValid(dynObj->TTDDiagOriginInfo)) { this->AppendLiteral("*"); diff --git a/lib/Runtime/Debug/TTSnapObjects.cpp b/lib/Runtime/Debug/TTSnapObjects.cpp index a9864a4210e..ff99b29e0c9 100644 --- a/lib/Runtime/Debug/TTSnapObjects.cpp +++ b/lib/Runtime/Debug/TTSnapObjects.cpp @@ -110,13 +110,13 @@ namespace TTD Js::DynamicObject* ReuseObjectCheckAndReset(const SnapObject* snpObject, InflateMap* inflator) { Js::RecyclableObject* robj = inflator->FindReusableObjectIfExists(snpObject->ObjectPtrId); - if(robj == nullptr || Js::DynamicObject::FromVar(robj)->GetTypeId() != snpObject->SnapType->JsTypeId || Js::DynamicObject::FromVar(robj)->IsCrossSiteObject() != snpObject->IsCrossSite) + if(robj == nullptr || Js::VarTo(robj)->GetTypeId() != snpObject->SnapType->JsTypeId || Js::VarTo(robj)->IsCrossSiteObject() != snpObject->IsCrossSite) { return nullptr; } TTDAssert(Js::DynamicType::Is(robj->GetTypeId()), "You should only do this for dynamic objects!!!"); - Js::DynamicObject* dynObj = Js::DynamicObject::FromVar(robj); + Js::DynamicObject* dynObj = Js::VarTo(robj); return ObjectPropertyReset_General(snpObject, dynObj, inflator); } @@ -276,7 +276,7 @@ namespace TTD //Many protos are set at creation, don't mess with them if they are already correct if(snpObject->SnapType->PrototypeVar != nullptr) { - Js::RecyclableObject* protoObj = Js::RecyclableObject::FromVar(inflator->InflateTTDVar(snpObject->SnapType->PrototypeVar)); + Js::RecyclableObject* protoObj = Js::VarTo(inflator->InflateTTDVar(snpObject->SnapType->PrototypeVar)); if(obj->GetType()->GetPrototype() != protoObj) { obj->SetPrototype(protoObj); @@ -304,7 +304,7 @@ namespace TTD continue; } - TTDAssert(!Js::JavascriptProxy::Is(obj), "I didn't think proxies could have real properties directly on them."); + TTDAssert(!Js::VarIs(obj), "I didn't think proxies could have real properties directly on them."); Js::PropertyId pid = handler->PropertyInfoArray[i].PropertyRecordId; @@ -708,7 +708,7 @@ namespace TTD Js::Var res = nullptr; ctx->GetThreadContext()->TTDContext->TTDExternalObjectFunctions.pfCreateExternalObject(ctx, nullptr, &res); - return Js::RecyclableObject::FromVar(res); + return Js::VarTo(res); } } @@ -739,7 +739,7 @@ namespace TTD void DoAddtlValueInstantiation_SnapScriptFunctionInfo(const SnapObject* snpObject, Js::RecyclableObject* obj, InflateMap* inflator) { - Js::ScriptFunction* fobj = Js::ScriptFunction::FromVar(obj); + Js::ScriptFunction* fobj = Js::VarTo(obj); SnapScriptFunctionInfo* snapFuncInfo = SnapObjectGetAddtlInfoAs(snpObject); DoAddtlValueInstantiation_SnapScriptFunctionInfoEx(snapFuncInfo, fobj, inflator); } @@ -748,7 +748,7 @@ namespace TTD { if(snapFuncInfo->CachedScopeObjId != TTD_INVALID_PTR_ID) { - func->SetCachedScope(Js::ActivationObjectEx::FromVar(inflator->LookupObject(snapFuncInfo->CachedScopeObjId))); + func->SetCachedScope(Js::VarTo(inflator->LookupObject(snapFuncInfo->CachedScopeObjId))); } if(snapFuncInfo->HomeObjId != TTD_INVALID_PTR_ID) @@ -1801,7 +1801,7 @@ namespace TTD SnapTypedArrayInfo* typedArrayInfo = SnapObjectGetAddtlInfoAs(snpObject); Js::JavascriptLibrary* jslib = ctx->GetLibrary(); - Js::ArrayBuffer* arrayBuffer = Js::ArrayBuffer::FromVar(inflator->LookupObject(typedArrayInfo->ArrayBufferAddr)); + Js::ArrayBuffer* arrayBuffer = Js::VarTo(inflator->LookupObject(typedArrayInfo->ArrayBufferAddr)); Js::Var tab = nullptr; switch(snpObject->SnapType->JsTypeId) @@ -1850,7 +1850,7 @@ namespace TTD break; } - return Js::RecyclableObject::FromVar(tab); + return Js::VarTo(tab); } void EmitAddtlInfo_SnapTypedArrayInfo(const SnapObject* snpObject, FileWriter* writer) @@ -2337,7 +2337,7 @@ namespace TTD void DoAddtlValueInstantiation_SnapGeneratorFunctionInfo(const SnapObject *snpObject, Js::RecyclableObject *obj, InflateMap *inflator) { - Js::JavascriptGeneratorFunction *func = Js::JavascriptGeneratorFunction::FromVar(obj); + Js::JavascriptGeneratorFunction *func = Js::VarTo(obj); SnapGeneratorFunctionInfo *sfi = SnapObjectGetAddtlInfoAs(snpObject); if(sfi->scriptFunction != TTD_INVALID_PTR_ID) @@ -2379,7 +2379,7 @@ namespace TTD void DoAddtlValueInstantiation_SnapAsyncFunction(const SnapObject* snpObject, Js::RecyclableObject* obj, InflateMap* inflator) { - Js::JavascriptAsyncFunction* func = Js::JavascriptAsyncFunction::FromVar(obj); + Js::JavascriptAsyncFunction* func = Js::VarTo(obj); SnapGeneratorFunctionInfo* info = SnapObjectGetAddtlInfoAs(snpObject); if (info->scriptFunction != TTD_INVALID_PTR_ID) @@ -2538,7 +2538,7 @@ namespace TTD void DoAddtlValueInstantiation_SnapJavascriptPromiseAsyncSpawnStepArgumentExecutorFunctionInfo(const SnapObject* snpObject, Js::RecyclableObject* obj, InflateMap* inflator) { } - + void EmitAddtlInfo_SnapJavascriptPromiseAsyncSpawnStepArgumentExecutorFunctionInfo(const SnapObject* snpObject, FileWriter* writer) { SnapJavascriptPromiseAsyncSpawnStepArgumentExecutorFunctionInfo* info = SnapObjectGetAddtlInfoAs(snpObject); diff --git a/lib/Runtime/Debug/TTSnapObjects.h b/lib/Runtime/Debug/TTSnapObjects.h index 9bf131bbe08..3ac92d446e1 100644 --- a/lib/Runtime/Debug/TTSnapObjects.h +++ b/lib/Runtime/Debug/TTSnapObjects.h @@ -66,7 +66,7 @@ namespace TTD //The numeric indexed properties associated with the object (or invalid if no associated array) TTD_PTR_ID OptIndexedObjectArray; - //Objects this depends on when creating (or nullptr if no dependencies) + //Objects this depends on when creating (or nullptr if no dependencies) DependsOnInfo* OptDependsOnInfo; //A ptr for the remaining info which must be cast when needed by handler methods @@ -127,16 +127,16 @@ namespace TTD Js::DynamicObject* ObjectPropertyReset_WellKnown(const SnapObject* snpObject, Js::DynamicObject* dynObj, InflateMap* inflator); Js::DynamicObject* ObjectPropertyReset_General(const SnapObject* snpObject, Js::DynamicObject* dynObj, InflateMap* inflator); - //Set all the general properties for the object + //Set all the general properties for the object void StdPropertyRestore(const SnapObject* snpObject, Js::DynamicObject* obj, InflateMap* inflator); - //serialize the object data + //serialize the object data void EmitObject(const SnapObject* snpObject, FileWriter* writer, NSTokens::Separator separator, const SnapObjectVTable* vtable, ThreadContext* threadContext); //de-serialize a SnapObject void ParseObject(SnapObject* snpObject, bool readSeparator, FileReader* reader, SlabAllocator& alloc, const SnapObjectVTable* vtable, const TTDIdentifierDictionary& ptrIdToTypeMap); -#if ENABLE_SNAPSHOT_COMPARE +#if ENABLE_SNAPSHOT_COMPARE void AssertSnapEquiv(const SnapObject* sobj1, const SnapObject* sobj2, TTDCompareMap& compareMap); #endif @@ -190,7 +190,7 @@ namespace TTD void EmitAddtlInfo_SnapScriptFunctionInfoEx(const SnapScriptFunctionInfo* snapFuncInfo, FileWriter* writer); void ParseAddtlInfo_SnapScriptFunctionInfoEx(SnapScriptFunctionInfo* snapFuncInfo, FileReader* reader, SlabAllocator& alloc); -#if ENABLE_SNAPSHOT_COMPARE +#if ENABLE_SNAPSHOT_COMPARE void AssertSnapEquiv_SnapScriptFunctionInfo(const SnapObject* sobj1, const SnapObject* sobj2, TTDCompareMap& compareMap); #endif @@ -211,7 +211,7 @@ namespace TTD void EmitAddtlInfo_SnapExternalFunctionInfo(const SnapObject* snpObject, FileWriter* writer); void ParseAddtlInfo_SnapExternalFunctionInfo(SnapObject* snpObject, FileReader* reader, SlabAllocator& alloc); -#if ENABLE_SNAPSHOT_COMPARE +#if ENABLE_SNAPSHOT_COMPARE void AssertSnapEquiv_SnapExternalFunctionInfo(const SnapObject* sobj1, const SnapObject* sobj2, TTDCompareMap& compareMap); #endif @@ -223,7 +223,7 @@ namespace TTD void EmitAddtlInfo_SnapRevokerFunctionInfo(const SnapObject* snpObject, FileWriter* writer); void ParseAddtlInfo_SnapRevokerFunctionInfo(SnapObject* snpObject, FileReader* reader, SlabAllocator& alloc); -#if ENABLE_SNAPSHOT_COMPARE +#if ENABLE_SNAPSHOT_COMPARE void AssertSnapEquiv_SnapRevokerFunctionInfo(const SnapObject* sobj1, const SnapObject* sobj2, TTDCompareMap& compareMap); #endif @@ -251,7 +251,7 @@ namespace TTD void EmitAddtlInfo_SnapBoundFunctionInfo(const SnapObject* snpObject, FileWriter* writer); void ParseAddtlInfo_SnapBoundFunctionInfo(SnapObject* snpObject, FileReader* reader, SlabAllocator& alloc); -#if ENABLE_SNAPSHOT_COMPARE +#if ENABLE_SNAPSHOT_COMPARE void AssertSnapEquiv_SnapBoundFunctionInfo(const SnapObject* sobj1, const SnapObject* sobj2, TTDCompareMap& compareMap); #endif @@ -277,7 +277,7 @@ namespace TTD //number of arguments uint32 NumOfArguments; - //The frame object + //The frame object bool IsFrameNullPtr; TTD_PTR_ID FrameObject; @@ -375,7 +375,7 @@ namespace TTD TTDVar Result; // - //We have the reaction info's inline even theought we want to preserve their pointer identity when inflating. + //We have the reaction info's inline even theought we want to preserve their pointer identity when inflating. //So we duplicate data here but avoid needed to add more kinds to the mark/extract logic and will check on inflation. // @@ -391,7 +391,7 @@ namespace TTD void EmitAddtlInfo_SnapPromiseInfo(const SnapObject* snpObject, FileWriter* writer); void ParseAddtlInfo_SnapPromiseInfo(SnapObject* snpObject, FileReader* reader, SlabAllocator& alloc); -#if ENABLE_SNAPSHOT_COMPARE +#if ENABLE_SNAPSHOT_COMPARE void AssertSnapEquiv_SnapPromiseInfo(const SnapObject* sobj1, const SnapObject* sobj2, TTDCompareMap& compareMap); #endif @@ -412,7 +412,7 @@ namespace TTD void EmitAddtlInfo_SnapPromiseResolveOrRejectFunctionInfo(const SnapObject* snpObject, FileWriter* writer); void ParseAddtlInfo_SnapPromiseResolveOrRejectFunctionInfo(SnapObject* snpObject, FileReader* reader, SlabAllocator& alloc); -#if ENABLE_SNAPSHOT_COMPARE +#if ENABLE_SNAPSHOT_COMPARE void AssertSnapEquiv_SnapPromiseResolveOrRejectFunctionInfo(const SnapObject* sobj1, const SnapObject* sobj2, TTDCompareMap& compareMap); #endif @@ -430,7 +430,7 @@ namespace TTD void EmitAddtlInfo_SnapPromiseReactionTaskFunctionInfo(const SnapObject* snpObject, FileWriter* writer); void ParseAddtlInfo_SnapPromiseReactionTaskFunctionInfo(SnapObject* snpObject, FileReader* reader, SlabAllocator& alloc); -#if ENABLE_SNAPSHOT_COMPARE +#if ENABLE_SNAPSHOT_COMPARE void AssertSnapEquiv_SnapPromiseReactionTaskFunctionInfo(const SnapObject* sobj1, const SnapObject* sobj2, TTDCompareMap& compareMap); #endif @@ -453,7 +453,7 @@ namespace TTD void EmitAddtlInfo_SnapPromiseAllResolveElementFunctionInfo(const SnapObject* snpObject, FileWriter* writer); void ParseAddtlInfo_SnapPromiseAllResolveElementFunctionInfo(SnapObject* snpObject, FileReader* reader, SlabAllocator& alloc); -#if ENABLE_SNAPSHOT_COMPARE +#if ENABLE_SNAPSHOT_COMPARE void AssertSnapEquiv_SnapPromiseAllResolveElementFunctionInfo(const SnapObject* sobj1, const SnapObject* sobj2, TTDCompareMap& compareMap); #endif @@ -467,7 +467,7 @@ namespace TTD void EmitAddtlInfo_SnapBoxedValue(const SnapObject* snpObject, FileWriter* writer); void ParseAddtlInfo_SnapBoxedValue(SnapObject* snpObject, FileReader* reader, SlabAllocator& alloc); -#if ENABLE_SNAPSHOT_COMPARE +#if ENABLE_SNAPSHOT_COMPARE void AssertSnapEquiv_SnapBoxedValue(const SnapObject* sobj1, const SnapObject* sobj2, TTDCompareMap& compareMap); #endif @@ -479,7 +479,7 @@ namespace TTD void EmitAddtlInfo_SnapDate(const SnapObject* snpObject, FileWriter* writer); void ParseAddtlInfo_SnapDate(SnapObject* snpObject, FileReader* reader, SlabAllocator& alloc); -#if ENABLE_SNAPSHOT_COMPARE +#if ENABLE_SNAPSHOT_COMPARE void AssertSnapEquiv_SnapDate(const SnapObject* sobj1, const SnapObject* sobj2, TTDCompareMap& compareMap); #endif @@ -507,7 +507,7 @@ namespace TTD void EmitAddtlInfo_SnapRegexInfo(const SnapObject* snpObject, FileWriter* writer); void ParseAddtlInfo_SnapRegexInfo(SnapObject* snpObject, FileReader* reader, SlabAllocator& alloc); -#if ENABLE_SNAPSHOT_COMPARE +#if ENABLE_SNAPSHOT_COMPARE void AssertSnapEquiv_SnapRegexInfo(const SnapObject* sobj1, const SnapObject* sobj2, TTDCompareMap& compareMap); #endif @@ -632,7 +632,7 @@ namespace TTD void SnapArrayInfo_EmitValue(TTDVar value, FileWriter* writer); void SnapArrayInfo_ParseValue(TTDVar* into, FileReader* reader, SlabAllocator& alloc); -#if ENABLE_SNAPSHOT_COMPARE +#if ENABLE_SNAPSHOT_COMPARE void SnapArrayInfo_EquivValue(int32 val1, int32 val2, TTDCompareMap& compareMap, int32 i); void SnapArrayInfo_EquivValue(double val1, double val2, TTDCompareMap& compareMap, int32 i); void SnapArrayInfo_EquivValue(TTDVar val1, TTDVar val2, TTDCompareMap& compareMap, int32 i); @@ -669,7 +669,7 @@ namespace TTD Js::DynamicObject* rcObj = ReuseObjectCheckAndReset(snpObject, inflator); if(rcObj != nullptr) { - Js::JavascriptArray::FromVar(rcObj)->SetLength(preAllocSpace); + Js::VarTo(rcObj)->SetLength(preAllocSpace); return rcObj; } else diff --git a/lib/Runtime/Debug/TTSnapValues.cpp b/lib/Runtime/Debug/TTSnapValues.cpp index 8e1f2160309..ef57bdc147a 100644 --- a/lib/Runtime/Debug/TTSnapValues.cpp +++ b/lib/Runtime/Debug/TTSnapValues.cpp @@ -29,7 +29,7 @@ namespace TTD return false; } - Js::TypeId tid = Js::RecyclableObject::FromVar(v)->GetTypeId(); + Js::TypeId tid = Js::VarTo(v)->GetTypeId(); return tid <= Js::TypeIds_LastToPrimitiveType; } @@ -40,7 +40,7 @@ namespace TTD return false; } - Js::TypeId tid = Js::RecyclableObject::FromVar(v)->GetTypeId(); + Js::TypeId tid = Js::VarTo(v)->GetTypeId(); return tid > Js::TypeIds_LastToPrimitiveType; } @@ -332,20 +332,20 @@ namespace TTD case Js::TypeIds_Null: break; case Js::TypeIds_Boolean: - snapValue->u_boolValue = Js::JavascriptBoolean::FromVar(jsValue)->GetValue(); + snapValue->u_boolValue = Js::VarTo(jsValue)->GetValue(); break; case Js::TypeIds_Number: snapValue->u_doubleValue = Js::JavascriptNumber::GetValue(jsValue); break; case Js::TypeIds_Int64Number: - snapValue->u_int64Value = Js::JavascriptInt64Number::FromVar(jsValue)->GetValue(); + snapValue->u_int64Value = Js::VarTo(jsValue)->GetValue(); break; case Js::TypeIds_UInt64Number: - snapValue->u_uint64Value = Js::JavascriptUInt64Number::FromVar(jsValue)->GetValue(); + snapValue->u_uint64Value = Js::VarTo(jsValue)->GetValue(); break; case Js::TypeIds_String: snapValue->u_stringValue = alloc.SlabAllocateStruct(); - alloc.CopyStringIntoWLength(Js::JavascriptString::FromVar(jsValue)->GetString(), Js::JavascriptString::FromVar(jsValue)->GetLength(), *(snapValue->u_stringValue)); + alloc.CopyStringIntoWLength(Js::VarTo(jsValue)->GetString(), Js::VarTo(jsValue)->GetLength(), *(snapValue->u_stringValue)); break; case Js::TypeIds_Symbol: snapValue->u_propertyIdValue = jslib->ExtractPrimitveSymbolId_TTD(jsValue); @@ -409,7 +409,7 @@ namespace TTD } } - inflator->AddObject(snapValue->PrimitiveValueId, Js::RecyclableObject::FromVar(res)); + inflator->AddObject(snapValue->PrimitiveValueId, Js::VarTo(res)); } void EmitSnapPrimitiveValue(const SnapPrimitiveValue* snapValue, FileWriter* writer, NSTokens::Separator separator) @@ -1653,7 +1653,7 @@ namespace TTD for(int32 k = 0; k < pendingAsyncList.Count(); ++k) { const TTDPendingAsyncBufferModification& pk = pendingAsyncList.Item(k); - snapCtx->PendingAsyncModArray[k].LogId = objToLogIdMap.Item(Js::RecyclableObject::FromVar(pk.ArrayBufferVar)); + snapCtx->PendingAsyncModArray[k].LogId = objToLogIdMap.Item(Js::VarTo(pk.ArrayBufferVar)); snapCtx->PendingAsyncModArray[k].Index = pk.Index; } } @@ -1762,8 +1762,8 @@ namespace TTD Js::RecyclableObject* buff = intoCtx->GetThreadContext()->TTDContext->LookupObjectForLogID(snpCtx->PendingAsyncModArray[i].LogId); uint32 index = snpCtx->PendingAsyncModArray[i].Index; - TTDAssert(Js::ArrayBuffer::Is(buff), "Not an ArrayBuffer!!!"); - intoCtx->TTDContextInfo->AddToAsyncPendingList(Js::ArrayBuffer::FromVar(buff), index); + TTDAssert(Js::VarIs(buff), "Not an ArrayBuffer!!!"); + intoCtx->TTDContextInfo->AddToAsyncPendingList(Js::VarTo(buff), index); } } diff --git a/lib/Runtime/Debug/TTSnapshot.cpp b/lib/Runtime/Debug/TTSnapshot.cpp index c5bdb582b66..8a134d69143 100644 --- a/lib/Runtime/Debug/TTSnapshot.cpp +++ b/lib/Runtime/Debug/TTSnapshot.cpp @@ -210,7 +210,7 @@ namespace TTD res = ctx->TTDWellKnownInfo->LookupKnownObjectFromPath(snpObject->OptWellKnownToken); //Well known objects may always be dirty (e.g. we are re-using a context) so we always want to clean them - res = NSSnapObjects::ObjectPropertyReset_WellKnown(snpObject, Js::DynamicObject::FromVar(res), inflator); + res = NSSnapObjects::ObjectPropertyReset_WellKnown(snpObject, Js::VarTo(res), inflator); TTDAssert(res != nullptr, "Should always produce a result!!!"); } else @@ -229,7 +229,7 @@ namespace TTD if(Js::DynamicType::Is(snpObject->SnapType->JsTypeId)) { //Always ok to be x-site but if snap was x-site then we must be too - Js::DynamicObject* dynObj = Js::DynamicObject::FromVar(res); + Js::DynamicObject* dynObj = Js::VarTo(res); if(snpObject->IsCrossSite && !dynObj->IsCrossSiteObject()) { Js::CrossSite::MarshalCrossSite_TTDInflate(dynObj); @@ -518,7 +518,7 @@ namespace TTD if(snpObj->OptWellKnownToken != TTD_INVALID_WELLKNOWN_TOKEN) { Js::RecyclableObject* rObj = inflator->FindReusableObject_WellKnowReuseCheck(snpObj->ObjectPtrId); - bool blocking = NSSnapObjects::DoesObjectBlockScriptContextReuse(snpObj, Js::DynamicObject::FromVar(rObj), inflator); + bool blocking = NSSnapObjects::DoesObjectBlockScriptContextReuse(snpObj, Js::VarTo(rObj), inflator); if(blocking) { @@ -609,7 +609,7 @@ namespace TTD if(Js::DynamicType::Is(sobj->SnapType->JsTypeId)) { - NSSnapObjects::StdPropertyRestore(sobj, Js::DynamicObject::FromVar(iobj), inflator); + NSSnapObjects::StdPropertyRestore(sobj, Js::VarTo(iobj), inflator); } } diff --git a/lib/Runtime/Debug/TTSnapshotExtractor.cpp b/lib/Runtime/Debug/TTSnapshotExtractor.cpp index 5217bedb169..6decdcd00a2 100644 --- a/lib/Runtime/Debug/TTSnapshotExtractor.cpp +++ b/lib/Runtime/Debug/TTSnapshotExtractor.cpp @@ -40,7 +40,7 @@ namespace TTD if(Js::DynamicType::Is(obj->GetTypeId())) { - Js::DynamicObject* dynObj = Js::DynamicObject::FromVar(obj); + Js::DynamicObject* dynObj = Js::VarTo(obj); dynObj->GetDynamicType()->GetTypeHandler()->MarkObjectSlots_TTD(this, dynObj); @@ -247,7 +247,7 @@ namespace TTD void SnapshotExtractor::MarkVisitVar(Js::Var var) { TTDAssert(var != nullptr, "I don't think this should happen but not 100% sure."); - TTDAssert(Js::JavascriptOperators::GetTypeId(var) < Js::TypeIds_Limit || Js::RecyclableObject::FromVar(var)->IsExternal(), "Not cool."); + TTDAssert(Js::JavascriptOperators::GetTypeId(var) < Js::TypeIds_Limit || Js::VarTo(var)->IsExternal(), "Not cool."); //We don't need to visit tagged things if(JsSupport::IsVarTaggedInline(var)) @@ -259,7 +259,7 @@ namespace TTD { if(this->m_marks.MarkAndTestAddr(var)) { - Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(var); + Js::RecyclableObject* obj = Js::VarTo(var); this->MarkVisitType(obj->GetType()); } } @@ -269,12 +269,12 @@ namespace TTD if(this->m_marks.MarkAndTestAddr(var)) { - Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(var); + Js::RecyclableObject* obj = Js::VarTo(var); //do this here instead of in mark visit type as it wants the dynamic object as well if(Js::DynamicType::Is(obj->GetTypeId())) { - Js::DynamicObject* dynObj = Js::DynamicObject::FromVar(obj); + Js::DynamicObject* dynObj = Js::VarTo(obj); if(dynObj->GetDynamicType()->GetTypeHandler()->IsDeferredTypeHandler()) { dynObj->GetDynamicType()->GetTypeHandler()->EnsureObjectReady(dynObj); @@ -476,7 +476,7 @@ namespace TTD case MarkTableTag::CompoundObjectTag: { this->ExtractTypeIfNeeded(this->m_marks.GetPtrValue()->GetType(), threadContext); - if(Js::ScriptFunction::Is(this->m_marks.GetPtrValue())) + if(Js::VarIs(this->m_marks.GetPtrValue())) { this->ExtractScriptFunctionEnvironmentIfNeeded(this->m_marks.GetPtrValue()); } diff --git a/lib/Runtime/Language/AsmJsLink.cpp b/lib/Runtime/Language/AsmJsLink.cpp index 982bd726bac..ba794b0ef0f 100644 --- a/lib/Runtime/Language/AsmJsLink.cpp +++ b/lib/Runtime/Language/AsmJsLink.cpp @@ -15,7 +15,7 @@ namespace Js{ return true; } - if (!JavascriptArrayBuffer::Is(bufferView)) + if (!VarIs(bufferView)) { AsmJSCompiler::OutputError(scriptContext, _u("Asm.js Runtime Error : Buffer parameter is not an Array buffer")); return false; @@ -42,12 +42,12 @@ namespace Js{ return true; } Assert(foreign); - if (!RecyclableObject::Is(foreign)) + if (!VarIs(foreign)) { AsmJSCompiler::OutputError(scriptContext, _u("Asm.js Runtime Error : FFI is not an object")); return false; } - TypeId foreignObjType = RecyclableObject::FromVar(foreign)->GetTypeId(); + TypeId foreignObjType = VarTo(foreign)->GetTypeId(); if (StaticType::Is(foreignObjType) || TypeIds_Proxy == foreignObjType) { AsmJSCompiler::OutputError(scriptContext, _u("Asm.js Runtime Error : FFI is not an object")); @@ -69,12 +69,12 @@ namespace Js{ return true; } Assert(stdlib); - if (!RecyclableObject::Is(stdlib)) + if (!VarIs(stdlib)) { AsmJSCompiler::OutputError(scriptContext, _u("Asm.js Runtime Error : StdLib is not an object")); return false; } - TypeId stdLibObjType = RecyclableObject::FromVar(stdlib)->GetTypeId(); + TypeId stdLibObjType = VarTo(stdlib)->GetTypeId(); if (StaticType::Is(stdLibObjType) || TypeIds_Proxy == stdLibObjType) { AsmJSCompiler::OutputError(scriptContext, _u("Asm.js Runtime Error : StdLib is not an object")); @@ -143,14 +143,14 @@ namespace Js{ { case AsmJSTypedArrayBuiltinFunction::AsmJSTypedArrayBuiltin_byteLength: arrayFuncObj = JavascriptOperators::OP_GetProperty(stdlib, PropertyIds::byteLength, scriptContext); - if (JavascriptFunction::Is(arrayFuncObj)) + if (VarIs(arrayFuncObj)) { JavascriptFunction* arrayLibFunc = (JavascriptFunction*)arrayFuncObj; if (arrayLibFunc->IsBoundFunction()) { BoundFunction* boundFunc = (BoundFunction*)arrayLibFunc; RecyclableObject* thisObj = boundFunc->GetBoundThis(); - if (JavascriptFunction::Is(thisObj)) + if (VarIs(thisObj)) { JavascriptFunction * thisFunc = (JavascriptFunction*)thisObj; if (thisFunc->GetFunctionInfo()->GetOriginalEntryPoint() != (&ArrayBuffer::EntryInfo::GetterByteLength)->GetOriginalEntryPoint()) @@ -191,8 +191,8 @@ namespace Js{ bool ASMLink::CheckIsBuiltinFunction(ScriptContext* scriptContext, const Var object, PropertyId propertyId, const FunctionInfo& funcInfo) { Var mathFuncObj = JavascriptOperators::OP_GetProperty(object, propertyId, scriptContext); - return JavascriptFunction::Is(mathFuncObj) && - JavascriptFunction::FromVar(mathFuncObj)->GetFunctionInfo()->GetOriginalEntryPoint() == funcInfo.GetOriginalEntryPoint(); + return VarIs(mathFuncObj) && + VarTo(mathFuncObj)->GetFunctionInfo()->GetOriginalEntryPoint() == funcInfo.GetOriginalEntryPoint(); } bool ASMLink::CheckIsBuiltinValue(ScriptContext* scriptContext, const Var object, PropertyId propertyId, double value) diff --git a/lib/Runtime/Language/AsmJsModule.cpp b/lib/Runtime/Language/AsmJsModule.cpp index 799cae79c8f..d418802b75b 100644 --- a/lib/Runtime/Language/AsmJsModule.cpp +++ b/lib/Runtime/Language/AsmJsModule.cpp @@ -1727,9 +1727,9 @@ namespace Js void AsmJsModuleInfo::EnsureHeapAttached(ScriptFunction * func) { #ifdef ENABLE_WASM - if (WasmScriptFunction::Is(func)) + if (VarIs(func)) { - WasmScriptFunction* wasmFunc = WasmScriptFunction::FromVar(func); + WasmScriptFunction* wasmFunc = VarTo(func); WebAssemblyMemory * wasmMem = wasmFunc->GetWebAssemblyMemory(); if (wasmMem && wasmMem->GetBuffer() && wasmMem->GetBuffer()->IsDetached()) { @@ -1739,7 +1739,7 @@ namespace Js else #endif { - AsmJsScriptFunction* asmFunc = AsmJsScriptFunction::FromVar(func); + AsmJsScriptFunction* asmFunc = VarTo(func); ArrayBuffer* moduleArrayBuffer = asmFunc->GetAsmJsArrayBuffer(); if (moduleArrayBuffer && moduleArrayBuffer->IsDetached()) { @@ -1761,7 +1761,7 @@ namespace Js // AsmJsModuleEnvironment is all laid out here Var * asmJsEnvironment = static_cast(env); Var * asmBufferPtr = asmJsEnvironment + asmModuleInfo->GetModuleMemory().mArrayBufferOffset; - ArrayBuffer * asmBuffer = *asmBufferPtr ? ArrayBuffer::FromVar(*asmBufferPtr) : nullptr; + ArrayBuffer * asmBuffer = *asmBufferPtr ? VarTo(*asmBufferPtr) : nullptr; Var stdLibObj = *(asmJsEnvironment + asmModuleInfo->GetModuleMemory().mStdLibOffset); Var asmMathObject = stdLibObj ? JavascriptOperators::OP_GetProperty(stdLibObj, PropertyIds::Math, scriptContext) : nullptr; diff --git a/lib/Runtime/Language/AsmJsUtils.cpp b/lib/Runtime/Language/AsmJsUtils.cpp index d5431d3a14f..310a6ab8d8c 100644 --- a/lib/Runtime/Language/AsmJsUtils.cpp +++ b/lib/Runtime/Language/AsmJsUtils.cpp @@ -152,7 +152,7 @@ namespace Js #if ENABLE_DEBUG_CONFIG_OPTIONS int64 ConvertStringToInt64(Var string, ScriptContext* scriptContext) { - JavascriptString* str = JavascriptString::FromVar(string); + JavascriptString* str = VarTo(string); charcount_t length = str->GetLength(); const char16* buf = str->GetString(); int radix = 10; @@ -197,7 +197,7 @@ namespace Js if (i < actualArgCount) { #if ENABLE_DEBUG_CONFIG_OPTIONS - if (allowTestInputs && JavascriptString::Is(*origArgs)) + if (allowTestInputs && VarIs(*origArgs)) { intVal = (int32)ConvertStringToInt64(*origArgs, scriptContext); } @@ -229,13 +229,13 @@ namespace Js int64 val; if (i < actualArgCount) { - if (JavascriptString::Is(*origArgs)) + if (VarIs(*origArgs)) { val = ConvertStringToInt64(*origArgs, scriptContext); } - else if (JavascriptObject::Is(*origArgs)) + else if (DynamicObject::IsBaseDynamicObject(*origArgs)) { - RecyclableObject* object = RecyclableObject::FromVar(*origArgs); + RecyclableObject* object = VarTo(*origArgs); PropertyRecord const * lowPropRecord = nullptr; PropertyRecord const * highPropRecord = nullptr; scriptContext->GetOrAddPropertyRecord(_u("low"), (int)wcslen(_u("low")), &lowPropRecord); @@ -268,7 +268,7 @@ namespace Js if (i < actualArgCount) { #if ENABLE_DEBUG_CONFIG_OPTIONS - if (allowTestInputs && JavascriptString::Is(*origArgs)) + if (allowTestInputs && VarIs(*origArgs)) { int32 val = (int32)ConvertStringToInt64(*origArgs, scriptContext); floatVal = *(float*)&val; @@ -293,7 +293,7 @@ namespace Js if (i < actualArgCount) { #if ENABLE_DEBUG_CONFIG_OPTIONS - if (allowTestInputs && JavascriptString::Is(*origArgs)) + if (allowTestInputs && VarIs(*origArgs)) { int64 val = ConvertStringToInt64(*origArgs, scriptContext); doubleVal = *(double*)&val; diff --git a/lib/Runtime/Language/CacheOperators.cpp b/lib/Runtime/Language/CacheOperators.cpp index 6f04d1de4db..4e1062a62e9 100644 --- a/lib/Runtime/Language/CacheOperators.cpp +++ b/lib/Runtime/Language/CacheOperators.cpp @@ -35,7 +35,7 @@ namespace Js PropertyIndex propertyIndex = info->GetPropertyIndex(); Assert(propertyIndex == objectWithProperty->GetPropertyIndex(propertyId) || - (RootObjectBase::Is(objectWithProperty) && propertyIndex == RootObjectBase::FromVar(objectWithProperty)->GetRootPropertyIndex(propertyId))); + (VarIs(objectWithProperty) && propertyIndex == VarTo(objectWithProperty)->GetRootPropertyIndex(propertyId))); Assert(DynamicType::Is(objectWithProperty->GetTypeId())); #if ENABLE_FIXED_FIELDS @@ -44,7 +44,7 @@ namespace Js Assert(info->IsNoCache() || !info->IsStoreFieldCacheEnabled() || info->GetInstance() != objectWithProperty || !objectWithProperty->IsFixedProperty(propertyId)); #endif - DynamicObject * dynamicObjectWithProperty = DynamicObject::FromVar(objectWithProperty); + DynamicObject * dynamicObjectWithProperty = VarTo(objectWithProperty); PropertyIndex slotIndex; bool isInlineSlot; dynamicObjectWithProperty->GetDynamicType()->GetTypeHandler()->PropertyIndexToInlineOrAuxSlotIndex(propertyIndex, &slotIndex, &isInlineSlot); @@ -57,8 +57,8 @@ namespace Js } else if( PropertyValueInfo::PrototypeCacheDisabled((PropertyValueInfo*)info) || - !RecyclableObject::Is(startingObject) || - RecyclableObject::UnsafeFromVar(startingObject)->GetScriptContext() != requestContext) + !VarIs(startingObject) || + UnsafeVarTo(startingObject)->GetScriptContext() != requestContext) { // Don't need to cache if the beginning property is number etc. return; @@ -80,7 +80,7 @@ namespace Js isProto, dynamicObjectWithProperty, isRoot, - RecyclableObject::FromVar(startingObject)->GetType(), + VarTo(startingObject)->GetType(), nullptr, propertyId, slotIndex, @@ -116,7 +116,7 @@ namespace Js Assert(DynamicType::Is(info->GetInstance()->GetTypeId())); - DynamicObject * dynamicInstance = DynamicObject::FromVar(info->GetInstance()); + DynamicObject * dynamicInstance = VarTo(info->GetInstance()); PropertyIndex slotIndex; bool isInlineSlot; dynamicInstance->GetDynamicType()->GetTypeHandler()->PropertyIndexToInlineOrAuxSlotIndex(info->GetPropertyIndex(), &slotIndex, &isInlineSlot); @@ -197,12 +197,12 @@ namespace Js } Assert((!isRoot && propertyIndex == object->GetPropertyIndex(propertyId)) || isSetter || - (isRoot && propertyIndex == RootObjectBase::FromVar(object)->GetRootPropertyIndex(propertyId))); + (isRoot && propertyIndex == VarTo(object)->GetRootPropertyIndex(propertyId))); Assert(DynamicType::Is(object->GetTypeId())); AssertMsg((info->GetFlags() & InlineCacheGetterFlag) == 0, "invalid getter for CachePropertyWrite"); RecyclableObject* instance = info->GetInstance(); - DynamicObject * dynamicInstance = DynamicObject::FromVar(instance); + DynamicObject * dynamicInstance = VarTo(instance); PropertyIndex slotIndex; bool isInlineSlot; dynamicInstance->GetDynamicType()->GetTypeHandler()->PropertyIndexToInlineOrAuxSlotIndex(propertyIndex, &slotIndex, &isInlineSlot); @@ -283,7 +283,7 @@ namespace Js Cache( false, - DynamicObject::FromVar(object), + VarTo(object), isRoot, object->GetType(), typeWithoutProperty, diff --git a/lib/Runtime/Language/CacheOperators.inl b/lib/Runtime/Language/CacheOperators.inl index fd93341aba6..fa4d177bcfb 100644 --- a/lib/Runtime/Language/CacheOperators.inl +++ b/lib/Runtime/Language/CacheOperators.inl @@ -350,7 +350,7 @@ namespace Js } // Before allowing proxies to cache, we would need to solve various issues (see JavascriptProxy::GetPropertyQuery). - Assert(!JavascriptProxy::Is(objectWithProperty)); + Assert(!VarIs(objectWithProperty)); } else { @@ -363,13 +363,13 @@ namespace Js // Built-in Function.prototype properties 'length', 'arguments', and 'caller' are special cases. Assert( objectWithProperty->IsWritable(propertyId) || - (isRoot && RootObjectBase::FromVar(objectWithProperty)->IsLetConstGlobal(propertyId)) || + (isRoot && VarTo(objectWithProperty)->IsLetConstGlobal(propertyId)) || JavascriptFunction::IsBuiltinProperty(objectWithProperty, propertyId)); } - const bool includeTypePropertyCache = - IncludeTypePropertyCache && - !isRoot && + const bool includeTypePropertyCache = + IncludeTypePropertyCache && + !isRoot && (info->GetFunctionBody() ? !PHASE_OFF(Js::TypePropertyCachePhase, info->GetFunctionBody()) : !PHASE_OFF1(Js::TypePropertyCachePhase) diff --git a/lib/Runtime/Language/DynamicProfileInfo.cpp b/lib/Runtime/Language/DynamicProfileInfo.cpp index 597c8e3ac94..67c3bc421a6 100644 --- a/lib/Runtime/Language/DynamicProfileInfo.cpp +++ b/lib/Runtime/Language/DynamicProfileInfo.cpp @@ -387,7 +387,7 @@ namespace Js return true; }; - FunctionInfo* calleeFunctionInfo = callee->GetTypeId() == TypeIds_Function ? JavascriptFunction::FromVar(callee)->GetFunctionInfo() : nullptr; + FunctionInfo* calleeFunctionInfo = callee->GetTypeId() == TypeIds_Function ? VarTo(callee)->GetFunctionInfo() : nullptr; if (calleeFunctionInfo == nullptr) { return false; @@ -434,12 +434,12 @@ namespace Js return; } - if (arg != nullptr && RecyclableObject::Is(arg) && JavascriptFunction::Is(arg)) + if (arg != nullptr && VarIs(arg) && VarIs(arg)) { CallbackInfo * callbackInfo = EnsureCallbackInfo(functionBody, callSiteId); if (callbackInfo->sourceId == NoSourceId) { - JavascriptFunction * callback = JavascriptFunction::UnsafeFromVar(arg); + JavascriptFunction * callback = UnsafeVarTo(arg); GetSourceAndFunctionId(functionBody, callback->GetFunctionInfo(), callback, &callbackInfo->sourceId, &callbackInfo->functionId); callbackInfo->argNumber = argNum; } @@ -453,7 +453,7 @@ namespace Js { Js::SourceId sourceId; Js::LocalFunctionId functionId; - JavascriptFunction * callback = JavascriptFunction::UnsafeFromVar(arg); + JavascriptFunction * callback = UnsafeVarTo(arg); GetSourceAndFunctionId(functionBody, callback->GetFunctionInfo(), callback, &sourceId, &functionId); if (sourceId != callbackInfo->sourceId || functionId != callbackInfo->functionId) diff --git a/lib/Runtime/Language/InlineCache.cpp b/lib/Runtime/Language/InlineCache.cpp index 15a6bf19624..37f43d662bb 100644 --- a/lib/Runtime/Language/InlineCache.cpp +++ b/lib/Runtime/Language/InlineCache.cpp @@ -322,12 +322,12 @@ namespace Js if (type == u.accessor.type) { - *callee = RecyclableObject::FromVar(DynamicObject::FromVar(object)->GetInlineSlot(u.accessor.slotIndex)); + *callee = VarTo(VarTo(object)->GetInlineSlot(u.accessor.slotIndex)); return true; } else if (taggedType == u.accessor.type) { - *callee = RecyclableObject::FromVar(DynamicObject::FromVar(object)->GetAuxSlot(u.accessor.slotIndex)); + *callee = VarTo(VarTo(object)->GetAuxSlot(u.accessor.slotIndex)); return true; } } @@ -344,19 +344,19 @@ namespace Js { if (type == u.local.type) { - const Var objectAtInlineSlot = DynamicObject::FromVar(obj)->GetInlineSlot(u.local.slotIndex); + const Var objectAtInlineSlot = VarTo(obj)->GetInlineSlot(u.local.slotIndex); if (!Js::TaggedNumber::Is(objectAtInlineSlot)) { - *callee = RecyclableObject::FromVar(objectAtInlineSlot); + *callee = VarTo(objectAtInlineSlot); return true; } } else if (taggedType == u.local.type) { - const Var objectAtAuxSlot = DynamicObject::FromVar(obj)->GetAuxSlot(u.local.slotIndex); + const Var objectAtAuxSlot = VarTo(obj)->GetAuxSlot(u.local.slotIndex); if (!Js::TaggedNumber::Is(objectAtAuxSlot)) { - *callee = RecyclableObject::FromVar(DynamicObject::FromVar(obj)->GetAuxSlot(u.local.slotIndex)); + *callee = VarTo(VarTo(obj)->GetAuxSlot(u.local.slotIndex)); return true; } } @@ -369,7 +369,7 @@ namespace Js const Var objectAtInlineSlot = u.proto.prototypeObject->GetInlineSlot(u.proto.slotIndex); if (!Js::TaggedNumber::Is(objectAtInlineSlot)) { - *callee = RecyclableObject::FromVar(objectAtInlineSlot); + *callee = VarTo(objectAtInlineSlot); return true; } } @@ -378,7 +378,7 @@ namespace Js const Var objectAtAuxSlot = u.proto.prototypeObject->GetAuxSlot(u.proto.slotIndex); if (!Js::TaggedNumber::Is(objectAtAuxSlot)) { - *callee = RecyclableObject::FromVar(objectAtAuxSlot); + *callee = VarTo(objectAtAuxSlot); return true; } } @@ -468,7 +468,7 @@ namespace Js { isUseFixedProperty = propertyOwnerTypeHandler->TryUseFixedAccessor(methodPropertyRecord, &fixedMethod, Js::FixedPropertyKind::FixedAccessorProperty, this->IsGetterAccessor(), functionBody->GetScriptContext()); } - AssertMsg(fixedMethod == nullptr || Js::JavascriptFunction::Is(fixedMethod), "The fixed value should have been a Method !!!"); + AssertMsg(fixedMethod == nullptr || Js::VarIs(fixedMethod), "The fixed value should have been a Method !!!"); *pFixedMethod = reinterpret_cast(fixedMethod); return isUseFixedProperty; } @@ -1181,7 +1181,7 @@ namespace Js Assert(function != NULL); if (this->function == function && - this->type == RecyclableObject::FromVar(instance)->GetType()) + this->type == VarTo(instance)->GetType()) { if (result != nullptr) { @@ -1222,7 +1222,7 @@ namespace Js this->Set(instanceType, function, result); } } - + /* static */ uint32 IsInstInlineCache::OffsetOfFunction() { diff --git a/lib/Runtime/Language/InlineCache.h b/lib/Runtime/Language/InlineCache.h index 51718a448ab..6513cea0775 100644 --- a/lib/Runtime/Language/InlineCache.h +++ b/lib/Runtime/Language/InlineCache.h @@ -430,11 +430,11 @@ namespace Js RecyclableObject * function; if (cache->u.accessor.isOnProto) { - function = RecyclableObject::UnsafeFromVar(cache->GetPropertyValue(cache->u.accessor.object, cache->u.accessor.slotIndex)); + function = UnsafeVarTo(cache->GetPropertyValue(cache->u.accessor.object, cache->u.accessor.slotIndex)); } else { - function = RecyclableObject::UnsafeFromVar(cache->GetPropertyValue(DynamicObject::UnsafeFromVar(propertyObject), cache->u.accessor.slotIndex)); + function = UnsafeVarTo(cache->GetPropertyValue(UnsafeVarTo(propertyObject), cache->u.accessor.slotIndex)); } *propertyValue = JavascriptOperators::CallGetter(function, instance, requestContext); @@ -460,7 +460,7 @@ namespace Js *propertyValue = InlineCache::GetPropertyValue(cache->GetSourceObject(propertyObject), cache->GetSlotIndex()); DebugOnly(Var getPropertyValue = JavascriptOperators::GetProperty(propertyObject, propertyId, requestContext)); Assert(*propertyValue == getPropertyValue || - (RootObjectBase::Is(propertyObject) && *propertyValue == JavascriptOperators::GetRootProperty(propertyObject, propertyId, requestContext))|| + (VarIs(propertyObject) && *propertyValue == JavascriptOperators::GetRootProperty(propertyObject, propertyId, requestContext))|| // In some cases, such as CustomExternalObject, if implicit calls are disabled GetPropertyQuery may return null. See CustomExternalObject::GetPropertyQuery for an example. (getPropertyValue == requestContext->GetLibrary()->GetNull() && requestContext->GetThreadContext()->IsDisableImplicitCall() && propertyObject->GetType()->IsExternal())); } diff --git a/lib/Runtime/Language/InlineCache.inl b/lib/Runtime/Language/InlineCache.inl index 82ff501254a..98a817e16fc 100644 --- a/lib/Runtime/Language/InlineCache.inl +++ b/lib/Runtime/Language/InlineCache.inl @@ -119,7 +119,7 @@ namespace Js template<> inline DynamicObject* InlineCache::GetSourceObject(RecyclableObject *const propertyObject) { - return DynamicObject::UnsafeFromVar(propertyObject); + return UnsafeVarTo(propertyObject); } template<> inline DynamicObject* InlineCache::GetSourceObject(RecyclableObject *const propertyObject) { @@ -183,7 +183,7 @@ namespace Js bool canSetField; // To verify if we can set a field on the object Var setterValue = nullptr; - { + { // We need to disable implicit call to ensure the check doesn't cause unwanted side effects in debug code // Save old disableImplicitFlags and implicitCallFlags and disable implicit call and exception ThreadContext * threadContext = requestContext->GetThreadContext(); @@ -199,7 +199,7 @@ namespace Js canSetField = true; // If there was an implicit call, inconclusive. Disable debug check. setterValue = nullptr; } - else + else if ((flags & Accessor) == Accessor) { Assert(setterValue != nullptr); @@ -216,10 +216,10 @@ namespace Js if (CheckLocal && type == u.local.type) { Assert(object->GetScriptContext() == requestContext); // we never cache a type from another script context - Assert(isRoot || object->GetPropertyIndex(propertyId) == DynamicObject::FromVar(object)->GetTypeHandler()->InlineOrAuxSlotIndexToPropertyIndex(u.local.slotIndex, true)); - Assert(!isRoot || RootObjectBase::FromVar(object)->GetRootPropertyIndex(propertyId) == DynamicObject::FromVar(object)->GetTypeHandler()->InlineOrAuxSlotIndexToPropertyIndex(u.local.slotIndex, true)); + Assert(isRoot || object->GetPropertyIndex(propertyId) == VarTo(object)->GetTypeHandler()->InlineOrAuxSlotIndexToPropertyIndex(u.local.slotIndex, true)); + Assert(!isRoot || VarTo(object)->GetRootPropertyIndex(propertyId) == VarTo(object)->GetTypeHandler()->InlineOrAuxSlotIndexToPropertyIndex(u.local.slotIndex, true)); Assert(object->CanStorePropertyValueDirectly(propertyId, isRoot)); - DynamicObject::UnsafeFromVar(object)->SetInlineSlot(SetSlotArgumentsRoot(propertyId, isRoot, u.local.slotIndex, propertyValue)); + UnsafeVarTo(object)->SetInlineSlot(SetSlotArgumentsRoot(propertyId, isRoot, u.local.slotIndex, propertyValue)); if (ReturnOperationInfo) { operationInfo->cacheType = CacheType_Local; @@ -232,10 +232,10 @@ namespace Js if (CheckLocal && TypeWithAuxSlotTag(type) == u.local.type) { Assert(object->GetScriptContext() == requestContext); // we never cache a type from another script context - Assert(isRoot || object->GetPropertyIndex(propertyId) == DynamicObject::FromVar(object)->GetTypeHandler()->InlineOrAuxSlotIndexToPropertyIndex(u.local.slotIndex, false)); - Assert(!isRoot || RootObjectBase::FromVar(object)->GetRootPropertyIndex(propertyId) == DynamicObject::FromVar(object)->GetTypeHandler()->InlineOrAuxSlotIndexToPropertyIndex(u.local.slotIndex, false)); + Assert(isRoot || object->GetPropertyIndex(propertyId) == VarTo(object)->GetTypeHandler()->InlineOrAuxSlotIndexToPropertyIndex(u.local.slotIndex, false)); + Assert(!isRoot || VarTo(object)->GetRootPropertyIndex(propertyId) == VarTo(object)->GetTypeHandler()->InlineOrAuxSlotIndexToPropertyIndex(u.local.slotIndex, false)); Assert(object->CanStorePropertyValueDirectly(propertyId, isRoot)); - DynamicObject::UnsafeFromVar(object)->SetAuxSlot(SetSlotArgumentsRoot(propertyId, isRoot, u.local.slotIndex, propertyValue)); + UnsafeVarTo(object)->SetAuxSlot(SetSlotArgumentsRoot(propertyId, isRoot, u.local.slotIndex, propertyValue)); if (ReturnOperationInfo) { operationInfo->cacheType = CacheType_Local; @@ -263,15 +263,15 @@ namespace Js AssertMsg(!((DynamicType*)u.local.typeWithoutProperty)->GetTypeHandler()->GetIsPrototype(), "Why did we cache a property add for a prototype?"); Assert(((DynamicType*)typeWithProperty)->GetTypeHandler()->CanStorePropertyValueDirectly((const DynamicObject*)object, propertyId, isRoot)); - DynamicObject *const dynamicObject = DynamicObject::UnsafeFromVar(object); + DynamicObject *const dynamicObject = UnsafeVarTo(object); // If we're adding a property to an inlined slot, we should never need to adjust auxiliary slot array size. Assert(newAuxSlotCapacity == 0); dynamicObject->type = typeWithProperty; - Assert(isRoot || object->GetPropertyIndex(propertyId) == DynamicObject::FromVar(object)->GetTypeHandler()->InlineOrAuxSlotIndexToPropertyIndex(propertyIndex, true)); - Assert(!isRoot || RootObjectBase::FromVar(object)->GetRootPropertyIndex(propertyId) == DynamicObject::FromVar(object)->GetTypeHandler()->InlineOrAuxSlotIndexToPropertyIndex(propertyIndex, true)); + Assert(isRoot || object->GetPropertyIndex(propertyId) == VarTo(object)->GetTypeHandler()->InlineOrAuxSlotIndexToPropertyIndex(propertyIndex, true)); + Assert(!isRoot || VarTo(object)->GetRootPropertyIndex(propertyId) == VarTo(object)->GetTypeHandler()->InlineOrAuxSlotIndexToPropertyIndex(propertyIndex, true)); dynamicObject->SetInlineSlot(SetSlotArgumentsRoot(propertyId, isRoot, propertyIndex, propertyValue)); @@ -299,7 +299,7 @@ namespace Js AssertMsg(!((DynamicType*)TypeWithoutAuxSlotTag(u.local.typeWithoutProperty))->GetTypeHandler()->GetIsPrototype(), "Why did we cache a property add for a prototype?"); Assert(((DynamicType*)typeWithProperty)->GetTypeHandler()->CanStorePropertyValueDirectly((const DynamicObject*)object, propertyId, isRoot)); - DynamicObject *const dynamicObject = DynamicObject::UnsafeFromVar(object); + DynamicObject *const dynamicObject = UnsafeVarTo(object); if (newAuxSlotCapacity > 0) { @@ -311,8 +311,8 @@ namespace Js dynamicObject->type = typeWithProperty; - Assert(isRoot || object->GetPropertyIndex(propertyId) == DynamicObject::FromVar(object)->GetTypeHandler()->InlineOrAuxSlotIndexToPropertyIndex(propertyIndex, false)); - Assert(!isRoot || RootObjectBase::FromVar(object)->GetRootPropertyIndex(propertyId) == DynamicObject::FromVar(object)->GetTypeHandler()->InlineOrAuxSlotIndexToPropertyIndex(propertyIndex, false)); + Assert(isRoot || object->GetPropertyIndex(propertyId) == VarTo(object)->GetTypeHandler()->InlineOrAuxSlotIndexToPropertyIndex(propertyIndex, false)); + Assert(!isRoot || VarTo(object)->GetRootPropertyIndex(propertyId) == VarTo(object)->GetTypeHandler()->InlineOrAuxSlotIndexToPropertyIndex(propertyIndex, false)); dynamicObject->SetAuxSlot(SetSlotArgumentsRoot(propertyId, isRoot, propertyIndex, propertyValue)); @@ -332,11 +332,11 @@ namespace Js RecyclableObject * function; if (u.accessor.isOnProto) { - function = RecyclableObject::UnsafeFromVar(u.accessor.object->GetInlineSlot(u.accessor.slotIndex)); + function = UnsafeVarTo(u.accessor.object->GetInlineSlot(u.accessor.slotIndex)); } else { - function = RecyclableObject::UnsafeFromVar(DynamicObject::FromVar(object)->GetInlineSlot(u.accessor.slotIndex)); + function = UnsafeVarTo(VarTo(object)->GetInlineSlot(u.accessor.slotIndex)); } Assert(setterValue == nullptr || setterValue == function); @@ -363,11 +363,11 @@ namespace Js RecyclableObject * function; if (u.accessor.isOnProto) { - function = RecyclableObject::UnsafeFromVar(u.accessor.object->GetAuxSlot(u.accessor.slotIndex)); + function = UnsafeVarTo(u.accessor.object->GetAuxSlot(u.accessor.slotIndex)); } else { - function = RecyclableObject::UnsafeFromVar(DynamicObject::FromVar(object)->GetAuxSlot(u.accessor.slotIndex)); + function = UnsafeVarTo(VarTo(object)->GetAuxSlot(u.accessor.slotIndex)); } Assert(setterValue == nullptr || setterValue == function); diff --git a/lib/Runtime/Language/InterpreterLoop.inl b/lib/Runtime/Language/InterpreterLoop.inl index 026d3e98365..d7c526009c6 100644 --- a/lib/Runtime/Language/InterpreterLoop.inl +++ b/lib/Runtime/Language/InterpreterLoop.inl @@ -170,7 +170,7 @@ Js::Var Js::InterpreterStackFrame::INTERPRETERLOOPNAME() } Assert(this->returnAddress != nullptr); - AssertMsg(!this->GetFunctionBody()->GetUsesArgumentsObject() || m_arguments == NULL || Js::ArgumentsObject::Is(m_arguments), "Bad arguments!"); + AssertMsg(!this->GetFunctionBody()->GetUsesArgumentsObject() || m_arguments == NULL || Js::VarIs(m_arguments), "Bad arguments!"); // IP Passing in the interpreter: // We keep a local copy of the bytecode's instruction pointer and diff --git a/lib/Runtime/Language/InterpreterStackFrame.cpp b/lib/Runtime/Language/InterpreterStackFrame.cpp index 476b41e704d..fb4fc785a51 100644 --- a/lib/Runtime/Language/InterpreterStackFrame.cpp +++ b/lib/Runtime/Language/InterpreterStackFrame.cpp @@ -1035,9 +1035,9 @@ namespace Js void InterpreterStackFrame::Setup::SetupInternal() { - if (this->function->GetHasInlineCaches() && Js::ScriptFunctionWithInlineCache::Is(this->function)) + if (this->function->GetHasInlineCaches() && Js::VarIs(this->function)) { - this->inlineCaches = (void**)Js::ScriptFunctionWithInlineCache::FromVar(this->function)->GetInlineCaches(); + this->inlineCaches = (void**)Js::VarTo(this->function)->GetInlineCaches(); Assert(this->inlineCaches != nullptr); } else @@ -1756,7 +1756,7 @@ namespace Js Var InterpreterStackFrame::InterpreterThunk(JavascriptCallStackLayout* layout) { - Js::ScriptFunction * function = Js::ScriptFunction::UnsafeFromVar(layout->functionObject); + Js::ScriptFunction * function = Js::UnsafeVarTo(layout->functionObject); Js::ArgumentReader args(&layout->callInfo, layout->args); void* localReturnAddress = _ReturnAddress(); void* localAddressOfReturnAddress = _AddressOfReturnAddress(); @@ -1770,8 +1770,8 @@ namespace Js ARGUMENTS(args, callInfo); void* localReturnAddress = _ReturnAddress(); void* localAddressOfReturnAddress = _AddressOfReturnAddress(); - Assert(ScriptFunction::Is(function)); - return InterpreterHelper(ScriptFunction::FromVar(function), args, localReturnAddress, localAddressOfReturnAddress); + Assert(VarIs(function)); + return InterpreterHelper(VarTo(function), args, localReturnAddress, localAddressOfReturnAddress); } #pragma optimize("", on) #endif @@ -1851,7 +1851,7 @@ namespace Js Assert(threadContext->IsScriptActive()); Assert(threadContext->IsInScript()); - FunctionBody* executeFunction = JavascriptFunction::UnsafeFromVar(function)->GetFunctionBody(); + FunctionBody* executeFunction = function->GetFunctionBody(); #ifdef ENABLE_DEBUG_CONFIG_OPTIONS if (!isAsmJs && executeFunction->IsInDebugMode() != functionScriptContext->IsScriptContextInDebugMode()) // debug mode mismatch { @@ -1934,7 +1934,7 @@ namespace Js // generator object. AssertOrFailFastMsg(args.Info.Count == 2 && ((args.Info.Flags & CallFlags_ExtraArg) == CallFlags_None), "Generator ScriptFunctions should only be invoked by generator APIs with the pair of arguments they pass in -- the generator object and a ResumeYieldData pointer"); - JavascriptGenerator* generator = JavascriptGenerator::FromVar(args[0]); + JavascriptGenerator* generator = VarTo(args[0]); newInstance = generator->GetFrame(); if (newInstance != nullptr) @@ -2214,7 +2214,7 @@ namespace Js template T InterpreterStackFrame::AsmJsInterpreter(AsmJsCallStackLayout* layout) { - Js::ScriptFunction * function = Js::ScriptFunction::FromVar(layout->functionObject); + Js::ScriptFunction * function = Js::VarTo(layout->functionObject); int flags = CallFlags_Value; ArgSlot nbArgs = ArgSlotMath::Add(function->GetFunctionBody()->GetAsmJsFunctionInfo()->GetArgCount(), 1); @@ -2632,7 +2632,7 @@ namespace Js if (CONFIG_FLAG(AsmJsEdge)) { // emscripten had a bug which caused this check to fail in some circumstances, so this check fails for some demos - if (!TaggedNumber::Is(value) && (!RecyclableObject::Is(value) || DynamicType::Is(RecyclableObject::FromVar(value)->GetTypeId()))) + if (!TaggedNumber::Is(value) && (!VarIs(value) || DynamicType::Is(VarTo(value)->GetTypeId()))) { AsmJSCompiler::OutputError(this->scriptContext, _u("Asm.js Runtime Error : Var import %s must be primitive"), this->scriptContext->GetPropertyName(import.field)->GetBuffer()); goto linkFailure; @@ -2675,7 +2675,7 @@ namespace Js AsmJSCompiler::OutputError(this->scriptContext, _u("Asm.js Runtime Error : Accessing foreign function import %s has side effects"), this->scriptContext->GetPropertyName(import.field)->GetBuffer()); return this->ProcessLinkFailedAsmJsModule(); } - if (!JavascriptFunction::Is(importFunc)) + if (!VarIs(importFunc)) { AsmJSCompiler::OutputError(this->scriptContext, _u("Asm.js Runtime Error : Foreign function import %s is not a function"), this->scriptContext->GetPropertyName(import.field)->GetBuffer()); goto linkFailure; @@ -2946,13 +2946,13 @@ namespace Js } // Load module environment - AsmJsScriptFunction* asmJsFunc = AsmJsScriptFunction::FromVar(this->function); + AsmJsScriptFunction* asmJsFunc = VarTo(this->function); m_localSlots[AsmJsFunctionMemory::ModuleEnvRegister] = asmJsFunc->GetModuleEnvironment(); m_localSlots[AsmJsFunctionMemory::ArrayBufferRegister] = nullptr; #ifdef ENABLE_WASM - if (WasmScriptFunction::Is(func)) + if (VarIs(func)) { - WasmScriptFunction* wasmFunc = WasmScriptFunction::FromVar(func); + WasmScriptFunction* wasmFunc = VarTo(func); m_wasmMemory = wasmFunc->GetWebAssemblyMemory(); m_signatures = func->GetFunctionBody()->GetAsmJsFunctionInfo()->GetWebAssemblyModule()->GetSignatures(); } @@ -3525,7 +3525,7 @@ namespace Js Js::Var instance = this->GetRootObject(); PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex); InlineCache *inlineCache = this->GetInlineCache(playout->inlineCacheIndex); - DynamicObject *obj = DynamicObject::UnsafeFromVar(instance); + DynamicObject *obj = UnsafeVarTo(instance); PropertyValueInfo info; PropertyValueInfo::SetCacheInfo(&info, GetFunctionBody(), inlineCache, playout->inlineCacheIndex, true); @@ -3551,7 +3551,7 @@ namespace Js GetFunctionBody(), GetInlineCache(playout->inlineCacheIndex), playout->inlineCacheIndex, - DynamicObject::UnsafeFromVar(rootInstance), + UnsafeVarTo(rootInstance), propertyId ); @@ -3577,9 +3577,9 @@ namespace Js PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex); RecyclableObject* obj = NULL; - if (RecyclableObject::Is(varInstance)) + if (VarIs(varInstance)) { - obj = RecyclableObject::FromVar(varInstance); + obj = VarTo(varInstance); } InlineCache *inlineCache = this->GetInlineCache(playout->inlineCacheIndex); @@ -3700,7 +3700,7 @@ namespace Js } void InterpreterStackFrame::OP_CallAsmInternalCommon(ScriptFunction* function, RegSlot returnReg) { - AsmJsScriptFunction* scriptFunc = AsmJsScriptFunction::FromVar(function); + AsmJsScriptFunction* scriptFunc = VarTo(function); AsmJsFunctionInfo* asmInfo = scriptFunc->GetFunctionBody()->GetAsmJsFunctionInfo(); uint alignedArgsSize = ::Math::Align(asmInfo->GetArgByteSize(), 16); #if _M_X64 && _WIN32 @@ -3893,7 +3893,7 @@ namespace Js FunctionBody* functionBody = this->m_functionBody; DynamicProfileInfo * dynamicProfileInfo = functionBody->GetDynamicProfileInfo(); FunctionInfo* functionInfo = function->GetTypeId() == TypeIds_Function ? - JavascriptFunction::FromVar(function)->GetFunctionInfo() : nullptr; + VarTo(function)->GetFunctionInfo() : nullptr; bool isConstructorCall = (CallFlags_New & flags) == CallFlags_New; dynamicProfileInfo->RecordCallSiteInfo(functionBody, profileId, functionInfo, functionInfo ? static_cast(function) : nullptr, playout->ArgCount, isConstructorCall, inlineCacheIndex); OP_CallCommon(playout, function, flags, spreadIndices); @@ -3926,7 +3926,7 @@ namespace Js InlineCache *inlineCache = this->GetInlineCache(playout->inlineCacheIndex); PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex); - DynamicObject * obj = DynamicObject::UnsafeFromVar(instance); + DynamicObject * obj = UnsafeVarTo(instance); PropertyValueInfo info; PropertyValueInfo::SetCacheInfo(&info, GetFunctionBody(), inlineCache, playout->inlineCacheIndex, true); @@ -3951,7 +3951,7 @@ namespace Js GetFunctionBody(), GetInlineCache(playout->inlineCacheIndex), playout->inlineCacheIndex, - DynamicObject::UnsafeFromVar(rootInstance), + UnsafeVarTo(rootInstance), propertyId ); @@ -3976,7 +3976,7 @@ namespace Js GetFunctionBody(), GetInlineCache(playout->inlineCacheIndex), playout->inlineCacheIndex, - DynamicObject::UnsafeFromVar(rootInstance), + UnsafeVarTo(rootInstance), propertyId ); @@ -4150,10 +4150,10 @@ namespace Js Var thisInstance = GetReg(playout->Value2); InlineCache *inlineCache = GetInlineCache(playout->PropertyIdIndex); PropertyId propertyId = GetPropertyIdFromCacheId(playout->PropertyIdIndex); - if (RecyclableObject::Is(instance) && RecyclableObject::Is(thisInstance)) + if (VarIs(instance) && VarIs(thisInstance)) { - RecyclableObject* superObj = RecyclableObject::FromVar(instance); - RecyclableObject* thisObj = RecyclableObject::FromVar(thisInstance); + RecyclableObject* superObj = VarTo(instance); + RecyclableObject* thisObj = VarTo(thisInstance); PropertyValueInfo info; PropertyValueInfo::SetCacheInfo(&info, GetFunctionBody(), inlineCache, playout->PropertyIdIndex, true); @@ -4275,7 +4275,7 @@ namespace Js int length = pScope->GetLength(); if (1 == length) { - RecyclableObject *obj = RecyclableObject::FromVar(pScope->GetItem(0)); + RecyclableObject *obj = VarTo(pScope->GetItem(0)); PropertyValueInfo info; PropertyValueInfo::SetCacheInfo(&info, GetFunctionBody(), inlineCache, playout->inlineCacheIndex, true); Var value; @@ -4378,7 +4378,7 @@ namespace Js int length = pScope->GetLength(); if (1 == length) { - RecyclableObject* obj = RecyclableObject::FromVar(pScope->GetItem(0)); + RecyclableObject* obj = VarTo(pScope->GetItem(0)); PropertyValueInfo info; PropertyValueInfo::SetCacheInfo(&info, GetFunctionBody(), inlineCache, playout->inlineCacheIndex, true); if (CacheOperators::TrySetProperty( @@ -4460,7 +4460,7 @@ namespace Js InlineCache *inlineCache; if (!TaggedNumber::Is(instance) - && TrySetPropertyLocalFastPath(playout, propertyId, RecyclableObject::UnsafeFromVar(instance), inlineCache, flags)) + && TrySetPropertyLocalFastPath(playout, propertyId, UnsafeVarTo(instance), inlineCache, flags)) { if (GetJavascriptFunction()->GetConstructorCache()->NeedsUpdateAfterCtor()) { @@ -4737,7 +4737,7 @@ namespace Js Assert(!TaggedNumber::Is(instance)); PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex); - if (TrySetPropertyLocalFastPath(playout, propertyId, RecyclableObject::UnsafeFromVar(instance), inlineCache)) + if (TrySetPropertyLocalFastPath(playout, propertyId, UnsafeVarTo(instance), inlineCache)) { return; } @@ -4752,7 +4752,7 @@ namespace Js GetFunctionBody(), GetInlineCache(playout->inlineCacheIndex), playout->inlineCacheIndex, - RecyclableObject::FromVar(instance), + VarTo(instance), GetPropertyIdFromCacheId(playout->inlineCacheIndex), GetReg(playout->Value)); } @@ -4767,7 +4767,7 @@ namespace Js Assert(!TaggedNumber::Is(instance)); PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex); - if (!TrySetPropertyLocalFastPath(playout, propertyId, RecyclableObject::UnsafeFromVar(instance), inlineCache, flags)) + if (!TrySetPropertyLocalFastPath(playout, propertyId, UnsafeVarTo(instance), inlineCache, flags)) { JavascriptOperators::OP_InitClassMember(instance, propertyId, GetReg(playout->Value)); } @@ -4829,7 +4829,7 @@ namespace Js Assert(!TaggedNumber::Is(instance)); PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex); - if (!TrySetPropertyLocalFastPath(playout, propertyId, RecyclableObject::UnsafeFromVar(instance), inlineCache, flags)) + if (!TrySetPropertyLocalFastPath(playout, propertyId, UnsafeVarTo(instance), inlineCache, flags)) { JavascriptOperators::OP_InitLetProperty(instance, propertyId, GetReg(playout->Value)); } @@ -4843,7 +4843,7 @@ namespace Js Assert(!TaggedNumber::Is(instance)); PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex); - if (!TrySetPropertyLocalFastPath(playout, propertyId, RecyclableObject::UnsafeFromVar(instance), inlineCache, flags)) + if (!TrySetPropertyLocalFastPath(playout, propertyId, UnsafeVarTo(instance), inlineCache, flags)) { JavascriptOperators::OP_InitConstProperty(instance, propertyId, GetReg(playout->Value)); } @@ -4963,7 +4963,7 @@ namespace Js void InterpreterStackFrame::OP_InitUndeclConsoleLetProperty(unaligned T* playout) { FrameDisplay* pScope = (FrameDisplay*)this->LdEnv(); - AssertMsg(ConsoleScopeActivationObject::Is((DynamicObject*)pScope->GetItem(pScope->GetLength() - 1)), "How come we got this opcode without ConsoleScopeActivationObject?"); + AssertMsg(VarIs((DynamicObject*)pScope->GetItem(pScope->GetLength() - 1)), "How come we got this opcode without ConsoleScopeActivationObject?"); PropertyId propertyId = m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex); JavascriptOperators::OP_InitLetProperty(pScope->GetItem(0), propertyId, this->scriptContext->GetLibrary()->GetUndeclBlockVar()); } @@ -4972,7 +4972,7 @@ namespace Js void InterpreterStackFrame::OP_InitUndeclConsoleConstProperty(unaligned T* playout) { FrameDisplay* pScope = (FrameDisplay*)this->LdEnv(); - AssertMsg(ConsoleScopeActivationObject::Is((DynamicObject*)pScope->GetItem(pScope->GetLength() - 1)), "How come we got this opcode without ConsoleScopeActivationObject?"); + AssertMsg(VarIs((DynamicObject*)pScope->GetItem(pScope->GetLength() - 1)), "How come we got this opcode without ConsoleScopeActivationObject?"); PropertyId propertyId = m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex); JavascriptOperators::OP_InitConstProperty(pScope->GetItem(0), propertyId, this->scriptContext->GetLibrary()->GetUndeclBlockVar()); } @@ -4982,7 +4982,7 @@ namespace Js void InterpreterStackFrame::ProfiledInitProperty(unaligned T* playout, Var instance) { ProfilingHelpers::ProfiledInitFld( - RecyclableObject::FromVar(instance), + VarTo(instance), GetPropertyIdFromCacheId(playout->inlineCacheIndex), GetInlineCache(playout->inlineCacheIndex), playout->inlineCacheIndex, @@ -5050,7 +5050,7 @@ namespace Js { element = ProfilingHelpers::ProfiledLdElem_FastPath( - JavascriptArray::UnsafeFromVar(instance), + UnsafeVarTo(instance), GetReg(playout->Element), GetScriptContext()); } @@ -5088,7 +5088,7 @@ namespace Js !JavascriptOperators::SetElementMayHaveImplicitCalls(GetScriptContext())) { ProfilingHelpers::ProfiledStElem_FastPath( - JavascriptArray::UnsafeFromVar(instance), + UnsafeVarTo(instance), varIndex, value, GetScriptContext(), @@ -5512,7 +5512,7 @@ namespace Js Var InterpreterStackFrame::OP_GetCachedFunc(Var instance, int32 index) { - ActivationObjectEx *obj = ActivationObjectEx::FromVar(instance); + ActivationObjectEx *obj = VarTo(instance); FuncCacheEntry *entry = obj->GetFuncCacheEntry((uint)index); return entry->func; @@ -5526,7 +5526,7 @@ namespace Js void InterpreterStackFrame::OP_CommitScopeHelper(const PropertyIdArray *propIds) { - ActivationObjectEx *obj = ActivationObjectEx::FromVar(this->localClosure); + ActivationObjectEx *obj = VarTo(this->localClosure); ScriptFunction *func = obj->GetParentFunc(); Assert(obj->GetParentFunc() == func); @@ -7414,7 +7414,7 @@ namespace Js { uint innerScopeIndex = playout->C1; Var scope = this->InnerScopeFromIndex(innerScopeIndex); - BlockActivationObject* blockScope = BlockActivationObject::FromVar(scope); + BlockActivationObject* blockScope = VarTo(scope); scope = JavascriptOperators::OP_CloneBlockScope(blockScope, scriptContext); this->SetInnerScopeFromIndex(innerScopeIndex, scope); @@ -8682,7 +8682,7 @@ namespace Js void InterpreterStackFrame::OP_LdArrWasmFunc(const unaligned T* playout) { #ifdef ENABLE_WASM - WebAssemblyTable * table = WebAssemblyTable::FromVar(GetRegRawPtr(playout->Instance)); + WebAssemblyTable * table = VarTo(GetRegRawPtr(playout->Instance)); const uint32 index = (uint32)GetRegRawInt(playout->SlotIndex); if (index >= table->GetCurrentLength()) { @@ -8701,7 +8701,7 @@ namespace Js void InterpreterStackFrame::OP_CheckSignature(const unaligned T* playout) { #ifdef ENABLE_WASM - ScriptFunction * func = ScriptFunction::FromVar(GetRegRawPtr(playout->R0)); + ScriptFunction * func = VarTo(GetRegRawPtr(playout->R0)); int sigIndex = playout->C1; Wasm::WasmSignature * expected = &m_signatures[sigIndex]; if (func->GetFunctionInfo()->IsDeferredParseFunction()) @@ -9267,7 +9267,7 @@ namespace Js isCachedScope = m_functionBody->HasCachedScopePropIds(); propIds = this->m_functionBody->GetFormalsPropIdArray(); - if (isScopeObjRestored && ActivationObject::Is(frameObject)) + if (isScopeObjRestored && VarIs(frameObject)) { Assert(this->GetFunctionBody()->GetDoScopeObjectCreation()); isCachedScope = true; @@ -9315,7 +9315,7 @@ namespace Js if (heapArgObj) { - Assert(frameObject == nullptr || ActivationObject::Is(frameObject)); + Assert(frameObject == nullptr || VarIs(frameObject)); heapArgObj->SetFormalCount(formalsCount); heapArgObj->SetFrameObject(frameObject != nullptr ? static_cast(frameObject) : nullptr); @@ -9345,7 +9345,7 @@ namespace Js Var InterpreterStackFrame::OP_ResumeYield(Var yieldDataVar, RegSlot yieldStarIterator) { ResumeYieldData* yieldData = static_cast(yieldDataVar); - RecyclableObject* iterator = yieldStarIterator != Constants::NoRegister ? RecyclableObject::FromVar(GetNonVarReg(yieldStarIterator)) : nullptr; + RecyclableObject* iterator = yieldStarIterator != Constants::NoRegister ? VarTo(GetNonVarReg(yieldStarIterator)) : nullptr; return JavascriptOperators::OP_ResumeYield(yieldData, iterator); } diff --git a/lib/Runtime/Language/JavascriptConversion.cpp b/lib/Runtime/Language/JavascriptConversion.cpp index 9f4b4c723a2..64e4d63ee5a 100644 --- a/lib/Runtime/Language/JavascriptConversion.cpp +++ b/lib/Runtime/Language/JavascriptConversion.cpp @@ -28,16 +28,17 @@ using namespace Js; //If Object has a [[Call]] internal method, then return true, otherwise return false bool JavascriptConversion::IsCallable(Var aValue) { - if (!RecyclableObject::Is(aValue)) + if (!VarIs(aValue)) { return false; } - return IsCallable(RecyclableObject::UnsafeFromVar(aValue)); + return IsCallable(UnsafeVarTo(aValue)); } bool JavascriptConversion::IsCallable(_In_ RecyclableObject* aValue) { - JavascriptMethod entryPoint = RecyclableObject::UnsafeFromVar(aValue)->GetEntryPoint(); + Assert(VarIsCorrectType(aValue)); + JavascriptMethod entryPoint = aValue->GetEntryPoint(); return RecyclableObject::DefaultEntryPoint != entryPoint; } @@ -88,13 +89,13 @@ using namespace Js; case TypeIds_Int64Number: { int leftValue = TaggedInt::ToInt32(aLeft); - __int64 rightValue = JavascriptInt64Number::UnsafeFromVar(aRight)->GetValue(); + __int64 rightValue = UnsafeVarTo(aRight)->GetValue(); return leftValue == rightValue; } case TypeIds_UInt64Number: { int leftValue = TaggedInt::ToInt32(aLeft); - unsigned __int64 rightValue = JavascriptInt64Number::FromVar(aRight)->GetValue(); + unsigned __int64 rightValue = VarTo(aRight)->GetValue(); return leftValue == rightValue; } } @@ -104,24 +105,24 @@ using namespace Js; { case TypeIds_Integer: { - __int64 leftValue = JavascriptInt64Number::UnsafeFromVar(aLeft)->GetValue(); + __int64 leftValue = UnsafeVarTo(aLeft)->GetValue(); int rightValue = TaggedInt::ToInt32(aRight); return leftValue == rightValue; } case TypeIds_Number: - dblLeft = (double)JavascriptInt64Number::UnsafeFromVar(aLeft)->GetValue(); + dblLeft = (double)UnsafeVarTo(aLeft)->GetValue(); dblRight = JavascriptNumber::GetValue(aRight); goto CommonNumber; case TypeIds_Int64Number: { - __int64 leftValue = JavascriptInt64Number::UnsafeFromVar(aLeft)->GetValue(); - __int64 rightValue = JavascriptInt64Number::UnsafeFromVar(aRight)->GetValue(); + __int64 leftValue = UnsafeVarTo(aLeft)->GetValue(); + __int64 rightValue = UnsafeVarTo(aRight)->GetValue(); return leftValue == rightValue; } case TypeIds_UInt64Number: { - __int64 leftValue = JavascriptInt64Number::UnsafeFromVar(aLeft)->GetValue(); - unsigned __int64 rightValue = JavascriptInt64Number::FromVar(aRight)->GetValue(); + __int64 leftValue = UnsafeVarTo(aLeft)->GetValue(); + unsigned __int64 rightValue = VarTo(aRight)->GetValue(); return ((unsigned __int64)leftValue == rightValue); } } @@ -131,24 +132,24 @@ using namespace Js; { case TypeIds_Integer: { - unsigned __int64 leftValue = JavascriptUInt64Number::UnsafeFromVar(aLeft)->GetValue(); + unsigned __int64 leftValue = UnsafeVarTo(aLeft)->GetValue(); __int64 rightValue = TaggedInt::ToInt32(aRight); return (leftValue == (unsigned __int64)rightValue); } case TypeIds_Number: - dblLeft = (double)JavascriptUInt64Number::UnsafeFromVar(aLeft)->GetValue(); + dblLeft = (double)UnsafeVarTo(aLeft)->GetValue(); dblRight = JavascriptNumber::GetValue(aRight); goto CommonNumber; case TypeIds_Int64Number: { - unsigned __int64 leftValue = JavascriptUInt64Number::UnsafeFromVar(aLeft)->GetValue(); - __int64 rightValue = JavascriptInt64Number::UnsafeFromVar(aRight)->GetValue(); + unsigned __int64 leftValue = UnsafeVarTo(aLeft)->GetValue(); + __int64 rightValue = UnsafeVarTo(aRight)->GetValue(); return (leftValue == (unsigned __int64)rightValue); } case TypeIds_UInt64Number: { - unsigned __int64 leftValue = JavascriptUInt64Number::UnsafeFromVar(aLeft)->GetValue(); - unsigned __int64 rightValue = JavascriptInt64Number::FromVar(aRight)->GetValue(); + unsigned __int64 leftValue = UnsafeVarTo(aLeft)->GetValue(); + unsigned __int64 rightValue = VarTo(aRight)->GetValue(); return leftValue == rightValue; } } @@ -162,11 +163,11 @@ using namespace Js; goto CommonNumber; case TypeIds_Int64Number: dblLeft = JavascriptNumber::GetValue(aLeft); - dblRight = (double)JavascriptInt64Number::UnsafeFromVar(aRight)->GetValue(); + dblRight = (double)UnsafeVarTo(aRight)->GetValue(); goto CommonNumber; case TypeIds_UInt64Number: dblLeft = JavascriptNumber::GetValue(aLeft); - dblRight = (double)JavascriptUInt64Number::UnsafeFromVar(aRight)->GetValue(); + dblRight = (double)UnsafeVarTo(aRight)->GetValue(); goto CommonNumber; case TypeIds_Number: dblLeft = JavascriptNumber::GetValue(aLeft); @@ -196,15 +197,15 @@ using namespace Js; switch (rightType) { case TypeIds_String: - return JavascriptString::Equals(JavascriptString::UnsafeFromVar(aLeft), JavascriptString::UnsafeFromVar(aRight)); + return JavascriptString::Equals(UnsafeVarTo(aLeft), UnsafeVarTo(aRight)); } break; #if DBG case TypeIds_Symbol: if (rightType == TypeIds_Symbol) { - JavascriptSymbol* leftSymbol = JavascriptSymbol::UnsafeFromVar(aLeft); - JavascriptSymbol* rightSymbol = JavascriptSymbol::UnsafeFromVar(aRight); + JavascriptSymbol* leftSymbol = UnsafeVarTo(aLeft); + JavascriptSymbol* rightSymbol = UnsafeVarTo(aRight); Assert(leftSymbol->GetValue() != rightSymbol->GetValue()); } #endif @@ -258,7 +259,7 @@ using namespace Js; return TRUE; default: - *object = RecyclableObject::FromVar(aValue)->ToObject(scriptContext); + *object = VarTo(aValue)->ToObject(scriptContext); return TRUE; } } @@ -275,19 +276,19 @@ using namespace Js; { Var key = JavascriptConversion::ToPrimitive(argument, scriptContext); PropertyString * propertyString = nullptr; - if (JavascriptSymbol::Is(key)) + if (VarIs(key)) { // If we are looking up a property keyed by a symbol, we already have the PropertyId in the symbol - *propertyRecord = JavascriptSymbol::UnsafeFromVar(key)->GetValue(); + *propertyRecord = UnsafeVarTo(key)->GetValue(); } else { // For all other types, convert the key into a string and use that as the property name JavascriptString * propName = JavascriptConversion::ToString(key, scriptContext); propName->GetPropertyRecord(propertyRecord); - if (PropertyString::Is(propName)) + if (VarIs(propName)) { - propertyString = PropertyString::UnsafeFromVar(propName); + propertyString = UnsafeVarTo(propName); } } @@ -330,7 +331,7 @@ using namespace Js; case TypeIds_VariantDate: { Var result = nullptr; - if (JavascriptVariantDate::UnsafeFromVar(aValue)->ToPrimitive(hint, &result, requestContext) != TRUE) + if (UnsafeVarTo(aValue)->ToPrimitive(hint, &result, requestContext) != TRUE) { result = nullptr; } @@ -339,7 +340,7 @@ using namespace Js; case TypeIds_StringObject: { - JavascriptStringObject * stringObject = JavascriptStringObject::UnsafeFromVar(aValue); + JavascriptStringObject * stringObject = UnsafeVarTo(aValue); ScriptContext * objectScriptContext = stringObject->GetScriptContext(); if (objectScriptContext->optimizationOverrides.GetSideEffects() & (hint == JavascriptHint::HintString ? SideEffects_ToString : SideEffects_ValueOf)) { @@ -351,7 +352,7 @@ using namespace Js; case TypeIds_NumberObject: { - JavascriptNumberObject * numberObject = JavascriptNumberObject::UnsafeFromVar(aValue); + JavascriptNumberObject * numberObject = UnsafeVarTo(aValue); ScriptContext * objectScriptContext = numberObject->GetScriptContext(); if (hint == JavascriptHint::HintString) { @@ -375,7 +376,7 @@ using namespace Js; case TypeIds_SymbolObject: { - JavascriptSymbolObject* symbolObject = JavascriptSymbolObject::UnsafeFromVar(aValue); + JavascriptSymbolObject* symbolObject = UnsafeVarTo(aValue); return CrossSite::MarshalVar(requestContext, symbolObject->Unwrap(), symbolObject->GetScriptContext()); } @@ -383,7 +384,7 @@ using namespace Js; case TypeIds_Date: case TypeIds_WinRTDate: { - JavascriptDate* dateObject = JavascriptDate::UnsafeFromVar(aValue); + JavascriptDate* dateObject = UnsafeVarTo(aValue); if(hint == JavascriptHint::HintNumber) { if (dateObject->GetScriptContext()->optimizationOverrides.GetSideEffects() & SideEffects_ValueOf) @@ -408,14 +409,14 @@ using namespace Js; // convert to JavascriptNumber case TypeIds_Int64Number: - return JavascriptInt64Number::UnsafeFromVar(aValue)->ToJavascriptNumber(); + return UnsafeVarTo(aValue)->ToJavascriptNumber(); case TypeIds_UInt64Number: - return JavascriptUInt64Number::UnsafeFromVar(aValue)->ToJavascriptNumber(); + return UnsafeVarTo(aValue)->ToJavascriptNumber(); default: // if no Method exists this function falls back to OrdinaryToPrimitive // if IsES6ToPrimitiveEnabled flag is off we also fall back to OrdinaryToPrimitive - return MethodCallToPrimitive(RecyclableObject::UnsafeFromVar(aValue), requestContext); + return MethodCallToPrimitive(UnsafeVarTo(aValue), requestContext); } } @@ -469,7 +470,7 @@ using namespace Js; { return OrdinaryToPrimitive(value, requestContext); } - if (!JavascriptFunction::Is(varMethod)) + if (!VarIs(varMethod)) { // Don't error if we disabled implicit calls JavascriptError::TryThrowTypeError(scriptContext, requestContext, JSERR_Property_NeedFunction, requestContext->GetPropertyName(PropertyIds::_symbolToPrimitive)->GetBuffer()); @@ -477,7 +478,7 @@ using namespace Js; } // Let exoticToPrim be GetMethod(input, @@toPrimitive). - JavascriptFunction* exoticToPrim = JavascriptFunction::UnsafeFromVar(varMethod); + JavascriptFunction* exoticToPrim = UnsafeVarTo(varMethod); JavascriptString* hintString = nullptr; if (hint == JavascriptHint::HintString) @@ -609,14 +610,14 @@ using namespace Js; return scriptContext->GetIntegerString(aValue); case TypeIds_Boolean: - return JavascriptBoolean::UnsafeFromVar(aValue)->GetValue() ? scriptContext->GetLibrary()->GetTrueDisplayString() : scriptContext->GetLibrary()->GetFalseDisplayString(); + return UnsafeVarTo(aValue)->GetValue() ? scriptContext->GetLibrary()->GetTrueDisplayString() : scriptContext->GetLibrary()->GetFalseDisplayString(); case TypeIds_Number: return JavascriptNumber::ToStringRadix10(JavascriptNumber::GetValue(aValue), scriptContext); case TypeIds_Int64Number: { - __int64 value = JavascriptInt64Number::UnsafeFromVar(aValue)->GetValue(); + __int64 value = UnsafeVarTo(aValue)->GetValue(); if (!TaggedInt::IsOverflow(value)) { return scriptContext->GetIntegerString((int)value); @@ -629,7 +630,7 @@ using namespace Js; case TypeIds_UInt64Number: { - unsigned __int64 value = JavascriptUInt64Number::UnsafeFromVar(aValue)->GetValue(); + unsigned __int64 value = UnsafeVarTo(aValue)->GetValue(); if (!TaggedInt::IsOverflow(value)) { return scriptContext->GetIntegerString((uint)value); @@ -642,18 +643,18 @@ using namespace Js; case TypeIds_String: { - ScriptContext* aValueScriptContext = Js::RecyclableObject::UnsafeFromVar(aValue)->GetScriptContext(); - return JavascriptString::UnsafeFromVar(CrossSite::MarshalVar(scriptContext, + ScriptContext* aValueScriptContext = Js::UnsafeVarTo(aValue)->GetScriptContext(); + return UnsafeVarTo(CrossSite::MarshalVar(scriptContext, aValue, aValueScriptContext)); } case TypeIds_VariantDate: - return JavascriptVariantDate::FromVar(aValue)->GetValueString(scriptContext); + return VarTo(aValue)->GetValueString(scriptContext); case TypeIds_Symbol: - return JavascriptSymbol::UnsafeFromVar(aValue)->ToString(scriptContext); + return UnsafeVarTo(aValue)->ToString(scriptContext); case TypeIds_SymbolObject: - return JavascriptSymbol::ToString(JavascriptSymbolObject::UnsafeFromVar(aValue)->GetValue(), scriptContext); + return JavascriptSymbol::ToString(UnsafeVarTo(aValue)->GetValue(), scriptContext); case TypeIds_GlobalObject: aValue = static_cast(aValue)->ToThis(); @@ -689,42 +690,42 @@ using namespace Js; return JavascriptNumber::ToLocaleString(TaggedInt::ToInt32(aValue), scriptContext); case TypeIds_Boolean: - return JavascriptBoolean::UnsafeFromVar(aValue)->GetValue() ? scriptContext->GetLibrary()->GetTrueDisplayString() : scriptContext->GetLibrary()->GetFalseDisplayString(); + return UnsafeVarTo(aValue)->GetValue() ? scriptContext->GetLibrary()->GetTrueDisplayString() : scriptContext->GetLibrary()->GetFalseDisplayString(); case TypeIds_Int64Number: - return JavascriptNumber::ToLocaleString((double)JavascriptInt64Number::UnsafeFromVar(aValue)->GetValue(), scriptContext); + return JavascriptNumber::ToLocaleString((double)UnsafeVarTo(aValue)->GetValue(), scriptContext); case TypeIds_UInt64Number: - return JavascriptNumber::ToLocaleString((double)JavascriptUInt64Number::UnsafeFromVar(aValue)->GetValue(), scriptContext); + return JavascriptNumber::ToLocaleString((double)UnsafeVarTo(aValue)->GetValue(), scriptContext); case TypeIds_Number: return JavascriptNumber::ToLocaleString(JavascriptNumber::GetValue(aValue), scriptContext); case TypeIds_String: - return JavascriptString::UnsafeFromVar(aValue); + return UnsafeVarTo(aValue); case TypeIds_VariantDate: // Legacy behavior was to create an empty object and call toLocaleString on it, which would result in this value return scriptContext->GetLibrary()->GetObjectDisplayString(); case TypeIds_Symbol: - return JavascriptSymbol::UnsafeFromVar(aValue)->ToString(scriptContext); + return UnsafeVarTo(aValue)->ToString(scriptContext); default: { - RecyclableObject* object = RecyclableObject::FromVar(aValue); + RecyclableObject* object = VarTo(aValue); Var value = JavascriptOperators::GetProperty(object, PropertyIds::toLocaleString, scriptContext, NULL); if (JavascriptConversion::IsCallable(value)) { - RecyclableObject* toLocaleStringFunction = RecyclableObject::FromVar(value); + RecyclableObject* toLocaleStringFunction = VarTo(value); Var aResult = scriptContext->GetThreadContext()->ExecuteImplicitCall(toLocaleStringFunction, Js::ImplicitCall_ToPrimitive, [=]()->Js::Var { return CALL_FUNCTION(scriptContext->GetThreadContext(), toLocaleStringFunction, CallInfo(1), aValue); }); - if (JavascriptString::Is(aResult)) + if (VarIs(aResult)) { - return JavascriptString::UnsafeFromVar(aResult); + return UnsafeVarTo(aResult); } else { @@ -756,9 +757,9 @@ using namespace Js; BOOL JavascriptConversion::ToBoolean_Full(Var aValue, ScriptContext* scriptContext) { AssertMsg(!TaggedInt::Is(aValue), "Should be detected"); - AssertMsg(RecyclableObject::Is(aValue), "Should be handled already"); + AssertMsg(VarIs(aValue), "Should be handled already"); - auto type = RecyclableObject::UnsafeFromVar(aValue)->GetType(); + auto type = UnsafeVarTo(aValue)->GetType(); switch (type->GetTypeId()) { @@ -771,7 +772,7 @@ using namespace Js; return true; case TypeIds_Boolean: - return JavascriptBoolean::UnsafeFromVar(aValue)->GetValue(); + return UnsafeVarTo(aValue)->GetValue(); #if !FLOATVAR case TypeIds_Number: @@ -783,19 +784,19 @@ using namespace Js; case TypeIds_Int64Number: { - __int64 value = JavascriptInt64Number::UnsafeFromVar(aValue)->GetValue(); + __int64 value = UnsafeVarTo(aValue)->GetValue(); return value != 0; } case TypeIds_UInt64Number: { - unsigned __int64 value = JavascriptUInt64Number::UnsafeFromVar(aValue)->GetValue(); + unsigned __int64 value = UnsafeVarTo(aValue)->GetValue(); return value != 0; } case TypeIds_String: { - JavascriptString * pstValue = JavascriptString::UnsafeFromVar(aValue); + JavascriptString * pstValue = UnsafeVarTo(aValue); return pstValue->GetLength() > 0; } @@ -831,7 +832,7 @@ using namespace Js; JIT_HELPER_REENTRANT_HEADER(Op_ConvNumber_FromPrimitive); Assert(Js::JavascriptStackWalker::ValidateTopJitFrame(scriptContext)); Assert(!TaggedNumber::Is(aValue)); - RecyclableObject *obj = RecyclableObject::FromVar(aValue); + RecyclableObject *obj = VarTo(aValue); // NOTE: Don't allow strings, otherwise JIT's float type specialization has to worry about concats if (obj->GetTypeId() >= TypeIds_String) @@ -863,7 +864,7 @@ using namespace Js; double JavascriptConversion::ToNumber_Full(Var aValue,ScriptContext* scriptContext) { AssertMsg(!TaggedInt::Is(aValue), "Should be detected"); - ScriptContext * objectScriptContext = RecyclableObject::Is(aValue) ? RecyclableObject::UnsafeFromVar(aValue)->GetScriptContext() : nullptr; + ScriptContext * objectScriptContext = VarIs(aValue) ? UnsafeVarTo(aValue)->GetScriptContext() : nullptr; BOOL fPrimitiveOnly = false; while(true) { @@ -883,22 +884,22 @@ using namespace Js; return TaggedInt::ToDouble(aValue); case TypeIds_Boolean: - return JavascriptBoolean::UnsafeFromVar(aValue)->GetValue() ? 1 : +0; + return UnsafeVarTo(aValue)->GetValue() ? 1 : +0; case TypeIds_Number: return JavascriptNumber::GetValue(aValue); case TypeIds_Int64Number: - return (double)JavascriptInt64Number::UnsafeFromVar(aValue)->GetValue(); + return (double)UnsafeVarTo(aValue)->GetValue(); case TypeIds_UInt64Number: - return (double)JavascriptUInt64Number::UnsafeFromVar(aValue)->GetValue(); + return (double)UnsafeVarTo(aValue)->GetValue(); case TypeIds_String: - return JavascriptString::UnsafeFromVar(aValue)->ToDouble(); + return UnsafeVarTo(aValue)->ToDouble(); case TypeIds_VariantDate: - return Js::DateImplementation::GetTvUtc(Js::DateImplementation::JsLocalTimeFromVarDate(JavascriptVariantDate::UnsafeFromVar(aValue)->GetValue()), scriptContext); + return Js::DateImplementation::GetTvUtc(Js::DateImplementation::JsLocalTimeFromVarDate(UnsafeVarTo(aValue)->GetValue()), scriptContext); default: { @@ -920,7 +921,7 @@ using namespace Js; double JavascriptConversion::ToInteger_Full(Var aValue,ScriptContext* scriptContext) { AssertMsg(!TaggedInt::Is(aValue), "Should be detected"); - ScriptContext * objectScriptContext = RecyclableObject::Is(aValue) ? RecyclableObject::UnsafeFromVar(aValue)->GetScriptContext() : nullptr; + ScriptContext * objectScriptContext = VarIs(aValue) ? UnsafeVarTo(aValue)->GetScriptContext() : nullptr; BOOL fPrimitiveOnly = false; while(true) { @@ -937,18 +938,18 @@ using namespace Js; return TaggedInt::ToInt32(aValue); case TypeIds_Boolean: - return JavascriptBoolean::UnsafeFromVar(aValue)->GetValue() ? 1 : +0; + return UnsafeVarTo(aValue)->GetValue() ? 1 : +0; case TypeIds_Number: return ToInteger(JavascriptNumber::GetValue(aValue)); case TypeIds_Int64Number: - return ToInteger((double)JavascriptInt64Number::UnsafeFromVar(aValue)->GetValue()); + return ToInteger((double)UnsafeVarTo(aValue)->GetValue()); case TypeIds_UInt64Number: - return ToInteger((double)JavascriptUInt64Number::UnsafeFromVar(aValue)->GetValue()); + return ToInteger((double)UnsafeVarTo(aValue)->GetValue()); case TypeIds_String: - return ToInteger(JavascriptString::UnsafeFromVar(aValue)->ToDouble()); + return ToInteger(UnsafeVarTo(aValue)->ToDouble()); case TypeIds_VariantDate: return ToInteger(ToNumber_Full(aValue, scriptContext)); @@ -991,7 +992,7 @@ using namespace Js; Assert(Js::JavascriptStackWalker::ValidateTopJitFrame(scriptContext)); AssertMsg(!TaggedInt::Is(aValue), "Should be detected"); - ScriptContext * objectScriptContext = RecyclableObject::Is(aValue) ? RecyclableObject::UnsafeFromVar(aValue)->GetScriptContext() : nullptr; + ScriptContext * objectScriptContext = VarIs(aValue) ? UnsafeVarTo(aValue)->GetScriptContext() : nullptr; // This is used when TaggedInt's overflow but remain under int32 // so Number is our most critical case: @@ -1015,22 +1016,22 @@ using namespace Js; return TaggedInt::ToInt32(aValue); case TypeIds_Boolean: - return JavascriptBoolean::UnsafeFromVar(aValue)->GetValue() ? 1 : +0; + return UnsafeVarTo(aValue)->GetValue() ? 1 : +0; case TypeIds_Int64Number: // we won't lose precision if the int64 is within 32bit boundary; otherwise we need to // treat it as double anyhow. - return JavascriptMath::ToInt32Core((double)JavascriptInt64Number::UnsafeFromVar(aValue)->GetValue()); + return JavascriptMath::ToInt32Core((double)UnsafeVarTo(aValue)->GetValue()); case TypeIds_UInt64Number: // we won't lose precision if the int64 is within 32bit boundary; otherwise we need to // treat it as double anyhow. - return JavascriptMath::ToInt32Core((double)JavascriptUInt64Number::UnsafeFromVar(aValue)->GetValue()); + return JavascriptMath::ToInt32Core((double)UnsafeVarTo(aValue)->GetValue()); case TypeIds_String: { double result; - if (JavascriptString::UnsafeFromVar(aValue)->ToDouble(&result)) + if (UnsafeVarTo(aValue)->ToDouble(&result)) { return JavascriptMath::ToInt32Core(result); } @@ -1059,7 +1060,7 @@ using namespace Js; return TaggedInt::ToInt32(aValue); case TypeIds_Boolean: - return JavascriptBoolean::UnsafeFromVar(aValue)->GetValue() ? 1 : +0; + return UnsafeVarTo(aValue)->GetValue() ? 1 : +0; case TypeIds_Number: return ToInt32(JavascriptNumber::GetValue(aValue)); @@ -1067,17 +1068,17 @@ using namespace Js; case TypeIds_Int64Number: // we won't lose precision if the int64 is within 32bit boundary; otherwise we need to // treat it as double anyhow. - return JavascriptMath::ToInt32Core((double)JavascriptInt64Number::UnsafeFromVar(aValue)->GetValue()); + return JavascriptMath::ToInt32Core((double)UnsafeVarTo(aValue)->GetValue()); case TypeIds_UInt64Number: // we won't lose precision if the int64 is within 32bit boundary; otherwise we need to // treat it as double anyhow. - return JavascriptMath::ToInt32Core((double)JavascriptUInt64Number::UnsafeFromVar(aValue)->GetValue()); + return JavascriptMath::ToInt32Core((double)UnsafeVarTo(aValue)->GetValue()); case TypeIds_String: { double result; - if (JavascriptString::UnsafeFromVar(aValue)->ToDouble(&result)) + if (UnsafeVarTo(aValue)->ToDouble(&result)) { return ToInt32(result); } @@ -1098,7 +1099,7 @@ using namespace Js; // a strict version of ToInt32 conversion that returns false for non int32 values like, inf, NaN, undef BOOL JavascriptConversion::ToInt32Finite(Var aValue, ScriptContext* scriptContext, int32* result) { - ScriptContext * objectScriptContext = RecyclableObject::Is(aValue) ? RecyclableObject::UnsafeFromVar(aValue)->GetScriptContext() : nullptr; + ScriptContext * objectScriptContext = VarIs(aValue) ? UnsafeVarTo(aValue)->GetScriptContext() : nullptr; BOOL fPrimitiveOnly = false; while(true) { @@ -1120,7 +1121,7 @@ using namespace Js; return true; case TypeIds_Boolean: - *result = JavascriptBoolean::UnsafeFromVar(aValue)->GetValue() ? 1 : +0; + *result = UnsafeVarTo(aValue)->GetValue() ? 1 : +0; return true; case TypeIds_Number: @@ -1129,15 +1130,15 @@ using namespace Js; case TypeIds_Int64Number: // we won't lose precision if the int64 is within 32bit boundary; otherwise we need to // treat it as double anyhow. - return ToInt32Finite((double)JavascriptInt64Number::UnsafeFromVar(aValue)->GetValue(), result); + return ToInt32Finite((double)UnsafeVarTo(aValue)->GetValue(), result); case TypeIds_UInt64Number: // we won't lose precision if the int64 is within 32bit boundary; otherwise we need to // treat it as double anyhow. - return ToInt32Finite((double)JavascriptUInt64Number::UnsafeFromVar(aValue)->GetValue(), result); + return ToInt32Finite((double)UnsafeVarTo(aValue)->GetValue(), result); case TypeIds_String: - return ToInt32Finite(JavascriptString::UnsafeFromVar(aValue)->ToDouble(), result); + return ToInt32Finite(UnsafeVarTo(aValue)->ToDouble(), result); case TypeIds_VariantDate: return ToInt32Finite(ToNumber_Full(aValue, scriptContext), result); @@ -1172,12 +1173,12 @@ using namespace Js; } case TypeIds_Int64Number: { - JavascriptInt64Number* int64Number = JavascriptInt64Number::UnsafeFromVar(aValue); + JavascriptInt64Number* int64Number = UnsafeVarTo(aValue); return int64Number->GetValue(); } case TypeIds_UInt64Number: { - JavascriptUInt64Number* uint64Number = JavascriptUInt64Number::UnsafeFromVar(aValue); + JavascriptUInt64Number* uint64Number = UnsafeVarTo(aValue); return (__int64)uint64Number->GetValue(); } case TypeIds_Number: @@ -1197,12 +1198,12 @@ using namespace Js; } case TypeIds_Int64Number: { - JavascriptInt64Number* int64Number = JavascriptInt64Number::UnsafeFromVar(aValue); + JavascriptInt64Number* int64Number = UnsafeVarTo(aValue); return (unsigned __int64)int64Number->GetValue(); } case TypeIds_UInt64Number: { - JavascriptUInt64Number* uint64Number = JavascriptUInt64Number::UnsafeFromVar(aValue); + JavascriptUInt64Number* uint64Number = UnsafeVarTo(aValue); return uint64Number->GetValue(); } case TypeIds_Number: @@ -1233,7 +1234,7 @@ using namespace Js; { JIT_HELPER_REENTRANT_HEADER(Conv_ToUInt32_Full); AssertMsg(!TaggedInt::Is(aValue), "Should be detected"); - ScriptContext * objectScriptContext = RecyclableObject::Is(aValue) ? RecyclableObject::UnsafeFromVar(aValue)->GetScriptContext() : nullptr; + ScriptContext * objectScriptContext = VarIs(aValue) ? UnsafeVarTo(aValue)->GetScriptContext() : nullptr; BOOL fPrimitiveOnly = false; while(true) { @@ -1250,7 +1251,7 @@ using namespace Js; return TaggedInt::ToUInt32(aValue); case TypeIds_Boolean: - return JavascriptBoolean::UnsafeFromVar(aValue)->GetValue() ? 1 : +0; + return UnsafeVarTo(aValue)->GetValue() ? 1 : +0; case TypeIds_Number: return JavascriptMath::ToUInt32(JavascriptNumber::GetValue(aValue)); @@ -1258,17 +1259,17 @@ using namespace Js; case TypeIds_Int64Number: // we won't lose precision if the int64 is within 32bit boundary; otherwise we need to // treat it as double anyhow. - return JavascriptMath::ToUInt32((double)JavascriptInt64Number::UnsafeFromVar(aValue)->GetValue()); + return JavascriptMath::ToUInt32((double)UnsafeVarTo(aValue)->GetValue()); case TypeIds_UInt64Number: // we won't lose precision if the int64 is within 32bit boundary; otherwise we need to // treat it as double anyhow. - return JavascriptMath::ToUInt32((double)JavascriptUInt64Number::UnsafeFromVar(aValue)->GetValue()); + return JavascriptMath::ToUInt32((double)UnsafeVarTo(aValue)->GetValue()); case TypeIds_String: { double result; - if (JavascriptString::UnsafeFromVar(aValue)->ToDouble(&result)) + if (UnsafeVarTo(aValue)->ToDouble(&result)) { return JavascriptMath::ToUInt32(result); } @@ -1314,7 +1315,7 @@ using namespace Js; uint16 JavascriptConversion::ToUInt16_Full(IN Var aValue, ScriptContext* scriptContext) { AssertMsg(!TaggedInt::Is(aValue), "Should be detected"); - ScriptContext * objectScriptContext = RecyclableObject::Is(aValue) ? RecyclableObject::UnsafeFromVar(aValue)->GetScriptContext() : nullptr; + ScriptContext * objectScriptContext = VarIs(aValue) ? UnsafeVarTo(aValue)->GetScriptContext() : nullptr; BOOL fPrimitiveOnly = false; while(true) { @@ -1331,7 +1332,7 @@ using namespace Js; return TaggedInt::ToUInt16(aValue); case TypeIds_Boolean: - return JavascriptBoolean::UnsafeFromVar(aValue)->GetValue() ? 1 : +0; + return UnsafeVarTo(aValue)->GetValue() ? 1 : +0; case TypeIds_Number: return ToUInt16(JavascriptNumber::GetValue(aValue)); @@ -1339,17 +1340,17 @@ using namespace Js; case TypeIds_Int64Number: // we won't lose precision if the int64 is within 16bit boundary; otherwise we need to // treat it as double anyhow. - return ToUInt16((double)JavascriptInt64Number::UnsafeFromVar(aValue)->GetValue()); + return ToUInt16((double)UnsafeVarTo(aValue)->GetValue()); case TypeIds_UInt64Number: // we won't lose precision if the int64 is within 16bit boundary; otherwise we need to // treat it as double anyhow. - return ToUInt16((double)JavascriptUInt64Number::UnsafeFromVar(aValue)->GetValue()); + return ToUInt16((double)UnsafeVarTo(aValue)->GetValue()); case TypeIds_String: { double result; - if (JavascriptString::UnsafeFromVar(aValue)->ToDouble(&result)) + if (UnsafeVarTo(aValue)->ToDouble(&result)) { return ToUInt16(result); } diff --git a/lib/Runtime/Language/JavascriptConversion.inl b/lib/Runtime/Language/JavascriptConversion.inl index f004f932091..2fe450f0348 100644 --- a/lib/Runtime/Language/JavascriptConversion.inl +++ b/lib/Runtime/Language/JavascriptConversion.inl @@ -248,7 +248,7 @@ namespace Js { { return nullptr; } - int64 int64Val = JavascriptInt64Number::UnsafeFromVar(value)->GetValue(); + int64 int64Val = UnsafeVarTo(value)->GetValue(); return TryCanonicalizeIntHelper(int64Val); @@ -259,7 +259,7 @@ namespace Js { { return nullptr; } - uint64 uint64Val = JavascriptUInt64Number::UnsafeFromVar(value)->GetValue(); + uint64 uint64Val = UnsafeVarTo(value)->GetValue(); return TryCanonicalizeIntHelper(uint64Val); } diff --git a/lib/Runtime/Language/JavascriptExceptionObject.cpp b/lib/Runtime/Language/JavascriptExceptionObject.cpp index 75b7bf2fbf0..4bb4ef3afe6 100644 --- a/lib/Runtime/Language/JavascriptExceptionObject.cpp +++ b/lib/Runtime/Language/JavascriptExceptionObject.cpp @@ -90,10 +90,10 @@ namespace Js } if (rethrownObject) { - if (JavascriptError::Is(rethrownObject)) + if (VarIs(rethrownObject)) { - JavascriptError* jsErrorObject = JavascriptError::FromVar(rethrownObject); + JavascriptError* jsErrorObject = VarTo(rethrownObject); if (jsErrorObject->GetScriptContext() != requestingScriptContext ) { Assert(requestingScriptContext->GetHostScriptContext()); @@ -109,7 +109,7 @@ namespace Js } else { - if (RecyclableObject::Is(rethrownObject)) + if (VarIs(rethrownObject)) { if (CrossSite::NeedMarshalVar(rethrownObject, requestingScriptContext)) { diff --git a/lib/Runtime/Language/JavascriptExceptionObject.h b/lib/Runtime/Language/JavascriptExceptionObject.h index 59f76f70635..52d76ceb172 100644 --- a/lib/Runtime/Language/JavascriptExceptionObject.h +++ b/lib/Runtime/Language/JavascriptExceptionObject.h @@ -19,7 +19,7 @@ namespace Js JavascriptExceptionObject(Var object, ScriptContext * scriptContext, JavascriptExceptionContext* exceptionContextIn, bool isPendingExceptionObject = false) : thrownObject(object), isPendingExceptionObject(isPendingExceptionObject), - scriptContext(scriptContext), tag(true), + scriptContext(scriptContext), tag(true), #ifdef ENABLE_SCRIPT_DEBUGGING isDebuggerSkip(false), byteCodeOffsetAfterDebuggerSkip(Constants::InvalidByteCodeOffset), hasDebuggerLogged(false), isFirstChance(false), isExceptionCaughtInNonUserCode(false), ignoreAdvanceToNextStatement(false), @@ -139,8 +139,8 @@ namespace Js void ReplaceThrownObject(Var object) { - AssertMsg(RecyclableObject::Is(object), "Why are we replacing a non recyclable thrown object?"); - AssertMsg(this->GetScriptContext() != RecyclableObject::FromVar(object)->GetScriptContext() || this->thrownObject != object, "If replaced thrownObject is from same context what's the need to replace?"); + AssertMsg(VarIs(object), "Why are we replacing a non recyclable thrown object?"); + AssertMsg(this->GetScriptContext() != VarTo(object)->GetScriptContext() || this->thrownObject != object, "If replaced thrownObject is from same context what's the need to replace?"); this->thrownObject = object; } @@ -179,7 +179,7 @@ namespace Js private: Field(Var) thrownObject; Field(ScriptContext *) scriptContext; - + #ifdef ENABLE_SCRIPT_DEBUGGING Field(int) byteCodeOffsetAfterDebuggerSkip; #endif diff --git a/lib/Runtime/Language/JavascriptExceptionOperators.cpp b/lib/Runtime/Language/JavascriptExceptionOperators.cpp index e8d09238320..b3f60e3dbc0 100644 --- a/lib/Runtime/Language/JavascriptExceptionOperators.cpp +++ b/lib/Runtime/Language/JavascriptExceptionOperators.cpp @@ -171,7 +171,7 @@ namespace Js // it so happens that this catch was on the stack and caught the exception. // Re-throw! JavascriptExceptionOperators::DoThrow(exception, scriptContext); - } + } Var exceptionObject = exception->GetThrownObject(scriptContext); AssertMsg(exceptionObject, "Caught object is null."); @@ -1011,18 +1011,18 @@ namespace Js Assert(scriptContext != nullptr); // TODO: FastDOM Trampolines will throw JS Exceptions but are not isScriptActive //AssertMsg(scriptContext->GetThreadContext()->IsScriptActive() || - // (JavascriptError::Is(object) && (JavascriptError::FromVar(object))->IsExternalError()), + // (VarIs(object) && (VarTo(object))->IsExternalError()), // "Javascript exception raised when script is not active"); AssertMsg(scriptContext->GetThreadContext()->IsInScript() || - (JavascriptError::Is(object) && (JavascriptError::FromVar(object))->IsExternalError()), + (VarIs(object) && (VarTo(object))->IsExternalError()), "Javascript exception raised without being in CallRootFunction"); JavascriptError *javascriptError = nullptr; - if (JavascriptError::Is(object)) + if (VarIs(object)) { // We keep track of the JavascriptExceptionObject that was created when this error // was first thrown so that we can always get the correct metadata. - javascriptError = JavascriptError::FromVar(object); + javascriptError = VarTo(object); JavascriptExceptionObject *exceptionObject = javascriptError->GetJavascriptExceptionObject(); if (exceptionObject) { @@ -1115,9 +1115,9 @@ namespace Js // In WER scenario, we should combine the original stack with latest throw stack as the final throw might be coming form // a different stack. uint64 i = 1; - if (crawlStackForWER && thrownObject && Js::JavascriptError::Is(thrownObject)) + if (crawlStackForWER && thrownObject && Js::VarIs(thrownObject)) { - Js::JavascriptError* errorObject = Js::JavascriptError::FromVar(thrownObject); + Js::JavascriptError* errorObject = Js::VarTo(thrownObject); Js::JavascriptExceptionContext::StackTrace *originalStackTrace = NULL; const Js::JavascriptExceptionObject* originalExceptionObject = errorObject->GetJavascriptExceptionObject(); if (!resetStack && errorObject->GetInternalProperty(errorObject, InternalPropertyIds::StackTrace, (Js::Var*) &originalStackTrace, NULL, &scriptContext) && @@ -1407,14 +1407,14 @@ namespace Js // bool JavascriptExceptionOperators::IsErrorInstance(Var thrownObject) { - if (thrownObject && JavascriptError::Is(thrownObject)) + if (thrownObject && VarIs(thrownObject)) { - return !JavascriptError::FromVar(thrownObject)->IsPrototype(); + return !VarTo(thrownObject)->IsPrototype(); } - if (thrownObject && RecyclableObject::Is(thrownObject)) + if (thrownObject && VarIs(thrownObject)) { - RecyclableObject* obj = RecyclableObject::FromVar(thrownObject); + RecyclableObject* obj = VarTo(thrownObject); while (true) { @@ -1424,7 +1424,7 @@ namespace Js break; } - if (JavascriptError::Is(obj)) + if (VarIs(obj)) { return true; } @@ -1458,7 +1458,7 @@ namespace Js // If we still have stack trace to store and obj is a thrown exception object, obj must be an Error instance. Assert(!isThrownException || IsErrorInstance(targetObject)); - RecyclableObject* obj = RecyclableObject::FromVar(targetObject); + RecyclableObject* obj = VarTo(targetObject); if (!resetStack && obj->HasProperty(PropertyIds::stack)) { return; // we don't want to overwrite an existing "stack" property @@ -1519,19 +1519,19 @@ namespace Js // If the first argument to the accessor is not a recyclable object, return undefined // for compat with other browsers - if (!RecyclableObject::Is(args[0])) + if (!VarIs(args[0])) { return scriptContext->GetLibrary()->GetUndefined(); } - RecyclableObject *obj = RecyclableObject::FromVar(args[0]); + RecyclableObject *obj = VarTo(args[0]); // If an argument was passed to the accessor, it is being called as a setter. // Set the internal StackTraceCache property accordingly. if (args.Info.Count > 1) { obj->SetInternalProperty(InternalPropertyIds::StackTraceCache, args[1], PropertyOperationFlags::PropertyOperation_None, NULL); - if (JavascriptError::Is(obj)) + if (VarIs(obj)) { ((JavascriptError *)obj)->SetStackPropertyRedefined(true); } @@ -1633,7 +1633,7 @@ namespace Js if (scriptContext->GetConfig()->IsErrorStackTraceEnabled() && IsErrorInstance(thrownObject)) { - HRESULT hr = JavascriptError::GetRuntimeError(RecyclableObject::FromVar(thrownObject), NULL); + HRESULT hr = JavascriptError::GetRuntimeError(VarTo(thrownObject), NULL); JavascriptFunction* error = scriptContext->GetLibrary()->GetErrorConstructor(); // If we are throwing StackOverflow and Error.stackTraceLimit is a custom getter, we can't make the getter diff --git a/lib/Runtime/Language/JavascriptOperators.cpp b/lib/Runtime/Language/JavascriptOperators.cpp index 3896f8e23d1..6f3ab153033 100644 --- a/lib/Runtime/Language/JavascriptOperators.cpp +++ b/lib/Runtime/Language/JavascriptOperators.cpp @@ -209,7 +209,7 @@ using namespace Js; // See Win8 bug 490489. callInfo.Flags = CallFlags_Value; - RecyclableObject *funcPtr = RecyclableObject::UnsafeFromVar(func); + RecyclableObject *funcPtr = UnsafeVarTo(func); PROBE_STACK(scriptContext, Js::Constants::MinStackDefault + argCount * 4); JavascriptMethod entryPoint = funcPtr->GetEntryPoint(); @@ -325,13 +325,13 @@ using namespace Js; return scriptContext->GetLibrary()->GetNumberTypeDisplayString(); default: // Falsy objects are typeof 'undefined'. - if (RecyclableObject::FromVar(var)->GetType()->IsFalsy()) + if (VarTo(var)->GetType()->IsFalsy()) { return scriptContext->GetLibrary()->GetUndefinedDisplayString(); } else { - return RecyclableObject::FromVar(var)->GetTypeOfString(scriptContext); + return VarTo(var)->GetTypeOfString(scriptContext); } } JIT_HELPER_END(Op_Typeof); @@ -540,7 +540,7 @@ using namespace Js; { return false; } - else if (JavascriptVariantDate::Is(aLeft) == false) // only need to check on aLeft - since they are the same var, aRight would do the same + else if (VarIs(aLeft) == false) // only need to check on aLeft - since they are the same var, aRight would do the same { return true; } @@ -567,7 +567,7 @@ using namespace Js; } else { - BOOL res = RecyclableObject::UnsafeFromVar(aRight)->Equals(aLeft, &result, requestContext); + BOOL res = UnsafeVarTo(aRight)->Equals(aLeft, &result, requestContext); AssertMsg(res, "Should have handled this"); return result; } @@ -584,13 +584,13 @@ using namespace Js; } else { - BOOL res = RecyclableObject::UnsafeFromVar(aRight)->Equals(aLeft, &result, requestContext); + BOOL res = UnsafeVarTo(aRight)->Equals(aLeft, &result, requestContext); AssertMsg(res, "Should have handled this"); return result; } } - if (RecyclableObject::UnsafeFromVar(aLeft)->Equals(aRight, &result, requestContext)) + if (UnsafeVarTo(aLeft)->Equals(aRight, &result, requestContext)) { return result; } @@ -679,15 +679,15 @@ using namespace Js; { case TypeIds_Int64Number: { - __int64 leftValue = JavascriptInt64Number::UnsafeFromVar(aLeft)->GetValue(); - __int64 rightValue = JavascriptInt64Number::UnsafeFromVar(aRight)->GetValue(); + __int64 leftValue = UnsafeVarTo(aLeft)->GetValue(); + __int64 rightValue = UnsafeVarTo(aRight)->GetValue(); return leftValue < rightValue; } break; case TypeIds_UInt64Number: { - __int64 leftValue = JavascriptInt64Number::UnsafeFromVar(aLeft)->GetValue(); - unsigned __int64 rightValue = JavascriptUInt64Number::UnsafeFromVar(aRight)->GetValue(); + __int64 leftValue = UnsafeVarTo(aLeft)->GetValue(); + unsigned __int64 rightValue = UnsafeVarTo(aRight)->GetValue(); if (rightValue <= INT_MAX && leftValue >= 0) { return leftValue < (__int64)rightValue; @@ -695,7 +695,7 @@ using namespace Js; } break; } - dblLeft = (double)JavascriptInt64Number::UnsafeFromVar(aLeft)->GetValue(); + dblLeft = (double)UnsafeVarTo(aLeft)->GetValue(); dblRight = JavascriptConversion::ToNumber(aRight, scriptContext); } break; @@ -709,8 +709,8 @@ using namespace Js; { case TypeIds_Int64Number: { - unsigned __int64 leftValue = JavascriptUInt64Number::UnsafeFromVar(aLeft)->GetValue(); - __int64 rightValue = JavascriptInt64Number::UnsafeFromVar(aRight)->GetValue(); + unsigned __int64 leftValue = UnsafeVarTo(aLeft)->GetValue(); + __int64 rightValue = UnsafeVarTo(aRight)->GetValue(); if (leftValue < INT_MAX && rightValue >= 0) { return (__int64)leftValue < rightValue; @@ -719,13 +719,13 @@ using namespace Js; break; case TypeIds_UInt64Number: { - unsigned __int64 leftValue = JavascriptUInt64Number::UnsafeFromVar(aLeft)->GetValue(); - unsigned __int64 rightValue = JavascriptUInt64Number::UnsafeFromVar(aRight)->GetValue(); + unsigned __int64 leftValue = UnsafeVarTo(aLeft)->GetValue(); + unsigned __int64 rightValue = UnsafeVarTo(aRight)->GetValue(); return leftValue < rightValue; } break; } - dblLeft = (double)JavascriptUInt64Number::UnsafeFromVar(aLeft)->GetValue(); + dblLeft = (double)UnsafeVarTo(aLeft)->GetValue(); dblRight = JavascriptConversion::ToNumber(aRight, scriptContext); } break; @@ -836,7 +836,7 @@ using namespace Js; switch (rightType) { case TypeIds_String: - return JavascriptString::Equals(JavascriptString::UnsafeFromVar(aLeft), JavascriptString::UnsafeFromVar(aRight)); + return JavascriptString::Equals(UnsafeVarTo(aLeft), UnsafeVarTo(aRight)); } return FALSE; case TypeIds_Integer: @@ -857,18 +857,18 @@ using namespace Js; { case TypeIds_Int64Number: { - __int64 leftValue = JavascriptInt64Number::UnsafeFromVar(aLeft)->GetValue(); - __int64 rightValue = JavascriptInt64Number::UnsafeFromVar(aRight)->GetValue(); + __int64 leftValue = UnsafeVarTo(aLeft)->GetValue(); + __int64 rightValue = UnsafeVarTo(aRight)->GetValue(); return leftValue == rightValue; } case TypeIds_UInt64Number: { - __int64 leftValue = JavascriptInt64Number::UnsafeFromVar(aLeft)->GetValue(); - unsigned __int64 rightValue = JavascriptInt64Number::FromVar(aRight)->GetValue(); + __int64 leftValue = UnsafeVarTo(aLeft)->GetValue(); + unsigned __int64 rightValue = VarTo(aRight)->GetValue(); return ((unsigned __int64)leftValue == rightValue); } case TypeIds_Number: - dblLeft = (double)JavascriptInt64Number::UnsafeFromVar(aLeft)->GetValue(); + dblLeft = (double)UnsafeVarTo(aLeft)->GetValue(); dblRight = JavascriptNumber::GetValue(aRight); goto CommonNumber; } @@ -878,18 +878,18 @@ using namespace Js; { case TypeIds_Int64Number: { - unsigned __int64 leftValue = JavascriptUInt64Number::UnsafeFromVar(aLeft)->GetValue(); - __int64 rightValue = JavascriptInt64Number::UnsafeFromVar(aRight)->GetValue(); + unsigned __int64 leftValue = UnsafeVarTo(aLeft)->GetValue(); + __int64 rightValue = UnsafeVarTo(aRight)->GetValue(); return (leftValue == (unsigned __int64)rightValue); } case TypeIds_UInt64Number: { - unsigned __int64 leftValue = JavascriptUInt64Number::UnsafeFromVar(aLeft)->GetValue(); - unsigned __int64 rightValue = JavascriptInt64Number::FromVar(aRight)->GetValue(); + unsigned __int64 leftValue = UnsafeVarTo(aLeft)->GetValue(); + unsigned __int64 rightValue = VarTo(aRight)->GetValue(); return leftValue == rightValue; } case TypeIds_Number: - dblLeft = (double)JavascriptUInt64Number::UnsafeFromVar(aLeft)->GetValue(); + dblLeft = (double)UnsafeVarTo(aLeft)->GetValue(); dblRight = JavascriptNumber::GetValue(aRight); goto CommonNumber; } @@ -904,11 +904,11 @@ using namespace Js; goto CommonNumber; case TypeIds_Int64Number: dblLeft = JavascriptNumber::GetValue(aLeft); - dblRight = (double)JavascriptInt64Number::FromVar(aRight)->GetValue(); + dblRight = (double)VarTo(aRight)->GetValue(); goto CommonNumber; case TypeIds_UInt64Number: dblLeft = JavascriptNumber::GetValue(aLeft); - dblRight = (double)JavascriptUInt64Number::UnsafeFromVar(aRight)->GetValue(); + dblRight = (double)UnsafeVarTo(aRight)->GetValue(); goto CommonNumber; case TypeIds_Number: dblLeft = JavascriptNumber::GetValue(aLeft); @@ -937,8 +937,8 @@ using namespace Js; case TypeIds_Symbol: if (rightType == TypeIds_Symbol) { - const PropertyRecord* leftValue = JavascriptSymbol::UnsafeFromVar(aLeft)->GetValue(); - const PropertyRecord* rightValue = JavascriptSymbol::UnsafeFromVar(aRight)->GetValue(); + const PropertyRecord* leftValue = UnsafeVarTo(aLeft)->GetValue(); + const PropertyRecord* rightValue = UnsafeVarTo(aRight)->GetValue(); Assert(leftValue != rightValue); } break; @@ -951,7 +951,7 @@ using namespace Js; case TypeIds_GlobalObject: { BOOL result; - if(RecyclableObject::UnsafeFromVar(aLeft)->StrictEquals(aRight, &result, requestContext)) + if(UnsafeVarTo(aLeft)->StrictEquals(aRight, &result, requestContext)) { return result; } @@ -961,10 +961,10 @@ using namespace Js; break; } - if (RecyclableObject::FromVar(aLeft)->IsExternal()) + if (VarTo(aLeft)->IsExternal()) { BOOL result; - if (RecyclableObject::FromVar(aLeft)->StrictEquals(aRight, &result, requestContext)) + if (VarTo(aLeft)->StrictEquals(aRight, &result, requestContext)) { if (result) { @@ -973,10 +973,10 @@ using namespace Js; } } - if (!TaggedNumber::Is(aRight) && RecyclableObject::FromVar(aRight)->IsExternal()) + if (!TaggedNumber::Is(aRight) && VarTo(aRight)->IsExternal()) { BOOL result; - if (RecyclableObject::FromVar(aRight)->StrictEquals(aLeft, &result, requestContext)) + if (VarTo(aRight)->StrictEquals(aLeft, &result, requestContext)) { if (result) { @@ -999,9 +999,9 @@ using namespace Js; { return FALSE; } - RecyclableObject* object = RecyclableObject::UnsafeFromVar(instance); + RecyclableObject* object = UnsafeVarTo(instance); - if (JavascriptProxy::Is(instance)) + if (VarIs(instance)) { PropertyDescriptor desc; return GetOwnPropertyDescriptor(object, propertyId, requestContext, &desc); @@ -1055,7 +1055,7 @@ using namespace Js; } else { - RecyclableObject* object = RecyclableObject::UnsafeFromVar(instance); + RecyclableObject* object = UnsafeVarTo(instance); result = object && object->GetAccessors(propertyId, getter, setter, requestContext); } return result; @@ -1063,7 +1063,8 @@ using namespace Js; JavascriptArray* JavascriptOperators::GetOwnPropertyNames(Var instance, ScriptContext *scriptContext) { - RecyclableObject *object = RecyclableObject::FromVar(ToObject(instance, scriptContext)); + RecyclableObject *object = ToObject(instance, scriptContext); + AssertOrFailFast(VarIsCorrectType(object)); // Consider moving this check into ToObject JavascriptProxy * proxy = JavascriptOperators::TryFromVar(instance); if (proxy) { @@ -1075,7 +1076,8 @@ using namespace Js; JavascriptArray* JavascriptOperators::GetOwnPropertySymbols(Var instance, ScriptContext *scriptContext) { - RecyclableObject *object = RecyclableObject::FromVar(ToObject(instance, scriptContext)); + RecyclableObject *object = ToObject(instance, scriptContext); + AssertOrFailFast(VarIsCorrectType(object)); CHAKRATEL_LANGSTATS_INC_BUILTINCOUNT(Object_Constructor_getOwnPropertySymbols); JavascriptProxy* proxy = JavascriptOperators::TryFromVar(instance); @@ -1089,7 +1091,8 @@ using namespace Js; JavascriptArray* JavascriptOperators::GetOwnPropertyKeys(Var instance, ScriptContext* scriptContext) { - RecyclableObject *object = RecyclableObject::FromVar(ToObject(instance, scriptContext)); + RecyclableObject *object = ToObject(instance, scriptContext); + AssertOrFailFast(VarIsCorrectType(object)); JavascriptProxy* proxy = JavascriptOperators::TryFromVar(instance); if (proxy) @@ -1117,7 +1120,7 @@ using namespace Js; { element = proxyResult->DirectGetItem(i); - Assert(!JavascriptSymbol::Is(element)); + Assert(!VarIs(element)); PropertyDescriptor propertyDescriptor; JavascriptConversion::ToPropertyKey(element, scriptContext, &propertyRecord, nullptr); @@ -1153,7 +1156,7 @@ using namespace Js; } else { - RecyclableObject* object = RecyclableObject::FromVar(instance); + RecyclableObject* object = VarTo(instance); result = object && object->GetProperty(object, propertyId, value, propertyValueInfo, requestContext); if (propertyValueInfo && result) @@ -1181,7 +1184,7 @@ using namespace Js; Assert(scriptContext); Assert(propertyDescriptor); - if (JavascriptProxy::Is(obj)) + if (VarIs(obj)) { return JavascriptProxy::GetOwnPropertyDescriptor(obj, propertyId, scriptContext, propertyDescriptor); } @@ -1329,7 +1332,7 @@ using namespace Js; return false; } - RecyclableObject* instance = RecyclableObject::UnsafeFromVar(instanceVar); + RecyclableObject* instance = UnsafeVarTo(instanceVar); ScriptContext* scriptContext = instance->GetScriptContext(); if (!PHASE_OFF1(IsConcatSpreadableCachePhase)) @@ -1401,18 +1404,18 @@ using namespace Js; RecyclableObject* function = GetIteratorFunction(aRight, scriptContext); JavascriptMethod method = function->GetEntryPoint(); - if (((JavascriptArray::Is(aRight) && + if (((JavascriptArray::IsNonES5Array(aRight) && ( JavascriptLibrary::IsDefaultArrayValuesFunction(function, scriptContext) // Verify that the head segment of the array covers all elements with no gaps. // Accessing an element on the prototype could have side-effects that would invalidate the optimization. - && JavascriptArray::UnsafeFromVar(aRight)->GetHead()->next == nullptr - && JavascriptArray::UnsafeFromVar(aRight)->GetHead()->left == 0 - && JavascriptArray::UnsafeFromVar(aRight)->GetHead()->length == JavascriptArray::FromVar(aRight)->GetLength() - && JavascriptArray::UnsafeFromVar(aRight)->HasNoMissingValues() - && !JavascriptArray::UnsafeFromVar(aRight)->IsCrossSiteObject() + && UnsafeVarTo(aRight)->GetHead()->next == nullptr + && UnsafeVarTo(aRight)->GetHead()->left == 0 + && UnsafeVarTo(aRight)->GetHead()->length == VarTo(aRight)->GetLength() + && UnsafeVarTo(aRight)->HasNoMissingValues() + && !UnsafeVarTo(aRight)->IsCrossSiteObject() )) || - (TypedArrayBase::Is(aRight) && method == TypedArrayBase::EntryInfo::Values.GetOriginalEntryPoint())) + (VarIs(aRight) && method == TypedArrayBase::EntryInfo::Values.GetOriginalEntryPoint())) // We can't optimize away the iterator if the array iterator prototype is user defined. && !JavascriptLibrary::ArrayIteratorPrototypeHasUserDefinedNext(scriptContext)) { @@ -1448,13 +1451,13 @@ using namespace Js; BOOL JavascriptOperators::IsPropertyUnscopable(Var instanceVar, PropertyId propertyId) { - RecyclableObject* instance = RecyclableObject::FromVar(instanceVar); + RecyclableObject* instance = VarTo(instanceVar); ScriptContext * scriptContext = instance->GetScriptContext(); Var unscopables = JavascriptOperators::GetProperty(instance, PropertyIds::_symbolUnscopables, scriptContext); if (JavascriptOperators::IsObject(unscopables)) { - DynamicObject *unscopablesList = DynamicObject::FromVar(unscopables); + DynamicObject *unscopablesList = VarTo(unscopables); Var value = nullptr; //8.1.1.2.1.9.c If blocked is not undefined if (JavascriptOperators::GetProperty(unscopablesList, propertyId, &value, scriptContext)) @@ -1489,7 +1492,7 @@ using namespace Js; BOOL JavascriptOperators::HasRootProperty(RecyclableObject* instance, PropertyId propertyId) { - Assert(RootObjectBase::Is(instance)); + Assert(VarIs(instance)); RootObjectBase* rootObject = static_cast(instance); if (rootObject->HasRootProperty(propertyId)) @@ -1534,7 +1537,7 @@ using namespace Js; JIT_HELPER_REENTRANT_HEADER(Op_HasProperty); RecyclableObject* object = TaggedNumber::Is(instance) ? scriptContext->GetLibrary()->GetNumberPrototype() : - RecyclableObject::FromVar(instance); + VarTo(instance); BOOL result = HasProperty(object, propertyId); return result; JIT_HELPER_END(Op_HasProperty); @@ -1544,7 +1547,7 @@ using namespace Js; { RecyclableObject* object = TaggedNumber::Is(instance) ? scriptContext->GetLibrary()->GetNumberPrototype() : - RecyclableObject::FromVar(instance); + VarTo(instance); BOOL result = HasOwnProperty(object, propertyId, scriptContext, nullptr); return result; } @@ -1554,7 +1557,7 @@ using namespace Js; { AssertMsg(!TaggedNumber::Is(instance), "HasOwnPropertyNoHostObject int passed"); - RecyclableObject* object = RecyclableObject::FromVar(instance); + RecyclableObject* object = VarTo(instance); return object && object->HasOwnPropertyNoHostObject(propertyId); } @@ -1564,13 +1567,13 @@ using namespace Js; { AssertMsg(!TaggedNumber::Is(instance), "HasOwnPropertyNoHostObjectForHeapEnum int passed"); - RecyclableObject * object = RecyclableObject::FromVar(instance); + RecyclableObject * object = VarTo(instance); if (StaticType::Is(object->GetTypeId())) { return FALSE; } getter = setter = NULL; - DynamicObject* dynamicObject = DynamicObject::FromVar(instance); + DynamicObject* dynamicObject = VarTo(instance); Assert(dynamicObject->GetScriptContext()->IsHeapEnumInProgress()); if (dynamicObject->UseDynamicObjectForNoHostObjectAccess()) { @@ -1578,7 +1581,7 @@ using namespace Js; { Var value = nullptr; if (!JavascriptConversion::PropertyQueryFlagsToBoolean(dynamicObject->DynamicObject::GetPropertyQuery(instance, propertyId, &value, NULL, requestContext)) || - (requestContext->IsUndeclBlockVar(value) && (ActivationObject::Is(instance) || RootObjectBase::Is(instance)))) + (requestContext->IsUndeclBlockVar(value) && (VarIs(instance) || VarIs(instance)))) { return FALSE; } @@ -1590,7 +1593,7 @@ using namespace Js; { Var value = nullptr; if (!object->GetProperty(instance, propertyId, &value, NULL, requestContext) || - (requestContext->IsUndeclBlockVar(value) && (ActivationObject::Is(instance) || RootObjectBase::Is(instance)))) + (requestContext->IsUndeclBlockVar(value) && (VarIs(instance) || VarIs(instance)))) { return FALSE; } @@ -1603,7 +1606,7 @@ using namespace Js; { AssertMsg(!TaggedNumber::Is(instance), "GetDataPropertyNoHostObject int passed"); Assert(HasOwnPropertyNoHostObjectForHeapEnum(instance, propertyId, requestContext, getter, setter) || getter || setter); - DynamicObject* dynamicObject = DynamicObject::FromVar(instance); + DynamicObject* dynamicObject = VarTo(instance); getter = setter = NULL; if (NULL == dynamicObject) { @@ -1636,10 +1639,10 @@ using namespace Js; BOOL JavascriptOperators::OP_HasOwnPropScoped(Var scope, PropertyId propertyId, Var defaultInstance, ScriptContext* scriptContext) { - AssertMsg(scope == scriptContext->GetLibrary()->GetNull() || JavascriptArray::Is(scope), + AssertMsg(scope == scriptContext->GetLibrary()->GetNull() || JavascriptArray::IsNonES5Array(scope), "Invalid scope chain pointer passed - should be null or an array"); - JavascriptArray* arrScope = JavascriptOperators::TryFromVar(scope); + JavascriptArray* arrScope = JavascriptArray::TryVarToNonES5Array(scope); if (arrScope) { Var instance = arrScope->DirectGetItem(0); @@ -1660,7 +1663,7 @@ using namespace Js; BOOL JavascriptOperators::GetRootProperty(Var instance, PropertyId propertyId, Var* value, ScriptContext* requestContext, PropertyValueInfo* info) { - return GetProperty_Internal(instance, RecyclableObject::FromVar(instance), true, propertyId, value, requestContext, info); + return GetProperty_Internal(instance, VarTo(instance), true, propertyId, value, requestContext, info); } BOOL JavascriptOperators::GetProperty_InternalSimple(Var instance, RecyclableObject* object, PropertyId propertyId, _Outptr_result_maybenull_ Var* value, ScriptContext* requestContext) @@ -1704,7 +1707,7 @@ using namespace Js; BOOL foundProperty = FALSE; if (isRoot) { - Assert(RootObjectBase::Is(object)); + Assert(VarIs(object)); RootObjectBase* rootObject = static_cast(object); foundProperty = rootObject->GetRootProperty(instance, propertyId, value, info, requestContext); @@ -1737,7 +1740,7 @@ using namespace Js; if (foundProperty) { #if ENABLE_FIXED_FIELDS && DBG - if (DynamicObject::Is(object)) + if (DynamicObject::IsBaseDynamicObject(object)) { DynamicObject* dynamicObject = (DynamicObject*)object; DynamicTypeHandler* dynamicTypeHandler = dynamicObject->GetDynamicType()->GetTypeHandler(); @@ -1745,10 +1748,10 @@ using namespace Js; if (dynamicTypeHandler->CheckFixedProperty(requestContext->GetPropertyName(propertyId), &property, requestContext)) { bool skipAssert = false; - if (value != nullptr && Js::RecyclableObject::Is(property)) + if (value != nullptr && Js::VarIs(property)) { - Js::RecyclableObject* pObject = Js::RecyclableObject::FromVar(property); - Js::RecyclableObject* pValue = Js::RecyclableObject::FromVar(*value); + Js::RecyclableObject* pObject = Js::VarTo(property); + Js::RecyclableObject* pValue = Js::VarTo(*value); if (pValue->GetScriptContext() != pObject->GetScriptContext()) { @@ -1763,7 +1766,7 @@ using namespace Js; // Don't cache the information if the value is undecl block var // REVIEW: We might want to only check this if we need to (For LdRootFld or ScopedLdFld) // Also we might want to throw here instead of checking it again in the caller - if (value && !requestContext->IsUndeclBlockVar(*value) && !WithScopeObject::Is(object)) + if (value && !requestContext->IsUndeclBlockVar(*value) && !VarIs(object)) { CacheOperators::CachePropertyRead(propertyObject, object, isRoot, propertyId, false, info, requestContext); } @@ -1813,12 +1816,12 @@ using namespace Js; // Here, any well-behaved subclasses of DynamicObject can opt in to getting included in the missing property cache. // For now, we only include basic objects and arrays. CustomExternalObject in particular is problematic because in // some cases it can add new properties without transitioning its type handler. - if (PHASE_OFF1(MissingPropertyCachePhase) || isRoot || !(DynamicObject::Is(instance) || DynamicObject::IsAnyArray(instance))) + if (PHASE_OFF1(MissingPropertyCachePhase) || isRoot || !(DynamicObject::IsBaseDynamicObject(instance) || DynamicObject::IsAnyArray(instance))) { return; } - DynamicTypeHandler* handler = DynamicObject::UnsafeFromVar(instance)->GetDynamicType()->GetTypeHandler(); + DynamicTypeHandler* handler = UnsafeVarTo(instance)->GetDynamicType()->GetTypeHandler(); // Only cache missing property lookups for non-root field loads on objects that have PathTypeHandlers, because only these types have the right behavior // when the missing property is later added. DictionaryTypeHandler's introduce the possibility that a stale TypePropertyCache entry with isMissing==true can @@ -1876,7 +1879,7 @@ using namespace Js; if (result != PropertyQueryFlags::Property_NotFound) { - if (!WithScopeObject::Is(object) && info->GetPropertyRecordUsageCache()) + if (!VarIs(object) && info->GetPropertyRecordUsageCache()) { PropertyId propertyId = info->GetPropertyRecordUsageCache()->GetPropertyRecord()->GetPropertyId(); CacheOperators::CachePropertyRead(instance, object, false, propertyId, false, info, requestContext); @@ -1952,7 +1955,7 @@ using namespace Js; *propertyObject = scriptContext->GetLibrary()->GetNumberPrototype(); return TRUE; } - RecyclableObject* object = RecyclableObject::UnsafeFromVar(instance); + RecyclableObject* object = UnsafeVarTo(instance); *propertyObject = object; if (JavascriptOperators::IsUndefinedOrNull(object)) { @@ -1993,10 +1996,10 @@ using namespace Js; Var JavascriptOperators::OP_GetRootProperty(Var instance, PropertyId propertyId, PropertyValueInfo * info, ScriptContext* scriptContext) { - AssertMsg(RootObjectBase::Is(instance), "Root must be an object!"); + AssertMsg(VarIs(instance), "Root must be an object!"); Var value = nullptr; - if (JavascriptOperators::GetRootProperty(RecyclableObject::FromVar(instance), propertyId, &value, scriptContext, info)) + if (JavascriptOperators::GetRootProperty(VarTo(instance), propertyId, &value, scriptContext, info)) { if (scriptContext->IsUndeclBlockVar(value) && scriptContext->GetThreadContext()->RecordImplicitException()) { @@ -2034,7 +2037,7 @@ using namespace Js; for (int i = 0; i < length; i += 1) { Var value = nullptr; - RecyclableObject *obj = RecyclableObject::FromVar(pScope->GetItem(i)); + RecyclableObject *obj = VarTo(pScope->GetItem(i)); if (JavascriptOperators::GetProperty(obj, Js::PropertyIds::_this, &value, scriptContext)) { return value; @@ -2047,7 +2050,7 @@ using namespace Js; Var JavascriptOperators::OP_UnwrapWithObj(Var aValue) { JIT_HELPER_NOT_REENTRANT_NOLOCK_HEADER(Op_UnwrapWithObj); - return RecyclableObject::FromVar(aValue)->GetThisObjectOrUnWrap(); + return VarTo(aValue)->GetThisObjectOrUnWrap(); JIT_HELPER_END(Op_UnwrapWithObj); } Var JavascriptOperators::OP_GetInstanceScoped(FrameDisplay *pScope, PropertyId propertyId, Var rootObject, Var* thisVar, ScriptContext* scriptContext) @@ -2163,7 +2166,7 @@ using namespace Js; if (isRoot) { - foundProperty = RootObjectBase::FromVar(object)->GetRootPropertyReference(instance, propertyId, value, info, requestContext); + foundProperty = VarTo(object)->GetRootPropertyReference(instance, propertyId, value, info, requestContext); } if (!foundProperty) { @@ -2191,7 +2194,7 @@ using namespace Js; } #if ENABLE_FIXED_FIELDS && DBG - if (DynamicObject::Is(object)) + if (DynamicObject::IsBaseDynamicObject(object)) { DynamicObject* dynamicObject = (DynamicObject*)object; DynamicTypeHandler* dynamicTypeHandler = dynamicObject->GetDynamicType()->GetTypeHandler(); @@ -2317,12 +2320,12 @@ using namespace Js; } if (setterValueOrProxy) { - if (!WithScopeObject::Is(receiver) && info->GetPropertyRecordUsageCache() && !JavascriptOperators::IsUndefinedAccessor(setterValueOrProxy, requestContext)) + if (!VarIs(receiver) && info->GetPropertyRecordUsageCache() && !JavascriptOperators::IsUndefinedAccessor(setterValueOrProxy, requestContext)) { - CacheOperators::CachePropertyWrite(RecyclableObject::FromVar(receiver), false, object->GetType(), info->GetPropertyRecordUsageCache()->GetPropertyRecord()->GetPropertyId(), info, requestContext); + CacheOperators::CachePropertyWrite(VarTo(receiver), false, object->GetType(), info->GetPropertyRecordUsageCache()->GetPropertyRecord()->GetPropertyId(), info, requestContext); } - receiver = (RecyclableObject::FromVar(receiver))->GetThisObjectOrUnWrap(); - RecyclableObject* func = RecyclableObject::FromVar(setterValueOrProxy); + receiver = (VarTo(receiver))->GetThisObjectOrUnWrap(); + RecyclableObject* func = VarTo(setterValueOrProxy); JavascriptOperators::CallSetter(func, receiver, newValue, requestContext); } @@ -2330,8 +2333,8 @@ using namespace Js; } else if ((flags & Proxy) == Proxy) { - Assert(JavascriptProxy::Is(setterValueOrProxy)); - JavascriptProxy* proxy = JavascriptProxy::FromVar(setterValueOrProxy); + Assert(VarIs(setterValueOrProxy)); + JavascriptProxy* proxy = VarTo(setterValueOrProxy); auto fn = [&](RecyclableObject* target) -> BOOL { return JavascriptOperators::SetPropertyWPCache(receiver, target, propertyKey, newValue, requestContext, propertyOperationFlags, info); }; @@ -2357,7 +2360,7 @@ using namespace Js; return FALSE; } - RecyclableObject* receiverObject = RecyclableObject::FromVar(receiver); + RecyclableObject* receiverObject = VarTo(receiver); if (receiver != object) { // If the receiver object has the property and it is an accessor then return false @@ -2373,9 +2376,9 @@ using namespace Js; // in 9.1.9, step 5, we should return false if receiver is not object, and that will happen in default RecyclableObject operation anyhow. if (receiverObject->SetProperty(propertyKey, newValue, propertyOperationFlags, info)) { - if (!JavascriptProxy::Is(receiver) && info->GetPropertyRecordUsageCache() && info->GetFlags() != InlineCacheSetterFlag && !object->IsExternal()) + if (!VarIs(receiver) && info->GetPropertyRecordUsageCache() && info->GetFlags() != InlineCacheSetterFlag && !object->IsExternal()) { - CacheOperators::CachePropertyWrite(RecyclableObject::FromVar(receiver), false, typeWithoutProperty, info->GetPropertyRecordUsageCache()->GetPropertyRecord()->GetPropertyId(), info, requestContext); + CacheOperators::CachePropertyWrite(VarTo(receiver), false, typeWithoutProperty, info->GetPropertyRecordUsageCache()->GetPropertyRecord()->GetPropertyId(), info, requestContext); if (info->GetInstance() == receiverObject) { @@ -2413,15 +2416,15 @@ using namespace Js; } if (setterValueOrProxy) { - RecyclableObject* func = RecyclableObject::FromVar(setterValueOrProxy); + RecyclableObject* func = VarTo(setterValueOrProxy); JavascriptOperators::CallSetter(func, receiver, newValue, requestContext); return TRUE; } } else if ((flags & Proxy) == Proxy) { - Assert(JavascriptProxy::Is(setterValueOrProxy)); - JavascriptProxy* proxy = JavascriptProxy::FromVar(setterValueOrProxy); + Assert(VarIs(setterValueOrProxy)); + JavascriptProxy* proxy = VarTo(setterValueOrProxy); const PropertyRecord* propertyRecord = nullptr; proxy->PropertyIdFromInt(index, &propertyRecord); return proxy->SetPropertyTrap(receiver, JavascriptProxy::SetPropertyTrapKind::SetItemOnTaggedNumberKind, propertyRecord->GetPropertyId(), newValue, requestContext, propertyOperationFlags); @@ -2462,7 +2465,7 @@ using namespace Js; } if (setterValueOrProxy) { - RecyclableObject* func = RecyclableObject::FromVar(setterValueOrProxy); + RecyclableObject* func = VarTo(setterValueOrProxy); Assert(info.GetFlags() == InlineCacheSetterFlag || info.GetPropertyIndex() == Constants::NoSlot); JavascriptOperators::CallSetter(func, receiver, newValue, requestContext); return TRUE; @@ -2470,8 +2473,8 @@ using namespace Js; } else if ((flags & Proxy) == Proxy) { - Assert(JavascriptProxy::Is(setterValueOrProxy)); - JavascriptProxy* proxy = JavascriptProxy::FromVar(setterValueOrProxy); + Assert(VarIs(setterValueOrProxy)); + JavascriptProxy* proxy = VarTo(setterValueOrProxy); return proxy->SetPropertyTrap(receiver, JavascriptProxy::SetPropertyTrapKind::SetPropertyOnTaggedNumberKind, propertyId, newValue, requestContext, propertyOperationFlags); } else @@ -2532,16 +2535,16 @@ using namespace Js; } if (setterValueOrProxy) { - RecyclableObject* func = RecyclableObject::FromVar(setterValueOrProxy); + RecyclableObject* func = VarTo(setterValueOrProxy); Assert(!info || info->GetFlags() == InlineCacheSetterFlag || info->GetPropertyIndex() == Constants::NoSlot); - if (WithScopeObject::Is(receiver)) + if (VarIs(receiver)) { - receiver = (RecyclableObject::FromVar(receiver))->GetThisObjectOrUnWrap(); + receiver = (VarTo(receiver))->GetThisObjectOrUnWrap(); } else if (!JavascriptOperators::IsUndefinedAccessor(setterValueOrProxy, requestContext)) { - CacheOperators::CachePropertyWrite(RecyclableObject::FromVar(receiver), isRoot, object->GetType(), propertyId, info, requestContext); + CacheOperators::CachePropertyWrite(VarTo(receiver), isRoot, object->GetType(), propertyId, info, requestContext); } #ifdef ENABLE_MUTATION_BREAKPOINT if (MutationBreakpoint::IsFeatureEnabled(requestContext)) @@ -2556,8 +2559,8 @@ using namespace Js; } else if ((flags & Proxy) == Proxy) { - Assert(JavascriptProxy::Is(setterValueOrProxy)); - JavascriptProxy* proxy = JavascriptProxy::FromVar(setterValueOrProxy); + Assert(VarIs(setterValueOrProxy)); + JavascriptProxy* proxy = VarTo(setterValueOrProxy); // We can't cache the property at this time. both target and handler can be changed outside of the proxy, so the inline cache needs to be // invalidate when target, handler, or handler prototype has changed. We don't have a way to achieve this yet. PropertyValueInfo::SetNoCache(info, proxy); @@ -2627,7 +2630,7 @@ using namespace Js; } else { - RecyclableObject* instanceObject = RecyclableObject::FromVar(receiver); + RecyclableObject* instanceObject = VarTo(receiver); while (!JavascriptOperators::IsNull(instanceObject)) { if (unscopables && JavascriptOperators::IsPropertyUnscopable(instanceObject, propertyId)) @@ -2655,9 +2658,9 @@ using namespace Js; if (updateCache) { - if (!JavascriptProxy::Is(receiver)) + if (!VarIs(receiver)) { - CacheOperators::CachePropertyWrite(RecyclableObject::FromVar(receiver), isRoot, typeWithoutProperty, propertyId, info, requestContext); + CacheOperators::CachePropertyWrite(VarTo(receiver), isRoot, typeWithoutProperty, propertyId, info, requestContext); } } return TRUE; @@ -2682,7 +2685,7 @@ using namespace Js; { return FALSE; } - RecyclableObject* object = RecyclableObject::FromVar(instance); + RecyclableObject* object = VarTo(instance); Var member = nullptr; // If the item is found in the array own body, then it is a number @@ -2750,7 +2753,7 @@ using namespace Js; if (!TaggedNumber::Is(instance) && !TaggedNumber::Is(thisInstance)) { - return JavascriptOperators::SetProperty(RecyclableObject::UnsafeFromVar(thisInstance), RecyclableObject::UnsafeFromVar(instance), propertyId, newValue, info, scriptContext, flags); + return JavascriptOperators::SetProperty(UnsafeVarTo(thisInstance), UnsafeVarTo(instance), propertyId, newValue, info, scriptContext, flags); } JavascriptError::ThrowCantAssignIfStrictMode(flags, scriptContext); @@ -2759,7 +2762,7 @@ using namespace Js; BOOL JavascriptOperators::OP_StFunctionExpression(Var obj, PropertyId propertyId, Var newValue) { - RecyclableObject* instance = RecyclableObject::FromVar(obj); + RecyclableObject* instance = VarTo(obj); JIT_HELPER_NOT_REENTRANT_HEADER(Op_StFunctionExpression, reentrancylock, instance->GetScriptContext()->GetThreadContext()); instance->SetProperty(propertyId, newValue, PropertyOperation_None, NULL); @@ -2773,7 +2776,7 @@ using namespace Js; BOOL JavascriptOperators::OP_InitClassMember(Var obj, PropertyId propertyId, Var newValue) { JIT_HELPER_REENTRANT_HEADER(Op_InitClassMember); - RecyclableObject* instance = RecyclableObject::FromVar(obj); + RecyclableObject* instance = VarTo(obj); PropertyOperationFlags flags = PropertyOperation_None; PropertyAttributes attributes = PropertyClassMemberDefaults; @@ -2787,12 +2790,12 @@ using namespace Js; BOOL JavascriptOperators::OP_InitLetProperty(Var obj, PropertyId propertyId, Var newValue) { JIT_HELPER_REENTRANT_HEADER(Op_InitLetFld); - RecyclableObject* instance = RecyclableObject::FromVar(obj); + RecyclableObject* instance = VarTo(obj); PropertyOperationFlags flags = instance->GetScriptContext()->IsUndeclBlockVar(newValue) ? PropertyOperation_SpecialValue : PropertyOperation_None; PropertyAttributes attributes = PropertyLetDefaults; - if (RootObjectBase::Is(instance)) + if (VarIs(instance)) { attributes |= PropertyLetConstGlobal; } @@ -2805,13 +2808,13 @@ using namespace Js; BOOL JavascriptOperators::OP_InitConstProperty(Var obj, PropertyId propertyId, Var newValue) { - RecyclableObject* instance = RecyclableObject::FromVar(obj); + RecyclableObject* instance = VarTo(obj); JIT_HELPER_REENTRANT_HEADER(Op_InitConstFld); PropertyOperationFlags flags = instance->GetScriptContext()->IsUndeclBlockVar(newValue) ? PropertyOperation_SpecialValue : PropertyOperation_None; PropertyAttributes attributes = PropertyConstDefaults; - if (RootObjectBase::Is(instance)) + if (VarIs(instance)) { attributes |= PropertyLetConstGlobal; } @@ -2824,7 +2827,7 @@ using namespace Js; BOOL JavascriptOperators::OP_InitUndeclRootLetProperty(Var obj, PropertyId propertyId) { - RecyclableObject* instance = RecyclableObject::FromVar(obj); + RecyclableObject* instance = VarTo(obj); JIT_HELPER_NOT_REENTRANT_HEADER(Op_InitUndeclRootLetFld, reentrancylock, instance->GetScriptContext()->GetThreadContext()); PropertyOperationFlags flags = static_cast(PropertyOperation_SpecialValue | PropertyOperation_AllowUndecl); @@ -2838,7 +2841,7 @@ using namespace Js; BOOL JavascriptOperators::OP_InitUndeclRootConstProperty(Var obj, PropertyId propertyId) { - RecyclableObject* instance = RecyclableObject::FromVar(obj); + RecyclableObject* instance = VarTo(obj); JIT_HELPER_NOT_REENTRANT_HEADER(Op_InitUndeclRootConstFld, reentrancylock, instance->GetScriptContext()->GetThreadContext()); PropertyOperationFlags flags = static_cast(PropertyOperation_SpecialValue | PropertyOperation_AllowUndecl); @@ -2853,8 +2856,8 @@ using namespace Js; BOOL JavascriptOperators::OP_InitUndeclConsoleLetProperty(Var obj, PropertyId propertyId) { FrameDisplay *pScope = (FrameDisplay*)obj; - AssertMsg(ConsoleScopeActivationObject::Is((DynamicObject*)pScope->GetItem(pScope->GetLength() - 1)), "How come we got this opcode without ConsoleScopeActivationObject?"); - RecyclableObject* instance = RecyclableObject::FromVar(pScope->GetItem(0)); + AssertMsg(VarIs((DynamicObject*)pScope->GetItem(pScope->GetLength() - 1)), "How come we got this opcode without ConsoleScopeActivationObject?"); + RecyclableObject* instance = VarTo(pScope->GetItem(0)); JIT_HELPER_NOT_REENTRANT_HEADER(Op_InitUndeclConsoleLetFld, reentrancylock, instance->GetScriptContext()->GetThreadContext()); PropertyOperationFlags flags = static_cast(PropertyOperation_SpecialValue | PropertyOperation_AllowUndecl); @@ -2867,8 +2870,8 @@ using namespace Js; BOOL JavascriptOperators::OP_InitUndeclConsoleConstProperty(Var obj, PropertyId propertyId) { FrameDisplay *pScope = (FrameDisplay*)obj; - AssertMsg(ConsoleScopeActivationObject::Is((DynamicObject*)pScope->GetItem(pScope->GetLength() - 1)), "How come we got this opcode without ConsoleScopeActivationObject?"); - RecyclableObject* instance = RecyclableObject::FromVar(pScope->GetItem(0)); + AssertMsg(VarIs((DynamicObject*)pScope->GetItem(pScope->GetLength() - 1)), "How come we got this opcode without ConsoleScopeActivationObject?"); + RecyclableObject* instance = VarTo(pScope->GetItem(0)); JIT_HELPER_NOT_REENTRANT_HEADER(Op_InitUndeclConsoleConstFld, reentrancylock, instance->GetScriptContext()->GetThreadContext()); PropertyOperationFlags flags = static_cast(PropertyOperation_SpecialValue | PropertyOperation_AllowUndecl); @@ -2886,7 +2889,7 @@ using namespace Js; BOOL JavascriptOperators::OP_InitProperty(Var instance, PropertyId propertyId, Var newValue) { if(TaggedNumber::Is(instance)) { return false; } - return JavascriptOperators::InitProperty(RecyclableObject::FromVar(instance), propertyId, newValue); + return JavascriptOperators::InitProperty(VarTo(instance), propertyId, newValue); } BOOL JavascriptOperators::DeleteProperty(RecyclableObject* instance, PropertyId propertyId, PropertyOperationFlags propertyOperationFlags) @@ -2958,7 +2961,7 @@ using namespace Js; return scriptContext->GetLibrary()->GetTrue(); } - RecyclableObject* recyclableObject = RecyclableObject::FromVar(instance); + RecyclableObject* recyclableObject = VarTo(instance); if (JavascriptOperators::IsUndefinedOrNull(recyclableObject)) { JavascriptError::ThrowTypeError(scriptContext, JSERR_Property_CannotDelete_NullOrUndefined, @@ -2974,7 +2977,7 @@ using namespace Js; { // In Edge the root is an External Object which can call Dispose and thus, can have reentrancy. JIT_HELPER_REENTRANT_HEADER(Op_DeleteRootProperty); - AssertMsg(RootObjectBase::Is(instance), "Root must be a global object!"); + AssertMsg(VarIs(instance), "Root must be a global object!"); RootObjectBase* rootObject = static_cast(instance); return scriptContext->GetLibrary()->CreateBoolean( @@ -3003,9 +3006,9 @@ using namespace Js; for (uint16 i = 0; i < length; i++) { - object = RecyclableObject::UnsafeFromVar(pDisplay->GetItem(i)); + object = UnsafeVarTo(pDisplay->GetItem(i)); - AssertMsg(!ConsoleScopeActivationObject::Is(object) || (i == length - 1), "Invalid location for ConsoleScopeActivationObject"); + AssertMsg(!VarIs(object) || (i == length - 1), "Invalid location for ConsoleScopeActivationObject"); Type* type = object->GetType(); if (CacheOperators::TrySetProperty( @@ -3059,7 +3062,7 @@ using namespace Js; CacheOperators::TraceCache(inlineCache, _u("PatchSetPropertyScoped"), propertyId, scriptContext, object); } #endif - if (!JavascriptProxy::Is(object) && !allowUndecInConsoleScope) + if (!VarIs(object) && !allowUndecInConsoleScope) { CacheOperators::CachePropertyWrite(object, false, type, propertyId, &info2, scriptContext); } @@ -3071,7 +3074,7 @@ using namespace Js; Assert(!isLexicalThisSlotSymbol); // If we have console scope and no one in the scope had the property add it to console scope - if ((length > 0) && ConsoleScopeActivationObject::Is(pDisplay->GetItem(length - 1))) + if ((length > 0) && VarIs(pDisplay->GetItem(length - 1))) { // CheckPrototypesForAccessorOrNonWritableProperty does not check for const in global object. We should check it here. if (length > 1) @@ -3099,7 +3102,7 @@ using namespace Js; } } - RecyclableObject* obj = RecyclableObject::FromVar((DynamicObject*)pDisplay->GetItem(length - 1)); + RecyclableObject* obj = VarTo(pDisplay->GetItem(length - 1)); OUTPUT_TRACE(Js::ConsoleScopePhase, _u("Adding property '%s' to console scope object\n"), scriptContext->GetPropertyName(propertyId)->GetBuffer()); JavascriptOperators::SetProperty(obj, obj, propertyId, newValue, scriptContext, propertyOperationFlags); return; @@ -3108,7 +3111,7 @@ using namespace Js; // No one in the scope stack has the property, so add it to the default instance provided by the caller. AssertMsg(!TaggedNumber::Is(defaultInstance), "Root object is an int or tagged float?"); Assert(defaultInstance != nullptr); - RecyclableObject* obj = RecyclableObject::FromVar(defaultInstance); + RecyclableObject* obj = VarTo(defaultInstance); { //SetPropertyScoped does not use inline cache for default instance PropertyValueInfo info2; @@ -3140,7 +3143,7 @@ using namespace Js; } AssertMsg(!TaggedNumber::Is(defaultInstance), "Root object is an int or tagged float?"); - return RecyclableObject::FromVar(defaultInstance)->InitFuncScoped(propertyId, newValue); + return VarTo(defaultInstance)->InitFuncScoped(propertyId, newValue); JIT_HELPER_END(Op_InitFuncScoped); } @@ -3160,7 +3163,7 @@ using namespace Js; } AssertMsg(!TaggedNumber::Is(defaultInstance), "Root object is an int or tagged float?"); - return RecyclableObject::FromVar(defaultInstance)->InitPropertyScoped(propertyId, newValue); + return VarTo(defaultInstance)->InitPropertyScoped(propertyId, newValue); } Var JavascriptOperators::OP_DeletePropertyScoped( @@ -3184,7 +3187,7 @@ using namespace Js; } } - return JavascriptOperators::OP_DeleteRootProperty(RecyclableObject::FromVar(defaultInstance), propertyId, scriptContext, propertyOperationFlags); + return JavascriptOperators::OP_DeleteRootProperty(VarTo(defaultInstance), propertyId, scriptContext, propertyOperationFlags); JIT_HELPER_END(Op_DeletePropertyScoped); } @@ -3203,7 +3206,7 @@ using namespace Js; } } - return JavascriptOperators::TypeofRootFld(RecyclableObject::FromVar(defaultInstance), propertyId, scriptContext); + return JavascriptOperators::TypeofRootFld(VarTo(defaultInstance), propertyId, scriptContext); JIT_HELPER_END(Op_TypeofPropertyScoped); } @@ -3308,15 +3311,15 @@ using namespace Js; } if (setterValueOrProxy) { - RecyclableObject* func = RecyclableObject::FromVar(setterValueOrProxy); + RecyclableObject* func = VarTo(setterValueOrProxy); JavascriptOperators::CallSetter(func, receiver, value, scriptContext); } return TRUE; } else if ((flags & Proxy) == Proxy) { - Assert(JavascriptProxy::Is(setterValueOrProxy)); - JavascriptProxy* proxy = JavascriptProxy::FromVar(setterValueOrProxy); + Assert(VarIs(setterValueOrProxy)); + JavascriptProxy* proxy = VarTo(setterValueOrProxy); const PropertyRecord* propertyRecord = nullptr; proxy->PropertyIdFromInt(index, &propertyRecord); return proxy->SetPropertyTrap(receiver, JavascriptProxy::SetPropertyTrapKind::SetItemKind, propertyRecord->GetPropertyId(), value, scriptContext, propertyOperationFlags, skipPrototypeCheck); @@ -3340,7 +3343,7 @@ using namespace Js; return FALSE; } - return (RecyclableObject::FromVar(receiver))->SetItem(index, value, propertyOperationFlags); + return (VarTo(receiver))->SetItem(index, value, propertyOperationFlags); } BOOL JavascriptOperators::DeleteItem(RecyclableObject* object, uint32 index, PropertyOperationFlags propertyOperationFlags) @@ -3358,7 +3361,7 @@ using namespace Js; { RecyclableObject* object = TaggedNumber::Is(instance) ? scriptContext->GetLibrary()->GetNumberPrototype() : - RecyclableObject::FromVar(instance); + VarTo(instance); uint32 indexVal; PropertyRecord const * propertyRecord = nullptr; @@ -3446,7 +3449,7 @@ using namespace Js; { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedFunction /* TODO-ERROR: get arg name - aFunc */); } - return RecyclableObject::UnsafeFromVar(callee); + return UnsafeVarTo(callee); } Var JavascriptOperators::OP_GetElementI_JIT(Var instance, Var index, ScriptContext *scriptContext) @@ -3494,7 +3497,7 @@ using namespace Js; return false; } - JavascriptArray* arrayPrototype = JavascriptArray::UnsafeFromVar(prototype); //Prototype must be Array.prototype (unless changed through __proto__) + JavascriptArray* arrayPrototype = UnsafeVarTo(prototype); //Prototype must be Array.prototype (unless changed through __proto__) if (arrayPrototype->GetLength() && arrayPrototype->GetItem(arrayPrototype, (uint32)indexInt, result, scriptContext)) { return true; @@ -3506,7 +3509,7 @@ using namespace Js; return false; } - if (DynamicObject::FromVar(prototype)->HasNonEmptyObjectArray()) + if (VarTo(prototype)->HasNonEmptyObjectArray()) { if (prototype->GetItem(arr, (uint32)indexInt, result, scriptContext)) { @@ -3527,7 +3530,7 @@ using namespace Js; case TypeIds_Array: //fast path for array { Var result; - if (OP_GetElementI_ArrayFastPath(JavascriptArray::UnsafeFromVar(instance), TaggedInt::ToInt32(index), &result, scriptContext)) + if (OP_GetElementI_ArrayFastPath(UnsafeVarTo(instance), TaggedInt::ToInt32(index), &result, scriptContext)) { return result; } @@ -3539,7 +3542,7 @@ using namespace Js; JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray(instance); #endif Var result; - if (OP_GetElementI_ArrayFastPath(JavascriptNativeIntArray::UnsafeFromVar(instance), TaggedInt::ToInt32(index), &result, scriptContext)) + if (OP_GetElementI_ArrayFastPath(UnsafeVarTo(instance), TaggedInt::ToInt32(index), &result, scriptContext)) { return result; } @@ -3548,7 +3551,7 @@ using namespace Js; case TypeIds_NativeFloatArray: { Var result; - if (OP_GetElementI_ArrayFastPath(JavascriptNativeFloatArray::UnsafeFromVar(instance), TaggedInt::ToInt32(index), &result, scriptContext)) + if (OP_GetElementI_ArrayFastPath(UnsafeVarTo(instance), TaggedInt::ToInt32(index), &result, scriptContext)) { return result; } @@ -3558,7 +3561,7 @@ using namespace Js; case TypeIds_String: // fast path for string { charcount_t indexInt = TaggedInt::ToUInt32(index); - JavascriptString* string = JavascriptString::UnsafeFromVar(instance); + JavascriptString* string = UnsafeVarTo(instance); Var result; if (JavascriptConversion::PropertyQueryFlagsToBoolean(string->JavascriptString::GetItemQuery(instance, indexInt, &result, scriptContext))) { @@ -3573,7 +3576,7 @@ using namespace Js; int32 indexInt = TaggedInt::ToInt32(index); if (VirtualTableInfo::HasVirtualTable(instance)) { - Int8VirtualArray* int8Array = Int8VirtualArray::UnsafeFromVar(instance); + Int8VirtualArray* int8Array = UnsafeVarTo(instance); if (indexInt >= 0) { return int8Array->DirectGetItem(indexInt); @@ -3581,7 +3584,7 @@ using namespace Js; } else if (VirtualTableInfo::HasVirtualTable(instance)) { - Int8Array* int8Array = Int8Array::UnsafeFromVar(instance); + Int8Array* int8Array = UnsafeVarTo(instance); if (indexInt >= 0) { return int8Array->DirectGetItem(indexInt); @@ -3596,7 +3599,7 @@ using namespace Js; int32 indexInt = TaggedInt::ToInt32(index); if (VirtualTableInfo::HasVirtualTable(instance)) { - Uint8VirtualArray* uint8Array = Uint8VirtualArray::UnsafeFromVar(instance); + Uint8VirtualArray* uint8Array = UnsafeVarTo(instance); if (indexInt >= 0) { return uint8Array->DirectGetItem(indexInt); @@ -3604,7 +3607,7 @@ using namespace Js; } else if (VirtualTableInfo::HasVirtualTable(instance)) { - Uint8Array* uint8Array = Uint8Array::UnsafeFromVar(instance); + Uint8Array* uint8Array = UnsafeVarTo(instance); if (indexInt >= 0) { return uint8Array->DirectGetItem(indexInt); @@ -3619,7 +3622,7 @@ using namespace Js; int32 indexInt = TaggedInt::ToInt32(index); if (VirtualTableInfo::HasVirtualTable(instance)) { - Uint8ClampedVirtualArray* uint8ClampedArray = Uint8ClampedVirtualArray::UnsafeFromVar(instance); + Uint8ClampedVirtualArray* uint8ClampedArray = UnsafeVarTo(instance); if (indexInt >= 0) { return uint8ClampedArray->DirectGetItem(indexInt); @@ -3627,7 +3630,7 @@ using namespace Js; } else if (VirtualTableInfo::HasVirtualTable(instance)) { - Uint8ClampedArray* uint8ClampedArray = Uint8ClampedArray::UnsafeFromVar(instance); + Uint8ClampedArray* uint8ClampedArray = UnsafeVarTo(instance); if (indexInt >= 0) { return uint8ClampedArray->DirectGetItem(indexInt); @@ -3643,7 +3646,7 @@ using namespace Js; if (VirtualTableInfo::HasVirtualTable(instance)) { - Int16VirtualArray* int16Array = Int16VirtualArray::UnsafeFromVar(instance); + Int16VirtualArray* int16Array = UnsafeVarTo(instance); if (indexInt >= 0) { return int16Array->DirectGetItem(indexInt); @@ -3651,7 +3654,7 @@ using namespace Js; } else if (VirtualTableInfo::HasVirtualTable(instance)) { - Int16Array* int16Array = Int16Array::UnsafeFromVar(instance); + Int16Array* int16Array = UnsafeVarTo(instance); if (indexInt >= 0) { return int16Array->DirectGetItem(indexInt); @@ -3667,7 +3670,7 @@ using namespace Js; if (VirtualTableInfo::HasVirtualTable(instance)) { - Uint16VirtualArray* uint16Array = Uint16VirtualArray::UnsafeFromVar(instance); + Uint16VirtualArray* uint16Array = UnsafeVarTo(instance); if (indexInt >= 0) { return uint16Array->DirectGetItem(indexInt); @@ -3675,7 +3678,7 @@ using namespace Js; } else if (VirtualTableInfo::HasVirtualTable(instance)) { - Uint16Array* uint16Array = Uint16Array::UnsafeFromVar(instance); + Uint16Array* uint16Array = UnsafeVarTo(instance); if (indexInt >= 0) { return uint16Array->DirectGetItem(indexInt); @@ -3689,7 +3692,7 @@ using namespace Js; int32 indexInt = TaggedInt::ToInt32(index); if (VirtualTableInfo::HasVirtualTable(instance)) { - Int32VirtualArray* int32Array = Int32VirtualArray::UnsafeFromVar(instance); + Int32VirtualArray* int32Array = UnsafeVarTo(instance); if (indexInt >= 0) { return int32Array->DirectGetItem(indexInt); @@ -3697,7 +3700,7 @@ using namespace Js; } else if (VirtualTableInfo::HasVirtualTable(instance)) { - Int32Array* int32Array = Int32Array::UnsafeFromVar(instance); + Int32Array* int32Array = UnsafeVarTo(instance); if (indexInt >= 0) { return int32Array->DirectGetItem(indexInt); @@ -3712,7 +3715,7 @@ using namespace Js; int32 indexInt = TaggedInt::ToInt32(index); if (VirtualTableInfo::HasVirtualTable(instance)) { - Uint32VirtualArray* uint32Array = Uint32VirtualArray::UnsafeFromVar(instance); + Uint32VirtualArray* uint32Array = UnsafeVarTo(instance); if (indexInt >= 0) { return uint32Array->DirectGetItem(indexInt); @@ -3720,7 +3723,7 @@ using namespace Js; } else if (VirtualTableInfo::HasVirtualTable(instance)) { - Uint32Array* uint32Array = Uint32Array::UnsafeFromVar(instance); + Uint32Array* uint32Array = UnsafeVarTo(instance); if (indexInt >= 0) { return uint32Array->DirectGetItem(indexInt); @@ -3735,7 +3738,7 @@ using namespace Js; if (VirtualTableInfo::HasVirtualTable(instance)) { - Float32VirtualArray* float32Array = Float32VirtualArray::UnsafeFromVar(instance); + Float32VirtualArray* float32Array = UnsafeVarTo(instance); if (indexInt >= 0) { return float32Array->DirectGetItem(indexInt); @@ -3743,7 +3746,7 @@ using namespace Js; } else if (VirtualTableInfo::HasVirtualTable(instance)) { - Float32Array* float32Array = Float32Array::UnsafeFromVar(instance); + Float32Array* float32Array = UnsafeVarTo(instance); if (indexInt >= 0) { return float32Array->DirectGetItem(indexInt); @@ -3757,7 +3760,7 @@ using namespace Js; int32 indexInt = TaggedInt::ToInt32(index); if (VirtualTableInfo::HasVirtualTable(instance)) { - Float64VirtualArray* float64Array = Float64VirtualArray::UnsafeFromVar(instance); + Float64VirtualArray* float64Array = UnsafeVarTo(instance); if (indexInt >= 0) { return float64Array->DirectGetItem(indexInt); @@ -3765,7 +3768,7 @@ using namespace Js; } else if (VirtualTableInfo::HasVirtualTable(instance)) { - Float64Array* float64Array = Float64Array::UnsafeFromVar(instance); + Float64Array* float64Array = UnsafeVarTo(instance); if (indexInt >= 0) { return float64Array->DirectGetItem(indexInt); @@ -3825,7 +3828,7 @@ using namespace Js; return GetElementIIntIndex(instance, index, scriptContext); } } - else if (RecyclableObject::Is(instance)) + else if (VarIs(instance)) { RecyclableObject* cacheOwner; PropertyRecordUsageCache* propertyRecordUsageCache; @@ -4074,7 +4077,7 @@ using namespace Js; { return JavascriptNativeIntArray::MissingItem; } - JavascriptArray * arr = JavascriptArray::FromVar(instance); + JavascriptArray * arr = VarTo(instance); int32 result; if (arr->DirectGetItemAt((uint32)indexInt, &result)) { @@ -4092,7 +4095,7 @@ using namespace Js; { return JavascriptNativeIntArray::MissingItem; } - JavascriptArray * arr = JavascriptArray::FromVar(instance); + JavascriptArray * arr = VarTo(instance); int32 result; if (arr->DirectGetItemAt((uint32)indexInt, &result)) { @@ -4151,7 +4154,7 @@ using namespace Js; } else { - JavascriptArray * arr = JavascriptArray::FromVar(instance); + JavascriptArray * arr = VarTo(instance); if (!arr->DirectGetItemAt((uint32)indexInt, &result)) { result = JavascriptNativeFloatArray::MissingItem; @@ -4171,7 +4174,7 @@ using namespace Js; } else { - JavascriptArray * arr = JavascriptArray::FromVar(instance); + JavascriptArray * arr = VarTo(instance); if (!arr->DirectGetItemAt((uint32)indexInt, &result)) { result = JavascriptNativeFloatArray::MissingItem; @@ -4378,7 +4381,7 @@ using namespace Js; if (isTypedArray) { - if (TaggedInt::Is(index) || JavascriptNumber::Is_NoTaggedIntCheck(index) || JavascriptString::Is(index)) + if (TaggedInt::Is(index) || JavascriptNumber::Is_NoTaggedIntCheck(index) || VarIs(index)) { BOOL returnValue = FALSE; bool isNumericIndex = false; @@ -4393,12 +4396,12 @@ using namespace Js; if (VirtualTableInfo::HasVirtualTable(instance)) { - Int8VirtualArray* int8Array = Int8VirtualArray::UnsafeFromVar(instance); + Int8VirtualArray* int8Array = UnsafeVarTo(instance); returnValue = int8Array->ValidateIndexAndDirectSetItem(index, value, &isNumericIndex); } else if( VirtualTableInfo::HasVirtualTable(instance)) { - Int8Array* int8Array = Int8Array::UnsafeFromVar(instance); + Int8Array* int8Array = UnsafeVarTo(instance); returnValue = int8Array->ValidateIndexAndDirectSetItem(index, value, &isNumericIndex); } break; @@ -4409,12 +4412,12 @@ using namespace Js; // The typed array will deal with all possible values for the index if (VirtualTableInfo::HasVirtualTable(instance)) { - Uint8VirtualArray* uint8Array = Uint8VirtualArray::UnsafeFromVar(instance); + Uint8VirtualArray* uint8Array = UnsafeVarTo(instance); returnValue = uint8Array->ValidateIndexAndDirectSetItem(index, value, &isNumericIndex); } else if (VirtualTableInfo::HasVirtualTable(instance)) { - Uint8Array* uint8Array = Uint8Array::UnsafeFromVar(instance); + Uint8Array* uint8Array = UnsafeVarTo(instance); returnValue = uint8Array->ValidateIndexAndDirectSetItem(index, value, &isNumericIndex); } break; @@ -4425,12 +4428,12 @@ using namespace Js; // The typed array will deal with all possible values for the index if (VirtualTableInfo::HasVirtualTable(instance)) { - Uint8ClampedVirtualArray* uint8ClampedArray = Uint8ClampedVirtualArray::UnsafeFromVar(instance); + Uint8ClampedVirtualArray* uint8ClampedArray = UnsafeVarTo(instance); returnValue = uint8ClampedArray->ValidateIndexAndDirectSetItem(index, value, &isNumericIndex); } else if(VirtualTableInfo::HasVirtualTable(instance)) { - Uint8ClampedArray* uint8ClampedArray = Uint8ClampedArray::UnsafeFromVar(instance); + Uint8ClampedArray* uint8ClampedArray = UnsafeVarTo(instance); returnValue = uint8ClampedArray->ValidateIndexAndDirectSetItem(index, value, &isNumericIndex); } break; @@ -4441,12 +4444,12 @@ using namespace Js; // The type array will deal with all possible values for the index if (VirtualTableInfo::HasVirtualTable(instance)) { - Int16VirtualArray* int16Array = Int16VirtualArray::UnsafeFromVar(instance); + Int16VirtualArray* int16Array = UnsafeVarTo(instance); returnValue = int16Array->ValidateIndexAndDirectSetItem(index, value, &isNumericIndex); } else if (VirtualTableInfo::HasVirtualTable(instance)) { - Int16Array* int16Array = Int16Array::UnsafeFromVar(instance); + Int16Array* int16Array = UnsafeVarTo(instance); returnValue = int16Array->ValidateIndexAndDirectSetItem(index, value, &isNumericIndex); } break; @@ -4458,12 +4461,12 @@ using namespace Js; if (VirtualTableInfo::HasVirtualTable(instance)) { - Uint16VirtualArray* uint16Array = Uint16VirtualArray::UnsafeFromVar(instance); + Uint16VirtualArray* uint16Array = UnsafeVarTo(instance); returnValue = uint16Array->ValidateIndexAndDirectSetItem(index, value, &isNumericIndex); } else if (VirtualTableInfo::HasVirtualTable(instance)) { - Uint16Array* uint16Array = Uint16Array::UnsafeFromVar(instance); + Uint16Array* uint16Array = UnsafeVarTo(instance); returnValue = uint16Array->ValidateIndexAndDirectSetItem(index, value, &isNumericIndex); } break; @@ -4473,12 +4476,12 @@ using namespace Js; // The type array will deal with all possible values for the index if (VirtualTableInfo::HasVirtualTable(instance)) { - Int32VirtualArray* int32Array = Int32VirtualArray::UnsafeFromVar(instance); + Int32VirtualArray* int32Array = UnsafeVarTo(instance); returnValue = int32Array->ValidateIndexAndDirectSetItem(index, value, &isNumericIndex); } else if(VirtualTableInfo::HasVirtualTable(instance)) { - Int32Array* int32Array = Int32Array::UnsafeFromVar(instance); + Int32Array* int32Array = UnsafeVarTo(instance); returnValue = int32Array->ValidateIndexAndDirectSetItem(index, value, &isNumericIndex); } break; @@ -4489,12 +4492,12 @@ using namespace Js; if (VirtualTableInfo::HasVirtualTable(instance)) { - Uint32VirtualArray* uint32Array = Uint32VirtualArray::UnsafeFromVar(instance); + Uint32VirtualArray* uint32Array = UnsafeVarTo(instance); returnValue = uint32Array->ValidateIndexAndDirectSetItem(index, value, &isNumericIndex); } else if (VirtualTableInfo::HasVirtualTable(instance)) { - Uint32Array* uint32Array = Uint32Array::UnsafeFromVar(instance); + Uint32Array* uint32Array = UnsafeVarTo(instance); returnValue = uint32Array->ValidateIndexAndDirectSetItem(index, value, &isNumericIndex); } break; @@ -4504,12 +4507,12 @@ using namespace Js; // The type array will deal with all possible values for the index if (VirtualTableInfo::HasVirtualTable(instance)) { - Float32VirtualArray* float32Array = Float32VirtualArray::UnsafeFromVar(instance); + Float32VirtualArray* float32Array = UnsafeVarTo(instance); returnValue = float32Array->ValidateIndexAndDirectSetItem(index, value, &isNumericIndex); } else if (VirtualTableInfo::HasVirtualTable(instance)) { - Float32Array* float32Array = Float32Array::UnsafeFromVar(instance); + Float32Array* float32Array = UnsafeVarTo(instance); returnValue = float32Array->ValidateIndexAndDirectSetItem(index, value, &isNumericIndex); } break; @@ -4519,12 +4522,12 @@ using namespace Js; // The type array will deal with all possible values for the index if (VirtualTableInfo::HasVirtualTable(instance)) { - Float64VirtualArray* float64Array = Float64VirtualArray::UnsafeFromVar(instance); + Float64VirtualArray* float64Array = UnsafeVarTo(instance); returnValue = float64Array->ValidateIndexAndDirectSetItem(index, value, &isNumericIndex); } else if (VirtualTableInfo::HasVirtualTable(instance)) { - Float64Array* float64Array = Float64Array::UnsafeFromVar(instance); + Float64Array* float64Array = UnsafeVarTo(instance); returnValue = float64Array->ValidateIndexAndDirectSetItem(index, value, &isNumericIndex); } break; @@ -4551,7 +4554,7 @@ using namespace Js; int indexInt = TaggedInt::ToInt32(index); if (indexInt >= 0 && scriptContext->optimizationOverrides.IsEnabledArraySetElementFastPath()) { - JavascriptArray::UnsafeFromVar(instance)->SetItem((uint32)indexInt, value, flags); + UnsafeVarTo(instance)->SetItem((uint32)indexInt, value, flags); return TRUE; } break; @@ -4601,7 +4604,7 @@ using namespace Js; } #if DBG_DUMP - scriptContext->forinNoCache += (!TaggedInt::Is(index) && JavascriptString::Is(index)); + scriptContext->forinNoCache += (!TaggedInt::Is(index) && VarIs(index)); #endif indexType = GetIndexType(index, scriptContext, &indexVal, &propertyRecord, &propertyNameString, false, true); if (scriptContext->GetThreadContext()->IsDisableImplicitCall() && @@ -4658,7 +4661,7 @@ using namespace Js; int32 indexInt = TaggedInt::ToInt32(aElementIndex); if (indexInt >= 0 && scriptContext->optimizationOverrides.IsEnabledArraySetElementFastPath()) { - JavascriptNativeIntArray *arr = JavascriptNativeIntArray::FromVar(instance); + JavascriptNativeIntArray *arr = VarTo(instance); if (!(arr->TryGrowHeadSegmentAndSetItem((uint32)indexInt, iValue))) { arr->SetItem(indexInt, iValue); @@ -4727,7 +4730,7 @@ using namespace Js; int32 indexInt = TaggedInt::ToInt32(aElementIndex); if (indexInt >= 0 && scriptContext->optimizationOverrides.IsEnabledArraySetElementFastPath()) { - JavascriptNativeFloatArray *arr = JavascriptNativeFloatArray::FromVar(instance); + JavascriptNativeFloatArray *arr = VarTo(instance); if (!(arr->TryGrowHeadSegmentAndSetItem((uint32)indexInt, dValue))) { arr->SetItem(indexInt, dValue); @@ -4799,7 +4802,7 @@ using namespace Js; } BOOL returnValue = false; -#define MEMCOPY_TYPED_ARRAY(type, conversion) type ## ::FromVar(dstInstance)->DirectSetItemAtRange( type ## ::FromVar(srcInstance), srcStart, dstStart, length, JavascriptConversion:: ## conversion) +#define MEMCOPY_TYPED_ARRAY(type, conversion) VarTo< type ## >(dstInstance)->DirectSetItemAtRange( VarTo< type ## >(srcInstance), srcStart, dstStart, length, JavascriptConversion:: ## conversion) switch (instanceType) { case TypeIds_Int8Array: @@ -4857,8 +4860,8 @@ using namespace Js; break; } // Upper bounds check for source array - JavascriptArray* srcArray = JavascriptArray::UnsafeFromVar(srcInstance); - JavascriptArray* dstArray = JavascriptArray::FromVar(dstInstance); + JavascriptArray* srcArray = UnsafeVarTo(srcInstance); + JavascriptArray* dstArray = VarTo(dstInstance); if (scriptContext->optimizationOverrides.IsEnabledArraySetElementFastPath()) { INT_PTR vt = VirtualTableInfoBase::GetVirtualTable(dstInstance); @@ -4913,7 +4916,7 @@ using namespace Js; { \ type## ::TypedArrayType typedValue = 0; \ if (!MemsetConversion(value, scriptContext, &typedValue)) return false; \ - returnValue = type## ::FromVar(instance)->DirectSetItemAtRange(start, length, typedValue); \ + returnValue = VarTo< type## >(instance)->DirectSetItemAtRange(start, length, typedValue); \ break; \ } switch (instanceType) @@ -4946,7 +4949,7 @@ using namespace Js; INT_PTR vt = VirtualTableInfoBase::GetVirtualTable(instance); if (instanceType == TypeIds_Array) { - returnValue = JavascriptArray::UnsafeFromVar(instance)->DirectSetItemAtRange(start, length, value); + returnValue = UnsafeVarTo(instance)->DirectSetItemAtRange(start, length, value); } else if (instanceType == TypeIds_NativeIntArray) { @@ -4960,7 +4963,7 @@ using namespace Js; { return false; } - returnValue = JavascriptArray::UnsafeFromVar(instance)->DirectSetItemAtRange(start, length, intValue); + returnValue = UnsafeVarTo(instance)->DirectSetItemAtRange(start, length, intValue); } else { @@ -4980,7 +4983,7 @@ using namespace Js; { return false; } - returnValue = JavascriptArray::UnsafeFromVar(instance)->DirectSetItemAtRange(start, length, doubleValue); + returnValue = UnsafeVarTo(instance)->DirectSetItemAtRange(start, length, doubleValue); } returnValue &= vt == VirtualTableInfoBase::GetVirtualTable(instance); } @@ -5035,7 +5038,7 @@ using namespace Js; #if ENABLE_COPYONACCESS_ARRAY JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray(instance); #endif - RecyclableObject* object = RecyclableObject::FromVar(instance); + RecyclableObject* object = VarTo(instance); if (JavascriptOperators::IsUndefinedOrNull(object)) { JavascriptError::ThrowTypeError(scriptContext, JSERR_Property_CannotDelete_NullOrUndefined, GetPropertyDisplayNameForError(index, scriptContext)); @@ -5116,7 +5119,7 @@ using namespace Js; else if (typeId == TypeIds_HostDispatch) { TypeId remoteTypeId = TypeIds_Limit; - if (RecyclableObject::FromVar(thisVar)->GetRemoteTypeId(&remoteTypeId)) + if (VarTo(thisVar)->GetRemoteTypeId(&remoteTypeId)) { if (remoteTypeId == TypeIds_Null || remoteTypeId == TypeIds_Undefined || remoteTypeId == TypeIds_ActivationObject) { @@ -5232,7 +5235,7 @@ using namespace Js; { return FALSE; } - return RecyclableObject::FromVar(aValue)->GetRemoteTypeId(typeId); + return VarTo(aValue)->GetRemoteTypeId(typeId); } BOOL JavascriptOperators::IsJsNativeType(TypeId type) @@ -5358,7 +5361,7 @@ using namespace Js; } else { - RecyclableObject* object = RecyclableObject::FromVar(instance); + RecyclableObject* object = VarTo(instance); if (JavascriptOperators::IsNull(object)) { return object; @@ -5536,9 +5539,9 @@ using namespace Js; switch (GetTypeId(var)) { case TypeIds_ArrayBuffer: - return Js::ArrayBuffer::FromVar(var)->DetachAndGetState(); + return Js::VarTo(var)->DetachAndGetState(); default: - if (!Js::RecyclableObject::FromVar(var)->IsExternal()) + if (!Js::VarTo(var)->IsExternal()) { AssertMsg(false, "We should explicitly have a case statement for each non-external object that can be detached."); } @@ -5551,7 +5554,7 @@ using namespace Js; switch (GetTypeId(var)) { case TypeIds_ArrayBuffer: - return Js::ArrayBuffer::FromVar(var)->IsDetached(); + return Js::VarTo(var)->IsDetached(); default: return false; } @@ -5654,17 +5657,17 @@ using namespace Js; Var JavascriptOperators::OP_InitCachedScope(Var varFunc, const Js::PropertyIdArray *propIds, Field(DynamicType*)* literalType, bool formalsAreLetDecls, ScriptContext *scriptContext) { JIT_HELPER_NOT_REENTRANT_HEADER(OP_InitCachedScope, reentrancylock, scriptContext->GetThreadContext()); - bool isGAFunction = JavascriptFunction::Is(varFunc); + bool isGAFunction = VarIs(varFunc); Assert(isGAFunction); if (isGAFunction) { - JavascriptFunction *function = JavascriptFunction::FromVar(varFunc); + JavascriptFunction *function = VarTo(varFunc); isGAFunction = JavascriptGeneratorFunction::Test(function) || JavascriptAsyncFunction::Test(function); } ScriptFunction *func = isGAFunction ? - JavascriptGeneratorFunction::FromVar(varFunc)->GetGeneratorVirtualScriptFunction() : - ScriptFunction::FromVar(varFunc); + VarTo(varFunc)->GetGeneratorVirtualScriptFunction() : + VarTo(varFunc); #ifdef PROFILE_OBJECT_LITERALS // Empty objects not counted in the object literal counts @@ -5762,8 +5765,8 @@ using namespace Js; Var item = disp->GetItem(envIndex); if (item != nullptr) { - Assert(ActivationObjectEx::Is(item)); - RecyclableObject *objScope = RecyclableObject::FromVar(item); + Assert(VarIs(item)); + RecyclableObject *objScope = VarTo(item); objScope->InvalidateCachedScope(); } JIT_HELPER_END(OP_InvalidateCachedScope); @@ -5772,7 +5775,7 @@ using namespace Js; void JavascriptOperators::OP_InitCachedFuncs(Var varScope, FrameDisplay *pDisplay, const FuncInfoArray *info, ScriptContext *scriptContext) { JIT_HELPER_NOT_REENTRANT_HEADER(OP_InitCachedFuncs, reentrancylock, scriptContext->GetThreadContext()); - ActivationObjectEx *scopeObj = ActivationObjectEx::FromVar(varScope); + ActivationObjectEx *scopeObj = VarTo(varScope); Assert(scopeObj->GetTypeHandler()->GetInlineSlotCapacity() == 0); uint funcCount = info->count; @@ -5930,7 +5933,7 @@ using namespace Js; if (JavascriptOperators::IsObjectType(prototypeType)) { - *prototypeObject = RecyclableObject::FromVar(prototypeProperty); + *prototypeObject = VarTo(prototypeProperty); return true; } *prototypeObject = constructorFunction->GetLibrary()->GetObjectPrototype(); @@ -5942,7 +5945,7 @@ using namespace Js; TypeId typeId = JavascriptOperators::GetTypeId(instance); if (typeId == TypeIds_Function) { - JavascriptFunction * function = JavascriptFunction::UnsafeFromVar(instance); + JavascriptFunction * function = UnsafeVarTo(instance); return function->GetFunctionInfo(); } if (typeId != TypeIds_HostDispatch && typeId != TypeIds_Proxy) @@ -5965,7 +5968,7 @@ using namespace Js; #if ENABLE_DEBUG_CONFIG_OPTIONS if (Js::Configuration::Global.flags.IsEnabled(Js::autoProxyFlag)) { - newObject = DynamicObject::FromVar(JavascriptProxy::AutoProxyWrapper(newObject)); + newObject = VarTo(JavascriptProxy::AutoProxyWrapper(newObject)); } #endif return newObject; @@ -6009,7 +6012,7 @@ using namespace Js; Var JavascriptOperators::NewScObjectNoArgNoCtorCommon(Var instance, ScriptContext* requestContext, bool isBaseClassConstructorNewScObject) { - RecyclableObject * object = RecyclableObject::FromVar(instance); + RecyclableObject * object = VarTo(instance); FunctionInfo* functionInfo = JavascriptOperators::GetConstructorFunctionInfo(instance, requestContext); Assert(functionInfo != &JavascriptObject::EntryInfo::NewInstance); // built-ins are not inlined Assert(functionInfo != &JavascriptArray::EntryInfo::NewInstance); // built-ins are not inlined @@ -6033,7 +6036,7 @@ using namespace Js; } FunctionInfo* functionInfo = JavascriptOperators::GetConstructorFunctionInfo(instance, requestContext); - RecyclableObject * object = RecyclableObject::FromVar(instance); + RecyclableObject * object = VarTo(instance); if (functionInfo == &JavascriptObject::EntryInfo::NewInstance) { @@ -6046,7 +6049,7 @@ using namespace Js; #if ENABLE_DEBUG_CONFIG_OPTIONS if (Js::Configuration::Global.flags.IsEnabled(Js::autoProxyFlag)) { - newObject = DynamicObject::FromVar(JavascriptProxy::AutoProxyWrapper(newObject)); + newObject = VarTo(JavascriptProxy::AutoProxyWrapper(newObject)); } #endif @@ -6054,7 +6057,7 @@ using namespace Js; DynamicType* newObjectType = newObject->GetDynamicType(); Assert(newObjectType->GetIsShared()); - JavascriptFunction* constructor = JavascriptFunction::FromVar(instance); + JavascriptFunction* constructor = VarTo(instance); Assert(!constructor->GetConstructorCache()->NeedsUpdateAfterCtor()); #endif @@ -6084,7 +6087,7 @@ using namespace Js; DynamicType* newArrayType = newArray->GetDynamicType(); Assert(newArrayType->GetIsShared()); - JavascriptFunction* constructor = JavascriptFunction::FromVar(instance); + JavascriptFunction* constructor = VarTo(instance); Assert(!constructor->GetConstructorCache()->NeedsUpdateAfterCtor()); #endif @@ -6125,7 +6128,7 @@ using namespace Js; #if ENABLE_DEBUG_CONFIG_OPTIONS if (Js::Configuration::Global.flags.IsEnabled(Js::autoProxyFlag)) { - DynamicObject* newDynamicObject = DynamicObject::FromVar(JavascriptProxy::AutoProxyWrapper(newObject)); + DynamicObject* newDynamicObject = VarTo(JavascriptProxy::AutoProxyWrapper(newObject)); // this might come from a different scriptcontext. newObject = CrossSite::MarshalVar(requestContext, newDynamicObject, newDynamicObject->GetScriptContext()); } @@ -6154,7 +6157,7 @@ using namespace Js; // We can still call into NewScObjectNoCtor variations in JIT code for performance; however for proxy we don't // really need the new object as the trap will handle the "this" pointer separately. pass back nullptr to ensure // failure in invalid case. - return (JavascriptProxy::Is(instance)) ? nullptr : NewScObjectNoCtorCommon(instance, requestContext, false); + return (VarIs(instance)) ? nullptr : NewScObjectNoCtorCommon(instance, requestContext, false); JIT_HELPER_END(NewScObjectNoCtor); } @@ -6164,11 +6167,11 @@ using namespace Js; if (functionInfo) { - return JavascriptOperators::NewScObjectCommon(RecyclableObject::UnsafeFromVar(instance), functionInfo, requestContext, isBaseClassConstructorNewScObject); + return JavascriptOperators::NewScObjectCommon(UnsafeVarTo(instance), functionInfo, requestContext, isBaseClassConstructorNewScObject); } else { - return JavascriptOperators::NewScObjectHostDispatchOrProxy(RecyclableObject::FromVar(instance), requestContext); + return JavascriptOperators::NewScObjectHostDispatchOrProxy(VarTo(instance), requestContext); } } @@ -6177,14 +6180,14 @@ using namespace Js; ScriptContext* functionScriptContext = function->GetScriptContext(); RecyclableObject * prototype = JavascriptOperators::GetPrototypeObject(function, functionScriptContext); - prototype = RecyclableObject::FromVar(CrossSite::MarshalVar(requestContext, prototype, functionScriptContext)); + prototype = VarTo(CrossSite::MarshalVar(requestContext, prototype, functionScriptContext)); Var object = requestContext->GetLibrary()->CreateObject(prototype); JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_OBJECT(object)); #if ENABLE_DEBUG_CONFIG_OPTIONS if (Js::Configuration::Global.flags.IsEnabled(Js::autoProxyFlag)) { - object = DynamicObject::FromVar(JavascriptProxy::AutoProxyWrapper(object)); + object = VarTo(JavascriptProxy::AutoProxyWrapper(object)); } #endif return object; @@ -6200,7 +6203,7 @@ using namespace Js; // the inline cache arena to allow it to be zeroed, but retain a recycler-allocated portion to hold on to the size of // inlined slots. - JavascriptFunction* constructor = JavascriptFunction::UnsafeFromVar(function); + JavascriptFunction* constructor = UnsafeVarTo(function); if (functionInfo->IsClassConstructor() && !isBaseClassConstructorNewScObject) { // If we are calling new on a class constructor, the contract is that we pass new.target as the 'this' argument. @@ -6232,7 +6235,7 @@ using namespace Js; #if ENABLE_DEBUG_CONFIG_OPTIONS if (Js::Configuration::Global.flags.IsEnabled(Js::autoProxyFlag)) { - object = DynamicObject::FromVar(JavascriptProxy::AutoProxyWrapper(object)); + object = VarTo(JavascriptProxy::AutoProxyWrapper(object)); } #endif return object; @@ -6308,7 +6311,7 @@ using namespace Js; bool prototypeCanBeCached; RecyclableObject* prototype = JavascriptOperators::GetPrototypeObjectForConstructorCache( function, constructorScriptContext, prototypeCanBeCached); - prototype = RecyclableObject::FromVar(CrossSite::MarshalVar(requestContext, + prototype = VarTo(CrossSite::MarshalVar(requestContext, prototype, constructorScriptContext)); DynamicObject* newObject = requestContext->GetLibrary()->CreateObject(prototype, 8); @@ -6317,14 +6320,14 @@ using namespace Js; #if ENABLE_DEBUG_CONFIG_OPTIONS if (Js::Configuration::Global.flags.IsEnabled(Js::autoProxyFlag)) { - newObject = DynamicObject::FromVar(JavascriptProxy::AutoProxyWrapper(newObject)); + newObject = VarTo(JavascriptProxy::AutoProxyWrapper(newObject)); } #endif Assert(newObject->GetTypeHandler()->GetPropertyCount() == 0); if (prototypeCanBeCached && functionBody != nullptr && requestContext == constructorScriptContext && - !Js::JavascriptProxy::Is(newObject) && + !Js::VarIs(newObject) && !PHASE_OFF1(ConstructorCachePhase) && !PHASE_OFF(ConstructorCachePhase, functionBody)) { DynamicType* newObjectType = newObject->GetDynamicType(); @@ -6380,7 +6383,7 @@ using namespace Js; void JavascriptOperators::UpdateNewScObjectCache(Var function, Var instance, ScriptContext* requestContext) { JIT_HELPER_NOT_REENTRANT_HEADER(UpdateNewScObjectCache, reentrancylock, requestContext->GetThreadContext()); - JavascriptFunction* constructor = JavascriptFunction::FromVar(function); + JavascriptFunction* constructor = VarTo(function); if(constructor->GetScriptContext() != requestContext) { // The cache is populated only when the constructor function's context is the same as the calling context. However, @@ -6416,7 +6419,7 @@ using namespace Js; FunctionBody* constructorBody = constructor->GetFunctionBody(); AssertMsg(constructorBody != nullptr, "Constructor function doesn't have a function body."); - Assert(RecyclableObject::Is(instance)); + Assert(VarIs(instance)); // The cache might have been invalidated between NewScObjectCommon and UpdateNewScObjectCache. This could occur, for example, if // the constructor updates its own prototype property. If that happens we don't want to re-populate it here. A new cache will @@ -6431,9 +6434,9 @@ using namespace Js; Assert(constructorCache->GetGuardValueAsType() != nullptr); - if (DynamicType::Is(RecyclableObject::FromVar(instance)->GetTypeId())) + if (DynamicType::Is(VarTo(instance)->GetTypeId())) { - DynamicObject *object = DynamicObject::UnsafeFromVar(instance); + DynamicObject *object = UnsafeVarTo(instance); DynamicType* type = object->GetDynamicType(); DynamicTypeHandler* typeHandler = type->GetTypeHandler(); @@ -6853,7 +6856,7 @@ using namespace Js; AssertMsg(false, "Illegal byte code: stack object as with scope"); Js::Throw::FatalInternalError(); } - if (!RecyclableObject::Is(argHead)) + if (!VarIs(argHead)) { AssertMsg(false, "Illegal byte code: non-object as with scope"); Js::Throw::FatalInternalError(); @@ -6888,7 +6891,7 @@ using namespace Js; void JavascriptOperators::OP_InitSetter(Var object, PropertyId propertyId, Var setter) { AssertMsg(!TaggedNumber::Is(object), "SetMember on a non-object?"); - RecyclableObject* recylableObject = RecyclableObject::FromVar(object); + RecyclableObject* recylableObject = VarTo(object); JIT_HELPER_NOT_REENTRANT_HEADER(OP_InitSetter, reentrancylock, recylableObject->GetScriptContext()->GetThreadContext()); recylableObject->SetAccessors(propertyId, nullptr, setter); JIT_HELPER_END(OP_InitSetter); @@ -6900,7 +6903,7 @@ using namespace Js; JIT_HELPER_SAME_ATTRIBUTES(Op_InitClassMemberSet, OP_InitSetter); JavascriptOperators::OP_InitSetter(object, propertyId, setter); - RecyclableObject::FromVar(object)->SetAttributes(propertyId, PropertyClassMemberDefaults); + VarTo(object)->SetAttributes(propertyId, PropertyClassMemberDefaults); JIT_HELPER_END(Op_InitClassMemberSet); } @@ -6911,7 +6914,7 @@ using namespace Js; PropertyId propertyId = JavascriptOperators::GetPropertyId(elementName, scriptContext); - RecyclableObject::FromVar(object)->SetAccessors(propertyId, nullptr, setter); + VarTo(object)->SetAccessors(propertyId, nullptr, setter); return propertyId; JIT_HELPER_END(OP_InitElemSetter); @@ -6954,10 +6957,10 @@ using namespace Js; { JIT_HELPER_REENTRANT_HEADER(Op_InitClassMemberSetComputedName); Js::PropertyId propertyId = JavascriptOperators::OP_InitElemSetter(object, elementName, value, scriptContext); - RecyclableObject* instance = RecyclableObject::FromVar(object); + RecyclableObject* instance = VarTo(object); // instance will be a function if it is the class constructor (otherwise it would be an object) - if (JavascriptFunction::Is(instance) && Js::PropertyIds::prototype == propertyId) + if (VarIs(instance) && Js::PropertyIds::prototype == propertyId) { // It is a TypeError to have a static member with a computed name that evaluates to 'prototype' JavascriptError::ThrowTypeError(scriptContext, JSERR_ClassStaticMethodCannotBePrototype); @@ -6992,7 +6995,7 @@ using namespace Js; void JavascriptOperators::OP_InitGetter(Var object, PropertyId propertyId, Var getter) { AssertMsg(!TaggedNumber::Is(object), "GetMember on a non-object?"); - RecyclableObject* recylableObject = RecyclableObject::FromVar(object); + RecyclableObject* recylableObject = VarTo(object); JIT_HELPER_NOT_REENTRANT_HEADER(OP_InitGetter, reentrancylock, recylableObject->GetScriptContext()->GetThreadContext()); recylableObject->SetAccessors(propertyId, getter, nullptr); JIT_HELPER_END(OP_InitGetter); @@ -7004,7 +7007,7 @@ using namespace Js; JIT_HELPER_SAME_ATTRIBUTES(Op_InitClassMemberGet, OP_InitGetter); JavascriptOperators::OP_InitGetter(object, propertyId, getter); - RecyclableObject::FromVar(object)->SetAttributes(propertyId, PropertyClassMemberDefaults); + VarTo(object)->SetAttributes(propertyId, PropertyClassMemberDefaults); JIT_HELPER_END(Op_InitClassMemberGet); } @@ -7015,7 +7018,7 @@ using namespace Js; PropertyId propertyId = JavascriptOperators::GetPropertyId(elementName, scriptContext); - RecyclableObject::FromVar(object)->SetAccessors(propertyId, getter, nullptr); + VarTo(object)->SetAccessors(propertyId, getter, nullptr); return propertyId; JIT_HELPER_END(OP_InitElemGetter); @@ -7025,10 +7028,10 @@ using namespace Js; { JIT_HELPER_REENTRANT_HEADER(Op_InitClassMemberGetComputedName); Js::PropertyId propertyId = JavascriptOperators::OP_InitElemGetter(object, elementName, value, scriptContext); - RecyclableObject* instance = RecyclableObject::FromVar(object); + RecyclableObject* instance = VarTo(object); // instance will be a function if it is the class constructor (otherwise it would be an object) - if (JavascriptFunction::Is(instance) && Js::PropertyIds::prototype == propertyId) + if (VarIs(instance) && Js::PropertyIds::prototype == propertyId) { // It is a TypeError to have a static member with a computed name that evaluates to 'prototype' JavascriptError::ThrowTypeError(scriptContext, JSERR_ClassStaticMethodCannotBePrototype); @@ -7043,7 +7046,7 @@ using namespace Js; JIT_HELPER_REENTRANT_HEADER(OP_InitComputedProperty); PropertyId propertyId = JavascriptOperators::GetPropertyId(elementName, scriptContext); - RecyclableObject::FromVar(object)->InitProperty(propertyId, value, flags); + VarTo(object)->InitProperty(propertyId, value, flags); JIT_HELPER_END(OP_InitComputedProperty); } @@ -7051,10 +7054,10 @@ using namespace Js; { JIT_HELPER_REENTRANT_HEADER(Op_InitClassMemberComputedName); PropertyId propertyId = JavascriptOperators::GetPropertyId(elementName, scriptContext); - RecyclableObject* instance = RecyclableObject::FromVar(object); + RecyclableObject* instance = VarTo(object); // instance will be a function if it is the class constructor (otherwise it would be an object) - if (JavascriptFunction::Is(instance) && Js::PropertyIds::prototype == propertyId) + if (VarIs(instance) && Js::PropertyIds::prototype == propertyId) { // It is a TypeError to have a static member with a computed name that evaluates to 'prototype' JavascriptError::ThrowTypeError(scriptContext, JSERR_ClassStaticMethodCannotBePrototype); @@ -7069,10 +7072,10 @@ using namespace Js; // void JavascriptOperators::OP_InitProto(Var instance, PropertyId propertyId, Var value) { - AssertMsg(RecyclableObject::Is(instance), "__proto__ member on a non-object?"); + AssertMsg(VarIs(instance), "__proto__ member on a non-object?"); Assert(propertyId == PropertyIds::__proto__); - RecyclableObject* object = RecyclableObject::FromVar(instance); + RecyclableObject* object = VarTo(instance); ScriptContext* scriptContext = object->GetScriptContext(); JIT_HELPER_NOT_REENTRANT_HEADER(OP_InitProto, reentrancylock, scriptContext->GetThreadContext()); @@ -7083,7 +7086,7 @@ using namespace Js; // b.Return NormalCompletion(empty). if (JavascriptOperators::IsObjectOrNull(value)) { - JavascriptObject::ChangePrototype(object, RecyclableObject::FromVar(value), /*validate*/false, scriptContext); + JavascriptObject::ChangePrototype(object, VarTo(value), /*validate*/false, scriptContext); } JIT_HELPER_END(OP_InitProto); } @@ -7164,7 +7167,7 @@ using namespace Js; DynamicObject* frameObject = nullptr; if (useCachedScope) { - frameObject = DynamicObject::FromVar(frameObj); + frameObject = VarTo(frameObj); __analysis_assume((uint32)frameObject->GetDynamicType()->GetTypeHandler()->GetSlotCapacity() >= formalsCount); } else @@ -7178,8 +7181,8 @@ using namespace Js; DynamicType* newType = nullptr; if (nonSimpleParamList) { - bool skipLetAttrForArguments = ((JavascriptGeneratorFunction::Is(funcCallee) || JavascriptAsyncFunction::Is(funcCallee)) ? - JavascriptGeneratorFunction::FromVar(funcCallee)->GetGeneratorVirtualScriptFunction()->GetFunctionBody()->HasReferenceableBuiltInArguments() + bool skipLetAttrForArguments = ((JavascriptGeneratorFunction::IsBaseGeneratorFunction(funcCallee) || VarIs(funcCallee)) ? + VarTo(funcCallee)->GetGeneratorVirtualScriptFunction()->GetFunctionBody()->HasReferenceableBuiltInArguments() : funcCallee->GetFunctionBody()->HasReferenceableBuiltInArguments()); if (skipLetAttrForArguments) @@ -7392,12 +7395,12 @@ using namespace Js; Var JavascriptOperators::OP_IsInst(Var instance, Var aClass, ScriptContext* scriptContext, IsInstInlineCache* inlineCache) { JIT_HELPER_REENTRANT_HEADER(ScrObj_OP_IsInst); - if (!RecyclableObject::Is(aClass)) + if (!VarIs(aClass)) { JavascriptError::ThrowTypeError(scriptContext, JSERR_Operand_Invalid_NeedFunction, _u("instanceof")); } - RecyclableObject* constructor = RecyclableObject::FromVar(aClass); + RecyclableObject* constructor = VarTo(aClass); if (scriptContext->GetConfig()->IsES6HasInstanceEnabled()) { Var instOfHandler = JavascriptOperators::GetPropertyNoCache(constructor, @@ -7415,7 +7418,7 @@ using namespace Js; } ThreadContext * threadContext = scriptContext->GetThreadContext(); - RecyclableObject *instFunc = RecyclableObject::FromVar(instOfHandler); + RecyclableObject *instFunc = VarTo(instOfHandler); Var result = threadContext->ExecuteImplicitCall(instFunc, ImplicitCall_Accessor, [=]()->Js::Var { return CALL_FUNCTION(scriptContext->GetThreadContext(), instFunc, CallInfo(CallFlags_Value, 2), constructor, instance); @@ -7439,7 +7442,7 @@ using namespace Js; JavascriptError::ThrowTypeError(scriptContext, JSERR_Operand_Invalid_NeedFunction, _u("class")); } - RecyclableObject * ctor = RecyclableObject::FromVar(constructor); + RecyclableObject * ctor = VarTo(constructor); if (extends) { @@ -7448,9 +7451,9 @@ using namespace Js; case Js::TypeId::TypeIds_Null: { Var ctorProto = JavascriptOperators::GetProperty(constructor, ctor, Js::PropertyIds::prototype, scriptContext); - RecyclableObject * ctorProtoObj = RecyclableObject::FromVar(ctorProto); + RecyclableObject * ctorProtoObj = VarTo(ctorProto); - ctorProtoObj->SetPrototype(RecyclableObject::FromVar(extends)); + ctorProtoObj->SetPrototype(VarTo(extends)); ctorProtoObj->EnsureProperty(Js::PropertyIds::constructor); ctorProtoObj->SetEnumerable(Js::PropertyIds::constructor, FALSE); @@ -7460,11 +7463,11 @@ using namespace Js; default: { - if (!RecyclableObject::Is(extends)) + if (!VarIs(extends)) { JavascriptError::ThrowTypeError(scriptContext, JSERR_ErrorOnNew); } - RecyclableObject * extendsObj = RecyclableObject::FromVar(extends); + RecyclableObject * extendsObj = VarTo(extends); if (!JavascriptOperators::IsConstructor(extendsObj)) { JavascriptError::ThrowTypeError(scriptContext, JSERR_ErrorOnNew); @@ -7482,15 +7485,15 @@ using namespace Js; } Var ctorProto = JavascriptOperators::GetPropertyNoCache(constructor, ctor, Js::PropertyIds::prototype, scriptContext); - RecyclableObject * ctorProtoObj = RecyclableObject::FromVar(ctorProto); + RecyclableObject * ctorProtoObj = VarTo(ctorProto); - ctorProtoObj->SetPrototype(RecyclableObject::FromVar(extendsProto)); + ctorProtoObj->SetPrototype(VarTo(extendsProto)); ctorProtoObj->EnsureProperty(Js::PropertyIds::constructor); ctorProtoObj->SetEnumerable(Js::PropertyIds::constructor, FALSE); Var protoCtor = JavascriptOperators::GetPropertyNoCache(ctorProto, ctorProtoObj, Js::PropertyIds::constructor, scriptContext); - RecyclableObject * protoCtorObj = RecyclableObject::FromVar(protoCtor); + RecyclableObject * protoCtorObj = VarTo(protoCtor); protoCtorObj->SetPrototype(extendsObj); break; @@ -7506,7 +7509,7 @@ using namespace Js; void JavascriptOperators::OP_LoadUndefinedToElement(Var instance, PropertyId propertyId) { - JIT_HELPER_NOT_REENTRANT_HEADER(Op_LdElemUndef, reentrancylock, RecyclableObject::FromVar(instance)->GetScriptContext()->GetThreadContext()); + JIT_HELPER_NOT_REENTRANT_HEADER(Op_LdElemUndef, reentrancylock, VarTo(instance)->GetScriptContext()->GetThreadContext()); AssertMsg(!TaggedNumber::Is(instance), "Invalid scope/root object"); JavascriptOperators::EnsureProperty(instance, propertyId); JIT_HELPER_END(Op_LdElemUndef); @@ -7540,22 +7543,22 @@ using namespace Js; JIT_HELPER_NOT_REENTRANT_HEADER(Op_LdElemUndefDynamic, reentrancylock, scriptContext->GetThreadContext()); if (!JavascriptOperators::HasOwnPropertyNoHostObject(instance, propertyId)) { - RecyclableObject::FromVar(instance)->InitPropertyScoped(propertyId, scriptContext->GetLibrary()->GetUndefined()); + VarTo(instance)->InitPropertyScoped(propertyId, scriptContext->GetLibrary()->GetUndefined()); } JIT_HELPER_END(Op_LdElemUndefDynamic); } BOOL JavascriptOperators::EnsureProperty(Var instance, PropertyId propertyId) { - RecyclableObject *obj = RecyclableObject::FromVar(instance); + RecyclableObject *obj = VarTo(instance); return (obj && obj->EnsureProperty(propertyId)); } void JavascriptOperators::OP_EnsureNoRootProperty(Var instance, PropertyId propertyId) { JIT_HELPER_NOT_REENTRANT_NOLOCK_HEADER(Op_EnsureNoRootProperty); - Assert(RootObjectBase::Is(instance)); - RootObjectBase *obj = RootObjectBase::FromVar(instance); + Assert(VarIs(instance)); + RootObjectBase *obj = VarTo(instance); obj->EnsureNoProperty(propertyId); JIT_HELPER_END(Op_EnsureNoRootProperty); } @@ -7563,8 +7566,8 @@ using namespace Js; void JavascriptOperators::OP_EnsureNoRootRedeclProperty(Var instance, PropertyId propertyId) { JIT_HELPER_NOT_REENTRANT_NOLOCK_HEADER(Op_EnsureNoRootRedeclProperty); - Assert(RootObjectBase::Is(instance)); - RecyclableObject *obj = RecyclableObject::FromVar(instance); + Assert(VarIs(instance)); + RecyclableObject *obj = VarTo(instance); obj->EnsureNoRedeclProperty(propertyId); JIT_HELPER_END(Op_EnsureNoRootRedeclProperty); } @@ -7578,14 +7581,14 @@ using namespace Js; for (i = 0; i < length; i++) { - object = RecyclableObject::FromVar(pDisplay->GetItem(i)); + object = VarTo(pDisplay->GetItem(i)); if (object->EnsureNoRedeclProperty(propertyId)) { return; } } - object = RecyclableObject::FromVar(defaultInstance); + object = VarTo(defaultInstance); object->EnsureNoRedeclProperty(propertyId); JIT_HELPER_END(Op_EnsureNoRedeclPropertyScoped); } @@ -7600,7 +7603,7 @@ using namespace Js; JavascriptError::ThrowTypeError(scriptContext, JSERR_Operand_Invalid_NeedObject, _u("in")); } - RecyclableObject* object = RecyclableObject::FromVar(instance); + RecyclableObject* object = VarTo(instance); BOOL result; PropertyRecord const * propertyRecord = nullptr; uint32 index; @@ -7618,7 +7621,7 @@ using namespace Js; PropertyValueInfo info; if (propertyRecordUsageCache->TryGetPropertyFromCache(instance, object, &value, scriptContext, &info, cacheOwner, nullptr)) { - Assert(JavascriptBoolean::Is(value)); + Assert(VarIs(value)); return value; } result = JavascriptOperators::GetPropertyWPCache(instance, object, propertyRecordUsageCache->GetPropertyRecord()->GetPropertyId(), &value, scriptContext, &info); @@ -7824,7 +7827,7 @@ using namespace Js; inline Var JavascriptOperators::PatchGetRootValue(FunctionBody *const functionBody, TInlineCache *const inlineCache, const InlineCacheIndex inlineCacheIndex, DynamicObject * object, PropertyId propertyId) { JIT_HELPER_REENTRANT_HEADER(Op_PatchGetRootValue); - AssertMsg(RootObjectBase::Is(object), "Root must be a global object!"); + AssertMsg(VarIs(object), "Root must be a global object!"); ScriptContext *const scriptContext = functionBody->GetScriptContext(); @@ -7857,7 +7860,7 @@ using namespace Js; Var JavascriptOperators::PatchGetRootValueForTypeOf(FunctionBody *const functionBody, TInlineCache *const inlineCache, const InlineCacheIndex inlineCacheIndex, DynamicObject * object, PropertyId propertyId) { JIT_HELPER_REENTRANT_HEADER(Op_PatchGetRootValueForTypeOf); - AssertMsg(RootObjectBase::Is(object), "Root must be a global object!"); + AssertMsg(VarIs(object), "Root must be a global object!"); ScriptContext *const scriptContext = functionBody->GetScriptContext(); @@ -7878,7 +7881,8 @@ using namespace Js; #endif value = nullptr; BEGIN_TYPEOF_ERROR_HANDLER(scriptContext); - if (JavascriptOperators::GetRootProperty(RecyclableObject::FromVar(object), propertyId, &value, scriptContext, &info)) + AssertOrFailFast(VarIsCorrectType(static_cast(object))); + if (JavascriptOperators::GetRootProperty(object, propertyId, &value, scriptContext, &info)) { if (scriptContext->IsUndeclBlockVar(value)) { @@ -7906,13 +7910,13 @@ using namespace Js; functionBody, inlineCache, inlineCacheIndex, - DynamicObject::FromVar(instance), + VarTo(instance), propertyId); } Var JavascriptOperators::PatchGetRootValueNoFastPath(FunctionBody *const functionBody, InlineCache *const inlineCache, const InlineCacheIndex inlineCacheIndex, DynamicObject* object, PropertyId propertyId) { - AssertMsg(RootObjectBase::Is(object), "Root must be a global object!"); + AssertMsg(VarIs(object), "Root must be a global object!"); ScriptContext *const scriptContext = functionBody->GetScriptContext(); @@ -7935,7 +7939,7 @@ using namespace Js; PropertyValueInfo::SetCacheInfo(&info, functionBody, inlineCache, inlineCacheIndex, !IsFromFullJit); for (uint16 i = 0; i < length; i++) { - RecyclableObject* object = RecyclableObject::UnsafeFromVar(pDisplay->GetItem(i)); + RecyclableObject* object = UnsafeVarTo(pDisplay->GetItem(i)); Var value; if (CacheOperators::TryGetProperty( @@ -7972,7 +7976,7 @@ using namespace Js; } // No one in the scope stack has the property, so get it from the default instance provided by the caller. - Var value = JavascriptOperators::PatchGetRootValue(functionBody, inlineCache, inlineCacheIndex, DynamicObject::FromVar(defaultInstance), propertyId); + Var value = JavascriptOperators::PatchGetRootValue(functionBody, inlineCache, inlineCacheIndex, VarTo(defaultInstance), propertyId); if (scriptContext->IsUndeclBlockVar(value)) { JavascriptError::ThrowReferenceError(scriptContext, JSERR_UseBeforeDeclaration); @@ -8077,7 +8081,7 @@ using namespace Js; JIT_HELPER_REENTRANT_HEADER(Op_PatchGetRootMethod); Assert(inlineCache != nullptr); - AssertMsg(RootObjectBase::Is(object), "Root must be a global object!"); + AssertMsg(VarIs(object), "Root must be a global object!"); ScriptContext *const scriptContext = functionBody->GetScriptContext(); @@ -8139,7 +8143,7 @@ using namespace Js; PropertyValueInfo info; PropertyValueInfo::SetCacheInfo(&info, functionBody, inlineCache, inlineCacheIndex, !IsFromFullJit); - const bool isRoot = RootObjectBase::Is(object); + const bool isRoot = VarIs(object); Var value; if (CacheOperators::TryGetProperty( instance, isRoot, object, propertyId, &value, scriptContext, nullptr, &info)) @@ -8194,13 +8198,13 @@ using namespace Js; functionBody, inlineCache, inlineCacheIndex, - DynamicObject::FromVar(instance), + VarTo(instance), propertyId); } Var JavascriptOperators::PatchGetRootMethodNoFastPath(FunctionBody *const functionBody, InlineCache *const inlineCache, const InlineCacheIndex inlineCacheIndex, DynamicObject* object, PropertyId propertyId) { - AssertMsg(RootObjectBase::Is(object), "Root must be a global object!"); + AssertMsg(VarIs(object), "Root must be a global object!"); PropertyValueInfo info; PropertyValueInfo::SetCacheInfo(&info, functionBody, inlineCache, inlineCacheIndex, true); @@ -8216,7 +8220,7 @@ using namespace Js; if (isRootLd) { - RootObjectBase* rootObject = RootObjectBase::FromVar(instance); + RootObjectBase* rootObject = VarTo(instance); foundValue = JavascriptOperators::GetRootPropertyReference(rootObject, propertyId, &value, scriptContext, info); } else @@ -8300,7 +8304,7 @@ using namespace Js; #if ENABLE_COPYONACCESS_ARRAY JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray(instance); #endif - RecyclableObject* object = RecyclableObject::FromVar(instance); + RecyclableObject* object = VarTo(instance); PropertyValueInfo info; PropertyValueInfo::SetCacheInfo(&info, functionBody, inlineCache, inlineCacheIndex, !IsFromFullJit); if (CacheOperators::TrySetProperty( @@ -8347,7 +8351,7 @@ using namespace Js; JIT_HELPER_REENTRANT_HEADER(Op_PatchPutRootValue); ScriptContext *const scriptContext = functionBody->GetScriptContext(); - RecyclableObject* object = RecyclableObject::FromVar(instance); + RecyclableObject* object = VarTo(instance); PropertyValueInfo info; PropertyValueInfo::SetCacheInfo(&info, functionBody, inlineCache, inlineCacheIndex, !IsFromFullJit); if (CacheOperators::TrySetProperty( @@ -8421,7 +8425,7 @@ using namespace Js; #if ENABLE_COPYONACCESS_ARRAY JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray(instance); #endif - RecyclableObject *object = RecyclableObject::UnsafeFromVar(instance); + RecyclableObject *object = UnsafeVarTo(instance); PropertyValueInfo info; PropertyValueInfo::SetCacheInfo(&info, functionBody, inlineCache, inlineCacheIndex, !IsFromFullJit); @@ -8469,7 +8473,7 @@ using namespace Js; JIT_HELPER_REENTRANT_HEADER(Op_PatchPutRootValueNoLocalFastPath); ScriptContext *const scriptContext = functionBody->GetScriptContext(); - RecyclableObject *object = RecyclableObject::FromVar(instance); + RecyclableObject *object = VarTo(instance); PropertyValueInfo info; PropertyValueInfo::SetCacheInfo(&info, functionBody, inlineCache, inlineCacheIndex, !IsFromFullJit); @@ -8525,7 +8529,7 @@ using namespace Js; JavascriptOperators::SetPropertyOnTaggedNumber(instance, nullptr, propertyId, newValue, scriptContext, flags); return; } - RecyclableObject* object = RecyclableObject::FromVar(instance); + RecyclableObject* object = VarTo(instance); PropertyValueInfo info; PropertyValueInfo::SetCacheInfo(&info, functionBody, inlineCache, inlineCacheIndex, true); @@ -8540,7 +8544,7 @@ using namespace Js; { ScriptContext *const scriptContext = functionBody->GetScriptContext(); - RecyclableObject* object = RecyclableObject::FromVar(instance); + RecyclableObject* object = VarTo(instance); PropertyValueInfo info; PropertyValueInfo::SetCacheInfo(&info, functionBody, inlineCache, inlineCacheIndex, true); @@ -8674,7 +8678,7 @@ using namespace Js; Assert(obj); Assert(scriptContext); - if (JavascriptProxy::Is(obj)) + if (VarIs(obj)) { return JavascriptProxy::DefineOwnPropertyDescriptor(obj, propId, descriptor, throwOnError, scriptContext); } @@ -8719,7 +8723,7 @@ using namespace Js; BOOL tempResult = obj->SetPropertyWithAttributes(propId, filledDescriptor.GetValue(), filledDescriptor.GetAttributes(), nullptr); if (!obj->IsExternal() && !tempResult) { - Assert(TypedArrayBase::Is(obj)); // typed array returns false when canonical numeric index is not integer or out of range + Assert(VarIs(obj)); // typed array returns false when canonical numeric index is not integer or out of range return FALSE; } } @@ -9100,7 +9104,7 @@ using namespace Js; return Reject(throwOnError, scriptContext, JSERR_InvalidTypedArrayIndex, propId); } } - // 4. Return ! OrdinaryDefineOwnProperty(O, P, Desc). + // 4. Return ! OrdinaryDefineOwnProperty(O, P, Desc). return DefineOwnPropertyDescriptor(typedArray, propId, descriptor, throwOnError, scriptContext); } @@ -9141,7 +9145,7 @@ using namespace Js; } Var value; - RecyclableObject* propertySpecObj = RecyclableObject::FromVar(propertySpec); + RecyclableObject* propertySpecObj = VarTo(propertySpec); if (JavascriptOperators::HasProperty(propertySpecObj, PropertyIds::enumerable) == TRUE) { @@ -9240,7 +9244,7 @@ using namespace Js; } Var value; - RecyclableObject* propertySpecObj = RecyclableObject::FromVar(propertySpec); + RecyclableObject* propertySpecObj = VarTo(propertySpec); if (JavascriptOperators::GetPropertyNoCache(propertySpecObj, PropertyIds::enumerable, &value, scriptContext)) { @@ -9285,9 +9289,9 @@ using namespace Js; BOOL JavascriptOperators::ToPropertyDescriptor(Var propertySpec, PropertyDescriptor* descriptor, ScriptContext* scriptContext) { - if (JavascriptProxy::Is(propertySpec) || ( - RecyclableObject::Is(propertySpec) && - JavascriptOperators::CheckIfPrototypeChainContainsProxyObject(RecyclableObject::FromVar(propertySpec)->GetPrototype()))) + if (VarIs(propertySpec) || ( + VarIs(propertySpec) && + JavascriptOperators::CheckIfPrototypeChainContainsProxyObject(VarTo(propertySpec)->GetPrototype()))) { if (ToPropertyDescriptorForProxyObjects(propertySpec, descriptor, scriptContext) == FALSE) { @@ -9387,7 +9391,7 @@ using namespace Js; } else if (descriptor.IsAccessorDescriptor()) { - // The reason is that JavascriptOperators::OP_SetProperty checks for RecyclableObject::FromVar(instance)->IsWritableOrAccessor(propertyId), + // The reason is that JavascriptOperators::OP_SetProperty checks for VarTo(instance)->IsWritableOrAccessor(propertyId), // which should in fact check for 'is writable or accessor' but since there is no GetAttributes, we can't do that efficiently. isWritable = TRUE; } @@ -9413,9 +9417,9 @@ using namespace Js; JIT_HELPER_NOT_REENTRANT_NOLOCK_HEADER(OP_ClearAttributes); Assert(instance); - if (RecyclableObject::Is(instance)) + if (VarIs(instance)) { - RecyclableObject* obj = RecyclableObject::FromVar(instance); + RecyclableObject* obj = VarTo(instance); obj->SetAttributes(propertyId, PropertyNone); } JIT_HELPER_END(OP_ClearAttributes); @@ -9581,7 +9585,7 @@ using namespace Js; Var thisVar = RootToThisObject(object, scriptContext); - RecyclableObject* marshalledFunction = RecyclableObject::UnsafeFromVar( + RecyclableObject* marshalledFunction = UnsafeVarTo( CrossSite::MarshalVar(requestContext, function, scriptContext)); Var result = CALL_ENTRYPOINT(threadContext, marshalledFunction->GetEntryPoint(), function, CallInfo(flags, 1), thisVar); @@ -9623,7 +9627,7 @@ using namespace Js; RecyclableObject* marshalledFunction = function; if (requestContext) { - marshalledFunction = RecyclableObject::UnsafeFromVar(CrossSite::MarshalVar(requestContext, function, function->GetScriptContext())); + marshalledFunction = UnsafeVarTo(CrossSite::MarshalVar(requestContext, function, function->GetScriptContext())); } Var result = CALL_ENTRYPOINT(threadContext, marshalledFunction->GetEntryPoint(), function, CallInfo(flags, 2), thisVar, putValue); @@ -9676,14 +9680,14 @@ using namespace Js; void JavascriptOperators::SetConcatStrMultiItem(Var concatStr, Var str, uint index, ScriptContext * scriptContext) { - ConcatStringMulti::FromVar(concatStr)->SetItem(index, + VarTo(concatStr)->SetItem(index, JavascriptConversion::ToPrimitiveString(str, scriptContext)); } void JavascriptOperators::SetConcatStrMultiItem2(Var concatStr, Var str1, Var str2, uint index, ScriptContext * scriptContext) { - ConcatStringMulti * cs = ConcatStringMulti::FromVar(concatStr); + ConcatStringMulti * cs = VarTo(concatStr); cs->SetItem(index, JavascriptConversion::ToPrimitiveString(str1, scriptContext)); cs->SetItem(index + 1, JavascriptConversion::ToPrimitiveString(str2, scriptContext)); } @@ -9691,14 +9695,14 @@ using namespace Js; void JavascriptOperators::OP_SetComputedNameVar(Var method, Var computedNameVar) { JIT_HELPER_NOT_REENTRANT_NOLOCK_HEADER(SetComputedNameVar); - ScriptFunctionBase *scriptFunction = ScriptFunctionBase::FromVar(method); + ScriptFunctionBase *scriptFunction = VarTo(method); scriptFunction->SetComputedNameVar(computedNameVar); JIT_HELPER_END(SetComputedNameVar); } void JavascriptOperators::OP_SetHomeObj(Var method, Var homeObj) { - ScriptFunctionBase *scriptFunction = ScriptFunctionBase::FromVar(method); + ScriptFunctionBase *scriptFunction = VarTo(method); scriptFunction->SetHomeObj(homeObj); } @@ -9706,12 +9710,12 @@ using namespace Js; { JIT_HELPER_NOT_REENTRANT_HEADER(LdHomeObj, reentrancylock, scriptContext->GetThreadContext()); // Ensure this is not a stack ScriptFunction - if (!ScriptFunction::Is(scriptFunction) || ThreadContext::IsOnStack(scriptFunction)) + if (!VarIs(scriptFunction) || ThreadContext::IsOnStack(scriptFunction)) { return scriptContext->GetLibrary()->GetUndefined(); } - ScriptFunction *instance = ScriptFunction::UnsafeFromVar(scriptFunction); + ScriptFunction *instance = UnsafeVarTo(scriptFunction); // We keep a reference to the current class rather than its super prototype // since the prototype could change. @@ -9724,12 +9728,12 @@ using namespace Js; Var JavascriptOperators::OP_LdHomeObjProto(Var homeObj, ScriptContext* scriptContext) { JIT_HELPER_NOT_REENTRANT_HEADER(LdHomeObjProto, reentrancylock, scriptContext->GetThreadContext()); - if (homeObj == nullptr || !RecyclableObject::Is(homeObj)) + if (homeObj == nullptr || !VarIs(homeObj)) { return scriptContext->GetLibrary()->GetUndefined(); } - RecyclableObject *thisObjPrototype = RecyclableObject::FromVar(homeObj); + RecyclableObject *thisObjPrototype = VarTo(homeObj); TypeId typeId = thisObjPrototype->GetTypeId(); @@ -9742,7 +9746,7 @@ using namespace Js; RecyclableObject *superBase = thisObjPrototype->GetPrototype(); - if (superBase == nullptr || !RecyclableObject::Is(superBase)) + if (superBase == nullptr || !VarIsCorrectType(superBase)) { return scriptContext->GetLibrary()->GetUndefined(); } @@ -9756,7 +9760,7 @@ using namespace Js; JIT_HELPER_NOT_REENTRANT_NOLOCK_HEADER(LdFuncObj); // use self as value of [[FunctionObject]] - this is true only for constructors - Assert(RecyclableObject::Is(scriptFunction)); + Assert(VarIs(scriptFunction)); return scriptFunction; JIT_HELPER_END(LdFuncObj); @@ -9765,7 +9769,7 @@ using namespace Js; Var JavascriptOperators::OP_LdFuncObjProto(Var funcObj, ScriptContext* scriptContext) { JIT_HELPER_NOT_REENTRANT_HEADER(LdFuncObjProto, reentrancylock, scriptContext->GetThreadContext()); - RecyclableObject *superCtor = RecyclableObject::FromVar(funcObj)->GetPrototype(); + RecyclableObject *superCtor = VarTo(funcObj)->GetPrototype(); if (superCtor == nullptr || !IsConstructor(superCtor)) { @@ -9919,7 +9923,7 @@ using namespace Js; } Var result = nullptr; - RecyclableObject* method = RecyclableObject::FromVar(prop); + RecyclableObject* method = VarTo(prop); BEGIN_SAFE_REENTRANT_CALL(scriptContext->GetThreadContext()) { Var args[] = { iterator, yieldData->data }; @@ -9949,7 +9953,7 @@ using namespace Js; JavascriptError::ThrowTypeError(scriptContext, JSERR_Property_NeedFunction, isNext ? _u("next") : isThrow ? _u("throw") : _u("return")); } - RecyclableObject* method = RecyclableObject::FromVar(prop); + RecyclableObject* method = VarTo(prop); Var result = scriptContext->GetThreadContext()->ExecuteImplicitCall(method, Js::ImplicitCall_Accessor, [=]()->Js::Var { Var args[] = { iterator, yieldData->data }; @@ -9970,7 +9974,7 @@ using namespace Js; return result; } - RecyclableObject* obj = RecyclableObject::FromVar(result); + RecyclableObject* obj = VarTo(result); Var done = JavascriptOperators::GetProperty(obj, PropertyIds::done, scriptContext); if (done == iterator->GetLibrary()->GetTrue()) { @@ -10036,15 +10040,15 @@ using namespace Js; case Js::TypeIds_Integer: return instance; case Js::TypeIds_RegEx: - return JavascriptRegExp::BoxStackInstance(JavascriptRegExp::FromVar(instance), deepCopy); + return JavascriptRegExp::BoxStackInstance(VarTo(instance), deepCopy); case Js::TypeIds_Object: - return DynamicObject::BoxStackInstance(DynamicObject::FromVar(instance), deepCopy); + return DynamicObject::BoxStackInstance(VarTo(instance), deepCopy); case Js::TypeIds_Array: - return JavascriptArray::BoxStackInstance(JavascriptArray::UnsafeFromVar(instance), deepCopy); + return JavascriptArray::BoxStackInstance(UnsafeVarTo(instance), deepCopy); case Js::TypeIds_NativeIntArray: - return JavascriptNativeIntArray::BoxStackInstance(JavascriptNativeIntArray::UnsafeFromVar(instance), deepCopy); + return JavascriptNativeIntArray::BoxStackInstance(UnsafeVarTo(instance), deepCopy); case Js::TypeIds_NativeFloatArray: - return JavascriptNativeFloatArray::BoxStackInstance(JavascriptNativeFloatArray::UnsafeFromVar(instance), deepCopy); + return JavascriptNativeFloatArray::BoxStackInstance(UnsafeVarTo(instance), deepCopy); case Js::TypeIds_Function: Assert(allowStackFunction); // Stack functions are deal with not mar mark them, but by nested function escape analysis @@ -10260,7 +10264,7 @@ using namespace Js; __out_bcount(length*elementSize) byte* buffer, Js::ScriptContext* scriptContext) { - Js::DynamicObject* dynamicObject = DynamicObject::FromVar(arrayObject); + Js::DynamicObject* dynamicObject = VarTo(arrayObject); if (dynamicObject->IsCrossSiteObject() || Js::TaggedInt::IsOverflow(length)) { Js::JavascriptOperators::ObjectToNativeArray(&arrayObject, valueType, length, elementSize, buffer, scriptContext); @@ -10273,13 +10277,13 @@ using namespace Js; switch (Js::JavascriptOperators::GetTypeId(arrayObject)) { case TypeIds_Array: - Js::JavascriptOperators::ObjectToNativeArray(Js::JavascriptArray::UnsafeFromVar(arrayObject), valueType, length, elementSize, buffer, scriptContext); + Js::JavascriptOperators::ObjectToNativeArray(Js::UnsafeVarTo(arrayObject), valueType, length, elementSize, buffer, scriptContext); break; case TypeIds_NativeFloatArray: - Js::JavascriptOperators::ObjectToNativeArray(Js::JavascriptNativeFloatArray::UnsafeFromVar(arrayObject), valueType, length, elementSize, buffer, scriptContext); + Js::JavascriptOperators::ObjectToNativeArray(Js::UnsafeVarTo(arrayObject), valueType, length, elementSize, buffer, scriptContext); break; case TypeIds_NativeIntArray: - Js::JavascriptOperators::ObjectToNativeArray(Js::JavascriptNativeIntArray::UnsafeFromVar(arrayObject), valueType, length, elementSize, buffer, scriptContext); + Js::JavascriptOperators::ObjectToNativeArray(Js::UnsafeVarTo(arrayObject), valueType, length, elementSize, buffer, scriptContext); break; // We can have more specialized template if needed. default: @@ -10313,7 +10317,7 @@ using namespace Js; //6.Let S be Get(C, @@species). //7.ReturnIfAbrupt(S). Var species = nullptr; - if (!JavascriptOperators::GetProperty(RecyclableObject::FromVar(constructor), + if (!JavascriptOperators::GetProperty(VarTo(constructor), PropertyIds::_symbolSpecies, &species, scriptContext) || JavascriptOperators::IsUndefinedOrNull(species)) { @@ -10470,7 +10474,7 @@ using namespace Js; JIT_HELPER_SAME_ATTRIBUTES(Op_Equal, Op_Equal_Full); if (aLeft == aRight) { - if (TaggedInt::Is(aLeft) || JavascriptObject::Is(aLeft)) + if (TaggedInt::Is(aLeft) || DynamicObject::IsBaseDynamicObject(aLeft)) { return true; } @@ -10480,7 +10484,7 @@ using namespace Js; } } - if (JavascriptString::Is(aLeft) && JavascriptString::Is(aRight)) + if (VarIs(aLeft) && VarIs(aRight)) { JavascriptString* left = (JavascriptString*)aLeft; JavascriptString* right = (JavascriptString*)aRight; @@ -10591,7 +10595,7 @@ using namespace Js; Var JavascriptOperators::ToWithObject(Var aRight, ScriptContext* scriptContext) { JIT_HELPER_NOT_REENTRANT_HEADER(Op_NewWithObject, reentrancylock, scriptContext->GetThreadContext()); - RecyclableObject* object = RecyclableObject::FromVar(aRight); + RecyclableObject* object = VarTo(aRight); WithScopeObject* withWrapper = RecyclerNew(scriptContext->GetRecycler(), WithScopeObject, object, scriptContext->GetLibrary()->GetWithType()); return withWrapper; @@ -10686,7 +10690,7 @@ using namespace Js; BOOL JavascriptOperators::IsNull(Var instance, JavascriptLibrary* library) { - Assert(!RecyclableObject::Is(instance) ? TRUE : ((RecyclableObject*)instance)->GetScriptContext()->GetLibrary() == library ); + Assert(!VarIs(instance) ? TRUE : ((RecyclableObject*)instance)->GetScriptContext()->GetLibrary() == library ); return library->GetNull() == instance; } @@ -10725,7 +10729,7 @@ using namespace Js; BOOL JavascriptOperators::IsUndefinedObject(Var instance, JavascriptLibrary* library) { - Assert(!RecyclableObject::Is(instance) ? TRUE : ((RecyclableObject*)instance)->GetScriptContext()->GetLibrary() == library ); + Assert(!VarIs(instance) ? TRUE : ((RecyclableObject*)instance)->GetScriptContext()->GetLibrary() == library ); return JavascriptOperators::IsUndefinedObject(instance, library->GetUndefined()); } @@ -10762,7 +10766,7 @@ using namespace Js; JavascriptError::ThrowTypeError(scriptContext, JSERR_Property_NeedFunction); } - RecyclableObject* function = RecyclableObject::FromVar(func); + RecyclableObject* function = VarTo(func); return function; } @@ -10786,7 +10790,7 @@ using namespace Js; JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedObject); } - return RecyclableObject::FromVar(iterator); + return VarTo(iterator); } void JavascriptOperators::IteratorClose(RecyclableObject* iterator, ScriptContext* scriptContext) @@ -10797,7 +10801,7 @@ using namespace Js; if (JavascriptConversion::IsCallable(func)) { - RecyclableObject* callable = RecyclableObject::FromVar(func); + RecyclableObject* callable = VarTo(func); scriptContext->GetThreadContext()->ExecuteImplicitCall(callable, ImplicitCall_Accessor, [=]()->Var { Js::Var args[] = { iterator }; @@ -10829,7 +10833,7 @@ using namespace Js; JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedFunction); } - RecyclableObject* callable = RecyclableObject::FromVar(func); + RecyclableObject* callable = VarTo(func); Var result = threadContext->ExecuteImplicitCall(callable, ImplicitCall_Accessor, [=]() -> Var { Js::Var args[] = { iterator, value }; @@ -10846,7 +10850,7 @@ using namespace Js; JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedObject); } - return RecyclableObject::FromVar(result); + return VarTo(result); } // IteratorComplete as described in ES6.0 (draft 22) Section 7.4.3 @@ -10902,9 +10906,9 @@ using namespace Js; // If constructor.prototype is an object, we should use that as the [[Prototype]] for our obj. // Else, we set the [[Prototype]] internal slot of obj to %intrinsicProto% - which should be the default. if (JavascriptOperators::IsObjectType(JavascriptOperators::GetTypeId(proto)) && - DynamicObject::FromVar(proto) != intrinsicProto) + VarTo(proto) != intrinsicProto) { - JavascriptObject::ChangePrototype(obj, RecyclableObject::FromVar(proto), /*validate*/true, scriptContext); + JavascriptObject::ChangePrototype(obj, VarTo(proto), /*validate*/true, scriptContext); } return obj; diff --git a/lib/Runtime/Language/JavascriptOperators.h b/lib/Runtime/Language/JavascriptOperators.h index 42b2b0dacd6..762d88cd291 100644 --- a/lib/Runtime/Language/JavascriptOperators.h +++ b/lib/Runtime/Language/JavascriptOperators.h @@ -26,7 +26,7 @@ namespace Js // and propagate all other exceptions. // // NB: Re-throw from catch unwinds the active frame but doesn't clear the stack - // (catch clauses keep accumulating at the top of the stack until a catch + // (catch clauses keep accumulating at the top of the stack until a catch // that doesn't re-throw). This is problematic if we've detected potential // stack overflow and report it via exceptions: the handling of throw // might actually overflow the stack and cause system SO exception. @@ -43,8 +43,8 @@ namespace Js if (exceptionObject != nullptr) \ { \ Js::Var errorObject = exceptionObject->GetThrownObject(nullptr); \ - HRESULT hr = (errorObject != nullptr && Js::JavascriptError::Is(errorObject)) \ - ? Js::JavascriptError::GetRuntimeError(Js::RecyclableObject::FromVar(errorObject), nullptr) \ + HRESULT hr = (errorObject != nullptr && Js::VarIs(errorObject)) \ + ? Js::JavascriptError::GetRuntimeError(Js::VarTo(errorObject), nullptr) \ : S_OK; \ if (JavascriptError::GetErrorNumberFromResourceID(JSERR_UndefVariable) != (int32)hr) \ { \ @@ -248,15 +248,15 @@ namespace Js static TypeId GetTypeId(_In_ const Var instance); static TypeId GetTypeId(_In_ RecyclableObject* instance); static TypeId GetTypeIdNoCheck(Var instance); - template - __forceinline static T* TryFromVar(_In_ RecyclableObject* value) + template + __forceinline static T* TryFromVar(_In_ U* value) { - return T::Is(value) ? T::UnsafeFromVar(value) : nullptr; + return VarIs(value) ? UnsafeVarTo(value) : nullptr; } - template - __forceinline static T* TryFromVar(_In_ Var value) + template + __forceinline static T* TryFromVar(WriteBarrierPtr value) { - return T::Is(value) ? T::UnsafeFromVar(value) : nullptr; + return VarIs(value) ? UnsafeVarTo(value) : nullptr; } static BOOL IsObject(_In_ Var instance); static BOOL IsObject(_In_ RecyclableObject* instance); @@ -782,5 +782,4 @@ namespace Js static BOOL IsRemoteArray(RecyclableObject* instance); }; - } // namespace Js diff --git a/lib/Runtime/Language/JavascriptOperators.inl b/lib/Runtime/Language/JavascriptOperators.inl index 12984b5b20a..6b60402c242 100644 --- a/lib/Runtime/Language/JavascriptOperators.inl +++ b/lib/Runtime/Language/JavascriptOperators.inl @@ -31,7 +31,7 @@ namespace Js #endif else { - return JavascriptOperators::GetTypeId(RecyclableObject::UnsafeFromVar(aValue)); + return JavascriptOperators::GetTypeId(UnsafeVarTo(aValue)); } } @@ -51,7 +51,7 @@ namespace Js #endif else { - auto typeId = RecyclableObject::FromVar(aValue)->GetTypeId(); + auto typeId = VarTo(aValue)->GetTypeId(); return typeId; } } diff --git a/lib/Runtime/Language/JavascriptStackWalker.cpp b/lib/Runtime/Language/JavascriptStackWalker.cpp index 75b0ff06062..4e218baa63c 100644 --- a/lib/Runtime/Language/JavascriptStackWalker.cpp +++ b/lib/Runtime/Language/JavascriptStackWalker.cpp @@ -163,7 +163,7 @@ namespace Js // Get the heap-allocated args for this frame. Var args = this->GetCurrentArgumentsObject(); - if (args && ArgumentsObject::Is(args)) + if (args && VarIs(args)) { args = ((ArgumentsObject*)args)->GetHeapArguments(); } @@ -280,7 +280,7 @@ namespace Js #endif if (this->GetCurrentFunction()->GetFunctionInfo()->IsCoroutine()) { - JavascriptGenerator* gen = JavascriptGenerator::FromVar(this->GetCurrentArgv()[JavascriptFunctionArgIndex_This]); + JavascriptGenerator* gen = VarTo(this->GetCurrentArgv()[JavascriptFunctionArgIndex_This]); return gen->GetArguments().Values; } else @@ -454,7 +454,7 @@ namespace Js // are inlined frames on the stack the InlineeCallInfo of the first inlined frame // has the native offset of the current physical frame. Assert(!*inlinee); - InlinedFrameWalker::FromPhysicalFrame(tmpFrameWalker, currentFrame, ScriptFunction::FromVar(parentFunction), PreviousInterpreterFrameIsFromBailout(), loopNum, this, useInternalFrameInfo, false /*noAlloc*/); + InlinedFrameWalker::FromPhysicalFrame(tmpFrameWalker, currentFrame, VarTo(parentFunction), PreviousInterpreterFrameIsFromBailout(), loopNum, this, useInternalFrameInfo, false /*noAlloc*/); inlineeOffset = tmpFrameWalker.GetBottomMostInlineeOffset(); tmpFrameWalker.Close(); } @@ -559,7 +559,7 @@ namespace Js } bool hasInlinedFramesOnStack = InlinedFrameWalker::FromPhysicalFrame(inlinedFrameWalker, currentFrame, - ScriptFunction::FromVar(function), true /*fromBailout*/, loopNum, this, false /*useInternalFrameInfo*/, false /*noAlloc*/); + VarTo(function), true /*fromBailout*/, loopNum, this, false /*useInternalFrameInfo*/, false /*noAlloc*/); if (hasInlinedFramesOnStack) { @@ -610,7 +610,7 @@ namespace Js bool inlinedFramesFound = InlinedFrameWalker::FromPhysicalFrame( inlinedFrameWalker, currentFrame, - ScriptFunction::FromVar(function), + VarTo(function), false, // fromBailout -1, // loopNum nullptr,// walker @@ -891,7 +891,7 @@ namespace Js return addressOfReturnAddress == nativeLibraryEntryAddress #if defined(_M_IX86) // Under some odd cases on x86, addressOfReturnAddress and stashed entry address need to be aligned. - // This happens when code is generated using two stack pointers. One or both have the address of + // This happens when code is generated using two stack pointers. One or both have the address of // return address offset by 4, 8, or 12. || (((uint)nativeLibraryEntryAddress - (uint)addressOfReturnAddress < 0x10) && *(void**)addressOfReturnAddress == *(void**)nativeLibraryEntryAddress @@ -956,7 +956,7 @@ namespace Js // wouldn't have created a new interpreterFrame if the bailout were from the loop body itself. Assert(this->interpreterFrame->TestFlags(Js::InterpreterStackFrameFlags_FromBailOut)); InlinedFrameWalker tmpFrameWalker; - Assert(InlinedFrameWalker::FromPhysicalFrame(tmpFrameWalker, currentFrame, Js::ScriptFunction::FromVar(argv[JavascriptFunctionArgIndex_Function]), + Assert(InlinedFrameWalker::FromPhysicalFrame(tmpFrameWalker, currentFrame, Js::VarTo(argv[JavascriptFunctionArgIndex_Function]), true /*fromBailout*/, this->tempInterpreterFrame->GetCurrentLoopNum(), this, false /*useInternalFrameInfo*/, true /*noAlloc*/)); tmpFrameWalker.Close(); } @@ -993,7 +993,7 @@ namespace Js return false; } - ScriptFunction* funcObj = Js::ScriptFunction::FromVar(argv[JavascriptFunctionArgIndex_Function]); + ScriptFunction* funcObj = Js::VarTo(argv[JavascriptFunctionArgIndex_Function]); if (funcObj->GetFunctionBody()->GetIsAsmjsMode()) { return false; @@ -1003,7 +1003,7 @@ namespace Js if (((CallInfo const *)&argv[JavascriptFunctionArgIndex_CallInfo])->Flags & CallFlags_InternalFrame) { if (includeInlineFrames && - InlinedFrameWalker::FromPhysicalFrame(inlinedFrameWalker, currentFrame, Js::ScriptFunction::FromVar(argv[JavascriptFunctionArgIndex_Function]), + InlinedFrameWalker::FromPhysicalFrame(inlinedFrameWalker, currentFrame, Js::VarTo(argv[JavascriptFunctionArgIndex_Function]), false /*fromBailout*/, this->tempInterpreterFrame->GetCurrentLoopNum(), this, false /*useInternalFrameInfo*/, false /*noAlloc*/)) { // Found inlined frames in a jitted loop body. We dont want to skip the inlined frames; walk all of them before setting codeAddress on lastInternalFrameInfo. @@ -1043,7 +1043,7 @@ namespace Js if (this->isNativeLibraryFrame) { // Return saved function. Do not read from stack as compiler may stackpack/optimize args. - return JavascriptFunction::FromVar(this->prevNativeLibraryEntry->function); + return VarTo(this->prevNativeLibraryEntry->function); } else { @@ -1083,7 +1083,7 @@ namespace Js } else if (this->GetCurrentFunction()->GetFunctionInfo()->IsCoroutine()) { - JavascriptGenerator* gen = JavascriptGenerator::FromVar(this->GetCurrentArgv()[JavascriptFunctionArgIndex_This]); + JavascriptGenerator* gen = VarTo(this->GetCurrentArgv()[JavascriptFunctionArgIndex_This]); callInfo = gen->GetArguments().Info; } else if (this->isNativeLibraryFrame) @@ -1116,7 +1116,7 @@ namespace Js if (this->GetCurrentFunction()->GetFunctionInfo()->IsCoroutine()) { - JavascriptGenerator* gen = JavascriptGenerator::FromVar(this->GetCurrentArgv()[JavascriptFunctionArgIndex_This]); + JavascriptGenerator* gen = VarTo(this->GetCurrentArgv()[JavascriptFunctionArgIndex_This]); return gen->GetArguments()[0]; } diff --git a/lib/Runtime/Language/ModuleNamespace.h b/lib/Runtime/Language/ModuleNamespace.h index 535be1d4353..11711e6bb3d 100644 --- a/lib/Runtime/Language/ModuleNamespace.h +++ b/lib/Runtime/Language/ModuleNamespace.h @@ -30,8 +30,6 @@ namespace Js static ModuleNamespace* GetModuleNamespace(ModuleRecordBase* moduleRecord); void Initialize(); ListForListIterator* GetSortedExportedNames() { return this->sortedExportedNames; } - static bool Is(Var aValue) { return JavascriptOperators::GetTypeId(aValue) == TypeIds_ModuleNamespace; } - static ModuleNamespace* FromVar(Var obj) { AssertOrFailFast(JavascriptOperators::GetTypeId(obj) == TypeIds_ModuleNamespace); return static_cast(obj); } virtual PropertyId GetPropertyId(BigPropertyIndex index) override; virtual PropertyQueryFlags HasPropertyQuery(PropertyId propertyId, _Inout_opt_ PropertyValueInfo* info) override; @@ -98,4 +96,9 @@ namespace Js // Methods used by NamespaceEnumerator; BOOL FindNextProperty(BigPropertyIndex& index, JavascriptString** propertyString, PropertyId* propertyId, PropertyAttributes* attributes, ScriptContext * requestContext) const; }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_ModuleNamespace; + } } diff --git a/lib/Runtime/Language/ModuleNamespaceEnumerator.cpp b/lib/Runtime/Language/ModuleNamespaceEnumerator.cpp index 7e1b3e1417c..248e7f43b4b 100644 --- a/lib/Runtime/Language/ModuleNamespaceEnumerator.cpp +++ b/lib/Runtime/Language/ModuleNamespaceEnumerator.cpp @@ -71,8 +71,8 @@ namespace Js currentLocalMapIndex++; if (currentLocalMapIndex < sortedExportedNames->Count()) { - Assert(JavascriptString::Is(sortedExportedNames->Item(currentLocalMapIndex))); - return JavascriptString::FromVar(sortedExportedNames->Item(currentLocalMapIndex)); + Assert(VarIs(sortedExportedNames->Item(currentLocalMapIndex))); + return VarTo(sortedExportedNames->Item(currentLocalMapIndex)); } else { diff --git a/lib/Runtime/Language/ProfilingHelpers.cpp b/lib/Runtime/Language/ProfilingHelpers.cpp index a78532c003b..9f871577314 100644 --- a/lib/Runtime/Language/ProfilingHelpers.cpp +++ b/lib/Runtime/Language/ProfilingHelpers.cpp @@ -36,7 +36,7 @@ using namespace Js; const bool fastPath = isJsArray; if(fastPath) { - JavascriptArray *const array = JavascriptArray::UnsafeFromVar(base); + JavascriptArray *const array = UnsafeVarTo(base); ldElemInfo.arrayType = ValueType::FromArray(ObjectType::Array, array, TypeIds_Array).ToLikely(); const Var element = ProfiledLdElem_FastPath(array, varIndex, functionBody->GetScriptContext(), &ldElemInfo); @@ -81,9 +81,9 @@ using namespace Js; bool isVirtual = (VirtualTableInfoBase::GetVirtualTable(base) == ValueType::GetVirtualTypedArrayVtable(arrayTypeId)); ldElemInfo.arrayType = ValueType::FromTypeId(arrayTypeId, isVirtual).ToLikely(); } - else if(Js::RecyclableObject::Is(base)) + else if(Js::VarIs(base)) { - ldElemInfo.arrayType = ValueType::FromObject(Js::RecyclableObject::UnsafeFromVar(base)).ToLikely(); + ldElemInfo.arrayType = ValueType::FromObject(Js::UnsafeVarTo(base)).ToLikely(); break; } else @@ -257,7 +257,7 @@ using namespace Js; const bool fastPath = isJsArray && !JavascriptOperators::SetElementMayHaveImplicitCalls(scriptContext); if(fastPath) { - JavascriptArray *const array = JavascriptArray::UnsafeFromVar(base); + JavascriptArray *const array = UnsafeVarTo(base); stElemInfo.arrayType = ValueType::FromArray(ObjectType::Array, array, TypeIds_Array).ToLikely(); stElemInfo.createdMissingValue = array->HasNoMissingValues(); @@ -273,7 +273,7 @@ using namespace Js; TypeId arrayTypeId; if(isJsArray) { - array = JavascriptArray::UnsafeFromVar(base); + array = UnsafeVarTo(base); isObjectWithArray = false; arrayTypeId = TypeIds_Array; } @@ -312,7 +312,7 @@ using namespace Js; { length = headSegmentLength; bool isVirtual = (VirtualTableInfoBase::GetVirtualTable(base) == ValueType::GetVirtualTypedArrayVtable(arrayTypeId)); - stElemInfo.arrayType = ValueType::FromTypeId(arrayTypeId, isVirtual).ToLikely(); + stElemInfo.arrayType = ValueType::FromTypeId(arrayTypeId, isVirtual).ToLikely(); if (!TaggedNumber::Is(value) && !JavascriptNumber::Is_NoTaggedIntCheck(value)) { // Non-number stored to a typed array. A helper call will be needed to convert the value. @@ -526,7 +526,7 @@ using namespace Js; ...) { ARGUMENTS(args, callee, framePointer, profileId, arrayProfileId, callInfo); - ScriptFunction* func = ScriptFunction::UnsafeFromVar(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); + ScriptFunction* func = UnsafeVarTo(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); JIT_HELPER_REENTRANT_HEADER(ProfiledNewScObjArray); return ProfiledNewScObjArray( @@ -549,7 +549,7 @@ using namespace Js; { ARGUMENTS(args, spreadIndices, callee, framePointer, profileId, arrayProfileId, callInfo); - Js::ScriptFunction *function = ScriptFunction::UnsafeFromVar(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); + Js::ScriptFunction *function = UnsafeVarTo(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); ScriptContext* scriptContext = function->GetScriptContext(); JIT_HELPER_REENTRANT_HEADER(ProfiledNewScObjArraySpread); @@ -638,7 +638,7 @@ using namespace Js; args.Values[0] = nullptr; Var array; - Js::RecyclableObject* calleeObject = RecyclableObject::UnsafeFromVar(callee); + Js::RecyclableObject* calleeObject = UnsafeVarTo(callee); if (arrayInfo->IsNativeIntArray()) { array = JavascriptNativeIntArray::NewInstance(calleeObject, args); @@ -701,7 +701,7 @@ using namespace Js; const auto calleeObject = JavascriptOperators::GetCallableObjectOrThrow(callee, scriptContext); const auto calleeFunctionInfo = calleeObject->GetTypeId() == TypeIds_Function - ? JavascriptFunction::UnsafeFromVar(calleeObject)->GetFunctionInfo() + ? UnsafeVarTo(calleeObject)->GetFunctionInfo() : nullptr; DynamicProfileInfo *profileInfo = callerFunctionBody->GetDynamicProfileInfo(); profileInfo->RecordCallSiteInfo( @@ -720,7 +720,7 @@ using namespace Js; retVal = JavascriptOperators::NewScObject(callee, args, scriptContext, spreadIndices); } END_SAFE_REENTRANT_CALL - + profileInfo->RecordReturnTypeOnCallSiteInfo(callerFunctionBody, profileId, retVal); return retVal; } @@ -751,7 +751,7 @@ using namespace Js; void *const framePointer) { JIT_HELPER_REENTRANT_HEADER(ProfiledLdLen); - ScriptFunction * const scriptFunction = ScriptFunction::UnsafeFromVar(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); + ScriptFunction * const scriptFunction = UnsafeVarTo(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); FunctionBody * functionBody = scriptFunction->GetFunctionBody(); DynamicProfileInfo * profileInfo = functionBody->GetDynamicProfileInfo(); @@ -778,7 +778,7 @@ using namespace Js; { JIT_HELPER_REENTRANT_HEADER(ProfiledLdFld); ScriptFunction *const scriptFunction = - ScriptFunction::UnsafeFromVar(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); + UnsafeVarTo(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); return ProfiledLdFld( instance, @@ -799,7 +799,7 @@ using namespace Js; { JIT_HELPER_REENTRANT_HEADER(ProfiledLdSuperFld); ScriptFunction *const scriptFunction = - ScriptFunction::UnsafeFromVar(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); + UnsafeVarTo(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); return ProfiledLdFld( instance, @@ -819,7 +819,7 @@ using namespace Js; { JIT_HELPER_REENTRANT_HEADER(ProfiledLdFldForTypeOf); ScriptFunction *const scriptFunction = - ScriptFunction::UnsafeFromVar(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); + UnsafeVarTo(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); return ProfiledLdFldForTypeOf( instance, @@ -839,7 +839,7 @@ using namespace Js; { JIT_HELPER_REENTRANT_HEADER(ProfiledLdFld_CallApplyTarget); ScriptFunction *const scriptFunction = - ScriptFunction::UnsafeFromVar(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); + UnsafeVarTo(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); return ProfiledLdFld( instance, @@ -859,7 +859,7 @@ using namespace Js; { JIT_HELPER_REENTRANT_HEADER(ProfiledLdMethodFld); ScriptFunction *const scriptFunction = - ScriptFunction::UnsafeFromVar(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); + UnsafeVarTo(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); return ProfiledLdFld( instance, @@ -879,7 +879,7 @@ using namespace Js; { JIT_HELPER_REENTRANT_HEADER(ProfiledLdRootFld); ScriptFunction *const scriptFunction = - ScriptFunction::UnsafeFromVar(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); + UnsafeVarTo(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); return ProfiledLdFld( instance, @@ -899,7 +899,7 @@ using namespace Js; { JIT_HELPER_REENTRANT_HEADER(ProfiledLdRootFldForTypeOf); ScriptFunction *const scriptFunction = - ScriptFunction::UnsafeFromVar(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); + UnsafeVarTo(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); return ProfiledLdFldForTypeOf( instance, @@ -918,7 +918,7 @@ using namespace Js; { JIT_HELPER_REENTRANT_HEADER(ProfiledLdRootMethodFld); ScriptFunction *const scriptFunction = - ScriptFunction::UnsafeFromVar(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); + UnsafeVarTo(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); return ProfiledLdFld( instance, @@ -954,17 +954,17 @@ using namespace Js; DynamicProfileInfo *const dynamicProfileInfo = functionBody->GetDynamicProfileInfo(); Var value; FldInfoFlags fldInfoFlags = FldInfo_NoInfo; - if (Root || (RecyclableObject::Is(instance) && RecyclableObject::Is(thisInstance))) + if (Root || (VarIs(instance) && VarIs(thisInstance))) { - RecyclableObject *const object = RecyclableObject::UnsafeFromVar(instance); - RecyclableObject *const thisObject = RecyclableObject::UnsafeFromVar(thisInstance); + RecyclableObject *const object = UnsafeVarTo(instance); + RecyclableObject *const thisObject = UnsafeVarTo(thisInstance); - if (!Root && Method && (propertyId == PropertyIds::apply || propertyId == PropertyIds::call) && ScriptFunction::Is(object)) + if (!Root && Method && (propertyId == PropertyIds::apply || propertyId == PropertyIds::call) && VarIs(object)) { // If the property being loaded is "apply"/"call", make an optimistic assumption that apply/call is not overridden and // undefer the function right here if it was defer parsed before. This is required so that the load of "apply"/"call" // happens from the same "type". Otherwise, we will have a polymorphic cache for load of "apply"/"call". - ScriptFunction *fn = ScriptFunction::UnsafeFromVar(object); + ScriptFunction *fn = UnsafeVarTo(object); if (fn->GetType()->GetEntryPoint() == JavascriptFunction::DeferredParsingThunk) { JavascriptFunction::DeferredParse(&fn); @@ -1086,7 +1086,7 @@ using namespace Js; { JIT_HELPER_REENTRANT_HEADER(ProfiledStFld); ScriptFunction *const scriptFunction = - ScriptFunction::UnsafeFromVar(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); + UnsafeVarTo(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); ProfiledStFld( instance, propertyId, @@ -1109,7 +1109,7 @@ using namespace Js; { JIT_HELPER_REENTRANT_HEADER(ProfiledStSuperFld); ScriptFunction *const scriptFunction = - ScriptFunction::UnsafeFromVar(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); + UnsafeVarTo(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); ProfiledStFld( instance, propertyId, @@ -1131,7 +1131,7 @@ using namespace Js; { JIT_HELPER_REENTRANT_HEADER(ProfiledStFld_Strict); ScriptFunction *const scriptFunction = - ScriptFunction::UnsafeFromVar(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); + UnsafeVarTo(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); ProfiledStFld( instance, propertyId, @@ -1153,7 +1153,7 @@ using namespace Js; { JIT_HELPER_REENTRANT_HEADER(ProfiledStRootFld); ScriptFunction *const scriptFunction = - ScriptFunction::UnsafeFromVar(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); + UnsafeVarTo(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); ProfiledStFld( instance, propertyId, @@ -1175,7 +1175,7 @@ using namespace Js; { JIT_HELPER_REENTRANT_HEADER(ProfiledStRootFld_Strict); ScriptFunction *const scriptFunction = - ScriptFunction::UnsafeFromVar(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); + UnsafeVarTo(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); ProfiledStFld( instance, propertyId, @@ -1216,10 +1216,10 @@ using namespace Js; ScriptContext *const scriptContext = functionBody->GetScriptContext(); FldInfoFlags fldInfoFlags = FldInfo_NoInfo; - if(Root || (RecyclableObject::Is(instance) && RecyclableObject::Is(thisInstance))) + if(Root || (VarIs(instance) && VarIs(thisInstance))) { - RecyclableObject *const object = RecyclableObject::UnsafeFromVar(instance); - RecyclableObject *const thisObject = RecyclableObject::UnsafeFromVar(thisInstance); + RecyclableObject *const object = UnsafeVarTo(instance); + RecyclableObject *const thisObject = UnsafeVarTo(thisInstance); PropertyCacheOperationInfo operationInfo; PropertyValueInfo propertyValueInfo; PropertyValueInfo::SetCacheInfo(&propertyValueInfo, functionBody, inlineCache, inlineCacheIndex, true); @@ -1326,9 +1326,9 @@ using namespace Js; { JIT_HELPER_REENTRANT_HEADER(ProfiledInitFld); ScriptFunction *const scriptFunction = - ScriptFunction::UnsafeFromVar(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); + UnsafeVarTo(JavascriptCallStackLayout::FromFramePointer(framePointer)->functionObject); ProfiledInitFld( - RecyclableObject::FromVar(instance), + VarTo(instance), propertyId, GetInlineCache(scriptFunction, inlineCacheIndex), inlineCacheIndex, @@ -1436,7 +1436,7 @@ using namespace Js; return scriptFunction->GetHasInlineCaches() - ? ScriptFunctionWithInlineCache::UnsafeFromVar(scriptFunction)->GetInlineCache(inlineCacheIndex) + ? UnsafeVarTo(scriptFunction)->GetInlineCache(inlineCacheIndex) : scriptFunction->GetFunctionBody()->GetInlineCache(inlineCacheIndex); } #endif diff --git a/lib/Runtime/Language/SourceTextModuleRecord.cpp b/lib/Runtime/Language/SourceTextModuleRecord.cpp index 3e2bf352c8f..4ac00db0104 100644 --- a/lib/Runtime/Language/SourceTextModuleRecord.cpp +++ b/lib/Runtime/Language/SourceTextModuleRecord.cpp @@ -1038,7 +1038,7 @@ namespace Js HRESULT SourceTextModuleRecord::OnHostException(void* errorVar) { - if (!RecyclableObject::Is(errorVar)) + if (!VarIs(errorVar)) { return E_INVALIDARG; } diff --git a/lib/Runtime/Language/SourceTextModuleRecord.h b/lib/Runtime/Language/SourceTextModuleRecord.h index f95bbf5c3ae..ad5a045f20f 100644 --- a/lib/Runtime/Language/SourceTextModuleRecord.h +++ b/lib/Runtime/Language/SourceTextModuleRecord.h @@ -50,11 +50,11 @@ namespace Js void SetSpecifier(Var specifier) { this->normalizedSpecifier = specifier; } Var GetSpecifier() const { return normalizedSpecifier; } - const char16 *GetSpecifierSz() const { return JavascriptString::FromVar(this->normalizedSpecifier)->GetSz(); } + const char16 *GetSpecifierSz() const { return VarTo(this->normalizedSpecifier)->GetSz(); } void SetModuleUrl(Var moduleUrl) { this->moduleUrl = moduleUrl; } Var GetModuleUrl() const { return moduleUrl;} - const char16 *GetModuleUrlSz() const { return JavascriptString::FromVar(this->moduleUrl)->GetSz(); } + const char16 *GetModuleUrlSz() const { return VarTo(this->moduleUrl)->GetSz(); } Var GetErrorObject() const { return errorObject; } diff --git a/lib/Runtime/Language/TaggedInt.h b/lib/Runtime/Language/TaggedInt.h index a6842ce37f2..ca154b1a74e 100644 --- a/lib/Runtime/Language/TaggedInt.h +++ b/lib/Runtime/Language/TaggedInt.h @@ -80,6 +80,11 @@ namespace Js { static const int k_nMaxValue = INT_MAX / AtomTag_Multiply; }; + template <> inline bool VarIs(Var aValue) + { + return TaggedInt::Is(aValue); + } + // Helper representing operations and checks on TaggedInteger // and JavascriptNumber ( aka TaggedFloat) - JavascriptNumber is a Tagged value // only for 64-bit platforms. diff --git a/lib/Runtime/Language/TaggedInt.inl b/lib/Runtime/Language/TaggedInt.inl index 0e2ffc9ce40..ac24cd60818 100644 --- a/lib/Runtime/Language/TaggedInt.inl +++ b/lib/Runtime/Language/TaggedInt.inl @@ -309,7 +309,7 @@ LblDone: bool isTaggedNumber; #if FLOATVAR // If we add another tagged representation that is not numerical - this will not work. - isTaggedNumber = !RecyclableObject::Is(aValue); + isTaggedNumber = !VarIs(aValue); #else isTaggedNumber = TaggedInt::Is(aValue); #endif diff --git a/lib/Runtime/Language/ValueType.cpp b/lib/Runtime/Language/ValueType.cpp index 4e66e0bd40e..bfdee9e0029 100644 --- a/lib/Runtime/Language/ValueType.cpp +++ b/lib/Runtime/Language/ValueType.cpp @@ -808,7 +808,7 @@ ValueType ValueType::SetArrayTypeId(const Js::TypeId typeId) const { using namespace Js; Assert(IsLikelyArrayOrObjectWithArray()); - Assert(JavascriptArray::Is(typeId)); + Assert(JavascriptArray::IsNonES5Array(typeId)); Assert(typeId == TypeIds_Array || IsLikelyObject() && GetObjectType() == ObjectType::Array); // objects with native arrays are currently not supported Bits newBits = bits & ~(Bits::NonInts | Bits::NonFloats); @@ -1100,7 +1100,7 @@ ValueType ValueType::Merge(const Js::Var var) const ? GetInt(false) : ValueType::Float); } - return Merge(FromObject(RecyclableObject::UnsafeFromVar(var))); + return Merge(FromObject(UnsafeVarTo(var))); } ValueType::Bits ValueType::TypeIdToBits[Js::TypeIds_Limit]; @@ -1352,7 +1352,7 @@ ValueType ValueType::FromObject(Js::RecyclableObject *const recyclableObject) } Assert(DynamicType::Is(typeId)); // all static type IDs have nonzero values in TypeIdToBits - if(!JavascriptArray::Is(typeId)) + if(!JavascriptArray::IsNonES5Array(typeId)) { // TODO: Once the issue with loop bodies and uninitialized interpreter local slots is fixed, use FromVar DynamicObject *const object = static_cast(recyclableObject); @@ -1376,7 +1376,7 @@ ValueType ValueType::FromObjectWithArray(Js::DynamicObject *const object) Assert(objectArray); if(!VirtualTableInfo::HasVirtualTable(objectArray)) return GetObject(ObjectType::Object); - return FromObjectArray(JavascriptArray::FromVar(objectArray)); + return FromObjectArray(VarTo(objectArray)); } ValueType ValueType::FromObjectArray(Js::JavascriptArray *const objectArray) diff --git a/lib/Runtime/Language/WebAssemblySource.cpp b/lib/Runtime/Language/WebAssemblySource.cpp index 99c02f01513..7a4155f05c6 100644 --- a/lib/Runtime/Language/WebAssemblySource.cpp +++ b/lib/Runtime/Language/WebAssemblySource.cpp @@ -27,15 +27,15 @@ WebAssemblySource::WebAssemblySource(byte* source, uint bufferLength, bool creat void WebAssemblySource::ReadBufferSource(Var val, ScriptContext * scriptContext) { BYTE* srcBuffer; - if (Js::TypedArrayBase::Is(val)) + if (Js::VarIs(val)) { - Js::TypedArrayBase* array = Js::TypedArrayBase::FromVar(val); + Js::TypedArrayBase* array = Js::VarTo(val); srcBuffer = array->GetByteBuffer(); bufferLength = array->GetByteLength(); } - else if (Js::ArrayBuffer::Is(val)) + else if (Js::VarIs(val)) { - Js::ArrayBuffer* arrayBuffer = Js::ArrayBuffer::FromVar(val); + Js::ArrayBuffer* arrayBuffer = Js::VarTo(val); srcBuffer = arrayBuffer->GetBuffer(); bufferLength = arrayBuffer->GetByteLength(); } diff --git a/lib/Runtime/Language/i386/AsmJsJitTemplate.cpp b/lib/Runtime/Language/i386/AsmJsJitTemplate.cpp index 4ac03c64cc9..78128610434 100644 --- a/lib/Runtime/Language/i386/AsmJsJitTemplate.cpp +++ b/lib/Runtime/Language/i386/AsmJsJitTemplate.cpp @@ -546,16 +546,25 @@ namespace Js AsmJsSIMDValue* simdArg; // setup stack memory - AsmJsScriptFunction* asmJsFunc = AsmJsScriptFunction::FromVar(func); + AsmJsScriptFunction* asmJsFunc = VarTo(func); Var moduleEnv = asmJsFunc->GetModuleEnvironment(); JavascriptArrayBuffer* arrayBuffer = asmJsFunc->GetAsmJsArrayBuffer(); int arraySize = 0; BYTE* arrayPtr = nullptr; - if (JavascriptArrayBuffer::Is(arrayBuffer)) + + if (VarIsCorrectType(arrayBuffer)) { arrayPtr = arrayBuffer->GetBuffer(); arraySize = arrayBuffer->GetByteLength(); } + else + { + // Null should be the only way to fail VarIsCorrectType + // TODO: just check for null above + Assert(arrayBuffer == nullptr); + arrayBuffer = nullptr; + } + Var* m_localSlots; int* m_localIntSlots; double* m_localDoubleSlots; @@ -1349,7 +1358,7 @@ namespace Js X86TemplateData* templateData = GetTemplateData( context ); int size = 0; leftOffset -= templateData->GetBaseOffSet(); - if (!isSrc2Const) + if (!isSrc2Const) { rightOffset -= templateData->GetBaseOffSet(); } @@ -1375,11 +1384,11 @@ namespace Js size += CMP::EncodeInstruction( buffer, InstrParamsRegAddr( reg1, RegEBP, rightOffset ) ); break; case 2: - if (isSrc2Const) + if (isSrc2Const) { size += CMP::EncodeInstruction(buffer, InstrParamsAddrImm(RegEBP, leftOffset, rightOffset)); } - else + else { size += CMP::EncodeInstruction(buffer, InstrParamsRegAddr(reg2, RegEBP, leftOffset)); } diff --git a/lib/Runtime/Library/ArgumentsObject.cpp b/lib/Runtime/Library/ArgumentsObject.cpp index d8302b6f017..80477729b55 100644 --- a/lib/Runtime/Library/ArgumentsObject.cpp +++ b/lib/Runtime/Library/ArgumentsObject.cpp @@ -27,11 +27,6 @@ namespace Js return TRUE; } - bool ArgumentsObject::Is(Var aValue) - { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Arguments; - } - HeapArgumentsObject::HeapArgumentsObject(DynamicType * type) : ArgumentsObject(type), frameObject(nullptr), formalCount(0), numOfArguments(0), callerDeleted(false), deletedArgs(nullptr) { @@ -40,7 +35,7 @@ namespace Js HeapArgumentsObject::HeapArgumentsObject(Recycler *recycler, ActivationObject* obj, uint32 formalCount, DynamicType * type) : ArgumentsObject(type), frameObject(obj), formalCount(formalCount), numOfArguments(0), callerDeleted(false), deletedArgs(nullptr) { - Assert(!frameObject || ActivationObject::Is(frameObject)); + Assert(!frameObject || VarIsCorrectType(frameObject)); } void HeapArgumentsObject::SetNumberOfArguments(uint32 len) @@ -55,9 +50,9 @@ namespace Js HeapArgumentsObject* HeapArgumentsObject::As(Var aValue) { - if (ArgumentsObject::Is(aValue) && static_cast(RecyclableObject::FromVar(aValue))->GetHeapArguments() == aValue) + if (VarIs(aValue) && static_cast(VarTo(aValue))->GetHeapArguments() == aValue) { - return static_cast(RecyclableObject::FromVar(aValue)); + return static_cast(VarTo(aValue)); } return NULL; } diff --git a/lib/Runtime/Library/ArgumentsObject.h b/lib/Runtime/Library/ArgumentsObject.h index 09c0d53db51..0d7bfc94388 100644 --- a/lib/Runtime/Library/ArgumentsObject.h +++ b/lib/Runtime/Library/ArgumentsObject.h @@ -19,8 +19,6 @@ namespace Js Assert(type->GetTypeId() == TypeIds_Arguments); } - static bool Is(Var aValue); - virtual BOOL GetDiagValueString(StringBuilder* stringBuilder, ScriptContext* requestContext) override; virtual BOOL GetDiagTypeString(StringBuilder* stringBuilder, ScriptContext* requestContext) override; virtual BOOL GetEnumerator(JavascriptStaticEnumerator * enumerator, EnumeratorFlags flags, ScriptContext* requestContext, EnumeratorCache * enumeratorCache = nullptr) override; @@ -32,6 +30,11 @@ namespace Js virtual BOOL AdvanceWalkerToArgsFrame(JavascriptStackWalker *walker) = 0; }; + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_Arguments; + } + class ES5HeapArgumentsObject; // The arguments passed to a function are cached as follows: @@ -120,7 +123,7 @@ namespace Js void SetFrameObject(ActivationObject * value) { AssertMsg(frameObject == nullptr, "Setting the frame object again?"); - Assert(!value || ActivationObject::Is(value)); + Assert(!value || VarIsCorrectType(value)); frameObject = value; } diff --git a/lib/Runtime/Library/ArrayBuffer.cpp b/lib/Runtime/Library/ArrayBuffer.cpp index 0587ba01356..cffd7421ca4 100644 --- a/lib/Runtime/Library/ArrayBuffer.cpp +++ b/lib/Runtime/Library/ArrayBuffer.cpp @@ -6,21 +6,9 @@ namespace Js { - bool ArrayBufferBase::Is(Var value) + template <> bool VarIsImpl(RecyclableObject* obj) { - return ArrayBuffer::Is(value) || SharedArrayBuffer::Is(value); - } - - ArrayBufferBase* ArrayBufferBase::FromVar(Var value) - { - AssertOrFailFast(ArrayBufferBase::Is(value)); - return static_cast (value); - } - - ArrayBufferBase* ArrayBufferBase::UnsafeFromVar(Var value) - { - Assert(ArrayBufferBase::Is(value)); - return static_cast (value); + return VarIs(obj) || VarIs(obj); } ArrayBuffer* ArrayBuffer::NewFromDetachedState(DetachedStateBase* state, JavascriptLibrary *library) @@ -57,7 +45,7 @@ namespace Js switch (JavascriptOperators::GetTypeId(parent)) { case TypeIds_Int8Array: - if (Int8VirtualArray::Is(parent)) + if (VarIs(parent)) { if (VirtualTableInfo::HasVirtualTable(parent)) { @@ -69,11 +57,11 @@ namespace Js VirtualTableInfo>::SetVirtualTable(parent); } } - TypedArrayBase::UnsafeFromVar(parent)->ClearLengthAndBufferOnDetach(); + UnsafeVarTo(parent)->ClearLengthAndBufferOnDetach(); break; case TypeIds_Uint8Array: - if (Uint8VirtualArray::Is(parent)) + if (VarIs(parent)) { if (VirtualTableInfo::HasVirtualTable(parent)) { @@ -85,11 +73,11 @@ namespace Js VirtualTableInfo>::SetVirtualTable(parent); } } - TypedArrayBase::UnsafeFromVar(parent)->ClearLengthAndBufferOnDetach(); + UnsafeVarTo(parent)->ClearLengthAndBufferOnDetach(); break; case TypeIds_Uint8ClampedArray: - if (Uint8ClampedVirtualArray::Is(parent)) + if (VarIs(parent)) { if (VirtualTableInfo::HasVirtualTable(parent)) { @@ -101,11 +89,11 @@ namespace Js VirtualTableInfo>::SetVirtualTable(parent); } } - TypedArrayBase::UnsafeFromVar(parent)->ClearLengthAndBufferOnDetach(); + UnsafeVarTo(parent)->ClearLengthAndBufferOnDetach(); break; case TypeIds_Int16Array: - if (Int16VirtualArray::Is(parent)) + if (VarIs(parent)) { if (VirtualTableInfo::HasVirtualTable(parent)) { @@ -117,11 +105,11 @@ namespace Js VirtualTableInfo>::SetVirtualTable(parent); } } - TypedArrayBase::UnsafeFromVar(parent)->ClearLengthAndBufferOnDetach(); + UnsafeVarTo(parent)->ClearLengthAndBufferOnDetach(); break; case TypeIds_Uint16Array: - if (Uint16VirtualArray::Is(parent)) + if (VarIs(parent)) { if (VirtualTableInfo::HasVirtualTable(parent)) { @@ -133,11 +121,11 @@ namespace Js VirtualTableInfo>::SetVirtualTable(parent); } } - TypedArrayBase::UnsafeFromVar(parent)->ClearLengthAndBufferOnDetach(); + UnsafeVarTo(parent)->ClearLengthAndBufferOnDetach(); break; case TypeIds_Int32Array: - if (Int32VirtualArray::Is(parent)) + if (VarIs(parent)) { if (VirtualTableInfo::HasVirtualTable(parent)) { @@ -149,11 +137,11 @@ namespace Js VirtualTableInfo>::SetVirtualTable(parent); } } - TypedArrayBase::UnsafeFromVar(parent)->ClearLengthAndBufferOnDetach(); + UnsafeVarTo(parent)->ClearLengthAndBufferOnDetach(); break; case TypeIds_Uint32Array: - if (Uint32VirtualArray::Is(parent)) + if (VarIs(parent)) { if (VirtualTableInfo::HasVirtualTable(parent)) { @@ -165,11 +153,11 @@ namespace Js VirtualTableInfo>::SetVirtualTable(parent); } } - TypedArrayBase::UnsafeFromVar(parent)->ClearLengthAndBufferOnDetach(); + UnsafeVarTo(parent)->ClearLengthAndBufferOnDetach(); break; case TypeIds_Float32Array: - if (Float32VirtualArray::Is(parent)) + if (VarIs(parent)) { if (VirtualTableInfo::HasVirtualTable(parent)) { @@ -181,11 +169,11 @@ namespace Js VirtualTableInfo>::SetVirtualTable(parent); } } - TypedArrayBase::UnsafeFromVar(parent)->ClearLengthAndBufferOnDetach(); + UnsafeVarTo(parent)->ClearLengthAndBufferOnDetach(); break; case TypeIds_Float64Array: - if (Float64VirtualArray::Is(parent)) + if (VarIs(parent)) { if (VirtualTableInfo::HasVirtualTable(parent)) { @@ -197,18 +185,18 @@ namespace Js VirtualTableInfo>::SetVirtualTable(parent); } } - TypedArrayBase::UnsafeFromVar(parent)->ClearLengthAndBufferOnDetach(); + UnsafeVarTo(parent)->ClearLengthAndBufferOnDetach(); break; case TypeIds_Int64Array: case TypeIds_Uint64Array: case TypeIds_CharArray: case TypeIds_BoolArray: - TypedArrayBase::UnsafeFromVar(parent)->ClearLengthAndBufferOnDetach(); + UnsafeVarTo(parent)->ClearLengthAndBufferOnDetach(); break; case TypeIds_DataView: - DataView::FromVar(parent)->ClearLengthAndBufferOnDetach(); + VarTo(parent)->ClearLengthAndBufferOnDetach(); break; default: @@ -294,6 +282,12 @@ namespace Js } } + ArrayBuffer * ArrayBuffer::GetAsArrayBuffer() + { + AssertOrFailFast(VarIsCorrectType(this)); + return this; + } + uint32 ArrayBuffer::ToIndex(Var value, int32 errorCode, ScriptContext *scriptContext, uint32 MaxAllowedLength, bool checkSameValueZero) { if (JavascriptOperators::IsUndefined(value)) @@ -357,8 +351,8 @@ namespace Js } RecyclableObject* newArr = scriptContext->GetLibrary()->CreateArrayBuffer(byteLength); - Assert(ArrayBuffer::Is(newArr)); - if (byteLength > 0 && !ArrayBuffer::FromVar(newArr)->GetByteLength()) + Assert(VarIs(newArr)); + if (byteLength > 0 && !VarTo(newArr)->GetByteLength()) { JavascriptError::ThrowRangeError(scriptContext, JSERR_FunctionArgument_Invalid); } @@ -369,7 +363,7 @@ namespace Js } #endif return isCtorSuperCall ? - JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), newArr, nullptr, scriptContext) : + JavascriptOperators::OrdinaryCreateFromConstructor(VarTo(newTarget), newArr, nullptr, scriptContext) : newArr; } @@ -383,12 +377,12 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !ArrayBuffer::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedArrayBufferObject); } - ArrayBuffer* arrayBuffer = ArrayBuffer::FromVar(args[0]); + ArrayBuffer* arrayBuffer = VarTo(args[0]); if (arrayBuffer->IsDetached()) { return JavascriptNumber::ToVar(0, scriptContext); @@ -417,7 +411,7 @@ namespace Js } // Only DataView or any TypedArray objects have [[ViewedArrayBuffer]] internal slots - if (DataView::Is(arg) || TypedArrayBase::Is(arg)) + if (VarIs(arg) || VarIs(arg)) { return library->GetTrue(); } @@ -438,12 +432,12 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count < 2 || !ArrayBuffer::Is(args[1])) + if (args.Info.Count < 2 || !VarIs(args[1])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedArrayBufferObject); } - ArrayBuffer* arrayBuffer = ArrayBuffer::FromVar(args[1]); + ArrayBuffer* arrayBuffer = VarTo(args[1]); if (arrayBuffer->IsDetached()) { @@ -471,13 +465,13 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (!ArrayBuffer::Is(args[0])) + if (!VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedArrayBufferObject); } JavascriptLibrary* library = scriptContext->GetLibrary(); - ArrayBuffer* arrayBuffer = ArrayBuffer::FromVar(args[0]); + ArrayBuffer* arrayBuffer = VarTo(args[0]); if (arrayBuffer->IsDetached()) // 24.1.4.3: 5. If IsDetachedBuffer(O) is true, then throw a TypeError exception. { @@ -533,12 +527,12 @@ namespace Js return JavascriptOperators::NewScObject(constructor, Js::Arguments(constructorCallInfo, constructorArgs), scriptContext); }); - if (!ArrayBuffer::Is(newVar)) // 24.1.4.3: 19.If new does not have an [[ArrayBufferData]] internal slot throw a TypeError exception. + if (!VarIs(newVar)) // 24.1.4.3: 19.If new does not have an [[ArrayBufferData]] internal slot throw a TypeError exception. { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedArrayBufferObject); } - newBuffer = ArrayBuffer::FromVar(newVar); + newBuffer = VarTo(newVar); if (newBuffer->IsDetached()) // 24.1.4.3: 21. If IsDetachedBuffer(new) is true, then throw a TypeError exception. { @@ -588,25 +582,6 @@ namespace Js return args[0]; } - ArrayBuffer* ArrayBuffer::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "var must be an ArrayBuffer"); - - return static_cast(aValue); - } - - ArrayBuffer* ArrayBuffer::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "var must be an ArrayBuffer"); - - return static_cast(aValue); - } - - bool ArrayBuffer::Is(Var aValue) - { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_ArrayBuffer; - } - template ArrayBuffer::ArrayBuffer(uint32 length, DynamicType * type, Allocator allocator) : ArrayBufferBase(type) @@ -977,7 +952,7 @@ namespace Js return nullptr; } - // We are transferring the buffer to the new owner. + // We are transferring the buffer to the new owner. // To avoid double-charge to the allocation quota we will free the "diff" amount here. this->GetRecycler()->ReportExternalMemoryFree(growSize); @@ -1016,7 +991,7 @@ namespace Js return nullptr; } - // We are transferring the buffer to the new owner. + // We are transferring the buffer to the new owner. // To avoid double-charge to the allocation quota we will free the "diff" amount here. this->GetRecycler()->ReportExternalMemoryFree(growSize); diff --git a/lib/Runtime/Library/ArrayBuffer.h b/lib/Runtime/Library/ArrayBuffer.h index 8845d6d458b..d4c4cf206fa 100644 --- a/lib/Runtime/Library/ArrayBuffer.h +++ b/lib/Runtime/Library/ArrayBuffer.h @@ -93,15 +93,14 @@ namespace Js virtual BYTE* GetBuffer() const = 0; virtual bool IsValidVirtualBufferLength(uint length) const { return false; }; - static bool Is(Var value); - static ArrayBufferBase* FromVar(Var value); - static ArrayBufferBase* UnsafeFromVar(Var value); static int GetIsDetachedOffset() { return offsetof(ArrayBufferBase, isDetached); } protected: Field(bool) isDetached; }; + template <> bool VarIsImpl(RecyclableObject* obj); + class ArrayBuffer : public ArrayBufferBase { public: @@ -163,10 +162,7 @@ namespace Js static Var EntryDetach(RecyclableObject* function, CallInfo callInfo, ...); #endif - static bool Is(Var aValue); static ArrayBuffer* NewFromDetachedState(DetachedStateBase* state, JavascriptLibrary *library); - static ArrayBuffer* FromVar(Var aValue); - static ArrayBuffer* UnsafeFromVar(Var aValue); virtual BOOL GetDiagTypeString(StringBuilder* stringBuilder, ScriptContext* requestContext) override; virtual BOOL GetDiagValueString(StringBuilder* stringBuilder, ScriptContext* requestContext) override; @@ -191,7 +187,7 @@ namespace Js virtual bool IsValidAsmJsBufferLength(uint length, bool forceCheck = false) { return false; } virtual bool IsArrayBuffer() override { return true; } virtual bool IsSharedArrayBuffer() override { return false; } - virtual ArrayBuffer * GetAsArrayBuffer() override { return ArrayBuffer::FromVar(this); } + virtual ArrayBuffer * GetAsArrayBuffer() override; static uint32 ToIndex(Var value, int32 errorCode, ScriptContext *scriptContext, uint32 MaxAllowedLength, bool checkSameValueZero = true); @@ -220,6 +216,11 @@ namespace Js Field(uint32) bufferLength; // Number of bytes allocated }; + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_ArrayBuffer; + } + class ArrayBufferParent : public ArrayObject { friend ArrayBuffer; diff --git a/lib/Runtime/Library/AtomicsObject.cpp b/lib/Runtime/Library/AtomicsObject.cpp index 391a47fa080..e8f9d6060d1 100644 --- a/lib/Runtime/Library/AtomicsObject.cpp +++ b/lib/Runtime/Library/AtomicsObject.cpp @@ -19,7 +19,7 @@ namespace Js { Var AtomicsObject::ValidateSharedIntegerTypedArray(Var typedArray, ScriptContext *scriptContext, bool onlyInt32) { - if (!TypedArrayBase::Is(typedArray)) + if (!VarIs(typedArray)) { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedTypedArrayObject); } @@ -41,9 +41,9 @@ namespace Js } } - TypedArrayBase *typedArrayBase = TypedArrayBase::UnsafeFromVar(typedArray); + TypedArrayBase *typedArrayBase = UnsafeVarTo(typedArray); ArrayBufferBase* arrayBuffer = typedArrayBase->GetArrayBuffer(); - if (arrayBuffer == nullptr || !ArrayBufferBase::Is(arrayBuffer) || !arrayBuffer->IsSharedArrayBuffer()) + if (arrayBuffer == nullptr || !VarIsCorrectType(arrayBuffer) || !arrayBuffer->IsSharedArrayBuffer()) { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedSharedArrayBufferObject); } @@ -53,7 +53,7 @@ namespace Js uint32 AtomicsObject::ValidateAtomicAccess(Var typedArray, Var requestIndex, ScriptContext *scriptContext) { - Assert(TypedArrayBase::Is(typedArray)); + Assert(VarIs(typedArray)); int32 accessIndex = -1; if (TaggedInt::Is(requestIndex)) @@ -74,7 +74,7 @@ namespace Js } } - if (accessIndex < 0 || accessIndex >= (int32)TypedArrayBase::FromVar(typedArray)->GetLength()) + if (accessIndex < 0 || accessIndex >= (int32)VarTo(typedArray)->GetLength()) { JavascriptError::ThrowRangeError(scriptContext, JSERR_InvalidTypedArrayIndex); } @@ -91,7 +91,7 @@ namespace Js *accessIndex = i; } - return TypedArrayBase::FromVar(typedArray); + return VarTo(typedArray); } Var AtomicsObject::EntryAdd(RecyclableObject* function, CallInfo callInfo, ...) @@ -222,7 +222,7 @@ namespace Js Assert(sharedArrayBuffer->GetSharedContents()->IsValidAgent(agent)); #pragma prefast(suppress:__WARNING_CALLER_FAILING_TO_HOLD, "This is a prefast false-positive caused by it being unable to identify that the critical section used here is the same as the one held by the AutoCriticalSection") awoken = waiterList->AddAndSuspendWaiter(agent, timeout); - if (!awoken) + if (!awoken) { waiterList->RemoveWaiter(agent); } diff --git a/lib/Runtime/Library/BoundFunction.cpp b/lib/Runtime/Library/BoundFunction.cpp index 3a5ada7fb33..bc242a144be 100644 --- a/lib/Runtime/Library/BoundFunction.cpp +++ b/lib/Runtime/Library/BoundFunction.cpp @@ -28,7 +28,7 @@ namespace Js AssertMsg(args.Info.Count > 0, "wrong number of args in BoundFunction"); ScriptContext *scriptContext = this->GetScriptContext(); - targetFunction = RecyclableObject::FromVar(args[0]); + targetFunction = VarTo(args[0]); Assert(!CrossSite::NeedMarshalVar(targetFunction, scriptContext)); @@ -85,7 +85,7 @@ namespace Js // Reduce length number of bound args len = len - this->count; len = max(len, 0); - + SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(len), PropertyConfigurable, nullptr, PropertyOperation_None, SideEffects_None); } @@ -123,7 +123,7 @@ namespace Js // target has an overriden new target make a new object from the newTarget Var newTargetVar = args.GetNewTarget(); AssertOrFailFastMsg(JavascriptOperators::IsConstructor(newTargetVar), "newTarget must be a constructor"); - RecyclableObject* newTarget = RecyclableObject::UnsafeFromVar(newTargetVar); + RecyclableObject* newTarget = UnsafeVarTo(newTargetVar); // Class constructors expect newTarget to be in args slot 0 (usually "this"), // because "this" is not constructed until we reach the most-super superclass. @@ -137,7 +137,7 @@ namespace Js args.Values[0] = newVarInstance = JavascriptOperators::CreateFromConstructor(newTarget, scriptContext); } } - else if (!JavascriptProxy::Is(targetFunction)) + else if (!VarIs(targetFunction)) { // No new target and target is not a proxy can make a new object in a "normal" way. // NewScObjectNoCtor will either construct an object or return targetFunction depending @@ -222,7 +222,7 @@ namespace Js aReturnValue = JavascriptFunction::CallFunction(targetFunction, targetFunction->GetEntryPoint(), actualArgs, /* useLargeArgCount */ true); } END_SAFE_REENTRANT_CALL - + // // [[Construct]] and call returned a non-object // return the newly created var instance @@ -240,14 +240,14 @@ namespace Js if (targetFunction != nullptr) { RecyclableObject* _targetFunction = targetFunction; - while (JavascriptProxy::Is(_targetFunction)) + while (VarIs(_targetFunction)) { - _targetFunction = JavascriptProxy::FromVar(_targetFunction)->GetTarget(); + _targetFunction = VarTo(_targetFunction)->GetTarget(); } - if (JavascriptFunction::Is(_targetFunction)) + if (VarIs(_targetFunction)) { - return JavascriptFunction::FromVar(_targetFunction); + return VarTo(_targetFunction); } // targetFunction should always be a JavascriptFunction. @@ -262,9 +262,9 @@ namespace Js if (targetFunction != nullptr) { Var value = JavascriptOperators::GetPropertyNoCache(targetFunction, PropertyIds::name, targetFunction->GetScriptContext()); - if (JavascriptString::Is(value)) + if (VarIs(value)) { - displayName = JavascriptString::FromVar(value); + displayName = VarTo(value); } } return JavascriptString::Concat(GetLibrary()->GetBoundFunctionPrefixString(), displayName); @@ -272,9 +272,9 @@ namespace Js RecyclableObject* BoundFunction::GetBoundThis() { - if (boundThis != nullptr && RecyclableObject::Is(boundThis)) + if (boundThis != nullptr && VarIs(boundThis)) { - return RecyclableObject::FromVar(boundThis); + return VarTo(boundThis); } return NULL; } diff --git a/lib/Runtime/Library/BoundFunction.h b/lib/Runtime/Library/BoundFunction.h index dae83d87a10..4dbbd1ca254 100644 --- a/lib/Runtime/Library/BoundFunction.h +++ b/lib/Runtime/Library/BoundFunction.h @@ -23,7 +23,6 @@ namespace Js public: static BoundFunction* New(ScriptContext* scriptContext, ArgumentReader args); - static bool Is(Var func){ return JavascriptFunction::Is(func) && JavascriptFunction::UnsafeFromVar(func)->IsBoundFunction(); } static Var NewInstance(RecyclableObject* function, CallInfo callInfo, ...); virtual JavascriptString* GetDisplayNameImpl() const override; virtual PropertyQueryFlags GetPropertyReferenceQuery(Var originalInstance, PropertyId propertyId, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) override; @@ -63,4 +62,9 @@ namespace Js Field(uint) count; Field(Field(Var)*) boundArgs; }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return VarIs(obj) && UnsafeVarTo(obj)->IsBoundFunction(); + } } // namespace Js diff --git a/lib/Runtime/Library/Chakra.Runtime.Library.vcxproj b/lib/Runtime/Library/Chakra.Runtime.Library.vcxproj index 2ad8484e353..2a1115cf8a8 100644 --- a/lib/Runtime/Library/Chakra.Runtime.Library.vcxproj +++ b/lib/Runtime/Library/Chakra.Runtime.Library.vcxproj @@ -307,7 +307,6 @@ - diff --git a/lib/Runtime/Library/Chakra.Runtime.Library.vcxproj.filters b/lib/Runtime/Library/Chakra.Runtime.Library.vcxproj.filters index 40decfc9e0e..447d46e61fd 100644 --- a/lib/Runtime/Library/Chakra.Runtime.Library.vcxproj.filters +++ b/lib/Runtime/Library/Chakra.Runtime.Library.vcxproj.filters @@ -236,7 +236,6 @@ - amd64 @@ -286,4 +285,4 @@ - + diff --git a/lib/Runtime/Library/CompoundString.cpp b/lib/Runtime/Library/CompoundString.cpp index 58b0be17a51..0816fac9578 100644 --- a/lib/Runtime/Library/CompoundString.cpp +++ b/lib/Runtime/Library/CompoundString.cpp @@ -383,7 +383,7 @@ using namespace Js; { AllocateBuffer(charCapacity, recycler); charLength = usedCharLength; - + ArrayWriteBarrierVerifyBits(Block::Pointers(Chars()), Block::PointerLengthFromCharLength(charCapacity)); js_wmemcpy_s(Chars(), charCapacity, (const char16*)(buffer), usedCharLength); // SWB: buffer may contain chars or pointers. Trigger write barrier for the whole buffer. @@ -584,7 +584,7 @@ using namespace Js; CompoundString * CompoundString::JitClone(CompoundString * cs) { JIT_HELPER_NOT_REENTRANT_NOLOCK_HEADER(Op_CompoundStringCloneForConcat); - Assert(Is(cs)); + Assert(VarIsCorrectType(cs)); return cs->Clone(false); JIT_HELPER_END(Op_CompoundStringCloneForConcat); } @@ -592,47 +592,22 @@ using namespace Js; CompoundString * CompoundString::JitCloneForAppending(CompoundString * cs) { JIT_HELPER_NOT_REENTRANT_NOLOCK_HEADER(Op_CompoundStringCloneForAppending); - Assert(Is(cs)); + Assert(VarIsCorrectType(cs)); return cs->Clone(true); JIT_HELPER_END(Op_CompoundStringCloneForAppending); } - bool CompoundString::Is(RecyclableObject *const object) - { - return VirtualTableInfo::HasVirtualTable(object); - } - - bool CompoundString::Is(const Var var) - { - return RecyclableObject::Is(var) && Is(RecyclableObject::FromVar(var)); - } - - CompoundString *CompoundString::FromVar(RecyclableObject *const object) - { - AssertOrFailFast(Is(object)); - - CompoundString *const cs = static_cast(object); - Assert(!cs->IsFinalized()); - return cs; - } - - CompoundString *CompoundString::UnsafeFromVar(RecyclableObject *const object) - { - Assert(Is(object)); - - CompoundString *const cs = static_cast(object); - Assert(!cs->IsFinalized()); - return cs; - } - - CompoundString *CompoundString::FromVar(const Var var) + template <> bool Js::VarIsImpl(RecyclableObject * object) { - return FromVar(RecyclableObject::FromVar(var)); - } - - CompoundString *CompoundString::UnsafeFromVar(const Var var) - { - return UnsafeFromVar(RecyclableObject::UnsafeFromVar(var)); + bool result = VirtualTableInfo::HasVirtualTable(object); +#if DBG + if (result) + { + CompoundString *const cs = static_cast(object); + Assert(!cs->IsFinalized()); + } +#endif + return result; } JavascriptString *CompoundString::GetImmutableOrScriptUnreferencedString(JavascriptString *const s) @@ -644,7 +619,7 @@ using namespace Js; // another CompoundString, for instance). If the provided string is a CompoundString, it must not be mutated by script // code after the concatenation operation. In that case, clone the string to ensure that it is not referenced by script // code. If the clone is never handed back to script code, it effectively behaves as an immutable string. - return Is(s) ? UnsafeFromVar(s)->Clone(false) : s; + return VarIs(s) ? UnsafeVarTo(s)->Clone(false) : s; } bool CompoundString::ShouldAppendChars(const CharCount appendCharLength) @@ -681,7 +656,7 @@ using namespace Js; // A compound string cannot flatten itself while appending itself to itself since flattening would make the append // illegal. Clone the string being appended if necessary, before flattening. - return s == this ? FromVar(s)->Clone(false)->GetSz() : s->GetString(); + return s == this ? VarTo(s)->Clone(false)->GetSz() : s->GetString(); } char16 *CompoundString::LastBlockChars() const @@ -1124,12 +1099,12 @@ using namespace Js; if(IsPackedInfo(pointer2)) { Assert(pointerIndex != 0); - s = JavascriptString::FromVar(blockPointers[--pointerIndex]); + s = VarTo(blockPointers[--pointerIndex]); } else #endif { - s = JavascriptString::FromVar(pointer2); + s = VarTo(pointer2); pointer2 = nullptr; } @@ -1144,7 +1119,7 @@ using namespace Js; } else { - JavascriptString *const s = JavascriptString::FromVar(pointer); + JavascriptString *const s = VarTo(pointer); const CharCount copyCharLength = s->GetLength(); Assert(remainingCharLengthToCopy >= copyCharLength); diff --git a/lib/Runtime/Library/CompoundString.h b/lib/Runtime/Library/CompoundString.h index bd89ab041aa..a38c663a10b 100644 --- a/lib/Runtime/Library/CompoundString.h +++ b/lib/Runtime/Library/CompoundString.h @@ -338,12 +338,6 @@ namespace Js static CompoundString * JitClone(CompoundString * cs); static CompoundString * JitCloneForAppending(CompoundString * cs); public: - static bool Is(RecyclableObject *const object); - static bool Is(const Var var); - static CompoundString *FromVar(RecyclableObject *const object); - static CompoundString *UnsafeFromVar(RecyclableObject *const object); - static CompoundString *FromVar(const Var var); - static CompoundString *UnsafeFromVar(const Var var); static size_t GetOffsetOfOwnsLastBlock() { return offsetof(CompoundString, ownsLastBlock); } static size_t GetOffsetOfDirectCharLength() { return offsetof(CompoundString, directCharLength); } static size_t GetOffsetOfLastBlockInfo() { return offsetof(CompoundString, lastBlockInfo); } @@ -444,6 +438,8 @@ namespace Js } }; + template <> bool VarIsImpl(RecyclableObject * object); + #pragma region CompoundString::Builder definition #ifndef CompoundStringJsDiag //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/lib/Runtime/Library/ConcatString.cpp b/lib/Runtime/Library/ConcatString.cpp index 7f4ef3f225b..a24d8147260 100644 --- a/lib/Runtime/Library/ConcatString.cpp +++ b/lib/Runtime/Library/ConcatString.cpp @@ -152,18 +152,11 @@ namespace Js } } - /* static */ - bool LiteralStringWithPropertyStringPtr::Is(RecyclableObject * obj) + template <> bool VarIsImpl(RecyclableObject * obj) { return VirtualTableInfo::HasVirtualTable(obj); } - /* static */ - bool LiteralStringWithPropertyStringPtr::Is(Var var) - { - return RecyclableObject::Is(var) && LiteralStringWithPropertyStringPtr::Is(RecyclableObject::UnsafeFromVar(var)); - } - void LiteralStringWithPropertyStringPtr::GetPropertyRecord(_Out_ PropertyRecord const** propRecord, bool dontLookupFromDictionary) { return GetPropertyRecordImpl(propRecord, dontLookupFromDictionary); @@ -538,24 +531,9 @@ namespace Js scriptContext->GetLibrary()->GetStringTypeStatic()); } - bool - ConcatStringMulti::Is(Var var) - { - return VirtualTableInfo::HasVirtualTable(var); - } - - ConcatStringMulti * - ConcatStringMulti::FromVar(Var var) - { - AssertOrFailFast(ConcatStringMulti::Is(var)); - return static_cast(var); - } - - ConcatStringMulti * - ConcatStringMulti::UnsafeFromVar(Var var) + template <> bool VarIsImpl(RecyclableObject* obj) { - Assert(ConcatStringMulti::Is(var)); - return static_cast(var); + return VirtualTableInfo::HasVirtualTable(obj); } const char16 * diff --git a/lib/Runtime/Library/ConcatString.h b/lib/Runtime/Library/ConcatString.h index 950b591b4f9..e9b0db1a58a 100644 --- a/lib/Runtime/Library/ConcatString.h +++ b/lib/Runtime/Library/ConcatString.h @@ -35,9 +35,6 @@ namespace Js template static LiteralStringWithPropertyStringPtr * ConvertString(StringType * originalString); static uint GetOffsetOfPropertyString() { return offsetof(LiteralStringWithPropertyStringPtr, propertyString); } - static bool Is(Var var); - static bool Is(RecyclableObject* var); - template static LiteralStringWithPropertyStringPtr* TryFromVar(T var); static JavascriptString * NewFromCString(const char * cString, const CharCount charCount, JavascriptLibrary *const library); @@ -60,17 +57,7 @@ namespace Js } }; - // Templated so that the Is call dispatchs to different function depending - // on if argument is already a RecyclableObject* or only known to be a Var - // - // In case it is known to be a RecyclableObject*, the Is call skips that check - template - inline LiteralStringWithPropertyStringPtr * LiteralStringWithPropertyStringPtr::TryFromVar(T var) - { - return LiteralStringWithPropertyStringPtr::Is(var) - ? reinterpret_cast(var) - : nullptr; - } + template <> bool VarIsImpl(RecyclableObject * obj); // Base class for concat strings. // Concat string is a virtual string, or a non-leaf node in concat string tree. @@ -279,9 +266,6 @@ namespace Js public: static ConcatStringMulti * New(uint slotCount, JavascriptString * a1, JavascriptString * a2, ScriptContext* scriptContext); const char16 * GetSz() override sealed; - static bool Is(Var var); - static ConcatStringMulti * FromVar(Var value); - static ConcatStringMulti * UnsafeFromVar(Var value); static size_t GetAllocSize(uint slotCount); void SetItem(_In_range_(0, slotCount - 1) uint index, JavascriptString* value); @@ -304,4 +288,6 @@ namespace Js return VTableValue::VtableConcatStringMulti; } }; + + template <> bool VarIsImpl(RecyclableObject* obj); } diff --git a/lib/Runtime/Library/CustomExternalIterator.cpp b/lib/Runtime/Library/CustomExternalIterator.cpp index 2bfc8053629..a5255271c4f 100644 --- a/lib/Runtime/Library/CustomExternalIterator.cpp +++ b/lib/Runtime/Library/CustomExternalIterator.cpp @@ -19,7 +19,7 @@ namespace Js void ExternalIteratorCreatorFunction::ThrowIfNotValidObject(Var instance) { JavascriptTypeId typeId = (JavascriptTypeId)Js::JavascriptOperators::GetTypeId(instance); - if (typeId != m_externalTypeId || !RecyclableObject::Is(m_prototypeForIterator)) + if (typeId != m_externalTypeId || !VarIs(m_prototypeForIterator)) { JavascriptError::ThrowTypeError(GetScriptContext(), JSERR_InvalidIterableObject); } @@ -52,7 +52,7 @@ namespace Js function->ThrowIfNotValidObject(instance); ScriptContext *scriptContext = function->GetScriptContext(); - AssertOrFailFast(RecyclableObject::Is(function->m_prototypeForIterator)); + AssertOrFailFast(VarIs(function->m_prototypeForIterator)); DynamicObject *prototype = static_cast(PointerValue(function->m_prototypeForIterator)); Js::DynamicType *type = scriptContext->GetLibrary()->CreateObjectTypeNoCache(prototype, TypeIds_ExternalIterator); @@ -140,22 +140,9 @@ namespace Js Assert(type->GetTypeId() == TypeIds_ExternalIterator); } - bool CustomExternalIterator::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - TypeId typeId = JavascriptOperators::GetTypeId(aValue); - return typeId == TypeIds_ExternalIterator; - } - - CustomExternalIterator* CustomExternalIterator::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'ExternalIterator'"); - return static_cast(aValue); - } - - CustomExternalIterator* CustomExternalIterator::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'ExternalIterator'"); - return static_cast(aValue); + return JavascriptOperators::GetTypeId(obj) == TypeIds_ExternalIterator; } Var CustomExternalIterator::CreateNextFunction(JavascriptLibrary *library, JavascriptTypeId typeId) @@ -177,12 +164,12 @@ namespace Js Var thisObj = args[0]; - if (!CustomExternalIterator::Is(thisObj)) + if (!VarIs(thisObj)) { JavascriptError::ThrowTypeError(scriptContext, JSERR_InvalidIteratorObject, _u("Iterator.prototype.next")); } - CustomExternalIterator * currentIterator = CustomExternalIterator::FromVar(thisObj); + CustomExternalIterator * currentIterator = VarTo(thisObj); if (iteratorNextFunction->GetExternalTypeId() != currentIterator->m_externalTypeId) { JavascriptError::ThrowTypeError(scriptContext, JSERR_InvalidIteratorObject, _u("Iterator.prototype.next")); diff --git a/lib/Runtime/Library/CustomExternalIterator.h b/lib/Runtime/Library/CustomExternalIterator.h index 8f1deb7715d..5084d20c8c0 100644 --- a/lib/Runtime/Library/CustomExternalIterator.h +++ b/lib/Runtime/Library/CustomExternalIterator.h @@ -104,11 +104,10 @@ namespace Js public: CustomExternalIterator(DynamicType* type, ExternalIteratorKind kind, JavascriptTypeId typeId, NextFunction nextFunction); - static bool Is(Var aValue); - static CustomExternalIterator* FromVar(Var aValue); - static CustomExternalIterator* UnsafeFromVar(Var aValue); static Var CreateNextFunction(JavascriptLibrary *library, JavascriptTypeId typeId); static Var EntryNext(RecyclableObject* function, CallInfo callInfo, ...); }; + template <> bool VarIsImpl(RecyclableObject* obj); + } diff --git a/lib/Runtime/Library/DataView.cpp b/lib/Runtime/Library/DataView.cpp index 0e9828cfca3..b33703786fd 100644 --- a/lib/Runtime/Library/DataView.cpp +++ b/lib/Runtime/Library/DataView.cpp @@ -62,9 +62,9 @@ namespace Js //3. If buffer does not have an [[ArrayBufferData]] internal slot, throw a TypeError exception. if (arrayBuffer == nullptr) { - if (ArrayBufferBase::Is(args[1])) + if (VarIs(args[1])) { - arrayBuffer = ArrayBufferBase::FromVar(args[1]); + arrayBuffer = VarTo(args[1]); } else { @@ -130,7 +130,7 @@ namespace Js //15. Return O. dataView = scriptContext->GetLibrary()->CreateDataView(arrayBuffer, offset, mappedLength); return isCtorSuperCall ? - JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), dataView, nullptr, scriptContext) : + JavascriptOperators::OrdinaryCreateFromConstructor(VarTo(newTarget), dataView, nullptr, scriptContext) : dataView; } @@ -141,11 +141,6 @@ namespace Js buffer = arrayBuffer->GetBuffer() + byteoffset; } - BOOL DataView::Is(Var aValue) - { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_DataView; - } - Var DataView::EntryGetInt8(RecyclableObject* function, CallInfo callInfo, ...) { PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault); @@ -155,7 +150,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !DataView::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDataView); } @@ -164,7 +159,7 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_DataView_NeedArgument, _u("offset")); } - DataView* dataView = DataView::FromVar(args[0]); + DataView* dataView = VarTo(args[0]); return dataView->template GetValue(args[1], _u("DataView.prototype.GetInt8"), FALSE); } @@ -177,7 +172,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !DataView::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDataView); } @@ -186,7 +181,7 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_DataView_NeedArgument, _u("offset")); } - DataView* dataView = DataView::FromVar(args[0]); + DataView* dataView = VarTo(args[0]); return dataView->GetValue(args[1], _u("DataView.prototype.GetUint8"), FALSE); } @@ -200,7 +195,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !DataView::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDataView); } @@ -213,7 +208,7 @@ namespace Js isLittleEndian = JavascriptConversion::ToBoolean(args[2], scriptContext); } - DataView* dataView = DataView::FromVar(args[0]); + DataView* dataView = VarTo(args[0]); return dataView->GetValue(args[1], _u("DataView.prototype.GetInt16"), isLittleEndian); } @@ -227,7 +222,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !DataView::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDataView); } @@ -240,7 +235,7 @@ namespace Js isLittleEndian = JavascriptConversion::ToBoolean(args[2], scriptContext); } - DataView* dataView = DataView::FromVar(args[0]); + DataView* dataView = VarTo(args[0]); return dataView->template GetValue(args[1], _u("DataView.prototype.GetUint16"), isLittleEndian); } @@ -254,7 +249,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !DataView::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDataView); } @@ -267,7 +262,7 @@ namespace Js isLittleEndian = JavascriptConversion::ToBoolean(args[2], scriptContext); } - DataView* dataView = DataView::FromVar(args[0]); + DataView* dataView = VarTo(args[0]); return dataView->GetValue(args[1], _u("DataView.prototype.GetUint32"), isLittleEndian); } @@ -281,7 +276,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !DataView::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDataView); } @@ -294,7 +289,7 @@ namespace Js isLittleEndian = JavascriptConversion::ToBoolean(args[2], scriptContext); } - DataView* dataView = DataView::FromVar(args[0]); + DataView* dataView = VarTo(args[0]); return dataView->GetValue(args[1], _u("DataView.prototype.GetInt32"), isLittleEndian); } @@ -308,7 +303,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !DataView::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDataView); } @@ -321,7 +316,7 @@ namespace Js isLittleEndian = JavascriptConversion::ToBoolean(args[2], scriptContext); } - DataView* dataView = DataView::FromVar(args[0]); + DataView* dataView = VarTo(args[0]); return dataView->GetValueWithCheck(args[1], _u("DataView.prototype.GetFloat32"), isLittleEndian); } @@ -335,7 +330,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !DataView::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDataView); } @@ -348,7 +343,7 @@ namespace Js isLittleEndian = JavascriptConversion::ToBoolean(args[2], scriptContext); } - DataView* dataView = DataView::FromVar(args[0]); + DataView* dataView = VarTo(args[0]); return dataView->GetValueWithCheck(args[1], _u("DataView.prototype.GetFloat64"), isLittleEndian); } @@ -361,7 +356,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !DataView::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDataView); } @@ -369,7 +364,7 @@ namespace Js { JavascriptError::ThrowTypeError(scriptContext, JSERR_DataView_NeedArgument, _u("offset or value")); } - DataView* dataView = DataView::FromVar(args[0]); + DataView* dataView = VarTo(args[0]); int8 value = JavascriptConversion::ToInt8(args[2], scriptContext); dataView->SetValue(args[1], value, _u("DataView.prototype.SetInt8")); return scriptContext->GetLibrary()->GetUndefined(); @@ -384,7 +379,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !DataView::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDataView); } @@ -392,7 +387,7 @@ namespace Js { JavascriptError::ThrowTypeError(scriptContext, JSERR_DataView_NeedArgument, _u("offset or value")); } - DataView* dataView = DataView::FromVar(args[0]); + DataView* dataView = VarTo(args[0]); uint8 value = JavascriptConversion::ToUInt8(args[2], scriptContext); dataView->SetValue(args[1], value, _u("DataView.prototype.SetUint8")); return scriptContext->GetLibrary()->GetUndefined(); @@ -408,7 +403,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !DataView::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDataView); } @@ -416,7 +411,7 @@ namespace Js { JavascriptError::ThrowTypeError(scriptContext, JSERR_DataView_NeedArgument, _u("offset or value")); } - DataView* dataView = DataView::FromVar(args[0]); + DataView* dataView = VarTo(args[0]); int16 value = JavascriptConversion::ToInt16(args[2], scriptContext); if (args.Info.Count > 3) { @@ -436,7 +431,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !DataView::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDataView); } @@ -444,7 +439,7 @@ namespace Js { JavascriptError::ThrowTypeError(scriptContext, JSERR_DataView_NeedArgument, _u("offset or value")); } - DataView* dataView = DataView::FromVar(args[0]); + DataView* dataView = VarTo(args[0]); uint16 value = JavascriptConversion::ToUInt16(args[2], scriptContext); if (args.Info.Count > 3) { @@ -464,7 +459,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !DataView::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDataView); } @@ -472,7 +467,7 @@ namespace Js { JavascriptError::ThrowTypeError(scriptContext, JSERR_DataView_NeedArgument, _u("offset or value")); } - DataView* dataView = DataView::FromVar(args[0]); + DataView* dataView = VarTo(args[0]); int32 value = JavascriptConversion::ToInt32(args[2], scriptContext); if (args.Info.Count > 3) { @@ -492,7 +487,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !DataView::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDataView); } @@ -500,7 +495,7 @@ namespace Js { JavascriptError::ThrowTypeError(scriptContext, JSERR_DataView_NeedArgument, _u("offset or value")); } - DataView* dataView = DataView::FromVar(args[0]); + DataView* dataView = VarTo(args[0]); uint32 value = JavascriptConversion::ToUInt32(args[2], scriptContext); if (args.Info.Count > 3) { @@ -520,7 +515,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !DataView::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDataView, _u("offset or value")); } @@ -528,7 +523,7 @@ namespace Js { JavascriptError::ThrowTypeError(scriptContext, JSERR_DataView_NeedArgument); } - DataView* dataView = DataView::FromVar(args[0]); + DataView* dataView = VarTo(args[0]); float value = JavascriptConversion::ToFloat(args[2], scriptContext); if (args.Info.Count > 3) { @@ -548,7 +543,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !DataView::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDataView); } @@ -556,7 +551,7 @@ namespace Js { JavascriptError::ThrowTypeError(scriptContext, JSERR_DataView_NeedArgument, _u("offset or value")); } - DataView* dataView = DataView::FromVar(args[0]); + DataView* dataView = VarTo(args[0]); double value = JavascriptConversion::ToNumber(args[2], scriptContext); if (args.Info.Count > 3) { @@ -575,12 +570,12 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !DataView::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDataView); } - DataView* dataView = DataView::FromVar(args[0]); + DataView* dataView = VarTo(args[0]); ArrayBufferBase* arrayBuffer = dataView->GetArrayBuffer(); if (arrayBuffer == nullptr) @@ -599,12 +594,12 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !DataView::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDataView); } - DataView* dataView = DataView::FromVar(args[0]); + DataView* dataView = VarTo(args[0]); ArrayBufferBase* arrayBuffer = dataView->GetArrayBuffer(); if (arrayBuffer == nullptr) @@ -628,12 +623,12 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !DataView::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDataView); } - DataView* dataView = DataView::FromVar(args[0]); + DataView* dataView = VarTo(args[0]); ArrayBufferBase* arrayBuffer = dataView->GetArrayBuffer(); if (arrayBuffer == nullptr) diff --git a/lib/Runtime/Library/DataView.h b/lib/Runtime/Library/DataView.h index 330c1813c14..bcec94c788d 100644 --- a/lib/Runtime/Library/DataView.h +++ b/lib/Runtime/Library/DataView.h @@ -41,20 +41,6 @@ namespace Js DataView(ArrayBufferBase* arrayBuffer, uint32 byteOffset, uint32 mappedLength, DynamicType* type); - static BOOL Is(Var aValue); - - static inline DataView* FromVar(Var aValue) - { - AssertOrFailFast(DataView::Is(aValue)); - return static_cast(aValue); - } - - static inline DataView* UnsafeFromVar(Var aValue) - { - Assert(DataView::Is(aValue)); - return static_cast(aValue); - } - uint32 GetByteOffset() const { return byteOffset; } void ClearLengthAndBufferOnDetach(); @@ -216,4 +202,9 @@ namespace Js Field(BYTE*) buffer; // beginning of buffer }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_DataView; + } } diff --git a/lib/Runtime/Library/ES5Array.cpp b/lib/Runtime/Library/ES5Array.cpp index 67351df1b84..267b41efdf9 100644 --- a/lib/Runtime/Library/ES5Array.cpp +++ b/lib/Runtime/Library/ES5Array.cpp @@ -13,23 +13,6 @@ namespace Js { } - bool ES5Array::Is(Var instance) - { - return JavascriptOperators::GetTypeId(instance) == TypeIds_ES5Array; - } - - ES5Array* ES5Array::FromVar(Var instance) - { - AssertOrFailFast(Is(instance)); - return static_cast(instance); - } - - ES5Array* ES5Array::UnsafeFromVar(Var instance) - { - Assert(Is(instance)); - return static_cast(instance); - } - DynamicType* ES5Array::DuplicateType() { return RecyclerNew(GetScriptContext()->GetRecycler(), ES5ArrayType, this->GetDynamicType()); diff --git a/lib/Runtime/Library/ES5Array.h b/lib/Runtime/Library/ES5Array.h index 9cf92234808..7f5baf39ed2 100644 --- a/lib/Runtime/Library/ES5Array.h +++ b/lib/Runtime/Library/ES5Array.h @@ -39,9 +39,6 @@ namespace Js bool GetSetterBuiltIns(PropertyId propertyId, PropertyValueInfo* info, DescriptorFlags* result); public: - static bool Is(Var instance); - static ES5Array* FromVar(Var instance); - static ES5Array* UnsafeFromVar(Var instance); static uint32 ToLengthValue(Var value, ScriptContext* scriptContext); bool IsLengthWritable() const; @@ -104,5 +101,10 @@ namespace Js virtual void ExtractSnapObjectDataInto(TTD::NSSnapObjects::SnapObject* objData, TTD::SlabAllocator& alloc) override; #endif }; + + template <> inline bool VarIsImpl(RecyclableObject* instance) + { + return JavascriptOperators::GetTypeId(instance) == TypeIds_ES5Array; + } } AUTO_REGISTER_RECYCLER_OBJECT_DUMPER(Js::ES5Array, &Js::RecyclableObject::DumpObjectFunction); diff --git a/lib/Runtime/Library/ES5ArrayIndexEnumerator.h b/lib/Runtime/Library/ES5ArrayIndexEnumerator.h index 138c9a76c29..1d0e2f39b8c 100644 --- a/lib/Runtime/Library/ES5ArrayIndexEnumerator.h +++ b/lib/Runtime/Library/ES5ArrayIndexEnumerator.h @@ -18,7 +18,7 @@ namespace Js DEFINE_VTABLE_CTOR(ES5ArrayIndexEnumerator, JavascriptArrayIndexEnumeratorBase); private: - ES5Array* GetArray() const { return ES5Array::FromVar(arrayObject); } + ES5Array* GetArray() const { return VarTo(arrayObject); } public: ES5ArrayIndexEnumerator(ES5Array* arrayObject, EnumeratorFlags flags, ScriptContext* scriptContext); diff --git a/lib/Runtime/Library/EngineInterfaceObject.cpp b/lib/Runtime/Library/EngineInterfaceObject.cpp index 220ff3b701f..3e493a58478 100644 --- a/lib/Runtime/Library/EngineInterfaceObject.cpp +++ b/lib/Runtime/Library/EngineInterfaceObject.cpp @@ -61,7 +61,7 @@ GetPropertyFrom(obj, Js::PropertyIds::builtInPropID) \ #define GetTypedPropertyBuiltInFrom(obj, builtInPropID, Type) \ - (GetPropertyFrom(obj, Js::PropertyIds::builtInPropID) && Type::Is(propertyValue)) \ + (GetPropertyFrom(obj, Js::PropertyIds::builtInPropID) && VarIs(propertyValue)) \ #define HasPropertyOn(obj, propID) \ Js::JavascriptOperators::HasProperty(obj, propID) \ @@ -116,24 +116,6 @@ namespace Js return newObject; } - bool EngineInterfaceObject::Is(Var aValue) - { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_EngineInterfaceObject; - } - - EngineInterfaceObject* EngineInterfaceObject::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "aValue is actually an EngineInterfaceObject"); - - return static_cast(aValue); - } - - EngineInterfaceObject* EngineInterfaceObject::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "aValue is actually an EngineInterfaceObject"); - - return static_cast(aValue); - } void EngineInterfaceObject::Initialize() { Recycler* recycler = this->GetRecycler(); @@ -253,12 +235,12 @@ namespace Js EngineInterfaceObject_CommonFunctionProlog(function, callInfo); #if DBG - if (callInfo.Count < 2 || !JavascriptString::Is(args.Values[1])) + if (callInfo.Count < 2 || !VarIs(args.Values[1])) { return scriptContext->GetLibrary()->GetUndefined(); } - JavascriptString* message = JavascriptString::FromVar(args.Values[1]); + JavascriptString* message = VarTo(args.Values[1]); Output::Print(message->GetString()); Output::Flush(); @@ -324,7 +306,7 @@ namespace Js Var existingName = nullptr; if (JavascriptOperators::GetOwnProperty(scriptFunction, PropertyIds::name, &existingName, scriptContext, nullptr)) { - JavascriptString *existingNameString = JavascriptString::FromVar(existingName); + JavascriptString *existingNameString = VarTo(existingName); if (existingNameString->GetLength() == 0) { // Only overwrite the name of the function object if it was anonymous coming in @@ -372,16 +354,16 @@ namespace Js EngineInterfaceObject_CommonFunctionProlog(function, callInfo); #pragma warning(pop) - AssertOrFailFast((args.Info.Count == 3 || args.Info.Count == 4) && ScriptFunction::Is(args.Values[1]) && JavascriptString::Is(args.Values[2])); + AssertOrFailFast((args.Info.Count == 3 || args.Info.Count == 4) && VarIs(args.Values[1]) && VarIs(args.Values[2])); - ScriptFunction *func = ScriptFunction::UnsafeFromVar(args[1]); - JavascriptString *methodName = JavascriptString::UnsafeFromVar(args[2]); + ScriptFunction *func = UnsafeVarTo(args[1]); + JavascriptString *methodName = UnsafeVarTo(args[2]); bool isConstructor = true; if (args.Info.Count == 4) { - AssertOrFailFast(JavascriptBoolean::Is(args.Values[3])); - isConstructor = JavascriptBoolean::UnsafeFromVar(args.Values[3])->GetValue(); + AssertOrFailFast(VarIs(args.Values[3])); + isConstructor = UnsafeVarTo(args.Values[3])->GetValue(); } // isConstructor = true is the default (when no 3rd arg is provided) @@ -395,13 +377,13 @@ namespace Js { EngineInterfaceObject_CommonFunctionProlog(function, callInfo); - if (callInfo.Count < 3 || !DynamicObject::Is(args.Values[1]) || !RecyclableObject::Is(args.Values[2])) + if (callInfo.Count < 3 || !DynamicObject::IsBaseDynamicObject(args.Values[1]) || !VarIs(args.Values[2])) { return scriptContext->GetLibrary()->GetUndefined(); } - DynamicObject* obj = DynamicObject::FromVar(args.Values[1]); - RecyclableObject* value = RecyclableObject::FromVar(args.Values[2]); + DynamicObject* obj = VarTo(args.Values[1]); + RecyclableObject* value = VarTo(args.Values[2]); obj->SetPrototype(value); @@ -440,13 +422,13 @@ namespace Js { EngineInterfaceObject_CommonFunctionProlog(function, callInfo); - if (callInfo.Count < 2 || !JavascriptString::Is(args.Values[1]) || !JavascriptRegExp::Is(args.Values[2])) + if (callInfo.Count < 2 || !VarIs(args.Values[1]) || !VarIs(args.Values[2])) { return scriptContext->GetLibrary()->GetUndefined(); } - JavascriptString *stringToUse = JavascriptString::FromVar(args.Values[1]); - JavascriptRegExp *regexpToUse = JavascriptRegExp::FromVar(args.Values[2]); + JavascriptString *stringToUse = VarTo(args.Values[1]); + JavascriptRegExp *regexpToUse = VarTo(args.Values[2]); return RegexHelper::RegexMatchNoHistory(scriptContext, regexpToUse, stringToUse, false); } @@ -463,7 +445,7 @@ namespace Js return scriptContext->GetLibrary()->GetUndefined(); } - RecyclableObject *func = RecyclableObject::FromVar(args.Values[1]); + RecyclableObject *func = VarTo(args.Values[1]); AssertOrFailFastMsg(func != scriptContext->GetLibrary()->GetUndefined(), "Trying to callInstanceFunction(undefined, ...)"); @@ -495,12 +477,12 @@ namespace Js { \ EngineInterfaceObject_CommonFunctionProlog(function, callInfo); \ \ - if(args.Info.Count < 2 || !JavascriptString::Is(args.Values[1])) \ + if(args.Info.Count < 2 || !VarIs(args.Values[1])) \ { \ Assert(false); \ JavascriptError::Throw##exceptionType(scriptContext, JSERR_##exceptionID); \ } \ - JavascriptError::Throw##exceptionType##Var(scriptContext, JSERR_##exceptionID, JavascriptString::FromVar(args.Values[1])->GetSz()); \ + JavascriptError::Throw##exceptionType##Var(scriptContext, JSERR_##exceptionID, VarTo(args.Values[1])->GetSz()); \ } #define BuiltInRaiseException2(exceptionType, exceptionID) \ @@ -508,12 +490,12 @@ namespace Js { \ EngineInterfaceObject_CommonFunctionProlog(function, callInfo); \ \ - if(args.Info.Count < 3 || !JavascriptString::Is(args.Values[1]) || !JavascriptString::Is(args.Values[2])) \ + if(args.Info.Count < 3 || !VarIs(args.Values[1]) || !VarIs(args.Values[2])) \ { \ Assert(false); \ JavascriptError::Throw##exceptionType(scriptContext, JSERR_##exceptionID); \ } \ - JavascriptError::Throw##exceptionType##Var(scriptContext, JSERR_##exceptionID, JavascriptString::FromVar(args.Values[1])->GetSz(), JavascriptString::FromVar(args.Values[2])->GetSz()); \ + JavascriptError::Throw##exceptionType##Var(scriptContext, JSERR_##exceptionID, VarTo(args.Values[1])->GetSz(), VarTo(args.Values[2])->GetSz()); \ } #define BuiltInRaiseException3(exceptionType, exceptionID) \ @@ -521,12 +503,12 @@ namespace Js { \ EngineInterfaceObject_CommonFunctionProlog(function, callInfo); \ \ - if(args.Info.Count < 4 || !JavascriptString::Is(args.Values[1]) || !JavascriptString::Is(args.Values[2]) || !JavascriptString::Is(args.Values[3])) \ + if(args.Info.Count < 4 || !VarIs(args.Values[1]) || !VarIs(args.Values[2]) || !VarIs(args.Values[3])) \ { \ Assert(false); \ JavascriptError::Throw##exceptionType(scriptContext, JSERR_##exceptionID); \ } \ - JavascriptError::Throw##exceptionType##Var(scriptContext, JSERR_##exceptionID, JavascriptString::FromVar(args.Values[1])->GetSz(), JavascriptString::FromVar(args.Values[2])->GetSz(), JavascriptString::FromVar(args.Values[3])->GetSz()); \ + JavascriptError::Throw##exceptionType##Var(scriptContext, JSERR_##exceptionID, VarTo(args.Values[1])->GetSz(), VarTo(args.Values[2])->GetSz(), VarTo(args.Values[3])->GetSz()); \ } #include "EngineInterfaceObjectBuiltIns.h" diff --git a/lib/Runtime/Library/EngineInterfaceObject.h b/lib/Runtime/Library/EngineInterfaceObject.h index 5a3fdbe591e..3943e46e342 100644 --- a/lib/Runtime/Library/EngineInterfaceObject.h +++ b/lib/Runtime/Library/EngineInterfaceObject.h @@ -71,9 +71,6 @@ namespace Js void SetEngineExtension(EngineInterfaceExtensionKind extensionKind, EngineExtensionObjectBase* extensionObject); static EngineInterfaceObject* New(Recycler * recycler, DynamicType * type); - static bool Is(Var aValue); - static EngineInterfaceObject* FromVar(Var aValue); - static EngineInterfaceObject* UnsafeFromVar(Var aValue); #if ENABLE_TTD virtual void MarkVisitKindSpecificPtrs(TTD::SnapshotExtractor* extractor) override; @@ -111,6 +108,11 @@ namespace Js #define EngineInterfaceBuiltIn2(propId, nativeMethod) static Var Entry_##nativeMethod(RecyclableObject *function, CallInfo callInfo, ...); #include "EngineInterfaceObjectBuiltIns.h" }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_EngineInterfaceObject; + } } #endif // ENABLE_INTL_OBJECT || ENABLE_JS_BUILTINS || ENABLE_PROJECTION diff --git a/lib/Runtime/Library/ForInObjectEnumerator.cpp b/lib/Runtime/Library/ForInObjectEnumerator.cpp index ea673f9303e..fab0740c733 100644 --- a/lib/Runtime/Library/ForInObjectEnumerator.cpp +++ b/lib/Runtime/Library/ForInObjectEnumerator.cpp @@ -102,7 +102,7 @@ namespace Js } if (!DynamicType::Is(firstPrototypeWithEnumerableProperties->GetTypeId()) - || !DynamicObject::UnsafeFromVar(firstPrototypeWithEnumerableProperties)->GetHasNoEnumerableProperties()) + || !UnsafeVarTo(firstPrototypeWithEnumerableProperties)->GetHasNoEnumerableProperties()) { break; } diff --git a/lib/Runtime/Library/GlobalObject.cpp b/lib/Runtime/Library/GlobalObject.cpp index b16a6ca331b..08d9b593354 100644 --- a/lib/Runtime/Library/GlobalObject.cpp +++ b/lib/Runtime/Library/GlobalObject.cpp @@ -54,23 +54,6 @@ using namespace Js; library = localLibrary; } - bool GlobalObject::Is(Var aValue) - { - return RecyclableObject::Is(aValue) && (RecyclableObject::UnsafeFromVar(aValue)->GetTypeId() == TypeIds_GlobalObject); - } - - GlobalObject* GlobalObject::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'GlobalObject'"); - return static_cast(aValue); - } - - GlobalObject* GlobalObject::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'GlobalObject'"); - return static_cast(aValue); - } - HRESULT GlobalObject::SetDirectHostObject(RecyclableObject* hostObject, RecyclableObject* secureDirectHostObject) { HRESULT hr = S_OK; @@ -158,7 +141,7 @@ using namespace Js; const char16 *source = nullptr; size_t sourceLength = 0; - if (Js::JavascriptString::Is(codeVar)) + if (Js::VarIs(codeVar)) { codeStringVar = (Js::JavascriptString *)codeVar; source = codeStringVar->GetString(); @@ -575,7 +558,7 @@ using namespace Js; } Var evalArg = args[1]; - if (!JavascriptString::Is(evalArg)) + if (!VarIs(evalArg)) { // "If x is not a string value, return x." return evalArg; @@ -588,7 +571,7 @@ using namespace Js; #endif ScriptFunction *pfuncScript = nullptr; - JavascriptString *argString = JavascriptString::FromVar(evalArg); + JavascriptString *argString = VarTo(evalArg); char16 const * sourceString = argString->GetSz(); charcount_t sourceLen = argString->GetLength(); FastEvalMapString key(sourceString, sourceLen, moduleID, strictMode, isLibraryCode); @@ -597,7 +580,7 @@ using namespace Js; // PropertyString's buffer references to PropertyRecord's inline buffer, if both PropertyString and PropertyRecord are collected // we'll leave the PropertyRecord's interior buffer pointer in the EvalMap. So do not use evalmap if we are evaluating PropertyString bool useEvalMap = !VirtualTableInfo::HasVirtualTable(argString) && debugEvalScriptContext == nullptr; // Don't use the cache in case of debugEval - + bool found = useEvalMap && scriptContext->IsInEvalMap(key, isIndirect, &pfuncScript); if (!found || (!isIndirect && pfuncScript->GetEnvironment() != &NullFrameDisplay)) { @@ -621,7 +604,7 @@ using namespace Js; // This is console scope scenario. DebugEval script context is on the top of the stack. But we are going // to execute the user script from target script context. In order to fix the script context stack we // need to marshall the function object. - pfuncScript = ScriptFunction::FromVar(CrossSite::MarshalVar(debugEvalScriptContext, pfuncScript)); + pfuncScript = VarTo(CrossSite::MarshalVar(debugEvalScriptContext, pfuncScript)); } if (useEvalMap && !found) @@ -1217,9 +1200,9 @@ using namespace Js; } // convert input to a string - if (JavascriptString::Is(args[1])) + if (VarIs(args[1])) { - str = JavascriptString::FromVar(args[1]); + str = VarTo(args[1]); } else { @@ -1280,9 +1263,9 @@ using namespace Js; } // convert input to a string - if (JavascriptString::Is(args[1])) + if (VarIs(args[1])) { - str = JavascriptString::FromVar(args[1]); + str = VarTo(args[1]); } else { @@ -1653,10 +1636,10 @@ using namespace Js; PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault); ARGUMENTS(args, callInfo); - TTDAssert(args.Info.Count >= 2 && Js::JavascriptString::Is(args[1]), "Bad arguments!!!"); + TTDAssert(args.Info.Count >= 2 && Js::VarIs(args[1]), "Bad arguments!!!"); - Js::JavascriptString* jsString = Js::JavascriptString::FromVar(args[1]); - bool doPrint = (args.Info.Count == 3) && Js::JavascriptBoolean::Is(args[2]) && (Js::JavascriptBoolean::FromVar(args[2])->GetValue()); + Js::JavascriptString* jsString = Js::VarTo(args[1]); + bool doPrint = (args.Info.Count == 3) && Js::VarIs(args[2]) && (Js::VarTo(args[2])->GetValue()); if(function->GetScriptContext()->ShouldPerformReplayAction()) { @@ -1715,7 +1698,7 @@ using namespace Js; Js::JavascriptLibrary* jslib = function->GetScriptContext()->GetLibrary(); - if(args.Info.Count != 2 || !Js::JavascriptString::Is(args[1])) + if(args.Info.Count != 2 || !Js::VarIs(args[1])) { return jslib->GetFalse(); } @@ -1729,7 +1712,7 @@ using namespace Js; if(function->GetScriptContext()->ShouldPerformRecordAction()) { - Js::JavascriptString* jsString = Js::JavascriptString::FromVar(args[1]); + Js::JavascriptString* jsString = Js::VarTo(args[1]); function->GetScriptContext()->GetThreadContext()->TTDLog->RecordEmitLogEvent(jsString); return jslib->GetTrue(); @@ -1773,7 +1756,7 @@ using namespace Js; } //get a pattern which doesn't contain leading and trailing stars - subPattern = JavascriptString::FromVar(JavascriptString::SubstringCore(pattern, idxStart, idxEnd - idxStart, scriptContext)); + subPattern = VarTo(JavascriptString::SubstringCore(pattern, idxStart, idxEnd - idxStart, scriptContext)); uint index = JavascriptString::strstr(propertyName, subPattern, false); diff --git a/lib/Runtime/Library/GlobalObject.h b/lib/Runtime/Library/GlobalObject.h index 2eea6440c8b..04c1f59f670 100644 --- a/lib/Runtime/Library/GlobalObject.h +++ b/lib/Runtime/Library/GlobalObject.h @@ -121,10 +121,6 @@ namespace Js BOOL registerDocument, BOOL isIndirect, BOOL strictMode); #endif /* IR_VIEWER */ - static bool Is(Var aValue); - static GlobalObject* FromVar(Var aValue); - static GlobalObject* UnsafeFromVar(Var aValue); - typedef ScriptFunction* (*EvalHelperType)(ScriptContext* scriptContext, const char16 *source, int sourceLength, ModuleID moduleID, uint32 grfscr, LPCOLESTR pszTitle, BOOL registerDocument, BOOL isIndirect, BOOL strictMode); FieldNoBarrier(EvalHelperType) EvalHelper; @@ -189,4 +185,9 @@ namespace Js virtual void ExtractSnapObjectDataInto(TTD::NSSnapObjects::SnapObject* objData, TTD::SlabAllocator& alloc) override; #endif }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return obj->GetTypeId() == TypeIds_GlobalObject; + } } diff --git a/lib/Runtime/Library/IntlEngineInterfaceExtensionObject.cpp b/lib/Runtime/Library/IntlEngineInterfaceExtensionObject.cpp index aa66f9359ee..2c6e3f4dc71 100644 --- a/lib/Runtime/Library/IntlEngineInterfaceExtensionObject.cpp +++ b/lib/Runtime/Library/IntlEngineInterfaceExtensionObject.cpp @@ -207,7 +207,7 @@ PROJECTED_ENUMS(PROJECTED_ENUM) GetPropertyFrom(obj, Js::PropertyIds::builtInPropID) \ #define GetTypedPropertyBuiltInFrom(obj, builtInPropID, Type) \ - (GetPropertyFrom(obj, Js::PropertyIds::builtInPropID) && Type::Is(propertyValue)) \ + (GetPropertyFrom(obj, Js::PropertyIds::builtInPropID) && VarIs(propertyValue)) \ #define HasPropertyOn(obj, propID) \ Js::JavascriptOperators::HasProperty(obj, propID) \ @@ -388,9 +388,9 @@ namespace Js Var propertyValue = nullptr; JavascriptOperators::GetProperty(state, propertyId, &propertyValue, state->GetScriptContext()); - AssertOrFailFast(propertyValue && T::Is(propertyValue)); + AssertOrFailFast(propertyValue && VarIs(propertyValue)); - return T::UnsafeFromVar(propertyValue); + return UnsafeVarTo(propertyValue); } static JavascriptString *AssertStringProperty(_In_ DynamicObject *state, _In_ PropertyIds propertyId) @@ -653,13 +653,13 @@ PROJECTED_ENUMS(PROJECTED_ENUM) return; } - if (!JavascriptOperators::GetProperty(DynamicObject::FromVar(propertyValue), Js::PropertyIds::prototype, &prototypeValue, scriptContext) || + if (!JavascriptOperators::GetProperty(VarTo(propertyValue), Js::PropertyIds::prototype, &prototypeValue, scriptContext) || !JavascriptOperators::IsObject(prototypeValue)) { return; } - prototypeObject = DynamicObject::FromVar(prototypeValue); + prototypeObject = VarTo(prototypeValue); if (!JavascriptOperators::GetProperty(prototypeObject, Js::PropertyIds::resolvedOptions, &resolvedOptionsValue, scriptContext) || !JavascriptOperators::IsObject(resolvedOptionsValue)) @@ -667,7 +667,7 @@ PROJECTED_ENUMS(PROJECTED_ENUM) return; } - functionObj = DynamicObject::FromVar(resolvedOptionsValue); + functionObj = VarTo(resolvedOptionsValue); functionObj->SetConfigurable(Js::PropertyIds::prototype, true); functionObj->DeleteProperty(Js::PropertyIds::prototype, Js::PropertyOperationFlags::PropertyOperation_None); @@ -677,7 +677,7 @@ PROJECTED_ENUMS(PROJECTED_ENUM) return; } - functionObj = DynamicObject::FromVar(getter); + functionObj = VarTo(getter); functionObj->SetConfigurable(Js::PropertyIds::prototype, true); functionObj->DeleteProperty(Js::PropertyIds::prototype, Js::PropertyOperationFlags::PropertyOperation_None); } @@ -881,7 +881,7 @@ PROJECTED_ENUMS(PROJECTED_ENUM) { EngineInterfaceObject_CommonFunctionProlog(function, callInfo); - if (args.Info.Count < 2 || !JavascriptError::Is(args.Values[1])) + if (args.Info.Count < 2 || !VarIs(args.Values[1])) { AssertMsg(false, "Intl's Assert platform API was called incorrectly."); return scriptContext->GetLibrary()->GetUndefined(); @@ -891,7 +891,7 @@ PROJECTED_ENUMS(PROJECTED_ENUM) #ifdef INTL_ICU_DEBUG Output::Print(_u("EntryIntl_RaiseAssert\n")); #endif - JavascriptExceptionOperators::Throw(JavascriptError::FromVar(args.Values[1]), scriptContext); + JavascriptExceptionOperators::Throw(VarTo(args.Values[1]), scriptContext); #else return scriptContext->GetLibrary()->GetUndefined(); #endif @@ -905,13 +905,13 @@ PROJECTED_ENUMS(PROJECTED_ENUM) #else EngineInterfaceObject_CommonFunctionProlog(function, callInfo); - if (args.Info.Count < 2 || !JavascriptString::Is(args.Values[1])) + if (args.Info.Count < 2 || !VarIs(args.Values[1])) { // IsWellFormedLanguageTag of undefined or non-string is false return scriptContext->GetLibrary()->GetFalse(); } - JavascriptString *argString = JavascriptString::FromVar(args.Values[1]); + JavascriptString *argString = VarTo(args.Values[1]); return TO_JSBOOL(scriptContext, GetWindowsGlobalizationAdapter(scriptContext)->IsWellFormedLanguageTag(scriptContext, argString->GetSz())); #endif @@ -922,10 +922,10 @@ PROJECTED_ENUMS(PROJECTED_ENUM) EngineInterfaceObject_CommonFunctionProlog(function, callInfo); #if defined(INTL_ICU) - INTL_CHECK_ARGS(args.Info.Count == 2 && JavascriptString::Is(args[1])); + INTL_CHECK_ARGS(args.Info.Count == 2 && VarIs(args[1])); UErrorCode status = U_ZERO_ERROR; - JavascriptString *langtag = JavascriptString::UnsafeFromVar(args[1]); + JavascriptString *langtag = UnsafeVarTo(args[1]); utf8::WideToNarrow langtag8(langtag->GetSz(), langtag->GetLength()); // ICU doesn't have a full-fledged canonicalization implementation that correctly replaces all preferred values @@ -972,13 +972,13 @@ PROJECTED_ENUMS(PROJECTED_ENUM) return JavascriptString::NewWithBuffer(canonicalized16, toLangTagResultLength, scriptContext); #else - if (args.Info.Count < 2 || !JavascriptString::Is(args.Values[1])) + if (args.Info.Count < 2 || !VarIs(args.Values[1])) { // NormalizeLanguageTag of undefined or non-string is undefined return scriptContext->GetLibrary()->GetUndefined(); } - JavascriptString *argString = JavascriptString::FromVar(args.Values[1]); + JavascriptString *argString = VarTo(args.Values[1]); JavascriptString *retVal; HRESULT hr; AutoHSTRING str; @@ -1081,9 +1081,9 @@ PROJECTED_ENUMS(PROJECTED_ENUM) Var IntlEngineInterfaceExtensionObject::EntryIntl_Is##ctorShortName##LocaleAvailable(RecyclableObject* function, CallInfo callInfo, ...) \ { \ EngineInterfaceObject_CommonFunctionProlog(function, callInfo); \ - INTL_CHECK_ARGS(args.Info.Count == 2 && JavascriptString::Is(args.Values[1])); \ + INTL_CHECK_ARGS(args.Info.Count == 2 && VarIs(args.Values[1])); \ return scriptContext->GetLibrary()->GetTrueOrFalse( \ - IsLocaleAvailable<##icuNamespace##_getAvailable, ##icuNamespace##_countAvailable>(JavascriptString::UnsafeFromVar(args.Values[1])) \ + IsLocaleAvailable<##icuNamespace##_getAvailable, ##icuNamespace##_countAvailable>(UnsafeVarTo(args.Values[1])) \ ); \ } #else @@ -1114,7 +1114,7 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) INTL_CHECK_ARGS( args.Info.Count == 3 && (JavascriptNumber::Is(args.Values[1]) || TaggedInt::Is(args.Values[1])) && - JavascriptString::Is(args.Values[2]) + VarIs(args.Values[2]) ); LocaleDataKind kind = (LocaleDataKind) (TaggedInt::Is(args.Values[1]) @@ -1125,7 +1125,7 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) UErrorCode status = U_ZERO_ERROR; char localeID[ULOC_FULLNAME_CAPACITY] = { 0 }; - JavascriptString *langtag = JavascriptString::UnsafeFromVar(args.Values[2]); + JavascriptString *langtag = UnsafeVarTo(args.Values[2]); LangtagToLocaleID(langtag, localeID); JavascriptLibrary *library = scriptContext->GetLibrary(); @@ -1340,7 +1340,7 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) { EngineInterfaceObject_CommonFunctionProlog(function, callInfo); - if (args.Info.Count < 2 || !JavascriptString::Is(args.Values[1])) + if (args.Info.Count < 2 || !VarIs(args.Values[1])) { // ResolveLocaleLookup of undefined or non-string is undefined return scriptContext->GetLibrary()->GetUndefined(); @@ -1352,7 +1352,7 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) #endif return scriptContext->GetLibrary()->GetNull(); #else - JavascriptString *argString = JavascriptString::FromVar(args.Values[1]); + JavascriptString *argString = VarTo(args.Values[1]); PCWSTR passedLocale = argString->GetSz(); // REVIEW should we zero the whole array for safety? WCHAR resolvedLocaleName[LOCALE_NAME_MAX_LENGTH]; @@ -1372,7 +1372,7 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) { EngineInterfaceObject_CommonFunctionProlog(function, callInfo); - if (args.Info.Count < 2 || !JavascriptString::Is(args.Values[1])) + if (args.Info.Count < 2 || !VarIs(args.Values[1])) { // NormalizeLanguageTag of undefined or non-string is undefined return scriptContext->GetLibrary()->GetUndefined(); @@ -1382,7 +1382,7 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) AssertOrFailFastMsg(false, "Intl-ICU does not implement ResolveLocaleBestFit"); return nullptr; #else // !INTL_ICU - JavascriptString *localeStrings = JavascriptString::FromVar(args.Values[1]); + JavascriptString *localeStrings = VarTo(args.Values[1]); PCWSTR passedLocale = localeStrings->GetSz(); DelayLoadWindowsGlobalization* wgl = scriptContext->GetThreadContext()->GetWindowsGlobalizationLibrary(); WindowsGlobalizationAdapter* wga = GetWindowsGlobalizationAdapter(scriptContext); @@ -1444,7 +1444,7 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) { EngineInterfaceObject_CommonFunctionProlog(function, callInfo); - if (args.Info.Count < 2 || !JavascriptString::Is(args.Values[1])) + if (args.Info.Count < 2 || !VarIs(args.Values[1])) { // NormalizeLanguageTag of undefined or non-string is undefined return scriptContext->GetLibrary()->GetUndefined(); @@ -1457,7 +1457,7 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) AutoCOMPtr language; AutoCOMPtr extensionSubtags; HRESULT hr; - if (FAILED(hr = wga->CreateLanguage(scriptContext, JavascriptString::FromVar(args.Values[1])->GetSz(), &language))) + if (FAILED(hr = wga->CreateLanguage(scriptContext, VarTo(args.Values[1])->GetSz(), &language))) { HandleOOMSOEHR(hr); return scriptContext->GetLibrary()->GetUndefined(); @@ -1523,10 +1523,10 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) Var IntlEngineInterfaceExtensionObject::EntryIntl_CacheNumberFormat(RecyclableObject * function, CallInfo callInfo, ...) { EngineInterfaceObject_CommonFunctionProlog(function, callInfo); - INTL_CHECK_ARGS(args.Info.Count == 2 && DynamicObject::Is(args.Values[1])); + INTL_CHECK_ARGS(args.Info.Count == 2 && DynamicObject::IsBaseDynamicObject(args.Values[1])); #if defined(INTL_ICU) - DynamicObject *state = DynamicObject::UnsafeFromVar(args.Values[1]); + DynamicObject *state = UnsafeVarTo(args.Values[1]); // always AssertOrFailFast that the properties we need are there, because if they aren't, Intl.js isn't functioning correctly NumberFormatStyle style = AssertEnumProperty(state, PropertyIds::formatterToUse); @@ -1597,14 +1597,14 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) #else HRESULT hr = S_OK; JavascriptString *localeJSstr = nullptr; - DynamicObject *options = DynamicObject::FromVar(args.Values[1]); + DynamicObject *options = VarTo(args.Values[1]); DelayLoadWindowsGlobalization* wgl = scriptContext->GetThreadContext()->GetWindowsGlobalizationLibrary(); WindowsGlobalizationAdapter* wga = GetWindowsGlobalizationAdapter(scriptContext); Var propertyValue; // Verify locale is present // REVIEW (doilij): Fix comparison of the unsigned value <= 0 - if (!GetTypedPropertyBuiltInFrom(options, __locale, JavascriptString) || (localeJSstr = JavascriptString::FromVar(propertyValue))->GetLength() <= 0) + if (!GetTypedPropertyBuiltInFrom(options, __locale, JavascriptString) || (localeJSstr = VarTo(propertyValue))->GetLength() <= 0) { // REVIEW (doilij): Should we throw? Or otherwise, from Intl.js, should detect something didn't work right here... return scriptContext->GetLibrary()->GetUndefined(); @@ -1630,7 +1630,7 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) return scriptContext->GetLibrary()->GetUndefined(); } //API call retrieves a currency formatter, have to query its interface for numberFormatter - IfFailThrowHr(GetWindowsGlobalizationAdapter(scriptContext)->CreateCurrencyFormatter(scriptContext, &locale, 1, JavascriptString::FromVar(propertyValue)->GetSz(), ¤cyFormatter)); + IfFailThrowHr(GetWindowsGlobalizationAdapter(scriptContext)->CreateCurrencyFormatter(scriptContext, &locale, 1, VarTo(propertyValue)->GetSz(), ¤cyFormatter)); if (GetTypedPropertyBuiltInFrom(options, __currencyDisplayToUse, TaggedInt)) // 0 is for symbol, 1 is for code, 2 is for name. //Currently name isn't supported; so it will default to code in that case. @@ -1668,7 +1668,7 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) if (GetTypedPropertyBuiltInFrom(options, __useGrouping, JavascriptBoolean)) { - IfFailThrowHr(numberFormatterOptions->put_IsGrouped((boolean)(JavascriptBoolean::FromVar(propertyValue)->GetValue()))); + IfFailThrowHr(numberFormatterOptions->put_IsGrouped((boolean)(VarTo(propertyValue)->GetValue()))); } //Get the numeral system and add it to the object since it will be located in the locale @@ -1732,13 +1732,13 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) { EngineInterfaceObject_CommonFunctionProlog(function, callInfo); - if (args.Info.Count < 3 || !DynamicObject::Is(args.Values[1]) || !JavascriptBoolean::Is(args.Values[2])) + if (args.Info.Count < 3 || !DynamicObject::IsBaseDynamicObject(args.Values[1]) || !VarIs(args.Values[2])) { return scriptContext->GetLibrary()->GetUndefined(); } #ifdef INTL_WINGLOB - DynamicObject* obj = DynamicObject::FromVar(args.Values[1]); + DynamicObject* obj = VarTo(args.Values[1]); DelayLoadWindowsGlobalization* wgl = scriptContext->GetThreadContext()->GetWindowsGlobalizationLibrary(); WindowsGlobalizationAdapter* wga = GetWindowsGlobalizationAdapter(scriptContext); @@ -1747,8 +1747,8 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) Var propertyValue = nullptr; uint32 length; - PCWSTR locale = GetTypedPropertyBuiltInFrom(obj, __locale, JavascriptString) ? JavascriptString::FromVar(propertyValue)->GetSz() : nullptr; - PCWSTR templateString = GetTypedPropertyBuiltInFrom(obj, __templateString, JavascriptString) ? JavascriptString::FromVar(propertyValue)->GetSz() : nullptr; + PCWSTR locale = GetTypedPropertyBuiltInFrom(obj, __locale, JavascriptString) ? VarTo(propertyValue)->GetSz() : nullptr; + PCWSTR templateString = GetTypedPropertyBuiltInFrom(obj, __templateString, JavascriptString) ? VarTo(propertyValue)->GetSz() : nullptr; if (locale == nullptr || templateString == nullptr) { @@ -1756,7 +1756,7 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) return scriptContext->GetLibrary()->GetUndefined(); } - PCWSTR clock = GetTypedPropertyBuiltInFrom(obj, __windowsClock, JavascriptString) ? JavascriptString::FromVar(propertyValue)->GetSz() : nullptr; + PCWSTR clock = GetTypedPropertyBuiltInFrom(obj, __windowsClock, JavascriptString) ? VarTo(propertyValue)->GetSz() : nullptr; AutoHSTRING hDummyCalendar; if (clock != nullptr) @@ -1808,7 +1808,7 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) SetPropertyBuiltInOn(obj, __patternStrings, patternStrings); //This parameter tells us whether we are caching it this time around; or just validating pattern strings - if ((boolean)(JavascriptBoolean::FromVar(args.Values[2])->GetValue())) + if ((boolean)(VarTo(args.Values[2])->GetValue())) { //If timeZone is undefined; then use the standard dateTimeFormatter to format in local time; otherwise use the IDateTimeFormatter2 to format using specified timezone (UTC) if (!GetPropertyBuiltInFrom(obj, __timeZone) || JavascriptOperators::IsUndefinedObject(propertyValue)) @@ -1846,16 +1846,16 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) EngineInterfaceObject_CommonFunctionProlog(function, callInfo); INTL_CHECK_ARGS( args.Info.Count == 5 && - JavascriptString::Is(args[1]) && - JavascriptString::Is(args[2]) && - DynamicObject::Is(args[3]) && - JavascriptBoolean::Is(args[4]) + VarIs(args[1]) && + VarIs(args[2]) && + DynamicObject::IsBaseDynamicObject(args[3]) && + VarIs(args[4]) ); - JavascriptString *left = JavascriptString::UnsafeFromVar(args[1]); - JavascriptString *right = JavascriptString::UnsafeFromVar(args[2]); - DynamicObject *state = DynamicObject::UnsafeFromVar(args[3]); - bool forStringPrototypeLocaleCompare = JavascriptBoolean::UnsafeFromVar(args[4])->GetValue(); + JavascriptString *left = UnsafeVarTo(args[1]); + JavascriptString *right = UnsafeVarTo(args[2]); + DynamicObject *state = UnsafeVarTo(args[3]); + bool forStringPrototypeLocaleCompare = UnsafeVarTo(args[4])->GetValue(); if (forStringPrototypeLocaleCompare) { CHAKRATEL_LANGSTATS_INC_BUILTINCOUNT(String_Prototype_localeCompare); @@ -2048,7 +2048,7 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) return nullptr; #else EngineInterfaceObject_CommonFunctionProlog(function, callInfo); - INTL_CHECK_ARGS(args.Info.Count >= 3 && JavascriptString::Is(args[1]) && JavascriptString::Is(args[2])); + INTL_CHECK_ARGS(args.Info.Count >= 3 && VarIs(args[1]) && VarIs(args[2])); const char16 *locale = nullptr; // args[3] char16 defaultLocale[LOCALE_NAME_MAX_LENGTH] = { 0 }; @@ -2057,8 +2057,8 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) bool ignorePunctuation = false; // args[5] bool numeric = false; // args[6] - JavascriptString *str1 = JavascriptString::FromVar(args.Values[1]); - JavascriptString *str2 = JavascriptString::FromVar(args.Values[2]); + JavascriptString *str1 = VarTo(args.Values[1]); + JavascriptString *str2 = VarTo(args.Values[2]); CollatorCaseFirst caseFirst = CollatorCaseFirst::Default; // args[7] // we only need to parse arguments 3 through 7 if locale and options are provided @@ -2070,9 +2070,9 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) JavascriptError::MapAndThrowError(scriptContext, E_INVALIDARG); } - if (!JavascriptOperators::IsUndefinedObject(args.Values[3]) && JavascriptString::Is(args.Values[3])) + if (!JavascriptOperators::IsUndefinedObject(args.Values[3]) && VarIs(args.Values[3])) { - locale = JavascriptString::FromVar(args.Values[3])->GetSz(); + locale = VarTo(args.Values[3])->GetSz(); } else { @@ -2084,14 +2084,14 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) sensitivity = static_cast(TaggedInt::ToUInt16(args.Values[4])); } - if (!JavascriptOperators::IsUndefinedObject(args.Values[5]) && JavascriptBoolean::Is(args.Values[5])) + if (!JavascriptOperators::IsUndefinedObject(args.Values[5]) && VarIs(args.Values[5])) { - ignorePunctuation = (JavascriptBoolean::FromVar(args.Values[5])->GetValue() != 0); + ignorePunctuation = (VarTo(args.Values[5])->GetValue() != 0); } - if (!JavascriptOperators::IsUndefinedObject(args.Values[6]) && JavascriptBoolean::Is(args.Values[6])) + if (!JavascriptOperators::IsUndefinedObject(args.Values[6]) && VarIs(args.Values[6])) { - numeric = (JavascriptBoolean::FromVar(args.Values[6])->GetValue() != 0); + numeric = (VarTo(args.Values[6])->GetValue() != 0); } if (!JavascriptOperators::IsUndefinedObject(args.Values[7]) && TaggedInt::Is(args.Values[7])) @@ -2166,10 +2166,10 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) INTL_CHECK_ARGS( args.Info.Count == 2 && - JavascriptString::Is(args.Values[1]) + VarIs(args.Values[1]) ); - const char16 *currencyCode = JavascriptString::UnsafeFromVar(args.Values[1])->GetSz(); + const char16 *currencyCode = UnsafeVarTo(args.Values[1])->GetSz(); #if defined(INTL_ICU) UErrorCode status = U_ZERO_ERROR; @@ -2409,15 +2409,15 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) INTL_CHECK_ARGS( args.Info.Count == 5 && (TaggedInt::Is(args[1]) || JavascriptNumber::Is(args[1])) && - DynamicObject::Is(args[2]) && - JavascriptBoolean::Is(args[3]) && - JavascriptBoolean::Is(args[4]) + DynamicObject::IsBaseDynamicObject(args[2]) && + VarIs(args[3]) && + VarIs(args[4]) ); double num = JavascriptConversion::ToNumber(args[1], scriptContext); - DynamicObject *state = DynamicObject::UnsafeFromVar(args[2]); - bool toParts = JavascriptBoolean::UnsafeFromVar(args[3])->GetValue(); - bool forNumberPrototypeToLocaleString = JavascriptBoolean::UnsafeFromVar(args[4])->GetValue(); + DynamicObject *state = UnsafeVarTo(args[2]); + bool toParts = UnsafeVarTo(args[3])->GetValue(); + bool forNumberPrototypeToLocaleString = UnsafeVarTo(args[4])->GetValue(); Var cachedUNumberFormat = nullptr; // cached by EntryIntl_CacheNumberFormat AssertOrFailFast(state->GetInternalProperty(state, InternalPropertyIds::CachedUNumberFormat, &cachedUNumberFormat, NULL, scriptContext)); @@ -2489,10 +2489,10 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) INTL_CHECK_ARGS( args.Info.Count == 3 && (TaggedInt::Is(args.Values[1]) || JavascriptNumber::Is(args.Values[1])) && - DynamicObject::Is(args.Values[2]) + DynamicObject::IsBaseDynamicObject(args.Values[2]) ); - DynamicObject *options = DynamicObject::FromVar(args.Values[2]); + DynamicObject *options = VarTo(args.Values[2]); Var hiddenObject = nullptr; AssertOrFailFastMsg(options->GetInternalProperty(options, Js::InternalPropertyIds::HiddenObject, &hiddenObject, NULL, scriptContext), "EntryIntl_FormatNumber: Could not retrieve hiddenObject."); @@ -2584,7 +2584,7 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) EngineInterfaceObject_CommonFunctionProlog(function, callInfo); #ifdef INTL_WINGLOB - if (args.Info.Count < 3 || !(TaggedInt::Is(args.Values[1]) || JavascriptNumber::Is(args.Values[1])) || !DynamicObject::Is(args.Values[2])) + if (args.Info.Count < 3 || !(TaggedInt::Is(args.Values[1]) || JavascriptNumber::Is(args.Values[1])) || !DynamicObject::IsBaseDynamicObject(args.Values[2])) { return scriptContext->GetLibrary()->GetUndefined(); } @@ -2606,7 +2606,7 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) Js::JavascriptError::ThrowRangeError(scriptContext, JSERR_OutOfDateTimeRange); } - DynamicObject* obj = DynamicObject::FromVar(args.Values[2]); + DynamicObject* obj = VarTo(args.Values[2]); Var hiddenObject = nullptr; AssertOrFailFastMsg(obj->GetInternalProperty(obj, Js::InternalPropertyIds::HiddenObject, &hiddenObject, NULL, scriptContext), "EntryIntl_FormatDateTime: Could not retrieve hiddenObject."); @@ -2630,7 +2630,7 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) HSTRING_HEADER timeZoneHeader; // IsValidTimeZone() has already verified that this is JavascriptString. - JavascriptString* userDefinedTimeZoneId = JavascriptString::FromVar(propertyValue); + JavascriptString* userDefinedTimeZoneId = VarTo(propertyValue); IfFailThrowHr(WindowsCreateStringReference(userDefinedTimeZoneId->GetSz(), userDefinedTimeZoneId->GetLength(), &timeZoneHeader, &timeZone)); Assert(timeZone); @@ -2643,14 +2643,14 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) // This function vaguely implements ECMA 402 #sec-partitiondatetimepattern INTL_CHECK_ARGS( args.Info.Count == 5 && - DynamicObject::Is(args[1]) && + DynamicObject::IsBaseDynamicObject(args[1]) && (TaggedInt::Is(args[2]) || JavascriptNumber::Is(args[2])) && - JavascriptBoolean::Is(args[3]) && - JavascriptBoolean::Is(args[4]) + VarIs(args[3]) && + VarIs(args[4]) ); - DynamicObject *state = DynamicObject::UnsafeFromVar(args[1]); - bool toParts = Js::JavascriptBoolean::UnsafeFromVar(args[3])->GetValue(); + DynamicObject *state = UnsafeVarTo(args[1]); + bool toParts = Js::UnsafeVarTo(args[3])->GetValue(); // 1. Let x be TimeClip(x) // 2. If x is NaN, throw a RangeError exception @@ -2660,7 +2660,7 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) JavascriptError::ThrowRangeError(scriptContext, JSERR_InvalidDate); } - bool forDatePrototypeToLocaleString = JavascriptBoolean::UnsafeFromVar(args[4])->GetValue(); + bool forDatePrototypeToLocaleString = UnsafeVarTo(args[4])->GetValue(); if (forDatePrototypeToLocaleString) { CHAKRATEL_LANGSTATS_INC_BUILTINCOUNT(Date_Prototype_toLocaleString); @@ -2848,10 +2848,10 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) { #ifdef INTL_ICU EngineInterfaceObject_CommonFunctionProlog(function, callInfo); - INTL_CHECK_ARGS(args.Info.Count == 3 && JavascriptString::Is(args.Values[1]) && JavascriptString::Is(args.Values[2])); + INTL_CHECK_ARGS(args.Info.Count == 3 && VarIs(args.Values[1]) && VarIs(args.Values[2])); - JavascriptString *langtag = JavascriptString::UnsafeFromVar(args.Values[1]); - JavascriptString *skeleton = JavascriptString::UnsafeFromVar(args.Values[2]); + JavascriptString *langtag = UnsafeVarTo(args.Values[1]); + JavascriptString *skeleton = UnsafeVarTo(args.Values[2]); UErrorCode status = U_ZERO_ERROR; char localeID[ULOC_FULLNAME_CAPACITY] = { 0 }; LangtagToLocaleID(langtag, localeID); @@ -2911,9 +2911,9 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) Var IntlEngineInterfaceExtensionObject::EntryIntl_ValidateAndCanonicalizeTimeZone(RecyclableObject* function, CallInfo callInfo, ...) { EngineInterfaceObject_CommonFunctionProlog(function, callInfo); - INTL_CHECK_ARGS(args.Info.Count == 2 && JavascriptString::Is(args.Values[1])); + INTL_CHECK_ARGS(args.Info.Count == 2 && VarIs(args.Values[1])); - JavascriptString *tz = JavascriptString::FromVar(args.Values[1]); + JavascriptString *tz = VarTo(args.Values[1]); #ifdef INTL_WINGLOB AutoHSTRING canonicalizedTimeZone; @@ -3051,7 +3051,7 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) { #ifdef INTL_ICU EngineInterfaceObject_CommonFunctionProlog(function, callInfo); - INTL_CHECK_ARGS(args.Info.Count == 2 && DynamicObject::Is(args[1])); + INTL_CHECK_ARGS(args.Info.Count == 2 && DynamicObject::IsBaseDynamicObject(args[1])); JavascriptArray *ret = scriptContext->GetLibrary()->CreateArray(0); @@ -3060,7 +3060,7 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) // uplrules_getKeywords is guaranteed to return at minimum. // This array is only used in resolved options, so the majority of the functionality can remain (namely, select() still works) #if defined(ICU_VERSION) && ICU_VERSION >= 61 - DynamicObject *state = DynamicObject::UnsafeFromVar(args[1]); + DynamicObject *state = UnsafeVarTo(args[1]); FinalizableUPluralRules *pr = GetOrCreateCachedUPluralRules(state, scriptContext); UErrorCode status = U_ZERO_ERROR; @@ -3087,9 +3087,9 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) { #ifdef INTL_ICU EngineInterfaceObject_CommonFunctionProlog(function, callInfo); - INTL_CHECK_ARGS(args.Info.Count == 3 && DynamicObject::Is(args[1])); + INTL_CHECK_ARGS(args.Info.Count == 3 && DynamicObject::IsBaseDynamicObject(args[1])); - DynamicObject *state = DynamicObject::UnsafeFromVar(args[1]); + DynamicObject *state = UnsafeVarTo(args[1]); double n = 0.0; if (TaggedInt::Is(args[2])) { @@ -3174,9 +3174,9 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) EngineInterfaceObject_CommonFunctionProlog(function, callInfo); // This function will only be used during the construction of the Intl object, hence Asserts are in place. - Assert(args.Info.Count >= 3 && JavascriptFunction::Is(args.Values[1]) && TaggedInt::Is(args.Values[2])); + Assert(args.Info.Count >= 3 && VarIs(args.Values[1]) && TaggedInt::Is(args.Values[2])); - JavascriptFunction *func = JavascriptFunction::FromVar(args.Values[1]); + JavascriptFunction *func = VarTo(args.Values[1]); int32 id = TaggedInt::ToInt32(args.Values[2]); Assert(id >= 0 && id < (int32)BuiltInFunctionID::Max); @@ -3214,12 +3214,12 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) { EngineInterfaceObject_CommonFunctionProlog(function, callInfo); - if (callInfo.Count < 2 || !DynamicObject::Is(args.Values[1])) + if (callInfo.Count < 2 || !DynamicObject::IsBaseDynamicObject(args.Values[1])) { return scriptContext->GetLibrary()->GetUndefined(); } - DynamicObject* obj = DynamicObject::FromVar(args.Values[1]); + DynamicObject* obj = VarTo(args.Values[1]); Var hiddenObject = nullptr; if (!obj->GetInternalProperty(obj, Js::InternalPropertyIds::HiddenObject, &hiddenObject, NULL, scriptContext)) { @@ -3232,13 +3232,13 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) { EngineInterfaceObject_CommonFunctionProlog(function, callInfo); - if (callInfo.Count < 3 || !DynamicObject::Is(args.Values[1]) || !DynamicObject::Is(args.Values[2])) + if (callInfo.Count < 3 || !DynamicObject::IsBaseDynamicObject(args.Values[1]) || !DynamicObject::IsBaseDynamicObject(args.Values[2])) { return scriptContext->GetLibrary()->GetUndefined(); } - DynamicObject* obj = DynamicObject::FromVar(args.Values[1]); - DynamicObject* value = DynamicObject::FromVar(args.Values[2]); + DynamicObject* obj = VarTo(args.Values[1]); + DynamicObject* value = VarTo(args.Values[2]); if (obj->SetInternalProperty(Js::InternalPropertyIds::HiddenObject, value, Js::PropertyOperationFlags::PropertyOperation_None, NULL)) { diff --git a/lib/Runtime/Library/JSON.cpp b/lib/Runtime/Library/JSON.cpp index 31da047eac4..c1ce141ceeb 100644 --- a/lib/Runtime/Library/JSON.cpp +++ b/lib/Runtime/Library/JSON.cpp @@ -46,7 +46,7 @@ namespace JSON Js::RecyclableObject* reviver = nullptr; if (args.Info.Count > 2 && Js::JavascriptConversion::IsCallable(args[2])) { - reviver = Js::RecyclableObject::UnsafeFromVar(args[2]); + reviver = Js::UnsafeVarTo(args[2]); } return Parse(input, reviver, scriptContext); @@ -60,7 +60,7 @@ namespace JSON TryFinally([&]() { - LazyJSONString* lazyString = LazyJSONString::TryFromVar(input); + LazyJSONString* lazyString = JavascriptOperators::TryFromVar(input); if (lazyString) { // Try to reconstruct object based on the data collected during stringify @@ -122,15 +122,16 @@ namespace JSON if (Js::JavascriptOperators::GetTypeId(value) == Js::TypeIds_HostDispatch) { // If we a remote object, we need to pull out the underlying JS object to stringify that - Js::DynamicObject* remoteObject = Js::RecyclableObject::FromVar(value)->GetRemoteObject(); + Js::DynamicObject* remoteObject = Js::VarTo(value)->GetRemoteObject(); if (remoteObject != nullptr) { - value = Js::DynamicObject::FromVar(remoteObject); + AssertOrFailFast(Js::VarIsCorrectType(remoteObject)); + value = remoteObject; } else { Js::Var result; - if (Js::RecyclableObject::FromVar(value)->InvokeBuiltInOperationRemotely(Stringify, args, &result)) + if (Js::VarTo(value)->InvokeBuiltInOperationRemotely(Stringify, args, &result)) { return result; } diff --git a/lib/Runtime/Library/JSONParser.cpp b/lib/Runtime/Library/JSONParser.cpp index 6e52444a2b7..991fb21b54a 100644 --- a/lib/Runtime/Library/JSONParser.cpp +++ b/lib/Runtime/Library/JSONParser.cpp @@ -68,14 +68,14 @@ namespace JSON "The holder argument in a JSON::Walk function must be an object or an array"); if (id == Constants::NoProperty) { - if (!Js::RecyclableObject::FromVar(holder)->GetItem(holder, index, &value, scriptContext)) + if (!Js::VarTo(holder)->GetItem(holder, index, &value, scriptContext)) { value = undefined; } } else { - if (!Js::RecyclableObject::FromVar(holder)->GetProperty(holder, id, &value, NULL, scriptContext)) + if (!Js::VarTo(holder)->GetProperty(holder, id, &value, NULL, scriptContext)) { value = undefined; } @@ -86,7 +86,7 @@ namespace JSON if (Js::DynamicObject::IsAnyArray(value)) { Js::JavascriptArray* arrayVal = JavascriptArray::EnsureNonNativeArray(Js::JavascriptArray::FromAnyArray(value)); - Assert(!Js::JavascriptNativeIntArray::Is(arrayVal) && !Js::JavascriptNativeFloatArray::Is(arrayVal)); + Assert(!Js::VarIs(arrayVal) && !Js::VarIs(arrayVal)); uint length = arrayVal->GetLength(); if (!arrayVal->IsCrossSiteObject()) { @@ -128,7 +128,7 @@ namespace JSON // normally we should have a JSON object here and the enumerator should be always be successful. However, the objects can be // modified by user code. It is better to skip a damaged object. ES5 spec doesn't specify an error here. - if(Js::RecyclableObject::FromVar(value)->GetEnumerator(&enumerator, EnumeratorFlags::SnapShotSemantics, scriptContext)) + if(Js::VarTo(value)->GetEnumerator(&enumerator, EnumeratorFlags::SnapShotSemantics, scriptContext)) { Js::JavascriptString * propertyName; @@ -148,11 +148,11 @@ namespace JSON Js::Var newElement = Walk(propertyName, idMember, value); if (Js::JavascriptOperators::IsUndefinedObject(newElement, undefined)) { - Js::JavascriptOperators::DeleteProperty(Js::RecyclableObject::FromVar(value), idMember); + Js::JavascriptOperators::DeleteProperty(Js::VarTo(value), idMember); } else { - Js::JavascriptOperators::SetProperty(value, Js::RecyclableObject::FromVar(value), idMember, newElement, scriptContext); + Js::JavascriptOperators::SetProperty(value, Js::VarTo(value), idMember, newElement, scriptContext); } } // For the numeric cases the enumerator is set to a NullEnumerator (see class in ForInObjectEnumerator.h) @@ -164,12 +164,12 @@ namespace JSON Js::Var newElement = Walk(propertyName, idMember, value, propertyIndex); if (Js::JavascriptOperators::IsUndefinedObject(newElement, undefined)) { - Js::JavascriptOperators::DeleteItem(Js::RecyclableObject::FromVar(value), propertyIndex); + Js::JavascriptOperators::DeleteItem(Js::VarTo(value), propertyIndex); } else { - Js::JavascriptOperators::SetItem(value, Js::RecyclableObject::FromVar(value), propertyIndex, newElement, scriptContext); + Js::JavascriptOperators::SetItem(value, Js::VarTo(value), propertyIndex, newElement, scriptContext); } } @@ -294,7 +294,7 @@ namespace JSON #if ENABLE_DEBUG_CONFIG_OPTIONS if (Js::Configuration::Global.flags.IsEnabled(Js::autoProxyFlag)) { - object = DynamicObject::FromVar(JavascriptProxy::AutoProxyWrapper(object)); + object = VarTo(JavascriptProxy::AutoProxyWrapper(object)); } #endif diff --git a/lib/Runtime/Library/JSONStringifier.cpp b/lib/Runtime/Library/JSONStringifier.cpp index ebefa76d9d3..4f8a71b1aee 100644 --- a/lib/Runtime/Library/JSONStringifier.cpp +++ b/lib/Runtime/Library/JSONStringifier.cpp @@ -67,7 +67,7 @@ JSONStringifier::ReadSpace(_In_opt_ Var space) break; } case TypeIds_String: - this->SetStringGap(JavascriptString::UnsafeFromVar(space)); + this->SetStringGap(UnsafeVarTo(space)); break; case TypeIds_StringObject: this->SetStringGap(JavascriptConversion::ToString(space, this->scriptContext)); @@ -88,7 +88,7 @@ JSONStringifier::AddToPropertyList(_In_ Var item, _Inout_ BVSparse* pr propertyName = this->scriptContext->GetIntegerString(item); break; case TypeIds_String: - propertyName = JavascriptString::UnsafeFromVar(item); + propertyName = UnsafeVarTo(item); break; case TypeIds_Number: case TypeIds_NumberObject: @@ -134,7 +134,7 @@ JSONStringifier::ReadReplacer(_In_opt_ Var replacer) BVSparse propertyListBV(recycler); this->propertyList = RecyclerNew(recycler, PropertyList, recycler); - JavascriptArray* propertyArray = JavascriptOperators::TryFromVar(replacer); + JavascriptArray* propertyArray = JavascriptArray::TryVarToNonES5Array(replacer); if (propertyArray != nullptr) { uint32 length = propertyArray->GetLength(); @@ -221,7 +221,7 @@ _Ret_notnull_ Var JSONStringifier::ReadValue(_In_ JavascriptString* key, _In_opt_ const PropertyRecord* propertyRecord, _In_ RecyclableObject* holder) { Var value = nullptr; - PropertyString* propertyString = PropertyString::TryFromVar(key); + PropertyString* propertyString = JavascriptOperators::TryFromVar(key); PropertyValueInfo info; if (propertyString != nullptr) { @@ -257,7 +257,7 @@ JSONStringifier::TryConvertPrimitiveObject(_In_ RecyclableObject* value) } else if (TypeIds_BooleanObject == id) { - return (JavascriptBooleanObject::UnsafeFromVar(value)->GetValue() != FALSE) + return (UnsafeVarTo(value)->GetValue() != FALSE) ? this->scriptContext->GetLibrary()->GetTrue() : this->scriptContext->GetLibrary()->GetFalse(); } @@ -325,7 +325,7 @@ JSONStringifier::ToJSON(_In_ JavascriptString* key, _In_ RecyclableObject* value } if (JavascriptConversion::IsCallable(toJSON)) { - RecyclableObject* func = RecyclableObject::UnsafeFromVar(toJSON); + RecyclableObject* func = UnsafeVarTo(toJSON); Var values[2]; Arguments args(2, values); args.Values[0] = valueObject; @@ -342,7 +342,7 @@ JSONStringifier::ToJSON(_In_ JavascriptString* key, _In_ RecyclableObject* value uint32 JSONStringifier::ReadArrayLength(_In_ RecyclableObject* value) { - JavascriptArray* arr = JavascriptOperators::TryFromVar(value); + JavascriptArray* arr = JavascriptArray::TryVarToNonES5Array(value); if (arr != nullptr) { return arr->GetLength(); @@ -361,7 +361,7 @@ void JSONStringifier::ReadArrayElement(uint32 index, _In_ RecyclableObject* arr, _Out_ JSONProperty* prop, _In_ JSONObjectStack* objectStack) { Var value = nullptr; - JavascriptArray* jsArray = JavascriptOperators::TryFromVar(arr); + JavascriptArray* jsArray = JavascriptArray::TryVarToNonES5Array(arr); if (jsArray && !jsArray->IsCrossSiteObject()) { value = jsArray->DirectGetItem(index); @@ -701,7 +701,7 @@ JSONStringifier::ReadData(_In_ RecyclableObject* valueObj, _Out_ JSONProperty* p return; case TypeIds_Boolean: - if (JavascriptBoolean::UnsafeFromVar(valueObj)->GetValue() != FALSE) + if (UnsafeVarTo(valueObj)->GetValue() != FALSE) { prop->type = JSONContentType::True; this->totalStringLength = UInt32Math::Add(this->totalStringLength, Constants::TrueStringLength); @@ -714,11 +714,11 @@ JSONStringifier::ReadData(_In_ RecyclableObject* valueObj, _Out_ JSONProperty* p return; case TypeIds_Int64Number: - this->SetNumericProperty(static_cast(JavascriptInt64Number::UnsafeFromVar(valueObj)->GetValue()), valueObj, prop); + this->SetNumericProperty(static_cast(UnsafeVarTo(valueObj)->GetValue()), valueObj, prop); return; case TypeIds_UInt64Number: - this->SetNumericProperty(static_cast(JavascriptUInt64Number::UnsafeFromVar(valueObj)->GetValue()), valueObj, prop); + this->SetNumericProperty(static_cast(UnsafeVarTo(valueObj)->GetValue()), valueObj, prop); return; #if !FLOATVAR @@ -728,7 +728,7 @@ JSONStringifier::ReadData(_In_ RecyclableObject* valueObj, _Out_ JSONProperty* p #endif case TypeIds_String: - prop->stringValue = JavascriptString::UnsafeFromVar(valueObj); + prop->stringValue = UnsafeVarTo(valueObj); prop->type = JSONContentType::String; this->totalStringLength = UInt32Math::Add(this->totalStringLength, CalculateStringElementLength(prop->stringValue)); return; diff --git a/lib/Runtime/Library/JavascriptArray.cpp b/lib/Runtime/Library/JavascriptArray.cpp index 2ff81ce8166..d7d38dc34c9 100644 --- a/lib/Runtime/Library/JavascriptArray.cpp +++ b/lib/Runtime/Library/JavascriptArray.cpp @@ -387,7 +387,7 @@ using namespace Js; JavascriptArray::JavascriptArray(uint32 length, DynamicType * type) : ArrayObject(type, false, length) { - Assert(JavascriptArray::Is(type->GetTypeId())); + Assert(JavascriptArray::IsNonES5Array(type->GetTypeId())); Assert(EmptySegment->length == 0 && EmptySegment->size == 0 && EmptySegment->next == NULL); InitArrayFlags(DynamicObjectFlags::InitialArrayValue); SetHeadAndLastUsedSegment(const_cast(EmptySegment)); @@ -452,17 +452,22 @@ using namespace Js; SparseArraySegment::From(head)->FillSegmentBuffer(0, size); } - bool JavascriptArray::Is(Var aValue) + bool JavascriptArray::IsNonES5Array(Var aValue) { TypeId typeId = JavascriptOperators::GetTypeId(aValue); - return JavascriptArray::Is(typeId); + return JavascriptArray::IsNonES5Array(typeId); } - bool JavascriptArray::Is(TypeId typeId) + bool JavascriptArray::IsNonES5Array(TypeId typeId) { return typeId >= TypeIds_ArrayFirst && typeId <= TypeIds_ArrayLast; } + JavascriptArray* JavascriptArray::TryVarToNonES5Array(Var aValue) + { + return JavascriptArray::IsNonES5Array(aValue) ? UnsafeVarTo(aValue) : nullptr; + } + bool JavascriptArray::IsVarArray(Var aValue) { TypeId typeId = JavascriptOperators::GetTypeId(aValue); @@ -506,39 +511,25 @@ using namespace Js; } } - JavascriptArray* JavascriptArray::FromVar(Var aValue) - { - AssertOrFailFastMsg(IsAnyArray(aValue), "Ensure var is actually a 'JavascriptArray'"); - - return static_cast(aValue); - } - - JavascriptArray* JavascriptArray::UnsafeFromVar(Var aValue) - { - AssertMsg(IsAnyArray(aValue), "Ensure var is actually a 'JavascriptArray'"); - - return static_cast(aValue); - } - // Get JavascriptArray* from a Var, which is either a JavascriptArray* or ESArray*. JavascriptArray* JavascriptArray::FromAnyArray(Var aValue) { - AssertOrFailFastMsg(Is(aValue) || ES5Array::Is(aValue), "Ensure var is actually a 'JavascriptArray' or 'ES5Array'"); + AssertOrFailFastMsg(VarIs(aValue), "Ensure var is actually a 'JavascriptArray' or 'ES5Array'"); - return static_cast(RecyclableObject::FromVar(aValue)); + return static_cast(VarTo(aValue)); } JavascriptArray* JavascriptArray::UnsafeFromAnyArray(Var aValue) { - AssertMsg(Is(aValue) || ES5Array::Is(aValue), "Ensure var is actually a 'JavascriptArray' or 'ES5Array'"); + AssertMsg(VarIs(aValue), "Ensure var is actually a 'JavascriptArray' or 'ES5Array'"); - return static_cast(RecyclableObject::UnsafeFromVar(aValue)); + return static_cast(UnsafeVarTo(aValue)); } // Check if a Var is a direct-accessible (fast path) JavascriptArray. bool JavascriptArray::IsDirectAccessArray(Var aValue) { - return RecyclableObject::Is(aValue) && + return VarIs(aValue) && (VirtualTableInfo::HasVirtualTable(aValue) || VirtualTableInfo::HasVirtualTable(aValue) || VirtualTableInfo::HasVirtualTable(aValue)); @@ -552,15 +543,15 @@ using namespace Js; } SparseArraySegmentBase* inlineHeadSegment = nullptr; - if (JavascriptNativeArray::Is(pArr)) + if (VarIs(pArr)) { - if (JavascriptNativeFloatArray::Is(pArr)) + if (VarIs(pArr)) { inlineHeadSegment = DetermineInlineHeadSegmentPointer((JavascriptNativeFloatArray*)pArr); } else { - AssertOrFailFast(JavascriptNativeIntArray::Is(pArr)); + AssertOrFailFast(VarIs(pArr)); inlineHeadSegment = DetermineInlineHeadSegmentPointer((JavascriptNativeIntArray*)pArr); } @@ -609,7 +600,7 @@ using namespace Js; *isObjectWithArrayRef = false; - if (!RecyclableObject::Is(var)) + if (!VarIs(var)) { return nullptr; } @@ -633,7 +624,7 @@ using namespace Js; if (!array) { - array = FromVar(var); + array = VarTo(var); } return array; } @@ -647,8 +638,8 @@ using namespace Js; if (*pVTable == VirtualTableInfo::Address || *pVTable == VirtualTableInfo>::Address) { - ArrayObject* objectArray = DynamicObject::FromVar(var)->GetObjectArray(); - *pArray = (objectArray && Is(objectArray)) ? FromVar(objectArray) : nullptr; + ArrayObject* objectArray = VarTo(var)->GetObjectArray(); + *pArray = (objectArray && VarIs(objectArray)) ? VarTo(objectArray) : nullptr; if (!(*pArray)) { return false; @@ -674,7 +665,7 @@ using namespace Js; *isObjectWithArrayRef = false; *arrayTypeIdRef = TypeIds_Undefined; - if(!RecyclableObject::Is(var)) + if(!VarIs(var)) { return nullptr; } @@ -683,8 +674,8 @@ using namespace Js; INT_PTR vtable = VirtualTableInfoBase::GetVirtualTable(var); if(vtable == VirtualTableInfo::Address) { - ArrayObject* objectArray = DynamicObject::FromVar(var)->GetObjectArray(); - array = (objectArray && Is(objectArray)) ? FromVar(objectArray) : nullptr; + ArrayObject* objectArray = VarTo(var)->GetObjectArray(); + array = (objectArray && IsNonES5Array(objectArray)) ? VarTo(objectArray) : nullptr; if(!array) { return nullptr; @@ -712,7 +703,7 @@ using namespace Js; if(!array) { - array = FromVar(var); + array = VarTo(var); } return array; } @@ -1095,8 +1086,8 @@ using namespace Js; JIT_HELPER_REENTRANT_HEADER(ScrArr_ProfiledNewInstance); ARGUMENTS(args, callInfo); - Assert(JavascriptFunction::Is(function) && - JavascriptFunction::FromVar(function)->GetFunctionInfo() == &JavascriptArray::EntryInfo::NewInstance); + Assert(VarIs(function) && + VarTo(function)->GetFunctionInfo() == &JavascriptArray::EntryInfo::NewInstance); Assert(callInfo.Count >= 2); ArrayCallSiteInfo *arrayInfo = (ArrayCallSiteInfo*)args[0]; @@ -1224,7 +1215,7 @@ using namespace Js; pNew = CreateArrayFromConstructorNoArg(function, scriptContext); return isCtorSuperCall ? - JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), pNew, nullptr, scriptContext) : + JavascriptOperators::OrdinaryCreateFromConstructor(VarTo(newTarget), pNew, nullptr, scriptContext) : pNew; } @@ -1288,7 +1279,7 @@ using namespace Js; pNew->ValidateArray(); #endif return isCtorSuperCall ? - JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), pNew, nullptr, scriptContext) : + JavascriptOperators::OrdinaryCreateFromConstructor(VarTo(newTarget), pNew, nullptr, scriptContext) : pNew; } @@ -1313,8 +1304,8 @@ using namespace Js; Var JavascriptArray::ProfiledNewInstanceNoArg(RecyclableObject *function, ScriptContext *scriptContext, ArrayCallSiteInfo *arrayInfo, RecyclerWeakReference *weakFuncRef) { JIT_HELPER_NOT_REENTRANT_HEADER(ScrArr_ProfiledNewInstanceNoArg, reentrancylock, scriptContext->GetThreadContext()); - Assert(JavascriptFunction::Is(function) && - JavascriptFunction::FromVar(function)->GetFunctionInfo() == &JavascriptArray::EntryInfo::NewInstance); + Assert(VarIs(function) && + VarTo(function)->GetFunctionInfo() == &JavascriptArray::EntryInfo::NewInstance); if (arrayInfo->IsNativeIntArray()) { @@ -1816,7 +1807,7 @@ using namespace Js; template<> void JavascriptArray::ChangeArrayTypeToNativeArray(JavascriptArray * varArray, ScriptContext * scriptContext) { - AssertMsg(!JavascriptNativeArray::Is(varArray), "Ensure that the incoming Array is a Var array"); + AssertMsg(!VarIs(varArray), "Ensure that the incoming Array is a Var array"); if (varArray->GetType() == scriptContext->GetLibrary()->GetArrayType()) { @@ -1863,7 +1854,7 @@ using namespace Js; template<> void JavascriptArray::ChangeArrayTypeToNativeArray(JavascriptArray * varArray, ScriptContext * scriptContext) { - AssertMsg(!JavascriptNativeArray::Is(varArray), "Ensure that the incoming Array is a Var array"); + AssertMsg(!VarIs(varArray), "Ensure that the incoming Array is a Var array"); if (varArray->GetType() == scriptContext->GetLibrary()->GetArrayType()) { @@ -1923,7 +1914,7 @@ using namespace Js; template NativeArrayType *JavascriptArray::ConvertToNativeArrayInPlace(JavascriptArray *varArray) { - AssertMsg(!JavascriptNativeArray::Is(varArray), "Ensure that the incoming Array is a Var array"); + AssertMsg(!VarIs(varArray), "Ensure that the incoming Array is a Var array"); ScriptContext *scriptContext = varArray->GetScriptContext(); SparseArraySegmentBase *seg, *nextSeg, *prevSeg = nullptr; @@ -2543,7 +2534,7 @@ using namespace Js; Var JavascriptNativeArray::FindMinOrMax(Js::ScriptContext * scriptContext, bool findMax) { - if (JavascriptNativeIntArray::Is(this)) + if (VarIs(this)) { return this->FindMinOrMax(scriptContext, findMax); } @@ -2758,11 +2749,11 @@ using namespace Js; uint32 JavascriptArray::GetNextIndex(uint32 index) const { - if (JavascriptNativeIntArray::Is((Var)this)) + if (VarIs((Var)this)) { return this->GetNextIndexHelper(index); } - else if (JavascriptNativeFloatArray::Is((Var)this)) + else if (VarIs((Var)this)) { return this->GetNextIndexHelper(index); } @@ -3120,7 +3111,7 @@ using namespace Js; void JavascriptArray::CreateDataPropertyOrThrow(RecyclableObject * obj, BigIndex index, Var item, ScriptContext * scriptContext) { JS_REENTRANCY_LOCK(jsReentLock, scriptContext->GetThreadContext()); - JavascriptArray * arr = JavascriptOperators::TryFromVar(obj); + JavascriptArray * arr = JavascriptArray::TryVarToNonES5Array(obj); if (arr != nullptr) { arr->GenericDirectSetItemAt(index, item); @@ -3161,7 +3152,7 @@ using namespace Js; Assert(obj != nullptr); Assert(length != nullptr); - *array = JavascriptOperators::TryFromVar(arg); + *array = JavascriptArray::TryVarToNonES5Array(arg); if (*array && !(*array)->IsCrossSiteObject()) { #if ENABLE_COPYONACCESS_ARRAY @@ -3221,7 +3212,7 @@ using namespace Js; ConcatSpreadableState previousItemSpreadableState /*= ConcatSpreadableState_NotChecked*/, BigIndex *firstPromotedItemLength /* = nullptr */) { JS_REENTRANCY_LOCK(jsReentLock, scriptContext->GetThreadContext()); - JavascriptArray* pDestArray = JavascriptOperators::TryFromVar(pDestObj); + JavascriptArray* pDestArray = JavascriptArray::TryVarToNonES5Array(pDestObj); if (pDestArray) { // ConcatArgs function expects to work on the Var array so we are ensuring it. @@ -3255,7 +3246,7 @@ using namespace Js; } if (pDestArray && JavascriptArray::IsDirectAccessArray(aItem) && JavascriptArray::IsDirectAccessArray(pDestArray) - && BigIndex(idxDest + JavascriptArray::UnsafeFromVar(aItem)->length).IsSmallIndex() && !JavascriptArray::UnsafeFromVar(aItem)->IsFillFromPrototypes()) // Fast path + && BigIndex(idxDest + UnsafeVarTo(aItem)->length).IsSmallIndex() && !UnsafeVarTo(aItem)->IsFillFromPrototypes()) // Fast path { JavascriptNativeIntArray *pIntItemArray = JavascriptOperators::TryFromVar(aItem); if (pIntItemArray) @@ -3273,7 +3264,7 @@ using namespace Js; } else { - JavascriptArray* pItemArray = JavascriptArray::UnsafeFromVar(aItem); + JavascriptArray* pItemArray = UnsafeVarTo(aItem); JS_REENTRANT(jsReentLock, CopyArrayElements(pDestArray, BigIndex(idxDest).GetSmallIndex(), pItemArray)); idxDest = idxDest + pItemArray->length; } @@ -3281,7 +3272,7 @@ using namespace Js; } else { - AssertOrFailFast(RecyclableObject::Is(aItem)); + AssertOrFailFast(VarIs(aItem)); //CONSIDER: enumerating remote array instead of walking all indices BigIndex length; @@ -3309,7 +3300,7 @@ using namespace Js; JavascriptError::ThrowTypeError(scriptContext, JSERR_IllegalArraySizeAndLength); } - RecyclableObject* itemObject = RecyclableObject::FromVar(aItem); + RecyclableObject* itemObject = VarTo(aItem); Var subItem; uint32 lengthToUin32Max = length.IsSmallIndex() ? length.GetSmallIndex() : MaxArrayLength; for (uint32 idxSubItem = 0u; idxSubItem < lengthToUin32Max; ++idxSubItem) @@ -3398,7 +3389,7 @@ using namespace Js; bool spreadable = false; JS_REENTRANT(jsReentLock, spreadable = !!JavascriptOperators::IsConcatSpreadable(aItem)); - if (!JavascriptNativeIntArray::Is(pDestArray)) + if (!VarIsCorrectType(pDestArray)) { JS_REENTRANT(jsReentLock, ConcatArgs(pDestArray, remoteTypeIds, args, scriptContext, idxArg, idxDest, spreadable ? ConcatSpreadableState_CheckedAndTrue : ConcatSpreadableState_CheckedAndFalse)); @@ -3409,7 +3400,7 @@ using namespace Js; { JS_REENTRANT(jsReentLock, pDestArray->SetItem(idxDest, aItem, PropertyOperation_ThrowIfNotExtensible)); idxDest++; - if (!JavascriptNativeIntArray::Is(pDestArray)) // SetItem could convert pDestArray to a var array if aItem is not an integer if so fall back + if (!VarIsCorrectType(pDestArray)) // SetItem could convert pDestArray to a var array if aItem is not an integer if so fall back { JS_REENTRANT(jsReentLock, ConcatArgs(pDestArray, remoteTypeIds, args, scriptContext, idxArg + 1, idxDest, ConcatSpreadableState_NotChecked)); return pDestArray; @@ -3482,7 +3473,7 @@ using namespace Js; bool spreadable = false; JS_REENTRANT(jsReentLock, spreadable = !!JavascriptOperators::IsConcatSpreadable(aItem)); - if (!JavascriptNativeFloatArray::Is(pDestArray)) + if (!VarIsCorrectType(pDestArray)) { JS_REENTRANT(jsReentLock, ConcatArgs(pDestArray, remoteTypeIds, args, scriptContext, idxArg, idxDest, spreadable ? ConcatSpreadableState_CheckedAndTrue : ConcatSpreadableState_CheckedAndFalse)); @@ -3494,7 +3485,7 @@ using namespace Js; JS_REENTRANT(jsReentLock, pDestArray->SetItem(idxDest, aItem, PropertyOperation_ThrowIfNotExtensible)); idxDest = idxDest + 1; - if (!JavascriptNativeFloatArray::Is(pDestArray)) // SetItem could convert pDestArray to a var array if aItem is not an integer if so fall back + if (!VarIsCorrectType(pDestArray)) // SetItem could convert pDestArray to a var array if aItem is not an integer if so fall back { JS_REENTRANT(jsReentLock, ConcatArgs(pDestArray, remoteTypeIds, args, scriptContext, idxArg + 1, idxDest, ConcatSpreadableState_NotChecked)); return pDestArray; @@ -3505,7 +3496,7 @@ using namespace Js; bool converted = false; if (JavascriptArray::IsAnyArray(aItem) || remoteTypeIds[idxArg] == TypeIds_Array) { - bool isFillFromPrototypes = JavascriptArray::UnsafeFromVar(aItem)->IsFillFromPrototypes(); + bool isFillFromPrototypes = UnsafeVarTo(aItem)->IsFillFromPrototypes(); JavascriptNativeIntArray * pIntItemArray = JavascriptOperators::TryFromVar(aItem); if (pIntItemArray && !isFillFromPrototypes) // Fast path { @@ -3612,10 +3603,10 @@ using namespace Js; JavascriptArray * pItemArray = JavascriptArray::FromAnyArray(aItem); if (isFloat) { - if (!JavascriptNativeIntArray::Is(pItemArray)) + if (!VarIs(pItemArray)) { isInt = false; - if (!JavascriptNativeFloatArray::Is(pItemArray)) + if (!VarIs(pItemArray)) { isFloat = false; } @@ -3634,7 +3625,7 @@ using namespace Js; // worth it. isInt = false; isFloat = false; - if (!JavascriptProxy::Is(aItem)) + if (!VarIs(aItem)) { if (scriptContext->GetConfig()->IsES6ToLengthEnabled()) { @@ -3719,15 +3710,15 @@ using namespace Js; // so that the data will be converted on copy. if (isInt) { - if (JavascriptNativeIntArray::Is(pDestObj)) + if (VarIs(pDestObj)) { isArray = true; } else { isInt = false; - isFloat = JavascriptNativeFloatArray::Is(pDestObj); - isArray = JavascriptArray::Is(pDestObj); + isFloat = VarIs(pDestObj); + isArray = JavascriptArray::IsNonES5Array(pDestObj); } } else if (isFloat) @@ -3740,8 +3731,8 @@ using namespace Js; } else { - isFloat = JavascriptNativeFloatArray::Is(pDestObj); - isArray = JavascriptArray::Is(pDestObj); + isFloat = VarIs(pDestObj); + isArray = JavascriptArray::IsNonES5Array(pDestObj); } } else @@ -3762,7 +3753,7 @@ using namespace Js; } else { - isArray = JavascriptArray::Is(pDestObj); + isArray = JavascriptArray::IsNonES5Array(pDestObj); } } } @@ -3772,14 +3763,14 @@ using namespace Js; { if (isInt) { - JavascriptNativeIntArray *pIntArray = isArray ? JavascriptNativeIntArray::FromVar(pDestObj) : scriptContext->GetLibrary()->CreateNativeIntArray(cDestLength); + JavascriptNativeIntArray *pIntArray = isArray ? VarTo(pDestObj) : scriptContext->GetLibrary()->CreateNativeIntArray(cDestLength); pIntArray->EnsureHead(); JS_REENTRANT(jsReentLock, pDestArray = ConcatIntArgs(pIntArray, remoteTypeIds, args, scriptContext)); } else if (isFloat) { - JavascriptNativeFloatArray *pFArray = isArray ? JavascriptNativeFloatArray::FromVar(pDestObj) : scriptContext->GetLibrary()->CreateNativeFloatArray(cDestLength); + JavascriptNativeFloatArray *pFArray = isArray ? VarTo(pDestObj) : scriptContext->GetLibrary()->CreateNativeFloatArray(cDestLength); pFArray->EnsureHead(); JS_REENTRANT(jsReentLock, pDestArray = ConcatFloatArgs(pFArray, remoteTypeIds, args, scriptContext)); @@ -3787,7 +3778,7 @@ using namespace Js; else { - pDestArray = isArray ? JavascriptArray::FromVar(pDestObj) : scriptContext->GetLibrary()->CreateArray(cDestLength); + pDestArray = isArray ? VarTo(pDestObj) : scriptContext->GetLibrary()->CreateArray(cDestLength); // if the constructor has changed then we no longer specialize for ints and floats pDestArray->EnsureHead(); @@ -3926,7 +3917,7 @@ using namespace Js; // The evaluation of method arguments may change the type of the array. Hence, we do that prior to the actual helper method calls. // The if clause of the conditional statement below applies to an JavascriptArray or TypedArray instances. The rest of the conditional // clauses apply to an ES5Array or other valid Javascript objects. - if ((pArr || TypedArrayBase::Is(obj)) && (length.IsSmallIndex() || length.IsUint32Max())) + if ((pArr || VarIs(obj)) && (length.IsSmallIndex() || length.IsUint32Max())) { uint32 len = length.IsUint32Max() ? MaxArrayLength : length.GetSmallIndex(); JS_REENTRANT(jsReentLock, BOOL gotParam = GetParamForIndexOf(len, args, search, fromIndex, scriptContext)); @@ -3953,9 +3944,9 @@ using namespace Js; } // Side effects (such as defining a property in a ToPrimitive call) during evaluation of fromIndex argument may convert the array to an ES5 array. - if (pArr && !JavascriptArray::Is(obj)) + if (pArr && !JavascriptArray::IsNonES5Array(obj)) { - AssertOrFailFastMsg(ES5Array::Is(obj), "The array should have been converted to an ES5Array"); + AssertOrFailFastMsg(VarIs(obj), "The array should have been converted to an ES5Array"); pArr = nullptr; } @@ -3988,9 +3979,9 @@ using namespace Js; case Js::TypeIds_Array: JS_REENTRANT_UNLOCK(jsReentLock, return TemplatedIndexOfHelper(pArr, search, fromIndex, len, scriptContext)); case Js::TypeIds_NativeIntArray: - JS_REENTRANT_UNLOCK(jsReentLock, return TemplatedIndexOfHelper(JavascriptNativeIntArray::UnsafeFromVar(pArr), search, fromIndex, len, scriptContext)); + JS_REENTRANT_UNLOCK(jsReentLock, return TemplatedIndexOfHelper(UnsafeVarTo(pArr), search, fromIndex, len, scriptContext)); case Js::TypeIds_NativeFloatArray: - JS_REENTRANT_UNLOCK(jsReentLock, return TemplatedIndexOfHelper(JavascriptNativeFloatArray::UnsafeFromVar(pArr), search, fromIndex, len, scriptContext)); + JS_REENTRANT_UNLOCK(jsReentLock, return TemplatedIndexOfHelper(UnsafeVarTo(pArr), search, fromIndex, len, scriptContext)); default: AssertMsg(FALSE, "invalid array typeid"); JS_REENTRANT_UNLOCK(jsReentLock, return TemplatedIndexOfHelper(pArr, search, fromIndex, len, scriptContext)); @@ -4203,7 +4194,7 @@ using namespace Js; //Consider: enumerating instead of walking all indices for (P i = fromIndex; i < toIndex; i++) { - if (!TryTemplatedGetItem(pArr, i, &element, scriptContext, !includesAlgorithm)) + if (!TryTemplatedGetItem(pArr, i, &element, scriptContext, !includesAlgorithm)) { if (doUndefinedSearch) { @@ -4244,7 +4235,7 @@ using namespace Js; int32 JavascriptArray::HeadSegmentIndexOfHelper(Var search, uint32 &fromIndex, uint32 toIndex, bool includesAlgorithm, ScriptContext * scriptContext) { - Assert(Is(GetTypeId()) && !JavascriptNativeArray::Is(GetTypeId())); + Assert(IsNonES5Array(GetTypeId()) && !JavascriptNativeArray::Is(GetTypeId())); if (!HasNoMissingValues() || fromIndex >= GetHead()->length) { @@ -4516,7 +4507,7 @@ using namespace Js; JS_REENTRANCY_LOCK(jsReentLock, scriptContext->GetThreadContext()); SETOBJECT_FOR_MUTATION(jsReentLock, thisArg); - JavascriptArray * arr = JavascriptOperators::TryFromVar(thisArg); + JavascriptArray * arr = JavascriptArray::TryVarToNonES5Array(thisArg); JavascriptProxy * proxy = JavascriptOperators::TryFromVar(thisArg); bool isArray = arr && (scriptContext == arr->GetScriptContext()); bool isProxy = proxy && (scriptContext == proxy->GetScriptContext()); @@ -4568,17 +4559,17 @@ using namespace Js; JS_REENTRANT(jsReentLock, res = JoinArrayHelper(arr, separator, scriptContext)); break; case Js::TypeIds_NativeIntArray: - JS_REENTRANT(jsReentLock, res = JoinArrayHelper(JavascriptNativeIntArray::UnsafeFromVar(arr), separator, scriptContext)); + JS_REENTRANT(jsReentLock, res = JoinArrayHelper(UnsafeVarTo(arr), separator, scriptContext)); break; case Js::TypeIds_NativeFloatArray: - JS_REENTRANT(jsReentLock, res = JoinArrayHelper(JavascriptNativeFloatArray::UnsafeFromVar(arr), separator, scriptContext)); + JS_REENTRANT(jsReentLock, res = JoinArrayHelper(UnsafeVarTo(arr), separator, scriptContext)); break; } } - else if (RecyclableObject::Is(thisArg)) + else if (VarIs(thisArg)) { - JS_REENTRANT(jsReentLock, res = JoinOtherHelper(RecyclableObject::FromVar(thisArg), separator, scriptContext)); + JS_REENTRANT(jsReentLock, res = JoinOtherHelper(VarTo(thisArg), separator, scriptContext)); } else { @@ -4643,7 +4634,7 @@ using namespace Js; cs->Append(separator); } - JS_REENTRANT(jsReentLock, gotItem = TryTemplatedGetItem(arr, i, &item, scriptContext)); + JS_REENTRANT(jsReentLock, gotItem = TryTemplatedGetItem(arr, i, &item, scriptContext)); if (gotItem) { JS_REENTRANT(jsReentLock, cs->Append(JavascriptArray::JoinToString(item, scriptContext))); @@ -4669,7 +4660,7 @@ using namespace Js; { JS_REENTRANT(jsReentLock, res = JavascriptArray::JoinToString(item, scriptContext)); } - JS_REENTRANT(jsReentLock, gotItem = TryTemplatedGetItem(arr, 1u, &item, scriptContext)); + JS_REENTRANT(jsReentLock, gotItem = TryTemplatedGetItem(arr, 1u, &item, scriptContext)); if (gotItem) { JS_REENTRANT(jsReentLock, JavascriptString *const itemString = JavascriptArray::JoinToString(item, scriptContext)); @@ -4823,9 +4814,9 @@ using namespace Js; } // Side effects (such as defining a property in a ToPrimitive call) during evaluation of fromIndex argument may convert the array to an ES5 array. - if (pArr && !JavascriptArray::Is(obj)) + if (pArr && !JavascriptArray::IsNonES5Array(obj)) { - AssertOrFailFastMsg(ES5Array::Is(obj), "The array should have been converted to an ES5Array"); + AssertOrFailFastMsg(VarIs(obj), "The array should have been converted to an ES5Array"); pArr = nullptr; } @@ -4836,9 +4827,9 @@ using namespace Js; case Js::TypeIds_Array: JS_REENTRANT_UNLOCK(jsReentLock, return LastIndexOfHelper(pArr, search, fromIndex, scriptContext)); case Js::TypeIds_NativeIntArray: - JS_REENTRANT_UNLOCK(jsReentLock, return LastIndexOfHelper(JavascriptNativeIntArray::UnsafeFromVar(pArr), search, fromIndex, scriptContext)); + JS_REENTRANT_UNLOCK(jsReentLock, return LastIndexOfHelper(UnsafeVarTo(pArr), search, fromIndex, scriptContext)); case Js::TypeIds_NativeFloatArray: - JS_REENTRANT_UNLOCK(jsReentLock, return LastIndexOfHelper(JavascriptNativeFloatArray::UnsafeFromVar(pArr), search, fromIndex, scriptContext)); + JS_REENTRANT_UNLOCK(jsReentLock, return LastIndexOfHelper(UnsafeVarTo(pArr), search, fromIndex, scriptContext)); default: AssertMsg(FALSE, "invalid array typeid"); JS_REENTRANT_UNLOCK(jsReentLock, return LastIndexOfHelper(pArr, search, fromIndex, scriptContext)); @@ -4925,7 +4916,7 @@ using namespace Js; { uint32 index = end - i; - if (!TryTemplatedGetItem(pArr, index, &element, scriptContext)) + if (!TryTemplatedGetItem(pArr, index, &element, scriptContext)) { continue; } @@ -4955,8 +4946,8 @@ using namespace Js; void JavascriptNativeArray::PopWithNoDst(Var nativeArray) { JIT_HELPER_NOT_REENTRANT_NOLOCK_HEADER(Array_NativePopWithNoDst); - Assert(JavascriptNativeArray::Is(nativeArray)); - JavascriptArray * arr = JavascriptArray::FromVar(nativeArray); + Assert(VarIs(nativeArray)); + JavascriptArray * arr = VarTo(nativeArray); // we will bailout on length 0 Assert(arr->GetLength() != 0); @@ -4977,8 +4968,8 @@ using namespace Js; int32 JavascriptNativeIntArray::Pop(ScriptContext * scriptContext, Var object) { JIT_HELPER_NOT_REENTRANT_HEADER(Array_NativeIntPop, reentrancylock, scriptContext->GetThreadContext()); - Assert(JavascriptNativeIntArray::Is(object)); - JavascriptNativeIntArray * arr = JavascriptNativeIntArray::FromVar(object); + Assert(VarIs(object)); + JavascriptNativeIntArray * arr = VarTo(object); Assert(arr->GetLength() != 0); @@ -5006,8 +4997,8 @@ using namespace Js; double JavascriptNativeFloatArray::Pop(ScriptContext * scriptContext, Var object) { JIT_HELPER_NOT_REENTRANT_HEADER(Array_NativeFloatPop, reentrancylock, scriptContext->GetThreadContext()); - Assert(JavascriptNativeFloatArray::Is(object)); - JavascriptNativeFloatArray * arr = JavascriptNativeFloatArray::FromVar(object); + Assert(VarIs(object)); + JavascriptNativeFloatArray * arr = VarTo(object); Assert(arr->GetLength() != 0); @@ -5032,9 +5023,9 @@ using namespace Js; Var JavascriptArray::Pop(ScriptContext * scriptContext, Var object) { JIT_HELPER_REENTRANT_HEADER(Array_VarPop); - if (JavascriptArray::Is(object)) + if (JavascriptArray::IsNonES5Array(object)) { - return EntryPopJavascriptArray(scriptContext, JavascriptArray::FromVar(object)); + return EntryPopJavascriptArray(scriptContext, VarTo(object)); } else { @@ -5141,9 +5132,9 @@ using namespace Js; JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NullOrUndefined, _u("Array.prototype.pop")); } - if (JavascriptArray::Is(args[0])) + if (JavascriptArray::IsNonES5Array(args[0])) { - JS_REENTRANT_UNLOCK(jsReentLock, return EntryPopJavascriptArray(scriptContext, JavascriptArray::FromVar(args.Values[0]))); + JS_REENTRANT_UNLOCK(jsReentLock, return EntryPopJavascriptArray(scriptContext, VarTo(args.Values[0]))); } else { @@ -5165,7 +5156,7 @@ using namespace Js; // JavascriptArray::Push will handle other cases. if (JavascriptNativeIntArray::IsNonCrossSite(array)) { - JavascriptNativeIntArray * nativeIntArray = JavascriptNativeIntArray::UnsafeFromVar(array); + JavascriptNativeIntArray * nativeIntArray = UnsafeVarTo(array); Assert(!nativeIntArray->IsCrossSiteObject()); uint32 n = nativeIntArray->length; @@ -5189,7 +5180,7 @@ using namespace Js; * Pushes Float element in a native Int Array. * We call the generic Push, if the array is not native Float or we have a really big array. */ - Var JavascriptNativeFloatArray::Push(ScriptContext * scriptContext, Var * array, double value) + Var JavascriptNativeFloatArray::Push(ScriptContext * scriptContext, Var array, double value) { JIT_HELPER_REENTRANT_HEADER(Array_NativeFloatPush); JIT_HELPER_SAME_ATTRIBUTES(Array_NativeFloatPush, Array_VarPush); @@ -5197,7 +5188,7 @@ using namespace Js; // JavascriptArray::Push will handle other cases. if(JavascriptNativeFloatArray::IsNonCrossSite(array)) { - JavascriptNativeFloatArray * nativeFloatArray = JavascriptNativeFloatArray::UnsafeFromVar(array); + JavascriptNativeFloatArray * nativeFloatArray = UnsafeVarTo(array); Assert(!nativeFloatArray->IsCrossSiteObject()); uint32 n = nativeFloatArray->length; @@ -5227,7 +5218,7 @@ using namespace Js; args[0] = object; args[1] = value; - if (JavascriptArray::Is(object)) + if (JavascriptArray::IsNonES5Array(object)) { return EntryPushJavascriptArray(scriptContext, args, 2); } @@ -5443,7 +5434,7 @@ using namespace Js; JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NullOrUndefined, _u("Array.prototype.push")); } - if (JavascriptArray::Is(args[0])) + if (JavascriptArray::IsNonES5Array(args[0])) { return EntryPushJavascriptArray(scriptContext, args.Values, args.Info.Count); } @@ -5538,7 +5529,7 @@ using namespace Js; RecyclableObject* protoObj = prototype; if (!(DynamicObject::IsAnyArray(protoObj) || JavascriptOperators::IsObject(protoObj)) - || JavascriptProxy::Is(protoObj) + || VarIs(protoObj) || protoObj->IsExternal()) { hasAnyES5Array = true; @@ -5547,7 +5538,7 @@ using namespace Js; if (DynamicObject::IsAnyArray(protoObj)) { - if (ES5Array::Is(protoObj)) + if (VarIs(protoObj)) { hasAnyES5Array = true; break; @@ -5555,9 +5546,9 @@ using namespace Js; } else if (DynamicType::Is(protoObj->GetTypeId())) { - DynamicObject* dynobj = DynamicObject::UnsafeFromVar(protoObj); + DynamicObject* dynobj = UnsafeVarTo(protoObj); ArrayObject* objectArray = dynobj->GetObjectArray(); - if (objectArray != nullptr && ES5Array::Is(objectArray)) + if (objectArray != nullptr && VarIs(objectArray)) { hasAnyES5Array = true; break; @@ -5593,9 +5584,9 @@ using namespace Js; } // If we came from Array.prototype.map and source object is not a JavascriptArray, source could be a TypedArray - if (!isTypedArrayEntryPoint && pArr == nullptr && TypedArrayBase::Is(obj)) + if (!isTypedArrayEntryPoint && pArr == nullptr && VarIs(obj)) { - typedArrayBase = TypedArrayBase::UnsafeFromVar(obj); + typedArrayBase = UnsafeVarTo(obj); } ThrowTypeErrorOnFailureHelper h(scriptContext, methodName); @@ -5652,11 +5643,11 @@ using namespace Js; pArr->ClearSegmentMap(); // Just dump the segment map on reverse - if (JavascriptNativeIntArray::Is(pArr)) + if (VarIs(pArr)) { isIntArray = true; } - else if (JavascriptNativeFloatArray::Is(pArr)) + else if (VarIs(pArr)) { isFloatArray = true; } @@ -5955,13 +5946,13 @@ using namespace Js; return res; } - bool useNoSideEffectShift = JavascriptArray::Is(args[0]) - && !JavascriptArray::FromVar(args[0])->IsCrossSiteObject() - && !HasAnyES5ArrayInPrototypeChain(JavascriptArray::UnsafeFromVar(args[0])); + bool useNoSideEffectShift = JavascriptArray::IsNonES5Array(args[0]) + && !VarTo(args[0])->IsCrossSiteObject() + && !HasAnyES5ArrayInPrototypeChain(UnsafeVarTo(args[0])); if (useNoSideEffectShift) { - JavascriptArray * pArr = JavascriptArray::UnsafeFromVar(args[0]); + JavascriptArray * pArr = UnsafeVarTo(args[0]); if (pArr->length == 0) { @@ -5996,15 +5987,15 @@ using namespace Js; bool isIntArray = false; bool isFloatArray = false; - if(JavascriptNativeIntArray::Is(pArr)) + if(VarIs(pArr)) { isIntArray = true; } - else if(JavascriptNativeFloatArray::Is(pArr)) + else if(VarIs(pArr)) { isFloatArray = true; } - + // Code below has potential to throw due to OOM or SO. Just FailFast on those cases AutoDisableInterrupt failFastOnError(scriptContext->GetThreadContext()); @@ -6153,7 +6144,7 @@ using namespace Js; Js::JavascriptNativeIntArray *pnewArr = scriptContext->GetLibrary()->CreateNativeIntArray(len); pnewArr->EnsureHead(); #if ENABLE_PROFILE_INFO - pnewArr->CopyArrayProfileInfo(Js::JavascriptNativeIntArray::UnsafeFromVar(baseArray)); + pnewArr->CopyArrayProfileInfo(Js::UnsafeVarTo(baseArray)); #endif return pnewArr; @@ -6163,7 +6154,7 @@ using namespace Js; Js::JavascriptNativeFloatArray *pnewArr = scriptContext->GetLibrary()->CreateNativeFloatArray(len); pnewArr->EnsureHead(); #if ENABLE_PROFILE_INFO - pnewArr->CopyArrayProfileInfo(Js::JavascriptNativeFloatArray::UnsafeFromVar(baseArray)); + pnewArr->CopyArrayProfileInfo(Js::UnsafeVarTo(baseArray)); #endif return pnewArr; @@ -6342,9 +6333,9 @@ using namespace Js; } // Side effects (such as defining a property in a ToPrimitive call) during evaluation of arguments start or end may convert the array to an ES5 array. - if (pArr && !JavascriptArray::Is(obj)) + if (pArr && !JavascriptArray::IsNonES5Array(obj)) { - AssertOrFailFastMsg(ES5Array::Is(obj), "The array should have been converted to an ES5Array"); + AssertOrFailFastMsg(VarIs(obj), "The array should have been converted to an ES5Array"); pArr = nullptr; } @@ -6354,9 +6345,9 @@ using namespace Js; } // If we came from Array.prototype.slice and source object is not a JavascriptArray, source could be a TypedArray - if (!isTypedArrayEntryPoint && pArr == nullptr && TypedArrayBase::Is(obj)) + if (!isTypedArrayEntryPoint && pArr == nullptr && VarIs(obj)) { - typedArrayBase = TypedArrayBase::UnsafeFromVar(obj); + typedArrayBase = UnsafeVarTo(obj); } // If the entry point is %TypedArray%.prototype.slice or the source object is an Array exotic object we should try to load the constructor property @@ -6370,10 +6361,10 @@ using namespace Js; AssertAndFailFast(pArr == nullptr); AssertOrFailFast(JavascriptOperators::IsConstructor(constructor)); - + bool isDefaultConstructor = constructor == defaultConstructor; JS_REENTRANT(jsReentLock, - newObj = RecyclableObject::FromVar( + newObj = VarTo( JavascriptOperators::NewObjectCreationHelper_ReentrancySafe(constructor, isDefaultConstructor, scriptContext->GetThreadContext(), [=]()->Js::Var { Js::Var constructorArgs[] = { constructor, JavascriptNumber::ToVar(newLenT, scriptContext) }; @@ -6418,7 +6409,7 @@ using namespace Js; else { // If the new object we created is an array, remember that as it will save us time setting properties in the object below - newArr = JavascriptOperators::TryFromVar(newObj); + newArr = JavascriptArray::TryVarToNonES5Array(newObj); if (newArr) { #if ENABLE_COPYONACCESS_ARRAY @@ -6441,9 +6432,9 @@ using namespace Js; // The ArraySpeciesCreate call above could have converted the source array into an ES5Array. If this happens // we will process the array elements like an ES5Array. - if (pArr && !JavascriptArray::Is(obj)) + if (pArr && !JavascriptArray::IsNonES5Array(obj)) { - AssertOrFailFastMsg(ES5Array::Is(obj), "The array should have been converted to an ES5Array"); + AssertOrFailFastMsg(VarIs(obj), "The array should have been converted to an ES5Array"); pArr = nullptr; } @@ -6478,11 +6469,11 @@ using namespace Js; { if (isIntArray) { - JS_REENTRANT(jsReentLock, CopyNativeIntArrayElements(JavascriptNativeIntArray::FromVar(newArr), 0, JavascriptNativeIntArray::FromVar(pArr), start, start + newLen)); + JS_REENTRANT(jsReentLock, CopyNativeIntArrayElements(VarTo(newArr), 0, VarTo(pArr), start, start + newLen)); } else if (isFloatArray) { - JS_REENTRANT(jsReentLock, CopyNativeFloatArrayElements(JavascriptNativeFloatArray::FromVar(newArr), 0, JavascriptNativeFloatArray::FromVar(pArr), start, start + newLen)); + JS_REENTRANT(jsReentLock, CopyNativeFloatArrayElements(VarTo(newArr), 0, VarTo(pArr), start, start + newLen)); } else { @@ -6506,9 +6497,9 @@ using namespace Js; // Side-effects in the prototype lookup may have changed the source array into an ES5Array. If this happens // we will process the rest of the array elements like an ES5Array. - if (!JavascriptArray::Is(obj)) + if (!JavascriptArray::IsNonES5Array(obj)) { - AssertOrFailFastMsg(ES5Array::Is(obj), "The array should have been converted to an ES5Array"); + AssertOrFailFastMsg(VarIs(obj), "The array should have been converted to an ES5Array"); JS_REENTRANT_UNLOCK(jsReentLock, return JavascriptArray::SliceObjectHelper(obj, start, i + 1, newArr, newObj, newLen, scriptContext)); } } @@ -6531,9 +6522,9 @@ using namespace Js; // Side-effects in the prototype lookup may have changed the source array into an ES5Array. If this happens // we will process the rest of the array elements like an ES5Array. - if (!JavascriptArray::Is(obj)) + if (!JavascriptArray::IsNonES5Array(obj)) { - AssertOrFailFastMsg(ES5Array::Is(obj), "The array should have been converted to an ES5Array"); + AssertOrFailFastMsg(VarIs(obj), "The array should have been converted to an ES5Array"); JS_REENTRANT_UNLOCK(jsReentLock, return JavascriptArray::SliceObjectHelper(obj, start, i + 1, newArr, newObj, newLen, scriptContext)); } } @@ -6541,7 +6532,7 @@ using namespace Js; } else if (typedArrayBase) { - AssertAndFailFast(TypedArrayBase::Is(typedArrayBase)); + AssertAndFailFast(VarIsCorrectType(typedArrayBase)); // Source is a TypedArray, we must have created the return object via a call to constructor, but newObj may not be a TypedArray (or an array either) TypedArrayBase* newTypedArray = JavascriptOperators::TryFromVar(newObj); @@ -6585,7 +6576,7 @@ using namespace Js; } #ifdef VALIDATE_ARRAY - JavascriptArray * jsArr = JavascriptOperators::TryFromVar(newObj); + JavascriptArray * jsArr = JavascriptArray::TryVarToNonES5Array(newObj); if (jsArr) { jsArr->ValidateArray(); @@ -6621,7 +6612,7 @@ using namespace Js; JavascriptOperators::SetProperty(newObj, newObj, Js::PropertyIds::length, JavascriptNumber::ToVar(newLen, scriptContext), scriptContext, PropertyOperation_ThrowIfNotExtensible)); #ifdef VALIDATE_ARRAY - JavascriptArray * jsArr = JavascriptOperators::TryFromVar(newObj); + JavascriptArray * jsArr = JavascriptArray::TryVarToNonES5Array(newObj); if (jsArr) { jsArr->ValidateArray(); @@ -7012,7 +7003,7 @@ using namespace Js; { if (JavascriptConversion::IsCallable(args[1])) { - compFn = RecyclableObject::FromVar(args[1]); + compFn = VarTo(args[1]); } else { @@ -7030,13 +7021,13 @@ using namespace Js; SETOBJECT_FOR_MUTATION(jsReentLock, args[0]); - bool useNoSideEffectSort = JavascriptArray::Is(args[0]) - && !JavascriptArray::FromVar(args[0])->IsCrossSiteObject() - && !HasAnyES5ArrayInPrototypeChain(JavascriptArray::UnsafeFromVar(args[0])); + bool useNoSideEffectSort = JavascriptArray::IsNonES5Array(args[0]) + && !VarTo(args[0])->IsCrossSiteObject() + && !HasAnyES5ArrayInPrototypeChain(UnsafeVarTo(args[0])); if (useNoSideEffectSort) { - JavascriptArray *arr = JavascriptArray::UnsafeFromVar(args[0]); + JavascriptArray *arr = UnsafeVarTo(args[0]); if (arr->length <= 1) { @@ -7158,9 +7149,9 @@ using namespace Js; } // Side effects (such as defining a property in a ToPrimitive call) during evaluation of arguments start or deleteCount may convert the array to an ES5 array. - if (pArr && !JavascriptArray::Is(pObj)) + if (pArr && !JavascriptArray::IsNonES5Array(pObj)) { - AssertOrFailFastMsg(ES5Array::Is(pObj), "The array should have been converted to an ES5Array"); + AssertOrFailFastMsg(VarIs(pObj), "The array should have been converted to an ES5Array"); pArr = nullptr; } @@ -7495,7 +7486,7 @@ using namespace Js; // insert elements if (insertLen > 0) { - Assert(!JavascriptNativeIntArray::Is(pArr) && !JavascriptNativeFloatArray::Is(pArr)); + Assert(!VarIs(pArr) && !VarIs(pArr)); // InsertPhase SparseArraySegment *segInsert = nullptr; @@ -7595,7 +7586,7 @@ using namespace Js; { pArr = EnsureNonNativeArray(pArr); // If the new object we created is an array, remember that as it will save us time setting properties in the object below - newArr = JavascriptOperators::TryFromVar(newObj); + newArr = JavascriptArray::TryVarToNonES5Array(newObj); if (newArr) { #if ENABLE_COPYONACCESS_ARRAY @@ -7763,7 +7754,7 @@ using namespace Js; } } - pnewArr = JavascriptOperators::TryFromVar(pNewObj); + pnewArr = JavascriptArray::TryVarToNonES5Array(pNewObj); if (pnewArr) { #if ENABLE_COPYONACCESS_ARRAY @@ -7879,7 +7870,7 @@ using namespace Js; if (JavascriptArray::IsDirectAccessArray(args[0])) { - JavascriptArray* arr = JavascriptArray::UnsafeFromVar(args[0]); + JavascriptArray* arr = UnsafeVarTo(args[0]); JS_REENTRANT_UNLOCK(jsReentLock, return ToLocaleString(arr, scriptContext)); } else @@ -8063,13 +8054,13 @@ using namespace Js; } JavascriptArray * pArr = nullptr; - if (JavascriptArray::Is(args[0]) - && !JavascriptArray::FromVar(args[0])->IsCrossSiteObject()) + if (JavascriptArray::IsNonES5Array(args[0]) + && !VarTo(args[0])->IsCrossSiteObject()) { #if ENABLE_COPYONACCESS_ARRAY JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray(args[0]); #endif - pArr = JavascriptArray::FromVar(args[0]); + pArr = VarTo(args[0]); } uint32 unshiftElements = args.Info.Count - 1; @@ -8103,7 +8094,7 @@ using namespace Js; EnsureNonNativeArray(pArr); JS_REENTRANT(jsReentLock, pArr->TruncateToProperties(MaxArrayLength, maxLen)); Assert(pArr->length + unshiftElements == MaxArrayLength); - if (ES5Array::Is(pArr)) + if (VarIs(pArr)) { JS_REENTRANT_UNLOCK(jsReentLock, return UnshiftObjectHelper(args, scriptContext)); } @@ -8115,11 +8106,11 @@ using namespace Js; bool isIntArray = false; bool isFloatArray = false; - if (JavascriptNativeIntArray::Is(pArr)) + if (VarIs(pArr)) { isIntArray = true; } - else if (JavascriptNativeFloatArray::Is(pArr)) + else if (VarIs(pArr)) { isFloatArray = true; } @@ -8227,7 +8218,7 @@ using namespace Js; JS_REENTRANT(jsReentLock, Var join = JavascriptOperators::GetPropertyNoCache(obj, PropertyIds::join, scriptContext)); if (JavascriptConversion::IsCallable(join)) { - RecyclableObject* func = RecyclableObject::FromVar(join); + RecyclableObject* func = VarTo(join); // We need to record implicit call here, because marked the Array.toString as no side effect, // but if we call user code here which may have side effect ThreadContext * threadContext = scriptContext->GetThreadContext(); @@ -8324,7 +8315,7 @@ using namespace Js; SETOBJECT_FOR_MUTATION(jsReentLock, arr); uint32 length = 0; - TypedArrayBase * typedArray = JavascriptOperators::TryFromVar(arr); + TypedArrayBase * typedArray = JavascriptOperators::TryFromVar(static_cast(arr)); if (typedArray) { // For a TypedArray use the actual length of the array. @@ -8478,7 +8469,7 @@ using namespace Js; } } - RecyclableObject* callBackFn = RecyclableObject::FromVar(args[1]); + RecyclableObject* callBackFn = VarTo(args[1]); Var thisArg; if (args.Info.Count > 2) @@ -8491,9 +8482,9 @@ using namespace Js; } // If we came from Array.prototype.find/findIndex and source object is not a JavascriptArray, source could be a TypedArray - if (typedArrayBase == nullptr && pArr == nullptr && TypedArrayBase::Is(obj)) + if (typedArrayBase == nullptr && pArr == nullptr && VarIs(obj)) { - typedArrayBase = TypedArrayBase::UnsafeFromVar(obj); + typedArrayBase = UnsafeVarTo(obj); } // The correct flag value is CallFlags_Value but we pass CallFlags_None in compat modes @@ -8531,9 +8522,9 @@ using namespace Js; // Side-effects in the callback function may have changed the source array into an ES5Array. If this happens // we will process the rest of the array elements like an ES5Array. - if (!JavascriptArray::Is(obj)) + if (!JavascriptArray::IsNonES5Array(obj)) { - AssertOrFailFastMsg(ES5Array::Is(obj), "The array should have been converted to an ES5Array"); + AssertOrFailFastMsg(VarIs(obj), "The array should have been converted to an ES5Array"); JS_REENTRANT_UNLOCK(jsReentLock, return JavascriptArray::FindObjectHelper(obj, length, k + 1, callBackFn, thisArg, scriptContext)); } } @@ -8803,7 +8794,7 @@ using namespace Js; } } - RecyclableObject* callBackFn = RecyclableObject::FromVar(args[1]); + RecyclableObject* callBackFn = VarTo(args[1]); Var thisArg = nullptr; @@ -8817,9 +8808,9 @@ using namespace Js; } // If we came from Array.prototype.map and source object is not a JavascriptArray, source could be a TypedArray - if (typedArrayBase == nullptr && pArr == nullptr && TypedArrayBase::Is(obj)) + if (typedArrayBase == nullptr && pArr == nullptr && VarIs(obj)) { - typedArrayBase = TypedArrayBase::UnsafeFromVar(obj); + typedArrayBase = UnsafeVarTo(obj); } Var element = nullptr; @@ -8829,7 +8820,7 @@ using namespace Js; if (typedArrayBase) { - AssertAndFailFast(TypedArrayBase::Is(typedArrayBase)); + AssertAndFailFast(VarIsCorrectType(typedArrayBase)); uint32 end = (uint32)min(length, (T)typedArrayBase->GetLength()); for (uint32 k = 0; k < end; k++) @@ -8956,7 +8947,7 @@ using namespace Js; } } - RecyclableObject* callBackFn = RecyclableObject::FromVar(args[1]); + RecyclableObject* callBackFn = VarTo(args[1]); Var thisArg = nullptr; if (args.Info.Count > 2) @@ -8969,9 +8960,9 @@ using namespace Js; } // If we came from Array.prototype.some and source object is not a JavascriptArray, source could be a TypedArray - if (typedArrayBase == nullptr && pArr == nullptr && TypedArrayBase::Is(obj)) + if (typedArrayBase == nullptr && pArr == nullptr && VarIs(obj)) { - typedArrayBase = TypedArrayBase::UnsafeFromVar(obj); + typedArrayBase = UnsafeVarTo(obj); } // The correct flag value is CallFlags_Value but we pass CallFlags_None in compat modes @@ -8981,7 +8972,7 @@ using namespace Js; if (typedArrayBase) { - AssertAndFailFast(TypedArrayBase::Is(typedArrayBase)); + AssertAndFailFast(VarIsCorrectType(typedArrayBase)); uint32 end = (uint32)min(length, (T)typedArrayBase->GetLength()); for (uint32 k = 0; k < end; k++) @@ -8990,7 +8981,7 @@ using namespace Js; element = typedArrayBase->DirectGetItem(k); - JS_REENTRANT_UNLOCK(jsReentLock, + JS_REENTRANT_UNLOCK(jsReentLock, BEGIN_SAFE_REENTRANT_CALL(scriptContext->GetThreadContext()) { testResult = CALL_FUNCTION(scriptContext->GetThreadContext(), callBackFn, CallInfo(flags, 4), thisArg, @@ -9086,7 +9077,7 @@ using namespace Js; { JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_NeedFunction, _u("Array.prototype.forEach")); } - callBackFn = RecyclableObject::FromVar(args[1]); + callBackFn = VarTo(args[1]); if (args.Info.Count > 2) { @@ -9177,9 +9168,9 @@ using namespace Js; int64 finalVal = length; // If we came from Array.prototype.copyWithin and source object is not a JavascriptArray, source could be a TypedArray - if (typedArrayBase == nullptr && pArr == nullptr && TypedArrayBase::Is(obj)) + if (typedArrayBase == nullptr && pArr == nullptr && VarIs(obj)) { - typedArrayBase = TypedArrayBase::UnsafeFromVar(obj); + typedArrayBase = UnsafeVarTo(obj); } if (args.Info.Count > 1) @@ -9255,9 +9246,9 @@ using namespace Js; } // Side effects (such as defining a property in a ToPrimitive call) during evaluation of arguments may convert the array to an ES5 array. - if (pArr && !JavascriptArray::Is(obj)) + if (pArr && !JavascriptArray::IsNonES5Array(obj)) { - AssertOrFailFastMsg(ES5Array::Is(obj), "The array should have been converted to an ES5Array"); + AssertOrFailFastMsg(VarIs(obj), "The array should have been converted to an ES5Array"); pArr = nullptr; } @@ -9315,9 +9306,9 @@ using namespace Js; val = pArr->DirectGetItem(fromIndex), pArr->SetItem(toIndex, val, Js::PropertyOperation_ThrowIfNotExtensible)); - if (!JavascriptArray::Is(obj)) + if (!JavascriptArray::IsNonES5Array(obj)) { - AssertOrFailFastMsg(ES5Array::Is(obj), "The array should have been converted to an ES5Array"); + AssertOrFailFastMsg(VarIs(obj), "The array should have been converted to an ES5Array"); pArr = nullptr; } } @@ -9373,9 +9364,9 @@ using namespace Js; JavascriptLibrary* library = scriptContext->GetLibrary(); // If we came from Array.prototype.fill and source object is not a JavascriptArray, source could be a TypedArray - if (typedArrayBase == nullptr && pArr == nullptr && TypedArrayBase::Is(obj)) + if (typedArrayBase == nullptr && pArr == nullptr && VarIs(obj)) { - typedArrayBase = TypedArrayBase::UnsafeFromVar(obj); + typedArrayBase = UnsafeVarTo(obj); } Var fillValue; @@ -9403,9 +9394,9 @@ using namespace Js; // Side-effects in the callback function may have changed the source array into an ES5Array. If this happens // we will process the array elements like an ES5Array. - if (pArr && !JavascriptArray::Is(obj)) + if (pArr && !JavascriptArray::IsNonES5Array(obj)) { - AssertOrFailFastMsg(ES5Array::Is(obj), "The array should have been converted to an ES5Array"); + AssertOrFailFastMsg(VarIs(obj), "The array should have been converted to an ES5Array"); pArr = nullptr; } } @@ -9427,7 +9418,7 @@ using namespace Js; } else { - JS_REENTRANT(jsReentLock, + JS_REENTRANT(jsReentLock, JavascriptOperators::OP_SetElementI_UInt32(obj, u32k, fillValue, scriptContext, Js::PropertyOperation_ThrowIfNotExtensible)); } @@ -9529,7 +9520,7 @@ using namespace Js; } } - RecyclableObject* callBackFn = RecyclableObject::FromVar(args[1]); + RecyclableObject* callBackFn = VarTo(args[1]); Var thisArg; if (args.Info.Count > 2) @@ -9542,9 +9533,9 @@ using namespace Js; } // If we came from Array.prototype.map and source object is not a JavascriptArray, source could be a TypedArray - if (!isTypedArrayEntryPoint && pArr == nullptr && TypedArrayBase::Is(obj)) + if (!isTypedArrayEntryPoint && pArr == nullptr && VarIs(obj)) { - typedArrayBase = TypedArrayBase::UnsafeFromVar(obj); + typedArrayBase = UnsafeVarTo(obj); } // If the entry point is %TypedArray%.prototype.map or the source object is an Array exotic object we should try to load the constructor property @@ -9552,16 +9543,16 @@ using namespace Js; if (isTypedArrayEntryPoint) { JavascriptFunction* defaultConstructor = TypedArrayBase::GetDefaultConstructor(args[0], scriptContext); - JS_REENTRANT(jsReentLock, + JS_REENTRANT(jsReentLock, RecyclableObject* constructor = JavascriptOperators::SpeciesConstructor(typedArrayBase, defaultConstructor, scriptContext)); - + isBuiltinArrayCtor = false; AssertOrFailFast(JavascriptOperators::IsConstructor(constructor)); bool isDefaultConstructor = constructor == defaultConstructor; JS_REENTRANT(jsReentLock, - newObj = RecyclableObject::FromVar( + newObj = VarTo( JavascriptOperators::NewObjectCreationHelper_ReentrancySafe(constructor, isDefaultConstructor, scriptContext->GetThreadContext(), [=]()->Js::Var { Js::Var constructorArgs[] = {constructor, JavascriptNumber::ToVar(length, scriptContext) }; @@ -9589,7 +9580,7 @@ using namespace Js; else { // If the new object we created is an array, remember that as it will save us time setting properties in the object below - newArr = JavascriptOperators::TryFromVar(newObj); + newArr = JavascriptArray::TryVarToNonES5Array(newObj); if (newArr) { #if ENABLE_COPYONACCESS_ARRAY @@ -9610,9 +9601,9 @@ using namespace Js; // The ArraySpeciesCreate call above could have converted the source array into an ES5Array. If this happens // we will process the array elements like an ES5Array. - if (pArr && !JavascriptArray::Is(obj)) + if (pArr && !JavascriptArray::IsNonES5Array(obj)) { - AssertOrFailFastMsg(ES5Array::Is(obj), "The array should have been converted to an ES5Array"); + AssertOrFailFastMsg(VarIs(obj), "The array should have been converted to an ES5Array"); pArr = nullptr; } @@ -9651,16 +9642,16 @@ using namespace Js; // Side-effects in the callback function may have changed the source array into an ES5Array. If this happens // we will process the rest of the array elements like an ES5Array. - if (!JavascriptArray::Is(obj)) + if (!JavascriptArray::IsNonES5Array(obj)) { - AssertOrFailFastMsg(ES5Array::Is(obj), "The array should have been converted to an ES5Array"); + AssertOrFailFastMsg(VarIs(obj), "The array should have been converted to an ES5Array"); JS_REENTRANT_UNLOCK(jsReentLock, return JavascriptArray::MapObjectHelper(obj, length, k + 1, newObj, newArr, isBuiltinArrayCtor, callBackFn, thisArg, scriptContext)); } } } else if (typedArrayBase != nullptr) { - AssertAndFailFast(TypedArrayBase::Is(typedArrayBase)); + AssertAndFailFast(VarIsCorrectType(typedArrayBase)); // Source is a TypedArray, we may have tried to call a constructor, but newObj may not be a TypedArray (or an array either) TypedArrayBase* newTypedArray = JavascriptOperators::TryFromVar(newObj); @@ -9678,7 +9669,7 @@ using namespace Js; // No need to do HasItem, as it cannot be observable unless 'typedArrayBase' is proxy. And we have established that it is indeed typedarray. element = typedArrayBase->DirectGetItem(k); - JS_REENTRANT(jsReentLock, + JS_REENTRANT(jsReentLock, BEGIN_SAFE_REENTRANT_CALL(scriptContext->GetThreadContext()) { mappedValue = CALL_FUNCTION(scriptContext->GetThreadContext(), callBackFn, callBackFnInfo, thisArg, @@ -9706,7 +9697,7 @@ using namespace Js; } #ifdef VALIDATE_ARRAY - if (JavascriptArray::Is(newObj)) + if (JavascriptArray::IsNonES5Array(newObj)) { newArr->ValidateArray(); } @@ -9757,7 +9748,7 @@ using namespace Js; } #ifdef VALIDATE_ARRAY - if (JavascriptArray::Is(newObj)) + if (JavascriptArray::IsNonES5Array(newObj)) { newArr->ValidateArray(); } @@ -9808,7 +9799,7 @@ using namespace Js; JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_NeedFunction, _u("Array.prototype.filter")); } - RecyclableObject* callBackFn = RecyclableObject::FromVar(args[1]); + RecyclableObject* callBackFn = VarTo(args[1]); Var thisArg = nullptr; if (args.Info.Count > 2) @@ -9834,7 +9825,7 @@ using namespace Js; else { // If the new object we created is an array, remember that as it will save us time setting properties in the object below - newArr = JavascriptOperators::TryFromVar(newObj); + newArr = JavascriptArray::TryVarToNonES5Array(newObj); if (newArr) { #if ENABLE_COPYONACCESS_ARRAY @@ -9955,13 +9946,13 @@ using namespace Js; } // If we came from Array.prototype.reduce and source object is not a JavascriptArray, source could be a TypedArray - if (typedArrayBase == nullptr && pArr == nullptr && TypedArrayBase::Is(obj)) + if (typedArrayBase == nullptr && pArr == nullptr && VarIs(obj)) { - typedArrayBase = TypedArrayBase::UnsafeFromVar(obj); + typedArrayBase = UnsafeVarTo(obj); } T k = 0; - RecyclableObject* callBackFn = RecyclableObject::FromVar(args[1]); + RecyclableObject* callBackFn = VarTo(args[1]); Var accumulator = nullptr; Var element = nullptr; @@ -9980,7 +9971,7 @@ using namespace Js; if (typedArrayBase) { - AssertAndFailFast(TypedArrayBase::Is(typedArrayBase)); + AssertAndFailFast(VarIsCorrectType(typedArrayBase)); uint32 end = (uint32)min(length, (T)typedArrayBase->GetLength()); for (; k < end && bPresent == false; k++) @@ -10020,7 +10011,7 @@ using namespace Js; if (typedArrayBase) { - AssertAndFailFast(TypedArrayBase::Is(typedArrayBase)); + AssertAndFailFast(VarIsCorrectType(typedArrayBase)); uint32 end = (uint32)min(length, (T)typedArrayBase->GetLength()); for (; k < end; k++) @@ -10135,12 +10126,12 @@ using namespace Js; } // If we came from Array.prototype.reduceRight and source object is not a JavascriptArray, source could be a TypedArray - if (typedArrayBase == nullptr && pArr == nullptr && TypedArrayBase::Is(obj)) + if (typedArrayBase == nullptr && pArr == nullptr && VarIs(obj)) { - typedArrayBase = TypedArrayBase::UnsafeFromVar(obj); + typedArrayBase = UnsafeVarTo(obj); } - RecyclableObject* callBackFn = RecyclableObject::FromVar(args[1]); + RecyclableObject* callBackFn = VarTo(args[1]); Var accumulator = nullptr; Var element = nullptr; T k = 0; @@ -10160,7 +10151,7 @@ using namespace Js; bool bPresent = false; if (typedArrayBase) { - AssertAndFailFast(TypedArrayBase::Is(typedArrayBase)); + AssertAndFailFast(VarIsCorrectType(typedArrayBase)); uint32 end = (uint32)min(length, (T)typedArrayBase->GetLength()); for (; k < end && bPresent == false; k++) @@ -10198,7 +10189,7 @@ using namespace Js; if (typedArrayBase) { - AssertAndFailFast(TypedArrayBase::Is(typedArrayBase)); + AssertAndFailFast(VarIsCorrectType(typedArrayBase)); uint32 end = (uint32)min(length, (T)typedArrayBase->GetLength()); for (; k < end; k++) @@ -10282,7 +10273,7 @@ using namespace Js; if (JavascriptOperators::IsConstructor(args[0])) { - constructor = RecyclableObject::FromVar(args[0]); + constructor = VarTo(args[0]); } RecyclableObject* items = nullptr; @@ -10292,7 +10283,7 @@ using namespace Js; JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_NeedObject, _u("Array.from")); } - JavascriptArray* itemsArr = JavascriptOperators::TryFromVar(items); + JavascriptArray* itemsArr = JavascriptArray::TryVarToNonES5Array(items); if (itemsArr) { @@ -10309,12 +10300,12 @@ using namespace Js; if (args.Info.Count >= 3 && !JavascriptOperators::IsUndefinedObject(args[2])) { - if (!JavascriptFunction::Is(args[2])) + if (!VarIs(args[2])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_NeedFunction, _u("Array.from")); } - mapFn = JavascriptFunction::FromVar(args[2]); + mapFn = VarTo(args[2]); if (args.Info.Count >= 4) { @@ -10341,14 +10332,14 @@ using namespace Js; Js::CallInfo constructorCallInfo(Js::CallFlags_New, _countof(constructorArgs)); Js::Arguments arguments(constructorCallInfo, constructorArgs); bool isDefaultConstructor = constructor == scriptContext->GetLibrary()->GetArrayConstructor(); - JS_REENTRANT(jsReentLock, - newObj = RecyclableObject::FromVar(JavascriptOperators::NewObjectCreationHelper_ReentrancySafe(constructor, isDefaultConstructor, scriptContext->GetThreadContext(), [=]()->Js::Var + JS_REENTRANT(jsReentLock, + newObj = VarTo(JavascriptOperators::NewObjectCreationHelper_ReentrancySafe(constructor, isDefaultConstructor, scriptContext->GetThreadContext(), [=]()->Js::Var { return JavascriptOperators::NewScObject(constructor, arguments, scriptContext); })) ); - newArr = JavascriptOperators::TryFromVar(newObj); + newArr = JavascriptArray::TryVarToNonES5Array(newObj); if (newArr) { #if ENABLE_COPYONACCESS_ARRAY @@ -10403,13 +10394,13 @@ using namespace Js; Js::Arguments arguments(constructorCallInfo, constructorArgs); bool isDefaultConstructor = constructor == scriptContext->GetLibrary()->GetArrayConstructor(); JS_REENTRANT(jsReentLock, - newObj = RecyclableObject::FromVar(JavascriptOperators::NewObjectCreationHelper_ReentrancySafe(constructor, isDefaultConstructor, scriptContext->GetThreadContext(), [=]()->Js::Var + newObj = VarTo(JavascriptOperators::NewObjectCreationHelper_ReentrancySafe(constructor, isDefaultConstructor, scriptContext->GetThreadContext(), [=]()->Js::Var { return JavascriptOperators::NewScObject(constructor, arguments, scriptContext); })) ); - newArr = JavascriptOperators::TryFromVar(newObj); + newArr = JavascriptArray::TryVarToNonES5Array(newObj); if (newArr) { #if ENABLE_COPYONACCESS_ARRAY @@ -10452,7 +10443,7 @@ using namespace Js; Assert(mapFnThisArg != nullptr); Var kVar = JavascriptNumber::ToVar(k, scriptContext); - JS_REENTRANT(jsReentLock, + JS_REENTRANT(jsReentLock, kValue = scriptContext->GetThreadContext()->ExecuteImplicitCall(mapFn, Js::ImplicitCall_Accessor, [=]()->Js::Var { return CALL_FUNCTION(scriptContext->GetThreadContext(), mapFn, CallInfo(CallFlags_Value, 3), mapFnThisArg, kValue, kVar) @@ -10519,7 +10510,7 @@ using namespace Js; if (JavascriptOperators::IsConstructor(args[0])) { - RecyclableObject* constructor = RecyclableObject::FromVar(args[0]); + RecyclableObject* constructor = VarTo(args[0]); isBuiltinArrayCtor = (constructor == scriptContext->GetLibrary()->GetArrayConstructor()); bool isBuiltInTypedArrayCtor = JavascriptLibrary::IsTypedArrayConstructor(constructor, scriptContext); @@ -10539,10 +10530,10 @@ using namespace Js; return JavascriptOperators::NewScObject(constructor, Js::Arguments(constructorCallInfo, constructorArgs), scriptContext); } }); - ) + ) // If the new object we created is an array, remember that as it will save us time setting properties in the object below - newArr = JavascriptOperators::TryFromVar(newObj); + newArr = JavascriptArray::TryVarToNonES5Array(newObj); if (newArr) { #if ENABLE_COPYONACCESS_ARRAY @@ -10551,9 +10542,9 @@ using namespace Js; SETOBJECT_FOR_MUTATION(jsReentLock, newArr); } - else if (TypedArrayBase::Is(newObj)) + else if (VarIs(newObj)) { - newTypedArray = TypedArrayBase::UnsafeFromVar(newObj); + newTypedArray = UnsafeVarTo(newObj); } } else @@ -10595,7 +10586,7 @@ using namespace Js; for (uint32 k = 0; k < len; k++) { Var kValue = args[k + 1]; - JS_REENTRANT(jsReentLock, ThrowErrorOnFailure(JavascriptArray::SetArrayLikeObjects(RecyclableObject::FromVar(newObj), k, kValue), scriptContext, k)); + JS_REENTRANT(jsReentLock, ThrowErrorOnFailure(JavascriptArray::SetArrayLikeObjects(VarTo(newObj), k, kValue), scriptContext, k)); } } @@ -10717,7 +10708,7 @@ using namespace Js; uint32 random1 = static_cast(rand()); if (random1 % 2 == 0) { - if (JavascriptNativeIntArray::Is(this)) + if (VarIs(this)) { uint32 random2 = static_cast(rand()); if (random2 % 2 == 0) @@ -10729,7 +10720,7 @@ using namespace Js; JavascriptNativeIntArray::ToVarArray(static_cast(this)); } } - else if (JavascriptNativeFloatArray::Is(this)) + else if (VarIs(this)) { JavascriptNativeFloatArray::ToVarArray(static_cast(this)); } @@ -10754,14 +10745,14 @@ using namespace Js; } else if (DynamicType::Is(obj->GetTypeId())) { - DynamicObject* dynobj = DynamicObject::UnsafeFromVar(obj); + DynamicObject* dynobj = UnsafeVarTo(obj); ArrayObject* objectArray = dynobj->GetObjectArray(); arr = (objectArray && JavascriptArray::IsAnyArray(objectArray)) ? JavascriptArray::UnsafeFromAnyArray(objectArray) : nullptr; } if (arr != nullptr) { - if (JavascriptArray::Is(arr)) + if (JavascriptArray::IsNonES5Array(arr)) { arr = EnsureNonNativeArray(arr); ArrayElementEnumerator e(arr, startIndex, limitIndex); @@ -10783,9 +10774,9 @@ using namespace Js; { ScriptContext* scriptContext = obj->GetScriptContext(); - Assert(ES5Array::Is(arr)); + Assert(VarIs(arr)); - ES5Array* es5Array = ES5Array::FromVar(arr); + ES5Array* es5Array = VarTo(arr); ES5ArrayIndexStaticEnumerator e(es5Array); while (e.MoveNext()) @@ -11467,11 +11458,11 @@ using namespace Js; #if ENABLE_COPYONACCESS_ARRAY JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray(arr); #endif - if (JavascriptNativeIntArray::Is(arr)) + if (VarIs(arr)) { arr = JavascriptNativeIntArray::ToVarArray((JavascriptNativeIntArray*)arr); } - else if (JavascriptNativeFloatArray::Is(arr)) + else if (VarIs(arr)) { arr = JavascriptNativeFloatArray::ToVarArray((JavascriptNativeFloatArray*)arr); } @@ -11558,7 +11549,7 @@ using namespace Js; #if ENABLE_COPYONACCESS_ARRAY JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray(arrayToSpread); #endif - JavascriptArray *array = FromVar(arrayToSpread); + JavascriptArray *array = VarTo(arrayToSpread); uint32 arrayLength = array->GetLength(); uint32 actualLength = arrayLength; @@ -11568,7 +11559,7 @@ using namespace Js; actualLength = UInt32Math::Add(actualLength - 1, GetSpreadArgLen(array->DirectGetItem(spreadIndices->elements[i]), scriptContext))); } - JavascriptArray *result = FromVar(OP_NewScArrayWithMissingValues(actualLength, scriptContext)); + JavascriptArray *result = VarTo(OP_NewScArrayWithMissingValues(actualLength, scriptContext)); // Now we copy each element and expand the spread parameters inline. for (unsigned i = 0, spreadArrIndex = 0, resultIndex = 0; i < arrayLength && resultIndex < actualLength; ++i) @@ -11577,7 +11568,7 @@ using namespace Js; // An array needs a slow copy if it is a cross-site object or we have missing values that need to be set to undefined. auto needArraySlowCopy = [&](Var instance) { - JavascriptArray *arr = JavascriptOperators::TryFromVar(instance); + JavascriptArray *arr = JavascriptArray::TryVarToNonES5Array(instance); if (arr) { JS_REENTRANT_UNLOCK(jsReentLock, return arr->IsCrossSiteObject() || arr->IsFillFromPrototypes()); @@ -11588,7 +11579,7 @@ using namespace Js; // Designed to have interchangeable arguments with CopyAnyArrayElementsToVar. auto slowCopy = [&scriptContext, &needArraySlowCopy ](JavascriptArray *dstArray, unsigned dstIndex, Var srcArray, uint32 start, uint32 end) { - Assert(needArraySlowCopy(srcArray) || ArgumentsObject::Is(srcArray) || TypedArrayBase::Is(srcArray) || JavascriptString::Is(srcArray)); + Assert(needArraySlowCopy(srcArray) || VarIs(srcArray) || VarIs(srcArray) || VarIs(srcArray)); JS_REENTRANCY_LOCK(jsReentLock, scriptContext->GetThreadContext()); RecyclableObject *propertyObject; @@ -11644,9 +11635,9 @@ using namespace Js; { JS_REENTRANT(jsReentLock, Var instance = array->DirectGetItem(i)); - if (SpreadArgument::Is(instance)) + if (VarIs(instance)) { - SpreadArgument* spreadArgument = SpreadArgument::FromVar(instance); + SpreadArgument* spreadArgument = VarTo(instance); uint32 len = spreadArgument->GetArgumentSpreadCount(); const Var* spreadItems = spreadArgument->GetArgumentSpread(); for (uint32 j = 0; j < len; j++) @@ -11676,7 +11667,7 @@ using namespace Js; // A spread argument can be anything that returns a 'length' property, even if that // property is null or undefined. spreadArg = CrossSite::MarshalVar(scriptContext, spreadArg); - JavascriptArray *arr = JavascriptOperators::TryFromVar(spreadArg); + JavascriptArray *arr = JavascriptArray::TryVarToNonES5Array(spreadArg); if (arr) { return arr->GetLength(); @@ -11688,9 +11679,9 @@ using namespace Js; return tarr->GetLength(); } - if (SpreadArgument::Is(spreadArg)) + if (VarIs(spreadArg)) { - SpreadArgument *spreadFunctionArgs = SpreadArgument::FromVar(spreadArg); + SpreadArgument *spreadFunctionArgs = VarTo(spreadArg); return spreadFunctionArgs->GetArgumentSpreadCount(); } @@ -11847,7 +11838,7 @@ using namespace Js; } else { - AssertMsg(RecyclableObject::Is(seg->elements[i]), "Invalid entry in segment"); + AssertMsg(VarIs(seg->elements[i]), "Invalid entry in segment"); } } ValidateSegment(seg); @@ -11991,13 +11982,13 @@ using namespace Js; switch (typeId) { case Js::TypeIds_Array: - arrayCopy = JavascriptArray::DeepCopyInstance(JavascriptArray::UnsafeFromVar(arrayObject)); + arrayCopy = JavascriptArray::DeepCopyInstance(UnsafeVarTo(arrayObject)); break; case Js::TypeIds_NativeIntArray: - arrayCopy = JavascriptArray::DeepCopyInstance(JavascriptNativeIntArray::UnsafeFromVar(arrayObject)); + arrayCopy = JavascriptArray::DeepCopyInstance(UnsafeVarTo(arrayObject)); break; case Js::TypeIds_NativeFloatArray: - arrayCopy = JavascriptArray::DeepCopyInstance(JavascriptNativeFloatArray::UnsafeFromVar(arrayObject)); + arrayCopy = JavascriptArray::DeepCopyInstance(UnsafeVarTo(arrayObject)); break; default: @@ -12235,9 +12226,9 @@ using namespace Js; JS_REENTRANCY_LOCK(jsReentLock, scriptContext->GetThreadContext()); SETOBJECT_FOR_MUTATION(jsReentLock, originalArray); - if (JavascriptArray::Is(originalArray) - && !DynamicObject::UnsafeFromVar(originalArray)->GetDynamicType()->GetTypeHandler()->GetIsNotPathTypeHandlerOrHasUserDefinedCtor() - && DynamicObject::UnsafeFromVar(originalArray)->GetPrototype() == scriptContext->GetLibrary()->GetArrayPrototype() + if (JavascriptArray::IsNonES5Array(originalArray) + && !UnsafeVarTo(originalArray)->GetDynamicType()->GetTypeHandler()->GetIsNotPathTypeHandlerOrHasUserDefinedCtor() + && UnsafeVarTo(originalArray)->GetPrototype() == scriptContext->GetLibrary()->GetArrayPrototype() && !scriptContext->GetLibrary()->GetArrayObjectHasUserDefinedSpecies()) { return nullptr; @@ -12248,7 +12239,7 @@ using namespace Js; JS_REENTRANT(jsReentLock, BOOL isArray = JavascriptOperators::IsArray(originalArray)); if (isArray) { - JS_REENTRANT(jsReentLock, BOOL getProp = JavascriptOperators::GetProperty(RecyclableObject::UnsafeFromVar(originalArray), PropertyIds::constructor, &constructor, scriptContext)); + JS_REENTRANT(jsReentLock, BOOL getProp = JavascriptOperators::GetProperty(UnsafeVarTo(originalArray), PropertyIds::constructor, &constructor, scriptContext)); if (!getProp) { return nullptr; @@ -12256,7 +12247,7 @@ using namespace Js; if (JavascriptOperators::IsConstructor(constructor)) { - ScriptContext* constructorScriptContext = RecyclableObject::UnsafeFromVar(constructor)->GetScriptContext(); + ScriptContext* constructorScriptContext = UnsafeVarTo(constructor)->GetScriptContext(); if (constructorScriptContext != scriptContext) { if (constructorScriptContext->GetLibrary()->GetArrayConstructor() == constructor) @@ -12298,7 +12289,7 @@ using namespace Js; else { // If the constructor function is the built-in Array constructor, we can be smart and create the right type of native array. - JavascriptArray* pArr = JavascriptArray::FromVar(originalArray); + JavascriptArray* pArr = VarTo(originalArray); pArr->GetArrayTypeAndConvert(pIsIntArray, pIsFloatArray); return CreateNewArrayHelper(static_cast(length), *pIsIntArray, *pIsFloatArray, pArr, scriptContext); } @@ -12317,13 +12308,13 @@ using namespace Js; Js::Var constructorArgs[] = { constructor, JavascriptNumber::ToVar(length, scriptContext) }; Js::CallInfo constructorCallInfo(Js::CallFlags_New, _countof(constructorArgs)); - AssertOrFailFast(Js::RecyclableObject::Is(constructor)); + AssertOrFailFast(Js::VarIs(constructor)); ThreadContext* threadContext = scriptContext->GetThreadContext(); Var scObject = threadContext->ExecuteImplicitCall((RecyclableObject*)constructor, ImplicitCall_Accessor, [&]()->Js::Var { JS_REENTRANT_UNLOCK(jsReentLock, return JavascriptOperators::NewScObject(constructor, Js::Arguments(constructorCallInfo, constructorArgs), scriptContext)); }); - return RecyclableObject::FromVar(scObject); + return VarTo(scObject); } /*static*/ PropertyId const JavascriptArray::specialPropertyIds[] = @@ -13014,101 +13005,23 @@ using namespace Js; return TRUE; } - bool JavascriptNativeArray::Is(Var aValue) - { - TypeId typeId = JavascriptOperators::GetTypeId(aValue); - return JavascriptNativeArray::Is(typeId); - } - bool JavascriptNativeArray::Is(TypeId typeId) { return JavascriptNativeIntArray::Is(typeId) || JavascriptNativeFloatArray::Is(typeId); } - JavascriptNativeArray* JavascriptNativeArray::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptNativeArray'"); - - return static_cast(aValue); - } - - JavascriptNativeArray* JavascriptNativeArray::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptNativeArray'"); - - return static_cast(aValue); - } - - bool JavascriptNativeIntArray::Is(Var aValue) - { - TypeId typeId = JavascriptOperators::GetTypeId(aValue); - return JavascriptNativeIntArray::Is(typeId); - } - -#if ENABLE_COPYONACCESS_ARRAY - bool JavascriptCopyOnAccessNativeIntArray::Is(Var aValue) - { - TypeId typeId = JavascriptOperators::GetTypeId(aValue); - return JavascriptCopyOnAccessNativeIntArray::Is(typeId); - } -#endif - bool JavascriptNativeIntArray::Is(TypeId typeId) { return typeId == TypeIds_NativeIntArray; } -#if ENABLE_COPYONACCESS_ARRAY - bool JavascriptCopyOnAccessNativeIntArray::Is(TypeId typeId) - { - return typeId == TypeIds_CopyOnAccessNativeIntArray; - } -#endif - bool JavascriptNativeIntArray::IsNonCrossSite(Var aValue) { bool ret = !TaggedInt::Is(aValue) && VirtualTableInfo::HasVirtualTable(aValue); - Assert(ret == (JavascriptNativeIntArray::Is(aValue) && !JavascriptNativeIntArray::FromVar(aValue)->IsCrossSiteObject())); + Assert(ret == (VarIs(aValue) && !VarTo(aValue)->IsCrossSiteObject())); return ret; } - JavascriptNativeIntArray* JavascriptNativeIntArray::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptNativeIntArray'"); - - return static_cast(aValue); - } - - JavascriptNativeIntArray* JavascriptNativeIntArray::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptNativeIntArray'"); - - return static_cast(aValue); - } - -#if ENABLE_COPYONACCESS_ARRAY - JavascriptCopyOnAccessNativeIntArray* JavascriptCopyOnAccessNativeIntArray::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptCopyOnAccessNativeIntArray'"); - - return static_cast(aValue); - } - - JavascriptCopyOnAccessNativeIntArray* JavascriptCopyOnAccessNativeIntArray::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptCopyOnAccessNativeIntArray'"); - - return static_cast(aValue); - } - -#endif - - bool JavascriptNativeFloatArray::Is(Var aValue) - { - TypeId typeId = JavascriptOperators::GetTypeId(aValue); - return JavascriptNativeFloatArray::Is(typeId); - } - bool JavascriptNativeFloatArray::Is(TypeId typeId) { return typeId == TypeIds_NativeFloatArray; @@ -13117,24 +13030,10 @@ using namespace Js; bool JavascriptNativeFloatArray::IsNonCrossSite(Var aValue) { bool ret = !TaggedInt::Is(aValue) && VirtualTableInfo::HasVirtualTable(aValue); - Assert(ret == (JavascriptNativeFloatArray::Is(aValue) && !JavascriptNativeFloatArray::FromVar(aValue)->IsCrossSiteObject())); + Assert(ret == (VarIs(aValue) && !VarTo(aValue)->IsCrossSiteObject())); return ret; } - JavascriptNativeFloatArray* JavascriptNativeFloatArray::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptNativeFloatArray'"); - - return static_cast(RecyclableObject::FromVar(aValue)); - } - - JavascriptNativeFloatArray* JavascriptNativeFloatArray::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptNativeFloatArray'"); - - return static_cast(RecyclableObject::UnsafeFromVar(aValue)); - } - template int Js::JavascriptArray::GetParamForIndexOf(unsigned int, Js::Arguments const&, void*&, unsigned int&, Js::ScriptContext*); template bool Js::JavascriptArray::ArrayElementEnumerator::MoveNext(); template void Js::JavascriptArray::SetArrayLiteralItem(unsigned int, void*); diff --git a/lib/Runtime/Library/JavascriptArray.h b/lib/Runtime/Library/JavascriptArray.h index f8bdeac0848..cf067858e38 100644 --- a/lib/Runtime/Library/JavascriptArray.h +++ b/lib/Runtime/Library/JavascriptArray.h @@ -211,10 +211,11 @@ namespace Js return this->DirectGetItemAt(index, &value) ? WritableData : None; } - static bool Is(Var aValue); - static bool Is(TypeId typeId); - static JavascriptArray* FromVar(Var aValue); - static JavascriptArray* UnsafeFromVar(Var aValue); + static bool IsNonES5Array(Var aValue); + static bool IsNonES5Array(TypeId typeId); + + // Returns the object if it is a non-ES5 array object. Otherwise returns null. + static JavascriptArray* TryVarToNonES5Array(Var aValue); static bool IsVarArray(Var aValue); static bool IsVarArray(TypeId typeId); @@ -385,7 +386,7 @@ namespace Js template void WalkExisting(Func func) { - Assert(!JavascriptNativeIntArray::Is(this) && !JavascriptNativeFloatArray::Is(this)); + Assert(!VarIs(this) && !VarIs(this)); ArrayElementEnumerator e(this, 0); while(e.MoveNext()) { @@ -647,10 +648,13 @@ namespace Js // NativeArrays may change it's content type, but not others template static bool MayChangeType() { return false; } + // Like normal VarIs, but will return false for if the array has transitioned to ES5Array type. + template static bool VarIsWithoutES5Array(RecyclableObject* object); + template - static BOOL TryTemplatedGetItem(T *arr, P index, Var *element, ScriptContext *scriptContext, bool checkHasItem = true) + static BOOL TryTemplatedGetItem(RecyclableObject* arr, P index, Var *element, ScriptContext *scriptContext, bool checkHasItem = true) { - return T::Is(arr) ? JavascriptArray::TemplatedGetItem(arr, index, element, scriptContext, checkHasItem) : + return VarIsWithoutES5Array(arr) ? JavascriptArray::TemplatedGetItem(static_cast(arr), index, element, scriptContext, checkHasItem) : JavascriptOperators::GetItem(arr, index, element, scriptContext); } @@ -660,20 +664,21 @@ namespace Js for (uint32 i = startIndex; i < limitIndex; i++) { Var element; - fn(i, TryTemplatedGetItem(arr, i, &element, scriptContext) ? element : missingItem); + RecyclableObject* curArr = arr; + fn(i, TryTemplatedGetItem(curArr, i, &element, scriptContext) ? element : missingItem); - if (hasSideEffect && MayChangeType() && !T::Is(arr)) + if (hasSideEffect && MayChangeType() && !VarIsWithoutES5Array(curArr)) { - // The function has changed, go to another ForEachItemInRange. It is possible that the array might have changed to + // The function has changed, go to another ForEachItemInRange. It is possible that the array might have changed to // an ES5Array, in such cases we don't need to call the JavascriptArray specific implementation. - if (JavascriptArray::Is(arr)) + if (JavascriptArray::IsNonES5Array(curArr)) { - JavascriptArray::FromVar(arr)->template ForEachItemInRange(i + 1, limitIndex, missingItem, scriptContext, fn); + UnsafeVarTo(curArr)->template ForEachItemInRange(i + 1, limitIndex, missingItem, scriptContext, fn); return; } else { - AssertOrFailFastMsg(ES5Array::Is(arr), "The array should have been converted to an ES5Array"); + AssertOrFailFastMsg(VarIs(curArr), "The array should have been converted to an ES5Array"); } } } @@ -685,22 +690,23 @@ namespace Js for (P i = startIndex; i < limitIndex; i++) { Var element; - if (TryTemplatedGetItem(arr, i, &element, scriptContext)) + RecyclableObject* curArr = arr; + if (TryTemplatedGetItem(curArr, i, &element, scriptContext)) { fn(i, element); - if (hasSideEffect && MayChangeType() && !T::Is(arr)) + if (hasSideEffect && MayChangeType() && !VarIsWithoutES5Array(curArr)) { - // The function has changed, go to another ForEachItemInRange. It is possible that the array might have changed to + // The function has changed, go to another ForEachItemInRange. It is possible that the array might have changed to // an ES5Array, in such cases we don't need to call the JavascriptArray specific implementation. - if (JavascriptArray::Is(arr)) + if (JavascriptArray::IsNonES5Array(curArr)) { - JavascriptArray::FromVar(arr)->template ForEachItemInRange(i + 1, limitIndex, scriptContext, fn); + UnsafeVarTo(curArr)->template ForEachItemInRange(i + 1, limitIndex, scriptContext, fn); return; } else { - AssertOrFailFastMsg(ES5Array::Is(arr), "The array should have been converted to an ES5Array"); + AssertOrFailFastMsg(VarIs(curArr), "The array should have been converted to an ES5Array"); } } } @@ -723,10 +729,10 @@ namespace Js TemplatedForEachItemInRange(this, startIndex, limitIndex, scriptContext, fn); break; case TypeIds_NativeIntArray: - TemplatedForEachItemInRange(JavascriptNativeIntArray::FromVar(this), startIndex, limitIndex, scriptContext, fn); + TemplatedForEachItemInRange(VarTo(this), startIndex, limitIndex, scriptContext, fn); break; case TypeIds_NativeFloatArray: - TemplatedForEachItemInRange(JavascriptNativeFloatArray::FromVar(this), startIndex, limitIndex, scriptContext, fn); + TemplatedForEachItemInRange(VarTo(this), startIndex, limitIndex, scriptContext, fn); break; default: Assert(false); @@ -743,10 +749,10 @@ namespace Js TemplatedForEachItemInRange(this, startIndex, limitIndex, missingItem, scriptContext, fn); break; case TypeIds_NativeIntArray: - TemplatedForEachItemInRange(JavascriptNativeIntArray::FromVar(this), startIndex, limitIndex, missingItem, scriptContext, fn); + TemplatedForEachItemInRange(VarTo(this), startIndex, limitIndex, missingItem, scriptContext, fn); break; case TypeIds_NativeFloatArray: - TemplatedForEachItemInRange(JavascriptNativeFloatArray::FromVar(this), startIndex, limitIndex, missingItem, scriptContext, fn); + TemplatedForEachItemInRange(VarTo(this), startIndex, limitIndex, missingItem, scriptContext, fn); break; default: Assert(false); @@ -854,11 +860,11 @@ namespace Js static void SetConcatItem(Var aItem, uint idxArg, JavascriptArray* pDestArray, RecyclableObject* pDestObj, T idxDest, ScriptContext *scriptContext); template - static void ConcatArgs(RecyclableObject* pDestObj, TypeId* remoteTypeIds, Js::Arguments& args, ScriptContext* scriptContext, uint start, + static void ConcatArgs(RecyclableObject* pDestObj, TypeId* remoteTypeIds, Js::Arguments& args, ScriptContext* scriptContext, uint start, BigIndex startIdxDest, ConcatSpreadableState previousItemSpreadableState = ConcatSpreadableState_NotChecked, BigIndex *firstPromotedItemLength = nullptr); template - static void ConcatArgs(RecyclableObject* pDestObj, TypeId* remoteTypeIds, Js::Arguments& args, ScriptContext* scriptContext, uint start = 0, uint startIdxDest = 0u, + static void ConcatArgs(RecyclableObject* pDestObj, TypeId* remoteTypeIds, Js::Arguments& args, ScriptContext* scriptContext, uint start = 0, uint startIdxDest = 0u, ConcatSpreadableState previousItemSpreadableState = ConcatSpreadableState_NotChecked, BigIndex *firstPromotedItemLength = nullptr); static JavascriptArray* ConcatIntArgs(JavascriptNativeIntArray* pDestArray, TypeId* remoteTypeIds, Js::Arguments& args, ScriptContext* scriptContext); @@ -934,6 +940,24 @@ namespace Js } }; + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return DynamicObject::IsAnyArray(obj); + } + + template bool JavascriptArray::VarIsWithoutES5Array(RecyclableObject* object) + { + return VarIs(object); + } + template <> inline bool JavascriptArray::VarIsWithoutES5Array(RecyclableObject* object) + { + return true; + } + template <> inline bool JavascriptArray::VarIsWithoutES5Array(RecyclableObject* object) + { + return IsNonES5Array(object); + } + // Ideally we would propagate the throw flag setting of true from the array operations down to the [[Delete]]/[[Put]]/... methods. But that is a big change // so we are checking for failure on DeleteProperty/DeleteItem/... etc instead. This helper makes that checking a little less intrusive. class ThrowTypeErrorOnFailureHelper @@ -972,10 +996,7 @@ namespace Js Field(RecyclerWeakReference *) weakRefToFuncBody; public: - static bool Is(Var aValue); static bool Is(TypeId typeId); - static JavascriptNativeArray* FromVar(Var aValue); - static JavascriptNativeArray* UnsafeFromVar(Var aValue); void SetArrayCallSite(ProfileId index, RecyclerWeakReference *weakRef) { @@ -1007,6 +1028,11 @@ namespace Js static void PopWithNoDst(Var nativeArray); }; + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptNativeArray::Is(JavascriptOperators::GetTypeId(obj)); + } + class JavascriptNativeFloatArray; class JavascriptNativeIntArray : public JavascriptNativeArray { @@ -1033,10 +1059,7 @@ namespace Js static Var NewInstance(RecyclableObject* function, CallInfo callInfo, ...); static Var NewInstance(RecyclableObject* function, Arguments args); - static bool Is(Var aValue); static bool Is(TypeId typeId); - static JavascriptNativeIntArray* FromVar(Var aValue); - static JavascriptNativeIntArray* UnsafeFromVar(Var aValue); static bool IsNonCrossSite(Var aValue); typedef int32 TElement; @@ -1114,6 +1137,11 @@ namespace Js } }; + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptNativeIntArray::Is(JavascriptOperators::GetTypeId(obj)); + } + #if ENABLE_COPYONACCESS_ARRAY class JavascriptCopyOnAccessNativeIntArray : public JavascriptNativeIntArray { @@ -1132,11 +1160,6 @@ namespace Js virtual BOOL IsCopyOnAccessArray() { return TRUE; } - static bool Is(Var aValue); - static bool Is(TypeId typeId); - static JavascriptCopyOnAccessNativeIntArray* FromVar(Var aValue); - static JavascriptCopyOnAccessNativeIntArray* UnsafeFromVar(Var aValue); - static DynamicType * GetInitialType(ScriptContext * scriptContext); void ConvertCopyOnAccessSegment(); @@ -1171,6 +1194,11 @@ namespace Js } }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_CopyOnAccessNativeIntArray; + } #endif class JavascriptNativeFloatArray : public JavascriptNativeArray @@ -1199,10 +1227,7 @@ namespace Js static Var NewInstance(RecyclableObject* function, CallInfo callInfo, ...); static Var NewInstance(RecyclableObject* function, Arguments args); - static bool Is(Var aValue); static bool Is(TypeId typeId); - static JavascriptNativeFloatArray* FromVar(Var aValue); - static JavascriptNativeFloatArray* UnsafeFromVar(Var aValue); static bool IsNonCrossSite(Var aValue); typedef double TElement; @@ -1255,7 +1280,7 @@ namespace Js } static DynamicType * GetInitialType(ScriptContext * scriptContext); - static Var Push(ScriptContext * scriptContext, Var * nativeFloatArray, double value); + static Var Push(ScriptContext * scriptContext, Var nativeFloatArray, double value); static JavascriptNativeFloatArray * BoxStackInstance(JavascriptNativeFloatArray * instance, bool deepCopy); static double Pop(ScriptContext * scriptContext, Var nativeFloatArray); private: @@ -1285,6 +1310,11 @@ namespace Js }; + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptNativeFloatArray::Is(JavascriptOperators::GetTypeId(obj)); + } + template <> inline bool JavascriptArray::MayChangeType() { return true; } template <> diff --git a/lib/Runtime/Library/JavascriptArrayIterator.cpp b/lib/Runtime/Library/JavascriptArrayIterator.cpp index 6bd164d1543..cb32e3ad20f 100644 --- a/lib/Runtime/Library/JavascriptArrayIterator.cpp +++ b/lib/Runtime/Library/JavascriptArrayIterator.cpp @@ -19,26 +19,6 @@ namespace Js } } - bool JavascriptArrayIterator::Is(Var aValue) - { - TypeId typeId = JavascriptOperators::GetTypeId(aValue); - return typeId == TypeIds_ArrayIterator; - } - - JavascriptArrayIterator* JavascriptArrayIterator::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptArrayIterator'"); - - return static_cast(aValue); - } - - JavascriptArrayIterator* JavascriptArrayIterator::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptArrayIterator'"); - - return static_cast(aValue); - } - Var JavascriptArrayIterator::EntryNext(RecyclableObject* function, CallInfo callInfo, ...) { PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault); @@ -56,12 +36,12 @@ namespace Js Var thisObj = args[0]; - if (!JavascriptArrayIterator::Is(thisObj)) + if (!VarIs(thisObj)) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedArrayIterator, _u("Array Iterator.prototype.next")); } - JavascriptArrayIterator* iterator = JavascriptArrayIterator::FromVar(thisObj); + JavascriptArrayIterator* iterator = VarTo(thisObj); Var iterable = iterator->m_iterableObject; if (iterable == nullptr) @@ -72,17 +52,17 @@ namespace Js int64 length; JavascriptArray* pArr = nullptr; TypedArrayBase *typedArrayBase = nullptr; - if (JavascriptArray::Is(iterable) && !JavascriptArray::FromVar(iterable)->IsCrossSiteObject()) + if (JavascriptArray::IsNonES5Array(iterable) && !VarTo(iterable)->IsCrossSiteObject()) { #if ENABLE_COPYONACCESS_ARRAY - Assert(!JavascriptCopyOnAccessNativeIntArray::Is(iterable)); + Assert(!VarIs(iterable)); #endif pArr = JavascriptArray::FromAnyArray(iterable); length = pArr->GetLength(); } - else if (TypedArrayBase::Is(iterable)) + else if (VarIs(iterable)) { - typedArrayBase = TypedArrayBase::UnsafeFromVar(iterable); + typedArrayBase = UnsafeVarTo(iterable); if (typedArrayBase->IsDetachedBuffer()) { JavascriptError::ThrowTypeError(scriptContext, JSERR_DetachedTypedArray); diff --git a/lib/Runtime/Library/JavascriptArrayIterator.h b/lib/Runtime/Library/JavascriptArrayIterator.h index 8ce7d5dfc73..c4fef665919 100644 --- a/lib/Runtime/Library/JavascriptArrayIterator.h +++ b/lib/Runtime/Library/JavascriptArrayIterator.h @@ -27,10 +27,6 @@ namespace Js public: JavascriptArrayIterator(DynamicType* type, Var iterable, JavascriptArrayIteratorKind kind); - static bool Is(Var aValue); - static JavascriptArrayIterator* FromVar(Var aValue); - static JavascriptArrayIterator* UnsafeFromVar(Var aValue); - class EntryInfo { public: @@ -42,4 +38,9 @@ namespace Js public: Var GetIteratorObjectForHeapEnum() { return m_iterableObject; } }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_ArrayIterator; + } } // namespace Js diff --git a/lib/Runtime/Library/JavascriptBoolean.cpp b/lib/Runtime/Library/JavascriptBoolean.cpp index 36256af7dfb..bf852031623 100644 --- a/lib/Runtime/Library/JavascriptBoolean.cpp +++ b/lib/Runtime/Library/JavascriptBoolean.cpp @@ -53,7 +53,7 @@ namespace Js { RecyclableObject* pNew = scriptContext->GetLibrary()->CreateBooleanObject(value); return isCtorSuperCall ? - JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), pNew, nullptr, scriptContext) : + JavascriptOperators::OrdinaryCreateFromConstructor(VarTo(newTarget), pNew, nullptr, scriptContext) : pNew; } @@ -70,13 +70,13 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if(JavascriptBoolean::Is(args[0])) + if(VarIs(args[0])) { return args[0]; } - else if (JavascriptBooleanObject::Is(args[0])) + else if (VarIs(args[0])) { - JavascriptBooleanObject* booleanObject = JavascriptBooleanObject::FromVar(args[0]); + JavascriptBooleanObject* booleanObject = VarTo(args[0]); return scriptContext->GetLibrary()->CreateBoolean(booleanObject->GetValue()); } else @@ -98,13 +98,13 @@ namespace Js BOOL bval; Var aValue = args[0]; - if(JavascriptBoolean::Is(aValue)) + if(VarIs(aValue)) { - bval = JavascriptBoolean::FromVar(aValue)->GetValue(); + bval = VarTo(aValue)->GetValue(); } - else if (JavascriptBooleanObject::Is(aValue)) + else if (VarIs(aValue)) { - JavascriptBooleanObject* booleanObject = JavascriptBooleanObject::FromVar(aValue); + JavascriptBooleanObject* booleanObject = VarTo(aValue); bval = booleanObject->GetValue(); } else @@ -129,7 +129,7 @@ namespace Js if (JavascriptOperators::GetTypeId(args[0]) == TypeIds_HostDispatch) { Var result; - if (RecyclableObject::FromVar(args[0])->InvokeBuiltInOperationRemotely(entryPoint, args, &result)) + if (VarTo(args[0])->InvokeBuiltInOperationRemotely(entryPoint, args, &result)) { return result; } @@ -161,13 +161,13 @@ namespace Js *value = left->GetValue() ? JavascriptNumber::GetValue(right) == 1.0 : JavascriptNumber::GetValue(right) == 0.0; break; case TypeIds_Int64Number: - *value = left->GetValue() ? JavascriptInt64Number::FromVar(right)->GetValue() == 1 : JavascriptInt64Number::FromVar(right)->GetValue() == 0; + *value = left->GetValue() ? VarTo(right)->GetValue() == 1 : VarTo(right)->GetValue() == 0; break; case TypeIds_UInt64Number: - *value = left->GetValue() ? JavascriptUInt64Number::FromVar(right)->GetValue() == 1 : JavascriptUInt64Number::FromVar(right)->GetValue() == 0; + *value = left->GetValue() ? VarTo(right)->GetValue() == 1 : VarTo(right)->GetValue() == 0; break; case TypeIds_Boolean: - *value = left->GetValue() == JavascriptBoolean::FromVar(right)->GetValue(); + *value = left->GetValue() == VarTo(right)->GetValue(); break; case TypeIds_String: *value = left->GetValue() ? JavascriptConversion::ToNumber(right, requestContext) == 1.0 : JavascriptConversion::ToNumber(right, requestContext) == 0.0; diff --git a/lib/Runtime/Library/JavascriptBoolean.h b/lib/Runtime/Library/JavascriptBoolean.h index 57fb29a09e0..4dcd5dae68b 100644 --- a/lib/Runtime/Library/JavascriptBoolean.h +++ b/lib/Runtime/Library/JavascriptBoolean.h @@ -20,9 +20,6 @@ namespace Js inline BOOL GetValue() { return value; } - static inline bool Is(Var aValue); - static inline JavascriptBoolean* FromVar(Var aValue); - static inline JavascriptBoolean* UnsafeFromVar(Var aValue); static Var ToVar(BOOL fValue,ScriptContext* scriptContext); class EntryInfo @@ -59,4 +56,9 @@ namespace Js static BOOL Equals(JavascriptBoolean* left, Var right, BOOL* value, ScriptContext * requestContext); static Var TryInvokeRemotelyOrThrow(JavascriptMethod entryPoint, ScriptContext * scriptContext, Arguments & args, int32 errorCode, PCWSTR varName); }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_Boolean; + } } diff --git a/lib/Runtime/Library/JavascriptBoolean.inl b/lib/Runtime/Library/JavascriptBoolean.inl deleted file mode 100644 index ef256ddfaa2..00000000000 --- a/lib/Runtime/Library/JavascriptBoolean.inl +++ /dev/null @@ -1,29 +0,0 @@ -//------------------------------------------------------------------------------------------------------- -// Copyright (C) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. -//------------------------------------------------------------------------------------------------------- - -#pragma once - -namespace Js -{ - // These function needs to be in INL file for static lib - inline bool JavascriptBoolean::Is(Var aValue) - { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Boolean; - } - - inline JavascriptBoolean* JavascriptBoolean::FromVar(Js::Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptBoolean'"); - - return static_cast(aValue); - } - - inline JavascriptBoolean* JavascriptBoolean::UnsafeFromVar(Js::Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptBoolean'"); - - return static_cast(aValue); - } -} // namespace Js diff --git a/lib/Runtime/Library/JavascriptBooleanObject.cpp b/lib/Runtime/Library/JavascriptBooleanObject.cpp index 346db9c3ba9..3c98a9030ea 100644 --- a/lib/Runtime/Library/JavascriptBooleanObject.cpp +++ b/lib/Runtime/Library/JavascriptBooleanObject.cpp @@ -12,25 +12,6 @@ namespace Js Assert(type->GetTypeId() == TypeIds_BooleanObject); } - bool JavascriptBooleanObject::Is(Var aValue) - { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_BooleanObject; - } - - JavascriptBooleanObject* JavascriptBooleanObject::FromVar(Js::Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptBooleanObject'"); - - return static_cast(aValue); - } - - JavascriptBooleanObject* JavascriptBooleanObject::UnsafeFromVar(Js::Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptBooleanObject'"); - - return static_cast(aValue); - } - BOOL JavascriptBooleanObject::GetValue() const { if (this->value == nullptr) @@ -71,7 +52,7 @@ namespace Js #if ENABLE_TTD void JavascriptBooleanObject::SetValue_TTD(Js::Var val) { - TTDAssert(val == nullptr || Js::JavascriptBoolean::Is(val), "Only allowable values!"); + TTDAssert(val == nullptr || Js::VarIs(val), "Only allowable values!"); this->value = static_cast(val); } diff --git a/lib/Runtime/Library/JavascriptBooleanObject.h b/lib/Runtime/Library/JavascriptBooleanObject.h index 6e000413bc3..4c447f22b17 100644 --- a/lib/Runtime/Library/JavascriptBooleanObject.h +++ b/lib/Runtime/Library/JavascriptBooleanObject.h @@ -15,9 +15,6 @@ namespace Js DEFINE_MARSHAL_OBJECT_TO_SCRIPT_CONTEXT(JavascriptBooleanObject); public: JavascriptBooleanObject(JavascriptBoolean* value, DynamicType * type); - static bool Is(Var aValue); - static JavascriptBooleanObject* FromVar(Js::Var aValue); - static JavascriptBooleanObject* UnsafeFromVar(Js::Var aValue); BOOL GetValue() const; void Initialize(JavascriptBoolean* value); @@ -35,4 +32,9 @@ namespace Js virtual void ExtractSnapObjectDataInto(TTD::NSSnapObjects::SnapObject* objData, TTD::SlabAllocator& alloc) override; #endif }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_BooleanObject; + } } diff --git a/lib/Runtime/Library/JavascriptDate.cpp b/lib/Runtime/Library/JavascriptDate.cpp index da166469a84..3e6e191fa69 100644 --- a/lib/Runtime/Library/JavascriptDate.cpp +++ b/lib/Runtime/Library/JavascriptDate.cpp @@ -20,26 +20,6 @@ namespace Js Assert(type->GetTypeId() == TypeIds_Date); } - bool JavascriptDate::Is(Var aValue) - { - // All WinRT Date's are also implicitly Javascript dates - return IsDateTypeId(JavascriptOperators::GetTypeId(aValue)); - } - - JavascriptDate* JavascriptDate::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'Date'"); - - return static_cast(aValue); - } - - JavascriptDate* JavascriptDate::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'Date'"); - - return static_cast(aValue); - } - Var JavascriptDate::GetDateData(JavascriptDate* date, DateImplementation::DateData dd, ScriptContext* scriptContext) { return JavascriptNumber::ToVarIntCheck(date->m_date.GetDateData(dd, false, scriptContext), scriptContext); @@ -115,7 +95,7 @@ namespace Js // RecyclableObject* pNew = NewInstanceAsConstructor(args, scriptContext); return isCtorSuperCall ? - JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), pNew, nullptr, scriptContext) : + JavascriptOperators::OrdinaryCreateFromConstructor(VarTo(newTarget), pNew, nullptr, scriptContext) : pNew; } } @@ -165,17 +145,17 @@ namespace Js // if (args.Info.Count == 2) { - if (JavascriptDate::Is(args[1])) + if (VarIs(args[1])) { - JavascriptDate* dateObject = JavascriptDate::FromVar(args[1]); + JavascriptDate* dateObject = VarTo(args[1]); timeValue = ((dateObject)->m_date).m_tvUtc; } else { Var value = JavascriptConversion::ToPrimitive(args[1], scriptContext); - if (JavascriptString::Is(value)) + if (VarIs(value)) { - timeValue = ParseHelper(scriptContext, JavascriptString::FromVar(value)); + timeValue = ParseHelper(scriptContext, VarTo(value)); } else { @@ -254,9 +234,9 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedObject, _u("Date[Symbol.toPrimitive]")); } - if (JavascriptString::Is(args[1])) + if (VarIs(args[1])) { - JavascriptString* StringObject = JavascriptString::FromVar(args[1]); + JavascriptString* StringObject = VarTo(args[1]); const char16 * str = StringObject->GetString(); if (wcscmp(str, _u("default")) == 0 || wcscmp(str, _u("string")) == 0) @@ -264,13 +244,13 @@ namespace Js // Date objects, are unique among built-in ECMAScript object in that they treat "default" as being equivalent to "string" // If hint is the string value "string" or the string value "default", then // Let tryFirst be "string". - return JavascriptConversion::OrdinaryToPrimitive(RecyclableObject::UnsafeFromVar(args[0]), scriptContext); + return JavascriptConversion::OrdinaryToPrimitive(UnsafeVarTo(args[0]), scriptContext); } // Else if hint is the string value "number", then // Let tryFirst be "number". else if(wcscmp(str, _u("number")) == 0) { - return JavascriptConversion::OrdinaryToPrimitive(RecyclableObject::UnsafeFromVar(args[0]), scriptContext); + return JavascriptConversion::OrdinaryToPrimitive(UnsafeVarTo(args[0]), scriptContext); } //anything else should throw a type error } @@ -288,7 +268,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryGetDate, scriptContext, args, &result)) @@ -297,7 +277,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.getDate")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); if (!date->m_date.IsNaN()) { @@ -315,7 +295,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryGetDay, scriptContext, args, &result)) @@ -324,7 +304,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.getDay")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); if (!date->m_date.IsNaN()) { @@ -342,7 +322,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryGetFullYear, scriptContext, args, &result)) @@ -351,7 +331,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.getFullYear")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); if (!date->m_date.IsNaN()) { @@ -369,7 +349,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryGetYear, scriptContext, args, &result)) @@ -378,7 +358,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.getYear")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); if (!date->m_date.IsNaN()) { @@ -396,7 +376,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryGetHours, scriptContext, args, &result)) @@ -405,7 +385,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.getHours")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); if (!date->m_date.IsNaN()) { @@ -423,7 +403,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryGetMilliseconds, scriptContext, args, &result)) @@ -432,7 +412,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.getMilliseconds")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); if (!date->m_date.IsNaN()) { @@ -450,7 +430,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryGetMinutes, scriptContext, args, &result)) @@ -459,7 +439,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.getMinutes")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); if (!date->m_date.IsNaN()) { @@ -477,7 +457,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryGetMonth, scriptContext, args, &result)) @@ -486,7 +466,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.getMonth")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); if (!date->m_date.IsNaN()) { @@ -504,7 +484,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryGetSeconds, scriptContext, args, &result)) @@ -513,7 +493,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.getSeconds")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); if (!date->m_date.IsNaN()) { @@ -531,7 +511,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryGetTime, scriptContext, args, &result)) @@ -540,7 +520,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.getTime")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptNumber::ToVarNoCheck(date->GetTime(), scriptContext); } @@ -554,7 +534,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryGetTimezoneOffset, scriptContext, args, &result)) @@ -563,7 +543,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.getTimezoneOffset")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::GetDateData(date, DateImplementation::DateData::TimezoneOffset, scriptContext); } @@ -577,7 +557,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryGetUTCDate, scriptContext, args, &result)) @@ -586,7 +566,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.getUTCDate")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::GetUTCDateData(date, DateImplementation::DateData::Date, scriptContext); } @@ -600,7 +580,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryGetUTCDay, scriptContext, args, &result)) @@ -609,7 +589,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.getUTCDay")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::GetUTCDateData(date, DateImplementation::DateData::Day, scriptContext); } @@ -623,7 +603,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryGetUTCFullYear, scriptContext, args, &result)) @@ -632,7 +612,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.getUTCFullYear")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::GetUTCDateData(date, DateImplementation::DateData::FullYear, scriptContext); } @@ -646,7 +626,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryGetUTCHours, scriptContext, args, &result)) @@ -655,7 +635,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.getUTCHours")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::GetUTCDateData(date, DateImplementation::DateData::Hours, scriptContext); } @@ -669,7 +649,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryGetUTCMilliseconds, scriptContext, args, &result)) @@ -678,7 +658,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.getUTCMilliseconds")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::GetUTCDateData(date, DateImplementation::DateData::Milliseconds, scriptContext); } @@ -692,7 +672,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryGetUTCMinutes, scriptContext, args, &result)) @@ -701,7 +681,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.getUTCMinutes")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::GetUTCDateData(date, DateImplementation::DateData::Minutes, scriptContext); } @@ -715,7 +695,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryGetUTCMonth, scriptContext, args, &result)) @@ -724,7 +704,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.getUTCMonth")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::GetUTCDateData(date, DateImplementation::DateData::Month, scriptContext); } @@ -738,7 +718,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryGetUTCSeconds, scriptContext, args, &result)) @@ -747,7 +727,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.getUTCSeconds")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::GetUTCDateData(date, DateImplementation::DateData::Seconds, scriptContext); } @@ -761,7 +741,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryGetVarDate, scriptContext, args, &result)) @@ -770,7 +750,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.getVarDate")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return scriptContext->GetLibrary()->CreateVariantDate( DateImplementation::VarDateFromJsUtcTime(date->GetTime(), scriptContext) @@ -852,7 +832,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntrySetDate, scriptContext, args, &result)) @@ -861,7 +841,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.setDate")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::SetDateData(date, args, DateImplementation::DateData::Date, scriptContext); } @@ -875,7 +855,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntrySetFullYear, scriptContext, args, &result)) @@ -884,7 +864,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.setFullYear")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::SetDateData(date, args, DateImplementation::DateData::FullYear, scriptContext); } @@ -898,7 +878,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntrySetYear, scriptContext, args, &result)) @@ -907,7 +887,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.setYear")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::SetDateData(date, args, DateImplementation::DateData::Year, scriptContext); } @@ -921,7 +901,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntrySetHours, scriptContext, args, &result)) @@ -930,7 +910,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.setHours")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::SetDateData(date, args, DateImplementation::DateData::Hours, scriptContext); } @@ -944,7 +924,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntrySetMilliseconds, scriptContext, args, &result)) @@ -953,7 +933,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.setMilliseconds")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::SetDateData(date, args, DateImplementation::DateData::Milliseconds, scriptContext); } @@ -967,7 +947,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntrySetMinutes, scriptContext, args, &result)) @@ -976,7 +956,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.setMinutes")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::SetDateData(date, args, DateImplementation::DateData::Minutes, scriptContext); } @@ -990,7 +970,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntrySetMonth, scriptContext, args, &result)) @@ -999,7 +979,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.setMonth")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::SetDateData(date, args, DateImplementation::DateData::Month, scriptContext); } @@ -1013,7 +993,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntrySetSeconds, scriptContext, args, &result)) @@ -1022,7 +1002,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.setSeconds")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::SetDateData(date, args, DateImplementation::DateData::Seconds, scriptContext); } @@ -1036,7 +1016,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntrySetTime, scriptContext, args, &result)) @@ -1045,7 +1025,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.setTime")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); AssertMsg(args.Info.Count > 0, "Negative argument count"); double value; @@ -1076,7 +1056,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntrySetUTCDate, scriptContext, args, &result)) @@ -1085,7 +1065,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.setUTCDate")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::SetUTCDateData(date, args, DateImplementation::DateData::Date, scriptContext); } @@ -1099,7 +1079,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntrySetUTCFullYear, scriptContext, args, &result)) @@ -1108,7 +1088,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.setUTCFullYear")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::SetUTCDateData(date, args, DateImplementation::DateData::FullYear, scriptContext); } @@ -1122,7 +1102,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntrySetUTCHours, scriptContext, args, &result)) @@ -1131,7 +1111,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.setUTCHours")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::SetUTCDateData(date, args, DateImplementation::DateData::Hours, scriptContext); } @@ -1145,7 +1125,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntrySetUTCMilliseconds, scriptContext, args, &result)) @@ -1154,7 +1134,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.setUTCMilliseconds")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::SetUTCDateData(date, args, DateImplementation::DateData::Milliseconds, scriptContext); } @@ -1168,7 +1148,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntrySetUTCMinutes, scriptContext, args, &result)) @@ -1177,7 +1157,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.setUTCMinutes")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::SetUTCDateData(date, args, DateImplementation::DateData::Minutes, scriptContext); } @@ -1191,7 +1171,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntrySetUTCMonth, scriptContext, args, &result)) @@ -1200,7 +1180,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.setUTCMonth")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::SetUTCDateData(date, args, DateImplementation::DateData::Month, scriptContext); } @@ -1214,7 +1194,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntrySetUTCSeconds, scriptContext, args, &result)) @@ -1223,7 +1203,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.setUTCSeconds")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); return JavascriptDate::SetUTCDateData(date, args, DateImplementation::DateData::Seconds, scriptContext); } @@ -1237,7 +1217,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryToDateString, scriptContext, args, &result)) @@ -1246,7 +1226,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.toDateString")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); AssertMsg(args.Info.Count > 0, "Negative argument count"); return date->m_date.GetString( @@ -1264,7 +1244,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); CHAKRATEL_LANGSTATS_INC_BUILTINCOUNT(Date_Prototype_toISOString); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryToISOString, scriptContext, args, &result)) @@ -1273,7 +1253,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.toISOString")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); AssertMsg(args.Info.Count > 0, "Negative argument count"); return date->m_date.GetISOString(scriptContext); @@ -1316,7 +1296,7 @@ namespace Js { JavascriptError::ThrowTypeError(scriptContext, JSERR_Property_NeedFunction, scriptContext->GetPropertyName(PropertyIds::toISOString)->GetBuffer()); } - RecyclableObject* toISOFunc = RecyclableObject::FromVar(toISO); + RecyclableObject* toISOFunc = VarTo(toISO); return scriptContext->GetThreadContext()->ExecuteImplicitCall(toISOFunc, Js::ImplicitCall_Accessor, [=]()->Js::Var { return CALL_FUNCTION(scriptContext->GetThreadContext(), toISOFunc, CallInfo(1), thisObj); @@ -1332,7 +1312,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryToLocaleDateString, scriptContext, args, &result)) @@ -1341,7 +1321,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.toLocaleDateString")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); #ifdef ENABLE_INTL_OBJECT if (CONFIG_FLAG(IntlBuiltIns) && scriptContext->IsIntlEnabled()){ @@ -1390,7 +1370,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryToLocaleString, scriptContext, args, &result)) @@ -1399,7 +1379,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.toLocaleString")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); #ifdef ENABLE_INTL_OBJECT if (CONFIG_FLAG(IntlBuiltIns) && scriptContext->IsIntlEnabled()){ @@ -1458,7 +1438,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryToLocaleTimeString, scriptContext, args, &result)) @@ -1467,7 +1447,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.toLocaleTimeString")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); #ifdef ENABLE_INTL_OBJECT if (CONFIG_FLAG(IntlBuiltIns) && scriptContext->IsIntlEnabled()){ @@ -1515,7 +1495,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryToTimeString, scriptContext, args, &result)) @@ -1524,7 +1504,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.toTimeString")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); AssertMsg(args.Info.Count > 0, "Negative argument count"); @@ -1542,7 +1522,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryToUTCString, scriptContext, args, &result)) @@ -1551,7 +1531,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.toUTCString")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); AssertMsg(args.Info.Count > 0, "Negative argument count"); return date->m_date.GetString( @@ -1568,7 +1548,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryValueOf, scriptContext, args, &result)) @@ -1577,7 +1557,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.valueOf")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); AssertMsg(args.Info.Count > 0, "Negative argument count"); double value = date->m_date.GetMilliSeconds(); @@ -1593,7 +1573,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !JavascriptDate::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { Var result = nullptr; if (TryInvokeRemotely(EntryToString, scriptContext, args, &result)) @@ -1602,7 +1582,7 @@ namespace Js } JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDate, _u("Date.prototype.toString")); } - JavascriptDate* date = JavascriptDate::FromVar(args[0]); + JavascriptDate* date = VarTo(args[0]); AssertMsg(args.Info.Count > 0, "Negative argument count"); return JavascriptDate::ToString(date, scriptContext); @@ -1612,7 +1592,7 @@ namespace Js { if (JavascriptOperators::GetTypeId(args[0]) == TypeIds_HostDispatch) { - if (RecyclableObject::FromVar(args[0])->InvokeBuiltInOperationRemotely(entryPoint, args, result)) + if (VarTo(args[0])->InvokeBuiltInOperationRemotely(entryPoint, args, result)) { return TRUE; } diff --git a/lib/Runtime/Library/JavascriptDate.h b/lib/Runtime/Library/JavascriptDate.h index 2d665f1a8a2..9aaeed45068 100644 --- a/lib/Runtime/Library/JavascriptDate.h +++ b/lib/Runtime/Library/JavascriptDate.h @@ -20,11 +20,7 @@ namespace Js JavascriptDate(double value, DynamicType * type); JavascriptDate(DynamicType * type); - static bool Is(Var aValue); - double GetTime() { return m_date.GetMilliSeconds(); } - static JavascriptDate* FromVar(Var aValue); - static JavascriptDate* UnsafeFromVar(Var aValue); class EntryInfo { @@ -159,4 +155,10 @@ namespace Js #endif }; + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + // All WinRT Date's are also implicitly Javascript dates + return IsDateTypeId(JavascriptOperators::GetTypeId(obj)); + } + } // namespace Js diff --git a/lib/Runtime/Library/JavascriptError.cpp b/lib/Runtime/Library/JavascriptError.cpp index 6abdfba24fb..7257732cee6 100644 --- a/lib/Runtime/Library/JavascriptError.cpp +++ b/lib/Runtime/Library/JavascriptError.cpp @@ -27,12 +27,6 @@ namespace Js return hr; } - bool JavascriptError::Is(Var aValue) - { - AssertMsg(aValue != NULL, "Error is NULL - did it come from an oom exception?"); - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Error; - } - bool JavascriptError::IsRemoteError(Var aValue) { // IJscriptInfo is not remotable (we don't register the proxy), @@ -76,7 +70,7 @@ namespace Js JavascriptExceptionOperators::AddStackTraceToObject(pError, exceptionContext.GetStackTrace(), *scriptContext, /*isThrownException=*/ false, /*resetSatck=*/ false); return isCtorSuperCall ? - JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), pError, nullptr, scriptContext) : + JavascriptOperators::OrdinaryCreateFromConstructor(VarTo(newTarget), pError, nullptr, scriptContext) : pError; } @@ -181,7 +175,7 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedObject, _u("Error.prototype.toString")); } - RecyclableObject * thisError = RecyclableObject::FromVar(args[0]); + RecyclableObject * thisError = VarTo(args[0]); Var value = NULL; JavascriptString *outputStr, *message; @@ -547,16 +541,16 @@ namespace Js // The description property always overrides any error message Var description = Js::JavascriptOperators::GetProperty(errorObject, Js::PropertyIds::description, scriptContext, NULL); - if (JavascriptString::Is(description)) + if (VarIs(description)) { // Always report the description to IE if it is a string, even if the user sets it - JavascriptString * messageString = JavascriptString::FromVar(description); + JavascriptString * messageString = VarTo(description); *pMessage = messageString->GetSz(); } - else if (Js::JavascriptError::Is(errorObject) && Js::JavascriptError::FromVar(errorObject)->originalRuntimeErrorMessage != nullptr) + else if (Js::VarIs(errorObject) && Js::VarTo(errorObject)->originalRuntimeErrorMessage != nullptr) { // use the runtime error message - *pMessage = Js::JavascriptError::FromVar(errorObject)->originalRuntimeErrorMessage; + *pMessage = Js::VarTo(errorObject)->originalRuntimeErrorMessage; } else if (FACILITY_CONTROL == HRESULT_FACILITY(hr)) { diff --git a/lib/Runtime/Library/JavascriptError.h b/lib/Runtime/Library/JavascriptError.h index 3f118b51f2d..0c530d62325 100644 --- a/lib/Runtime/Library/JavascriptError.h +++ b/lib/Runtime/Library/JavascriptError.h @@ -33,27 +33,12 @@ namespace Js m_errorType = kjstCustomError; } - static bool Is(Var aValue); static bool IsRemoteError(Var aValue); ErrorTypeEnum GetErrorType() { return m_errorType; } virtual bool HasDebugInfo(); - static JavascriptError* FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptError'"); - - return static_cast(RecyclableObject::FromVar(aValue)); - } - - static JavascriptError* UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptError'"); - - return static_cast(RecyclableObject::UnsafeFromVar(aValue)); - } - void SetNotEnumerable(PropertyId propertyId); static Var NewInstance(RecyclableObject* function, JavascriptError* pError, CallInfo callInfo, Var newTarget, Var message); @@ -191,4 +176,9 @@ namespace Js virtual void ExtractSnapObjectDataInto(TTD::NSSnapObjects::SnapObject* objData, TTD::SlabAllocator& alloc) override; #endif }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_Error; + } } diff --git a/lib/Runtime/Library/JavascriptExternalFunction.cpp b/lib/Runtime/Library/JavascriptExternalFunction.cpp index 7e065ca928a..36dc8ffdd9c 100644 --- a/lib/Runtime/Library/JavascriptExternalFunction.cpp +++ b/lib/Runtime/Library/JavascriptExternalFunction.cpp @@ -138,13 +138,13 @@ namespace Js #if FLOATVAR case TypeIds_Number: #endif // FLOATVAR - Assert(!Js::RecyclableObject::Is(thisVar)); + Assert(!Js::VarIs(thisVar)); break; default: { - Assert(Js::RecyclableObject::Is(thisVar)); + Assert(Js::VarIs(thisVar)); - ScriptContext* scriptContextThisVar = Js::RecyclableObject::FromVar(thisVar)->GetScriptContext(); + ScriptContext* scriptContextThisVar = Js::VarTo(thisVar)->GetScriptContext(); // We need to verify "this" pointer is active as well. The problem is that DOM prototype functions are // the same across multiple frames, and caller can do function.call(closedthis) Assert(!scriptContext->GetThreadContext()->IsDisableImplicitException()); @@ -317,10 +317,10 @@ namespace Js bool marshallingMayBeNeeded = false; if (result != nullptr) { - marshallingMayBeNeeded = Js::RecyclableObject::Is(result); + marshallingMayBeNeeded = Js::VarIs(result); if (marshallingMayBeNeeded) { - Js::RecyclableObject * obj = Js::RecyclableObject::FromVar(result); + Js::RecyclableObject * obj = Js::VarTo(result); // For JSRT, we could get result marshalled in different context. bool isJSRT = scriptContext->GetThreadContext()->IsJSRT(); diff --git a/lib/Runtime/Library/JavascriptFunction.cpp b/lib/Runtime/Library/JavascriptFunction.cpp index 0675936216d..51110a0d81a 100644 --- a/lib/Runtime/Library/JavascriptFunction.cpp +++ b/lib/Runtime/Library/JavascriptFunction.cpp @@ -96,27 +96,9 @@ using namespace Js; return functionInfo->HasBody(); } - bool JavascriptFunction::Is(Var aValue) + template <> bool Js::VarIsImpl(RecyclableObject* obj) { - if (JavascriptOperators::GetTypeId(aValue) == TypeIds_Function) - { - return true; - } - return false; - } - - JavascriptFunction* JavascriptFunction::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptFunction'"); - - return static_cast(aValue); - } - - JavascriptFunction* JavascriptFunction::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptFunction'"); - - return static_cast(aValue); + return JavascriptOperators::GetTypeId(obj) == TypeIds_Function; } BOOL JavascriptFunction::IsStrictMode() const @@ -139,8 +121,8 @@ using namespace Js; /* static */ bool JavascriptFunction::IsBuiltinProperty(Var objectWithProperty, PropertyIds propertyId) { - return ScriptFunctionBase::Is(objectWithProperty) - && (propertyId == PropertyIds::length || (JavascriptFunction::FromVar(objectWithProperty)->HasRestrictedProperties() && (propertyId == PropertyIds::arguments || propertyId == PropertyIds::caller))); + return VarIs(objectWithProperty) + && (propertyId == PropertyIds::length || (VarTo(objectWithProperty)->HasRestrictedProperties() && (propertyId == PropertyIds::arguments || propertyId == PropertyIds::caller))); } #endif @@ -151,7 +133,7 @@ using namespace Js; static char16 const closeFormals[] = _u("\n)"); static char16 const openFuncBody[] = _u(" {"); static char16 const closeFuncBody[] = _u("\n}"); - + Var JavascriptFunction::NewInstanceHelper(ScriptContext *scriptContext, RecyclableObject* function, CallInfo callInfo, Js::ArgumentReader& args, FunctionKind functionKind /* = FunctionKind::Normal */) { JavascriptLibrary* library = function->GetLibrary(); @@ -320,7 +302,7 @@ using namespace Js; } return isCtorSuperCall ? - JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), pfuncScript, nullptr, scriptContext) : + JavascriptOperators::OrdinaryCreateFromConstructor(VarTo(newTarget), pfuncScript, nullptr, scriptContext) : pfuncScript; } @@ -437,7 +419,7 @@ using namespace Js; Var thisVar = NULL; Var argArray = NULL; - RecyclableObject* pFunc = RecyclableObject::FromVar(args[0]); + RecyclableObject* pFunc = VarTo(args[0]); if (args.Info.Count == 1) { @@ -483,7 +465,7 @@ using namespace Js; } else { - bool isArray = JavascriptArray::Is(argArray); + bool isArray = JavascriptArray::IsNonES5Array(argArray); TypeId typeId = JavascriptOperators::GetTypeId(argArray); bool isNullOrUndefined = typeId <= TypeIds_UndefinedOrNull; @@ -494,7 +476,7 @@ using namespace Js; int64 len; JavascriptArray* arr = NULL; - RecyclableObject* dynamicObject = RecyclableObject::FromVar(argArray); + RecyclableObject* dynamicObject = VarTo(argArray); if (isNullOrUndefined) { @@ -505,7 +487,7 @@ using namespace Js; #if ENABLE_COPYONACCESS_ARRAY JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray(argArray); #endif - arr = JavascriptArray::FromVar(argArray); + arr = VarTo(argArray); len = arr->GetLength(); } else @@ -644,7 +626,7 @@ using namespace Js; JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedFunction, _u("Function.prototype.call")); } - RecyclableObject *pFunc = RecyclableObject::FromVar(args[0]); + RecyclableObject *pFunc = VarTo(args[0]); if (argCount == 1) { args.Values[0] = scriptContext->GetLibrary()->GetUndefined(); @@ -678,7 +660,7 @@ using namespace Js; { ScriptContext* requestContext = scriptContext->GetThreadContext()-> GetPreviousHostScriptContext()->GetScriptContext(); - func = JavascriptFunction::FromVar(CrossSite::MarshalVar(requestContext, + func = VarTo(CrossSite::MarshalVar(requestContext, func, scriptContext)); } return func->CallRootFunction(args, scriptContext, true); @@ -839,10 +821,10 @@ using namespace Js; && !scriptContext->IsInterpreted() && !CONFIG_FLAG(ForceDiagnosticsMode) // Does not work nicely if we change the default settings. && function->GetEntryPoint() != scriptContext->CurrentThunk && !CrossSite::IsThunk(function->GetEntryPoint()) - && JavascriptFunction::Is(function)) + && VarIs(function)) { - JavascriptFunction *jsFunction = JavascriptFunction::FromVar(function); + JavascriptFunction *jsFunction = VarTo(function); if (!jsFunction->IsBoundFunction() && !jsFunction->GetFunctionInfo()->IsDeferred() && (jsFunction->GetFunctionInfo()->GetAttributes() & FunctionInfo::DoNotProfile) != FunctionInfo::DoNotProfile @@ -888,7 +870,7 @@ using namespace Js; } // JavascriptOperators::NewScObjectNoCtor should have thrown if 'v' is not a constructor - RecyclableObject* functionObj = RecyclableObject::UnsafeFromVar(v); + RecyclableObject* functionObj = UnsafeVarTo(v); const unsigned STACK_ARGS_ALLOCA_THRESHOLD = 8; // Number of stack args we allow before using _alloca Var stackArgs[STACK_ARGS_ALLOCA_THRESHOLD]; @@ -941,9 +923,9 @@ using namespace Js; CallInfo newCallInfo(newFlags, args.Info.Count); Arguments newArgs(newCallInfo, newValues); - if (JavascriptProxy::Is(v)) + if (VarIs(v)) { - JavascriptProxy* proxy = JavascriptProxy::FromVar(v); + JavascriptProxy* proxy = VarTo(v); return proxy->ConstructorTrap(newArgs, scriptContext, spreadIndices); } @@ -968,8 +950,8 @@ using namespace Js; FinishConstructor( functionResult, resultObject, - JavascriptFunction::Is(functionObj) && functionObj->GetScriptContext() == scriptContext ? - JavascriptFunction::FromVar(functionObj) : + VarIs(functionObj) && functionObj->GetScriptContext() == scriptContext ? + VarTo(functionObj) : nullptr, overridingNewTarget != nullptr); } @@ -1080,9 +1062,9 @@ using namespace Js; // Expand the spread element. Var instance = args[spreadIndex]; - if (SpreadArgument::Is(instance)) + if (VarIs(instance)) { - SpreadArgument* spreadedArgs = SpreadArgument::FromVar(instance); + SpreadArgument* spreadedArgs = VarTo(instance); uint size = spreadedArgs->GetArgumentSpreadCount(); if (size > 0) { @@ -1568,20 +1550,20 @@ void __cdecl _alloca_probe_16() Var arg0 = args[0]; - // callable proxy is considered as having [[Call]] internal method + // callable proxy is considered as having [[Call]] internal method // and should behave here like a function. // we will defer to the underlying target. - while (JavascriptProxy::Is(arg0) && JavascriptConversion::IsCallable(arg0)) + while (VarIs(arg0) && JavascriptConversion::IsCallable(arg0)) { - arg0 = JavascriptProxy::FromVar(arg0)->GetTarget(); + arg0 = VarTo(arg0)->GetTarget(); } AssertMsg(args.Info.Count > 0, "Should always have implicit 'this'"); - if (args.Info.Count == 0 || !JavascriptFunction::Is(arg0)) + if (args.Info.Count == 0 || !VarIs(arg0)) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedFunction, _u("Function.prototype.toString")); } - JavascriptFunction *pFunc = JavascriptFunction::FromVar(arg0); + JavascriptFunction *pFunc = VarTo(arg0); // pFunc can be from a different script context if Function.prototype.toString is invoked via .call/.apply. // Marshal the resulting string to the current script context (that of the toString) @@ -1920,7 +1902,7 @@ void __cdecl _alloca_probe_16() } Var* addressOfFuncObj = GetAddressOfFuncObj(); - if (!addressOfFuncObj || *addressOfFuncObj == nullptr || !ScriptFunction::Is(*addressOfFuncObj)) + if (!addressOfFuncObj || *addressOfFuncObj == nullptr || !VarIs(*addressOfFuncObj)) { return nullptr; } @@ -2307,12 +2289,12 @@ void __cdecl _alloca_probe_16() return false; } - bool isAsmJs = AsmJsScriptFunction::Is(func); - bool isWasmOnly = WasmScriptFunction::Is(func); + bool isAsmJs = VarIs(func); + bool isWasmOnly = VarIs(func); uintptr_t faultingAddr = helper.GetFaultingAddress(); if (isAsmJs) { - AsmJsScriptFunction* asmFunc = AsmJsScriptFunction::FromVar(func); + AsmJsScriptFunction* asmFunc = VarTo(func); // some extra checks for asm.js because we have slightly more information that we can validate if (!asmFunc->GetModuleEnvironment()) { @@ -2324,7 +2306,7 @@ void __cdecl _alloca_probe_16() #ifdef ENABLE_WASM if (isWasmOnly) { - WebAssemblyMemory* mem = WasmScriptFunction::FromVar(func)->GetWebAssemblyMemory(); + WebAssemblyMemory* mem = VarTo(func)->GetWebAssemblyMemory(); arrayBuffer = mem->GetBuffer(); reservationSize = MAX_WASM__ARRAYBUFFER_LENGTH; } @@ -2473,7 +2455,7 @@ void __cdecl _alloca_probe_16() { Assert(CrossSite::IsThunk(callEntryPoint)); } - else if (ScriptFunction::Is(this)) + else if (VarIs(this)) { } else @@ -2722,22 +2704,22 @@ void __cdecl _alloca_probe_16() funcCaller = nullValue; } - if (ScriptFunction::Is(funcCaller)) + if (VarIs(funcCaller)) { // If this is the internal function of a generator function then return the original generator function - funcCaller = ScriptFunction::FromVar(funcCaller)->GetRealFunctionObject(); + funcCaller = VarTo(funcCaller)->GetRealFunctionObject(); // This function is escaping, so make sure there isn't some nested parent that has a cached scope. - if (ScriptFunction::Is(funcCaller)) + if (VarIs(funcCaller)) { - FrameDisplay * pFrameDisplay = Js::ScriptFunction::FromVar(funcCaller)->GetEnvironment(); + FrameDisplay * pFrameDisplay = Js::VarTo(funcCaller)->GetEnvironment(); uint length = (uint)pFrameDisplay->GetLength(); for (uint i = 0; i < length; i++) { Var scope = pFrameDisplay->GetItem(i); - if (scope && !Js::ScopeSlots::Is(scope) && Js::ActivationObjectEx::Is(scope)) + if (scope && !Js::ScopeSlots::Is(scope) && Js::VarIs(scope)) { - Js::ActivationObjectEx::FromVar(scope)->InvalidateCachedScope(); + Js::VarTo(scope)->InvalidateCachedScope(); } } } @@ -2819,7 +2801,7 @@ void __cdecl _alloca_probe_16() } } - if (Js::JavascriptFunction::Is(*value) && Js::JavascriptFunction::FromVar(*value)->IsStrictMode()) + if (Js::VarIs(*value) && Js::VarTo(*value)->IsStrictMode()) { if (scriptContext->GetThreadContext()->RecordImplicitException()) { @@ -3168,8 +3150,8 @@ void __cdecl _alloca_probe_16() } else { - Assert(JavascriptString::Is(sourceString)); - pString = JavascriptString::FromVar(sourceString); + Assert(VarIs(sourceString)); + pString = VarTo(sourceString); } } @@ -3230,7 +3212,7 @@ void __cdecl _alloca_probe_16() return true; } - Assert(!ScriptFunction::Is(thisFunction)); + Assert(!VarIs(thisFunction)); return GetSourceStringName(name); } @@ -3248,8 +3230,8 @@ void __cdecl _alloca_probe_16() *name = scriptContext->GetPropertyString(propertyIdOfSourceString); return true; } - Assert(JavascriptString::Is(sourceString)); - *name = JavascriptString::FromVar(sourceString); + Assert(VarIs(sourceString)); + *name = VarTo(sourceString); return true; } return false; @@ -3308,10 +3290,10 @@ void __cdecl _alloca_probe_16() return JavascriptBoolean::ToVar(FALSE, scriptContext); } - RecyclableObject * constructor = RecyclableObject::FromVar(args[0]); + RecyclableObject * constructor = VarTo(args[0]); Var instance = args[1]; - Assert(JavascriptProxy::Is(constructor) || JavascriptFunction::Is(constructor)); + Assert(VarIs(constructor) || VarIs(constructor)); return JavascriptBoolean::ToVar(constructor->HasInstance(instance, scriptContext, NULL), scriptContext); } @@ -3346,8 +3328,8 @@ void __cdecl _alloca_probe_16() if (inlineCache && inlineCache->function == nullptr && scriptContext == function->GetScriptContext())// only register when function has same scriptContext { - inlineCache->Cache(RecyclableObject::Is(instance) ? - RecyclableObject::UnsafeFromVar(instance)->GetType() : nullptr, + inlineCache->Cache(VarIs(instance) ? + UnsafeVarTo(instance)->GetType() : nullptr, function, scriptContext->GetLibrary()->GetFalse(), scriptContext); } return result; @@ -3394,7 +3376,7 @@ void __cdecl _alloca_probe_16() // However, object o's type (even if it is of the same "shape" as before, and even if o is the very same object) will be different, // because the object types are permanently bound and unique to the script context from which they were created. - RecyclableObject* instanceObject = RecyclableObject::FromVar(instance); + RecyclableObject* instanceObject = VarTo(instance); Var prototype = JavascriptOperators::GetPrototype(instanceObject); if (!JavascriptOperators::IsObject(funcPrototype)) @@ -3412,7 +3394,7 @@ void __cdecl _alloca_probe_16() break; } - prototype = JavascriptOperators::GetPrototype(RecyclableObject::FromVar(prototype)); + prototype = JavascriptOperators::GetPrototype(VarTo(prototype)); } // Now that we know the answer, let's cache it for next time if we have a cache. @@ -3421,7 +3403,7 @@ void __cdecl _alloca_probe_16() Assert(function != NULL); JavascriptBoolean * boolResult = result ? scriptContext->GetLibrary()->GetTrue() : scriptContext->GetLibrary()->GetFalse(); - Type * instanceType = RecyclableObject::FromVar(instance)->GetType(); + Type * instanceType = VarTo(instance)->GetType(); if (!instanceType->HasSpecialPrototype() && scriptContext == function->GetScriptContext()) // only register when function has same scriptContext, otherwise when scriptContext close @@ -3451,12 +3433,12 @@ void __cdecl _alloca_probe_16() Js::Throw::FatalInternalError(); } - if (args.Info.Count < 2 || !ArrayBufferBase::Is(args[1])) + if (args.Info.Count < 2 || !VarIs(args[1])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedArrayBufferObject); } - ArrayBufferBase* arrayBuffer = ArrayBufferBase::FromVar(args[1]); + ArrayBufferBase* arrayBuffer = VarTo(args[1]); const byte* buffer = arrayBuffer->GetBuffer(); uint32 size = arrayBuffer->GetByteLength(); HRESULT hr = JitFromEncodedWorkItem(scriptContext->GetNativeCodeGenerator(), buffer, size); diff --git a/lib/Runtime/Library/JavascriptFunction.h b/lib/Runtime/Library/JavascriptFunction.h index 44e23b89f37..c421cac597e 100644 --- a/lib/Runtime/Library/JavascriptFunction.h +++ b/lib/Runtime/Library/JavascriptFunction.h @@ -110,9 +110,6 @@ namespace Js static Var EntryInvokeJit(RecyclableObject* function, CallInfo callInfo, ...); #endif - static bool Is(Var aValue); - static JavascriptFunction* FromVar(Var aValue); - static JavascriptFunction* UnsafeFromVar(Var aValue); Var CallFunction(Arguments args); Var CallRootFunction(Arguments args, ScriptContext * scriptContext, bool inScript); #ifdef ASMJS_PLAT @@ -232,6 +229,9 @@ namespace Js private: static int CallRootEventFilter(int exceptionCode, PEXCEPTION_POINTERS exceptionInfo); }; + + template <> bool VarIsImpl(RecyclableObject* obj); + #if ENABLE_NATIVE_CODEGEN && defined(_M_X64) class ArrayAccessDecoder { diff --git a/lib/Runtime/Library/JavascriptGenerator.cpp b/lib/Runtime/Library/JavascriptGenerator.cpp index eea093ab1a9..105d60bf8d7 100644 --- a/lib/Runtime/Library/JavascriptGenerator.cpp +++ b/lib/Runtime/Library/JavascriptGenerator.cpp @@ -41,23 +41,9 @@ namespace Js return obj; } - bool JavascriptGenerator::Is(Var var) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(var) == TypeIds_Generator; - } - - JavascriptGenerator* JavascriptGenerator::FromVar(Var var) - { - AssertOrFailFastMsg(Is(var), "Ensure var is actually a 'JavascriptGenerator'"); - - return static_cast(var); - } - - JavascriptGenerator* JavascriptGenerator::UnsafeFromVar(Var var) - { - AssertMsg(Is(var), "Ensure var is actually a 'JavascriptGenerator'"); - - return static_cast(var); + return JavascriptOperators::GetTypeId(obj) == TypeIds_Generator; } void JavascriptGenerator::SetFrame(InterpreterStackFrame* frame, size_t bytes) @@ -180,12 +166,12 @@ namespace Js AUTO_TAG_NATIVE_LIBRARY_ENTRY(function, callInfo, _u("Generator.prototype.next")); - if (!JavascriptGenerator::Is(args[0])) + if (!VarIs(args[0])) { JavascriptError::ThrowTypeErrorVar(scriptContext, JSERR_NeedObjectOfType, _u("Generator.prototype.next"), _u("Generator")); } - JavascriptGenerator* generator = JavascriptGenerator::FromVar(args[0]); + JavascriptGenerator* generator = VarTo(args[0]); Var input = args.Info.Count > 1 ? args[1] : library->GetUndefined(); if (generator->IsCompleted()) @@ -207,12 +193,12 @@ namespace Js AUTO_TAG_NATIVE_LIBRARY_ENTRY(function, callInfo, _u("Generator.prototype.return")); - if (!JavascriptGenerator::Is(args[0])) + if (!VarIs(args[0])) { JavascriptError::ThrowTypeErrorVar(scriptContext, JSERR_NeedObjectOfType, _u("Generator.prototype.return"), _u("Generator")); } - JavascriptGenerator* generator = JavascriptGenerator::FromVar(args[0]); + JavascriptGenerator* generator = VarTo(args[0]); Var input = args.Info.Count > 1 ? args[1] : library->GetUndefined(); if (generator->IsSuspendedStart()) @@ -239,12 +225,12 @@ namespace Js AUTO_TAG_NATIVE_LIBRARY_ENTRY(function, callInfo, _u("Generator.prototype.throw")); - if (!JavascriptGenerator::Is(args[0])) + if (!VarIs(args[0])) { JavascriptError::ThrowTypeErrorVar(scriptContext, JSERR_NeedObjectOfType, _u("Generator.prototype.throw"), _u("Generator")); } - JavascriptGenerator* generator = JavascriptGenerator::FromVar(args[0]); + JavascriptGenerator* generator = VarTo(args[0]); Var input = args.Info.Count > 1 ? args[1] : library->GetUndefined(); if (generator->IsSuspendedStart()) @@ -312,7 +298,7 @@ namespace Js // TODO: BUGBUG - figure out how to determine what the prototype was gi->generatorPrototype = 0; - //if (this->GetPrototype() == this->GetScriptContext()->GetLibrary()->GetNull()) + //if (this->GetPrototype() == this->GetScriptContext()->GetLibrary()->GetNull()) //{ // gi->generatorPrototype = 1; //} diff --git a/lib/Runtime/Library/JavascriptGenerator.h b/lib/Runtime/Library/JavascriptGenerator.h index a84f9b6f736..edd1ea59633 100644 --- a/lib/Runtime/Library/JavascriptGenerator.h +++ b/lib/Runtime/Library/JavascriptGenerator.h @@ -77,10 +77,6 @@ namespace Js const Arguments& GetArguments() const { return args; } - static bool Is(Var var); - static JavascriptGenerator* FromVar(Var var); - static JavascriptGenerator* UnsafeFromVar(Var var); - class EntryInfo { public: @@ -99,4 +95,6 @@ namespace Js //virtual void ProcessCorePaths() override; #endif }; + + template <> bool VarIsImpl(RecyclableObject* obj); } diff --git a/lib/Runtime/Library/JavascriptGeneratorFunction.cpp b/lib/Runtime/Library/JavascriptGeneratorFunction.cpp index b7598d4079f..c24d4c3cf9d 100644 --- a/lib/Runtime/Library/JavascriptGeneratorFunction.cpp +++ b/lib/Runtime/Library/JavascriptGeneratorFunction.cpp @@ -46,12 +46,10 @@ using namespace Js; return scriptContext->GetLibrary()->CreateAsyncFunction(functionInfo.GetOriginalEntryPoint(), scriptFunction); } - bool JavascriptGeneratorFunction::Is(Var var) + bool JavascriptGeneratorFunction::IsBaseGeneratorFunction(RecyclableObject* obj) { - if (JavascriptFunction::Is(var)) + if (VarIs(obj)) { - JavascriptFunction* obj = JavascriptFunction::UnsafeFromVar(var); - return VirtualTableInfo::HasVirtualTable(obj) || VirtualTableInfo>::HasVirtualTable(obj); } @@ -59,26 +57,15 @@ using namespace Js; return false; } - JavascriptGeneratorFunction* JavascriptGeneratorFunction::FromVar(Var var) - { - AssertOrFailFast(JavascriptGeneratorFunction::Is(var) || JavascriptAsyncFunction::Is(var)); - - return static_cast(var); - } - - JavascriptGeneratorFunction* JavascriptGeneratorFunction::UnsafeFromVar(Var var) + template <> bool Js::VarIsImpl(RecyclableObject* obj) { - Assert(JavascriptGeneratorFunction::Is(var) || JavascriptAsyncFunction::Is(var)); - - return static_cast(var); + return JavascriptGeneratorFunction::IsBaseGeneratorFunction(obj) || VarIs(obj); } - bool JavascriptAsyncFunction::Is(Var var) + template <> bool Js::VarIsImpl(RecyclableObject* obj) { - if (JavascriptFunction::Is(var)) + if (VarIs(obj)) { - JavascriptFunction* obj = JavascriptFunction::UnsafeFromVar(var); - return VirtualTableInfo::HasVirtualTable(obj) || VirtualTableInfo>::HasVirtualTable(obj); } @@ -86,20 +73,6 @@ using namespace Js; return false; } - JavascriptAsyncFunction* JavascriptAsyncFunction::FromVar(Var var) - { - AssertOrFailFast(JavascriptAsyncFunction::Is(var)); - - return static_cast(var); - } - - JavascriptAsyncFunction* JavascriptAsyncFunction::UnsafeFromVar(Var var) - { - Assert(JavascriptAsyncFunction::Is(var)); - - return static_cast(var); - } - JavascriptGeneratorFunction* JavascriptGeneratorFunction::OP_NewScGenFunc(FrameDisplay *environment, FunctionInfoPtrPtr infoRef) { FunctionProxy* functionProxy = (*infoRef)->GetFunctionProxy(); @@ -143,7 +116,7 @@ using namespace Js; Assert(!(callInfo.Flags & CallFlags_New)); ScriptContext* scriptContext = function->GetScriptContext(); - JavascriptGeneratorFunction* generatorFunction = JavascriptGeneratorFunction::FromVar(function); + JavascriptGeneratorFunction* generatorFunction = VarTo(function); // InterpreterStackFrame takes a pointer to the args, so copy them to the recycler heap // and use that buffer for this InterpreterStackFrame. @@ -186,7 +159,7 @@ using namespace Js; JavascriptPromiseResolveOrRejectFunction* reject; JavascriptPromiseAsyncSpawnExecutorFunction* executor = library->CreatePromiseAsyncSpawnExecutorFunction( - scriptContext->GetLibrary()->CreateGenerator(heapArgs, JavascriptAsyncFunction::FromVar(function)->GetGeneratorVirtualScriptFunction(), prototype), + scriptContext->GetLibrary()->CreateGenerator(heapArgs, VarTo(function)->GetGeneratorVirtualScriptFunction(), prototype), stackArgs[0]); JavascriptPromise* promise = library->CreatePromise(); diff --git a/lib/Runtime/Library/JavascriptGeneratorFunction.h b/lib/Runtime/Library/JavascriptGeneratorFunction.h index bed37861e84..04bf2931517 100644 --- a/lib/Runtime/Library/JavascriptGeneratorFunction.h +++ b/lib/Runtime/Library/JavascriptGeneratorFunction.h @@ -27,9 +27,8 @@ namespace Js virtual JavascriptString* GetDisplayNameImpl() const override; GeneratorVirtualScriptFunction* GetGeneratorVirtualScriptFunction() { return scriptFunction; } - static JavascriptGeneratorFunction* FromVar(Var var); - static JavascriptGeneratorFunction* UnsafeFromVar(Var var); - static bool Is(Var var); + // Returns whether this function is exactly a JavascriptGeneratorFunction, not a JavascriptAsyncFunction + static bool IsBaseGeneratorFunction(RecyclableObject* obj); inline static bool Test(JavascriptFunction *obj) { return VirtualTableInfo::HasVirtualTable(obj) @@ -97,6 +96,8 @@ namespace Js } }; + template <> bool VarIsImpl(RecyclableObject* obj); + class JavascriptAsyncFunction : public JavascriptGeneratorFunction { private: @@ -114,9 +115,6 @@ namespace Js static JavascriptAsyncFunction* New(ScriptContext* scriptContext, GeneratorVirtualScriptFunction* scriptFunction); static DWORD GetOffsetOfScriptFunction() { return JavascriptGeneratorFunction::GetOffsetOfScriptFunction(); } - static JavascriptAsyncFunction* FromVar(Var var); - static JavascriptAsyncFunction* UnsafeFromVar(Var var); - static bool Is(Var var); inline static bool Test(JavascriptFunction *obj) { return VirtualTableInfo::HasVirtualTable(obj) @@ -135,6 +133,8 @@ namespace Js } }; + template <> bool VarIsImpl(RecyclableObject* obj); + class GeneratorVirtualScriptFunction : public ScriptFunction { private: @@ -145,7 +145,7 @@ namespace Js protected: DEFINE_VTABLE_CTOR(GeneratorVirtualScriptFunction, ScriptFunction); - + public: GeneratorVirtualScriptFunction(FunctionProxy* proxy, ScriptFunctionType* deferredPrototypeType) : ScriptFunction(proxy, deferredPrototypeType) { } diff --git a/lib/Runtime/Library/JavascriptLibrary.cpp b/lib/Runtime/Library/JavascriptLibrary.cpp index fadae5b2590..4bf53ec3d72 100644 --- a/lib/Runtime/Library/JavascriptLibrary.cpp +++ b/lib/Runtime/Library/JavascriptLibrary.cpp @@ -699,7 +699,7 @@ namespace Js bool JavascriptLibrary::InitializeGeneratorFunction(DynamicObject *instance, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode) { - JavascriptGeneratorFunction *function = JavascriptGeneratorFunction::FromVar(instance); + JavascriptGeneratorFunction *function = VarTo(instance); bool isAnonymousFunction = function->IsAnonymousFunction(); JavascriptLibrary* javascriptLibrary = function->GetType()->GetLibrary(); @@ -731,7 +731,7 @@ namespace Js bool JavascriptLibrary::InitializeAsyncFunction(DynamicObject *function, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode) { // Async function instances do not have a prototype property as they are not constructable - JavascriptAsyncFunction* asyncFunction = JavascriptAsyncFunction::FromVar(function); + JavascriptAsyncFunction* asyncFunction = VarTo(function); if (!asyncFunction->IsAnonymousFunction()) { @@ -771,13 +771,13 @@ namespace Js template bool JavascriptLibrary::InitializeFunction(DynamicObject *instance, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode) { - JavascriptFunction * function = JavascriptFunction::FromVar(instance); + JavascriptFunction * function = VarTo(instance); JavascriptLibrary* javascriptLibrary = function->GetType()->GetLibrary(); ScriptFunction *scriptFunction = nullptr; bool useAnonymous = false; - if (ScriptFunction::Is(function)) + if (VarIs(function)) { - scriptFunction = Js::ScriptFunction::FromVar(function); + scriptFunction = Js::VarTo(function); useAnonymous = scriptFunction->IsAnonymousFunction(); } @@ -801,7 +801,7 @@ namespace Js else { typeHandler->ConvertFunction(function, useLengthType ? javascriptLibrary->functionWithPrototypeAndLengthTypeHandler : javascriptLibrary->functionWithPrototypeTypeHandler); - } + } DynamicObject *protoObject = javascriptLibrary->CreateConstructorPrototypeObject(function); if (scriptFunction && scriptFunction->GetFunctionInfo()->IsClassConstructor()) { @@ -4322,7 +4322,8 @@ namespace Js } else { - objPrototype = Js::RecyclableObject::FromVar(prototype); + AssertOrFailFast(Js::VarIsCorrectType(prototype)); + objPrototype = prototype; Js::JavascriptOperators::InitProperty(objPrototype, Js::PropertyIds::constructor, function); objPrototype->SetEnumerable(Js::PropertyIds::constructor, false); } @@ -4565,7 +4566,7 @@ namespace Js { typeHandler->Convert(engineInterface, mode, 3); - EngineInterfaceObject::FromVar(engineInterface)->Initialize(); + VarTo(engineInterface)->Initialize(); engineInterface->SetHasNoEnumerableProperties(true); @@ -4615,7 +4616,7 @@ namespace Js void JavascriptLibrary::EnqueueTask(Var taskVar) { - Assert(JavascriptFunction::Is(taskVar)); + Assert(VarIs(taskVar)); if(this->nativeHostPromiseContinuationFunction) { @@ -4903,7 +4904,7 @@ namespace Js #if ENABLE_TTD Js::PropertyId JavascriptLibrary::ExtractPrimitveSymbolId_TTD(Var value) { - return Js::JavascriptSymbol::FromVar(value)->GetValue()->GetPropertyId(); + return Js::VarTo(value)->GetValue()->GetPropertyId(); } Js::RecyclableObject* JavascriptLibrary::CreatePrimitveSymbol_TTD(Js::PropertyId pid) @@ -4939,16 +4940,16 @@ namespace Js switch(obj->GetTypeId()) { case Js::TypeIds_BooleanObject: - Js::JavascriptBooleanObject::FromVar(obj)->SetValue_TTD(value); + Js::VarTo(obj)->SetValue_TTD(value); break; case Js::TypeIds_NumberObject: - Js::JavascriptNumberObject::FromVar(obj)->SetValue_TTD(value); + Js::VarTo(obj)->SetValue_TTD(value); break; case Js::TypeIds_StringObject: - Js::JavascriptStringObject::FromVar(obj)->SetValue_TTD(value); + Js::VarTo(obj)->SetValue_TTD(value); break; case Js::TypeIds_SymbolObject: - Js::JavascriptSymbolObject::FromVar(obj)->SetValue_TTD(value); + Js::VarTo(obj)->SetValue_TTD(value); break; default: TTDAssert(false, "Unsupported nullptr value boxed object."); @@ -4984,7 +4985,7 @@ namespace Js void JavascriptLibrary::SetLengthWritableES5Array_TTD(Js::RecyclableObject* es5Array, bool isLengthWritable) { - Js::ES5Array* es5a = Js::ES5Array::FromVar(es5Array); + Js::ES5Array* es5a = Js::VarTo(es5Array); if(es5a->IsLengthWritable() != isLengthWritable) { es5a->SetWritable(Js::PropertyIds::length, isLengthWritable ? TRUE : FALSE); @@ -5008,9 +5009,9 @@ namespace Js void JavascriptLibrary::AddWeakSetElementInflate_TTD(Js::JavascriptWeakSet* set, Var value) { - set->GetScriptContext()->TTDContextInfo->TTDWeakReferencePinSet->Add(Js::DynamicObject::FromVar(value)); + set->GetScriptContext()->TTDContextInfo->TTDWeakReferencePinSet->Add(Js::VarTo(value)); - set->Add(Js::DynamicObject::FromVar(value)); + set->Add(Js::VarTo(value)); } Js::RecyclableObject* JavascriptLibrary::CreateMap_TTD() @@ -5030,9 +5031,9 @@ namespace Js void JavascriptLibrary::AddWeakMapElementInflate_TTD(Js::JavascriptWeakMap* map, Var key, Var value) { - map->GetScriptContext()->TTDContextInfo->TTDWeakReferencePinSet->Add(Js::DynamicObject::FromVar(key)); + map->GetScriptContext()->TTDContextInfo->TTDWeakReferencePinSet->Add(Js::VarTo(key)); - map->Set(Js::DynamicObject::FromVar(key), value); + map->Set(Js::VarTo(key), value); } Js::RecyclableObject* JavascriptLibrary::CreateExternalFunction_TTD(Js::Var fname) @@ -5138,7 +5139,7 @@ namespace Js Js::RecyclableObject* JavascriptLibrary::CreatePromiseResolveOrRejectFunction_TTD(RecyclableObject* promise, bool isReject, JavascriptPromiseResolveOrRejectFunctionAlreadyResolvedWrapper* alreadyResolved) { - TTDAssert(JavascriptPromise::Is(promise), "Not a promise!"); + TTDAssert(VarIs(promise), "Not a promise!"); return this->CreatePromiseResolveOrRejectFunction(JavascriptPromise::EntryResolveOrRejectFunction, static_cast(promise), isReject, alreadyResolved); } @@ -5158,7 +5159,7 @@ namespace Js Js::RecyclableObject* JavascriptLibrary::CreatePromiseAllResolveElementFunction_TTD(Js::JavascriptPromiseCapability* capabilities, uint32 index, Js::JavascriptPromiseAllResolveElementFunctionRemainingElementsWrapper* wrapper, Js::RecyclableObject* values, bool alreadyCalled) { - Js::JavascriptPromiseAllResolveElementFunction* res = this->CreatePromiseAllResolveElementFunction(JavascriptPromise::EntryAllResolveElementFunction, index, Js::JavascriptArray::FromVar(values), capabilities, wrapper); + Js::JavascriptPromiseAllResolveElementFunction* res = this->CreatePromiseAllResolveElementFunction(JavascriptPromise::EntryAllResolveElementFunction, index, Js::VarTo(values), capabilities, wrapper); res->SetAlreadyCalled(alreadyCalled); return res; @@ -5179,11 +5180,11 @@ namespace Js { Assert(function->GetDynamicType()->GetIsLocked()); - if (ScriptFunction::Is(function)) + if (VarIs(function)) { this->SetCrossSiteForLockedNonBuiltInFunctionType(function); } - else if (BoundFunction::Is(function)) + else if (VarIs(function)) { this->SetCrossSiteForLockedNonBuiltInFunctionType(function); } @@ -5253,7 +5254,7 @@ namespace Js #endif return function; } - + #if DBG_DUMP const char16* JavascriptLibrary::GetStringTemplateCallsiteObjectKey(Var callsite) { @@ -5261,11 +5262,11 @@ namespace Js // Key is combination of the raw string literals delimited by '${}' since string template literals cannot include that symbol. // `str1${expr1}str2${expr2}str3` => "str1${}str2${}str3" - ES5Array* callsiteObj = ES5Array::FromVar(callsite); + ES5Array* callsiteObj = VarTo(callsite); ScriptContext* scriptContext = callsiteObj->GetScriptContext(); Var var = JavascriptOperators::OP_GetProperty(callsiteObj, Js::PropertyIds::raw, scriptContext); - ES5Array* rawArray = ES5Array::FromVar(var); + ES5Array* rawArray = VarTo(var); uint32 arrayLength = rawArray->GetLength(); uint32 totalStringLength = 0; JavascriptString* str; @@ -5276,7 +5277,7 @@ namespace Js for (uint32 i = 0; i < arrayLength; i++) { rawArray->DirectGetItemAt(i, &var); - str = JavascriptString::FromVar(var); + str = VarTo(var); totalStringLength += str->GetLength(); } @@ -5287,7 +5288,7 @@ namespace Js // Get first item before loop - there always must be at least one item rawArray->DirectGetItemAt(0, &var); - str = JavascriptString::FromVar(var); + str = VarTo(var); charcount_t len = str->GetLength(); js_wmemcpy_s(ptr, remainingSpace, str->GetString(), len); @@ -5303,7 +5304,7 @@ namespace Js remainingSpace -= len; rawArray->DirectGetItemAt(i, &var); - str = JavascriptString::FromVar(var); + str = VarTo(var); len = str->GetLength(); js_wmemcpy_s(ptr, remainingSpace, str->GetString(), len); @@ -5318,7 +5319,7 @@ namespace Js } #endif - + DynamicType * JavascriptLibrary::GetObjectLiteralType(uint16 requestedInlineSlotCapacity) { @@ -5891,9 +5892,9 @@ namespace Js JavascriptExternalFunction* JavascriptLibrary::CreateStdCallExternalFunction(StdCallJavascriptMethod entryPoint, Var name, void *callbackState) { Var functionNameOrId = name; - if (JavascriptString::Is(name)) + if (VarIs(name)) { - JavascriptString * functionName = JavascriptString::FromVar(name); + JavascriptString * functionName = VarTo(name); const char16 * functionNameBuffer = functionName->GetString(); int functionNameBufferLength = functionName->GetLengthAsSignedInt(); @@ -6382,8 +6383,9 @@ namespace Js JavascriptListIterator* JavascriptLibrary::CreateListIterator(ListForListIterator* list) { JavascriptListIterator* iterator = RecyclerNew(this->GetRecycler(), JavascriptListIterator, listIteratorType, list); - RuntimeFunction* nextFunction = DefaultCreateFunction(&JavascriptListIterator::EntryInfo::Next, 0, nullptr, nullptr, PropertyIds::next); - JavascriptOperators::SetProperty(iterator, iterator, PropertyIds::next, RuntimeFunction::FromVar(nextFunction), GetScriptContext(), PropertyOperation_None); + JavascriptFunction* nextFunction = DefaultCreateFunction(&JavascriptListIterator::EntryInfo::Next, 0, nullptr, nullptr, PropertyIds::next); + AssertOrFailFast(VarIsCorrectType(nextFunction)); + JavascriptOperators::SetProperty(iterator, iterator, PropertyIds::next, nextFunction, GetScriptContext(), PropertyOperation_None); return iterator; } diff --git a/lib/Runtime/Library/JavascriptListIterator.cpp b/lib/Runtime/Library/JavascriptListIterator.cpp index bf9d621f282..54a57635202 100644 --- a/lib/Runtime/Library/JavascriptListIterator.cpp +++ b/lib/Runtime/Library/JavascriptListIterator.cpp @@ -15,27 +15,6 @@ namespace Js count = list->Count(); } - bool JavascriptListIterator::Is(Var aValue) - { - TypeId typeId = JavascriptOperators::GetTypeId(aValue); - return typeId == TypeIds_ListIterator; - } - - JavascriptListIterator* JavascriptListIterator::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptListIterator'"); - - return static_cast(aValue); - } - - JavascriptListIterator* JavascriptListIterator::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptListIterator'"); - - return static_cast(aValue); - } - - Var JavascriptListIterator::EntryNext(RecyclableObject* function, CallInfo callInfo, ...) { PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault); @@ -48,12 +27,12 @@ namespace Js Var thisObj = args[0]; - if (!JavascriptListIterator::Is(thisObj)) + if (!VarIs(thisObj)) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedListIterator, _u("ListIterator.next")); } - JavascriptListIterator* iterator = JavascriptListIterator::FromVar(thisObj); + JavascriptListIterator* iterator = VarTo(thisObj); ListForListIterator* list = iterator->listForIterator; if (list == nullptr) diff --git a/lib/Runtime/Library/JavascriptListIterator.h b/lib/Runtime/Library/JavascriptListIterator.h index c54ce9df3c2..549df6ccca7 100644 --- a/lib/Runtime/Library/JavascriptListIterator.h +++ b/lib/Runtime/Library/JavascriptListIterator.h @@ -20,10 +20,6 @@ namespace Js public: JavascriptListIterator(DynamicType* type, ListForListIterator* list); - static bool Is(Var aValue); - static JavascriptListIterator* FromVar(Var aValue); - static JavascriptListIterator* UnsafeFromVar(Var aValue); - class EntryInfo { public: @@ -33,5 +29,10 @@ namespace Js static Var EntryNext(RecyclableObject* function, CallInfo callInfo, ...); }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_ListIterator; + } } // namespace Js diff --git a/lib/Runtime/Library/JavascriptMap.cpp b/lib/Runtime/Library/JavascriptMap.cpp index 0500cbed33e..e60abe8e2b2 100644 --- a/lib/Runtime/Library/JavascriptMap.cpp +++ b/lib/Runtime/Library/JavascriptMap.cpp @@ -18,25 +18,6 @@ JavascriptMap* JavascriptMap::New(ScriptContext* scriptContext) return map; } -bool JavascriptMap::Is(Var aValue) -{ - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Map; -} - -JavascriptMap* JavascriptMap::FromVar(Var aValue) -{ - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptMap'"); - - return static_cast(aValue); -} - -JavascriptMap* JavascriptMap::UnsafeFromVar(Var aValue) -{ - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptMap'"); - - return static_cast(aValue); -} - JavascriptMap::MapDataList::Iterator JavascriptMap::GetIterator() { return list.GetIterator(); @@ -87,7 +68,7 @@ Var JavascriptMap::NewInstance(RecyclableObject* function, CallInfo callInfo, .. { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedFunction); } - adder = RecyclableObject::FromVar(adderVar); + adder = VarTo(adderVar); } if (iter != nullptr) @@ -100,7 +81,7 @@ Var JavascriptMap::NewInstance(RecyclableObject* function, CallInfo callInfo, .. JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedObject); } - RecyclableObject* obj = RecyclableObject::FromVar(nextItem); + RecyclableObject* obj = VarTo(nextItem); Var key = nullptr, value = nullptr; @@ -124,7 +105,7 @@ Var JavascriptMap::NewInstance(RecyclableObject* function, CallInfo callInfo, .. } return isCtorSuperCall ? - JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), mapObject, nullptr, scriptContext) : + JavascriptOperators::OrdinaryCreateFromConstructor(VarTo(newTarget), mapObject, nullptr, scriptContext) : mapObject; } @@ -184,7 +165,7 @@ Var JavascriptMap::EntryForEach(RecyclableObject* function, CallInfo callInfo, . { JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_NeedFunction, _u("Map.prototype.forEach")); } - RecyclableObject* callBackFn = RecyclableObject::FromVar(args[1]); + RecyclableObject* callBackFn = VarTo(args[1]); Var thisArg = (args.Info.Count > 2) ? args[2] : scriptContext->GetLibrary()->GetUndefined(); diff --git a/lib/Runtime/Library/JavascriptMap.h b/lib/Runtime/Library/JavascriptMap.h index ac0948a1dd9..e0b831d7083 100644 --- a/lib/Runtime/Library/JavascriptMap.h +++ b/lib/Runtime/Library/JavascriptMap.h @@ -60,10 +60,6 @@ namespace Js static JavascriptMap* New(ScriptContext* scriptContext); - static bool Is(Var aValue); - static JavascriptMap* FromVar(Var aValue); - static JavascriptMap* UnsafeFromVar(Var aValue); - void Clear(); bool Delete(Var key); @@ -118,4 +114,9 @@ namespace Js static JavascriptMap* CreateForSnapshotRestore(ScriptContext* ctx); #endif }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_Map; + } } diff --git a/lib/Runtime/Library/JavascriptMapIterator.cpp b/lib/Runtime/Library/JavascriptMapIterator.cpp index a37034257f6..374af21853e 100644 --- a/lib/Runtime/Library/JavascriptMapIterator.cpp +++ b/lib/Runtime/Library/JavascriptMapIterator.cpp @@ -15,26 +15,6 @@ namespace Js Assert(type->GetTypeId() == TypeIds_MapIterator); } - bool JavascriptMapIterator::Is(Var aValue) - { - TypeId typeId = JavascriptOperators::GetTypeId(aValue); - return typeId == TypeIds_MapIterator; - } - - JavascriptMapIterator* JavascriptMapIterator::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptMapIterator'"); - - return static_cast(aValue); - } - - JavascriptMapIterator* JavascriptMapIterator::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptMapIterator'"); - - return static_cast(aValue); - } - Var JavascriptMapIterator::EntryNext(RecyclableObject* function, CallInfo callInfo, ...) { PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault); @@ -47,12 +27,12 @@ namespace Js Var thisObj = args[0]; - if (!JavascriptMapIterator::Is(thisObj)) + if (!VarIs(thisObj)) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedMapIterator, _u("Map Iterator.prototype.next")); } - JavascriptMapIterator* iterator = JavascriptMapIterator::FromVar(thisObj); + JavascriptMapIterator* iterator = VarTo(thisObj); JavascriptMap* map = iterator->m_map; auto& mapIterator = iterator->m_mapIterator; diff --git a/lib/Runtime/Library/JavascriptMapIterator.h b/lib/Runtime/Library/JavascriptMapIterator.h index 96849c6029a..526b8ad5b5d 100644 --- a/lib/Runtime/Library/JavascriptMapIterator.h +++ b/lib/Runtime/Library/JavascriptMapIterator.h @@ -27,10 +27,6 @@ namespace Js public: JavascriptMapIterator(DynamicType* type, JavascriptMap* map, JavascriptMapIteratorKind kind); - static bool Is(Var aValue); - static JavascriptMapIterator* FromVar(Var aValue); - static JavascriptMapIterator* UnsafeFromVar(Var aValue); - class EntryInfo { public: @@ -42,4 +38,9 @@ namespace Js public: JavascriptMap* GetMapForHeapEnum() { return m_map; } }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_MapIterator; + } } // namespace Js diff --git a/lib/Runtime/Library/JavascriptNumber.cpp b/lib/Runtime/Library/JavascriptNumber.cpp index c7572d71a96..3d61a259c79 100644 --- a/lib/Runtime/Library/JavascriptNumber.cpp +++ b/lib/Runtime/Library/JavascriptNumber.cpp @@ -383,9 +383,9 @@ namespace Js { result = args[1]; } - else if (JavascriptNumberObject::Is(args[1])) + else if (VarIs(args[1])) { - result = JavascriptNumber::ToVarNoCheck(JavascriptNumberObject::FromVar(args[1])->GetValue(), scriptContext); + result = JavascriptNumber::ToVarNoCheck(VarTo(args[1])->GetValue(), scriptContext); } else { @@ -404,7 +404,7 @@ namespace Js } return isCtorSuperCall ? - JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), RecyclableObject::FromVar(result), nullptr, scriptContext) : + JavascriptOperators::OrdinaryCreateFromConstructor(VarTo(newTarget), VarTo(result), nullptr, scriptContext) : result; } @@ -567,7 +567,7 @@ namespace Js if (JavascriptOperators::GetTypeId(args[0]) == TypeIds_HostDispatch) { Var result; - if (RecyclableObject::FromVar(args[0])->InvokeBuiltInOperationRemotely(EntryToExponential, args, &result)) + if (VarTo(args[0])->InvokeBuiltInOperationRemotely(EntryToExponential, args, &result)) { return result; } @@ -634,7 +634,7 @@ namespace Js if (JavascriptOperators::GetTypeId(args[0]) == TypeIds_HostDispatch) { Var result; - if (RecyclableObject::FromVar(args[0])->InvokeBuiltInOperationRemotely(EntryToFixed, args, &result)) + if (VarTo(args[0])->InvokeBuiltInOperationRemotely(EntryToFixed, args, &result)) { return result; } @@ -708,7 +708,7 @@ namespace Js if (JavascriptOperators::GetTypeId(args[0]) == TypeIds_HostDispatch) { Var result; - if (RecyclableObject::FromVar(args[0])->InvokeBuiltInOperationRemotely(EntryToPrecision, args, &result)) + if (VarTo(args[0])->InvokeBuiltInOperationRemotely(EntryToPrecision, args, &result)) { return result; } @@ -783,7 +783,7 @@ namespace Js { BEGIN_SAFE_REENTRANT_CALL(scriptContext->GetThreadContext()) { - return JavascriptString::FromVar(func->CallFunction(args)); + return VarTo(func->CallFunction(args)); } END_SAFE_REENTRANT_CALL } @@ -794,7 +794,7 @@ namespace Js { BEGIN_SAFE_REENTRANT_CALL(scriptContext->GetThreadContext()) { - return JavascriptString::FromVar(func->CallFunction(args)); + return VarTo(func->CallFunction(args)); } END_SAFE_REENTRANT_CALL } @@ -808,9 +808,9 @@ namespace Js if (JavascriptOperators::GetTypeId(args[0]) == TypeIds_HostDispatch) { Var result; - if (RecyclableObject::FromVar(args[0])->InvokeBuiltInOperationRemotely(EntryToLocaleString, args, &result)) + if (VarTo(args[0])->InvokeBuiltInOperationRemotely(EntryToLocaleString, args, &result)) { - return JavascriptString::FromVar(result); + return VarTo(result); } } @@ -846,7 +846,7 @@ namespace Js if (JavascriptOperators::GetTypeId(args[0]) == TypeIds_HostDispatch) { Var result; - if (RecyclableObject::FromVar(args[0])->InvokeBuiltInOperationRemotely(EntryToString, args, &result)) + if (VarTo(args[0])->InvokeBuiltInOperationRemotely(EntryToString, args, &result)) { return result; } @@ -905,9 +905,9 @@ namespace Js { return value; } - else if (JavascriptNumberObject::Is(value)) + else if (VarIs(value)) { - JavascriptNumberObject* obj = JavascriptNumberObject::FromVar(value); + JavascriptNumberObject* obj = VarTo(value); return CrossSite::MarshalVar(scriptContext, obj->Unwrap(), obj->GetScriptContext()); } else if (Js::JavascriptOperators::GetTypeId(value) == TypeIds_Int64Number) @@ -923,7 +923,7 @@ namespace Js if (JavascriptOperators::GetTypeId(value) == TypeIds_HostDispatch) { Var result; - if (RecyclableObject::FromVar(value)->InvokeBuiltInOperationRemotely(EntryValueOf, args, &result)) + if (VarTo(value)->InvokeBuiltInOperationRemotely(EntryValueOf, args, &result)) { return result; } @@ -1020,12 +1020,12 @@ namespace Js } else if (typeId == TypeIds_Int64Number) { - *pDouble = (double)JavascriptInt64Number::FromVar(aValue)->GetValue(); + *pDouble = (double)VarTo(aValue)->GetValue(); return TRUE; } else if (typeId == TypeIds_UInt64Number) { - *pDouble = (double)JavascriptUInt64Number::FromVar(aValue)->GetValue(); + *pDouble = (double)VarTo(aValue)->GetValue(); return TRUE; } else if (JavascriptNumber::Is_NoTaggedIntCheck(aValue)) @@ -1035,7 +1035,7 @@ namespace Js } else if (typeId == TypeIds_NumberObject) { - JavascriptNumberObject* obj = JavascriptNumberObject::FromVar(aValue); + JavascriptNumberObject* obj = VarTo(aValue); *pDouble = obj->GetValue(); return TRUE; } @@ -1094,7 +1094,7 @@ namespace Js JavascriptString *result = nullptr; - JavascriptString *dblStr = JavascriptString::FromVar(FormatDoubleToString(value, NumberUtilities::FormatFixed, -1, scriptContext)); + JavascriptString *dblStr = VarTo(FormatDoubleToString(value, NumberUtilities::FormatFixed, -1, scriptContext)); const char16* szValue = dblStr->GetSz(); const size_t szLength = dblStr->GetLength(); diff --git a/lib/Runtime/Library/JavascriptNumber.inl b/lib/Runtime/Library/JavascriptNumber.inl index 80e563b4ad6..539ec3836c1 100644 --- a/lib/Runtime/Library/JavascriptNumber.inl +++ b/lib/Runtime/Library/JavascriptNumber.inl @@ -161,7 +161,7 @@ namespace Js #if !defined(USED_IN_STATIC_LIB) inline bool JavascriptNumber::Is_NoTaggedIntCheck(Var aValue) { - RecyclableObject* object = RecyclableObject::FromVar(aValue); + RecyclableObject* object = VarTo(aValue); AssertMsg((object->GetTypeId() == TypeIds_Number) == VirtualTableInfo::HasVirtualTable(object), "JavascriptNumber has no unique VTABLE?"); return VirtualTableInfo::HasVirtualTable(object); } diff --git a/lib/Runtime/Library/JavascriptNumberObject.cpp b/lib/Runtime/Library/JavascriptNumberObject.cpp index cae552183a2..6e552066cc8 100644 --- a/lib/Runtime/Library/JavascriptNumberObject.cpp +++ b/lib/Runtime/Library/JavascriptNumberObject.cpp @@ -20,25 +20,6 @@ namespace Js Assert(TaggedInt::Is(value) || !ThreadContext::IsOnStack(value)); } - bool JavascriptNumberObject::Is(Var aValue) - { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_NumberObject; - } - - JavascriptNumberObject* JavascriptNumberObject::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptNumber'"); - - return static_cast(aValue); - } - - JavascriptNumberObject* JavascriptNumberObject::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptNumber'"); - - return static_cast(aValue); - } - Var JavascriptNumberObject::Unwrap() const { return value; diff --git a/lib/Runtime/Library/JavascriptNumberObject.h b/lib/Runtime/Library/JavascriptNumberObject.h index 461951eda6e..bfd865daa02 100644 --- a/lib/Runtime/Library/JavascriptNumberObject.h +++ b/lib/Runtime/Library/JavascriptNumberObject.h @@ -18,9 +18,6 @@ namespace Js public: JavascriptNumberObject(Var value, DynamicType * type); - static bool Is(Var aValue); - static JavascriptNumberObject* FromVar(Var aValue); - static JavascriptNumberObject* UnsafeFromVar(Var aValue); double GetValue() const; void SetValue(Var value); Var Unwrap() const; @@ -38,4 +35,9 @@ namespace Js virtual void ExtractSnapObjectDataInto(TTD::NSSnapObjects::SnapObject* objData, TTD::SlabAllocator& alloc) override; #endif }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_NumberObject; + } } diff --git a/lib/Runtime/Library/JavascriptObject.cpp b/lib/Runtime/Library/JavascriptObject.cpp index a204f4a6ed0..02e9e3cfb2b 100644 --- a/lib/Runtime/Library/JavascriptObject.cpp +++ b/lib/Runtime/Library/JavascriptObject.cpp @@ -44,7 +44,7 @@ Var JavascriptObject::NewInstance(RecyclableObject* function, CallInfo callInfo, case TypeIds_ActivationObject: case TypeIds_SymbolObject: return isCtorSuperCall ? - JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), RecyclableObject::FromVar(args[1]), nullptr, scriptContext) : + JavascriptOperators::OrdinaryCreateFromConstructor(VarTo(newTarget), VarTo(args[1]), nullptr, scriptContext) : args[1]; default: @@ -56,7 +56,7 @@ Var JavascriptObject::NewInstance(RecyclableObject* function, CallInfo callInfo, } return isCtorSuperCall ? - JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), result, nullptr, scriptContext) : + JavascriptOperators::OrdinaryCreateFromConstructor(VarTo(newTarget), result, nullptr, scriptContext) : result; } } @@ -67,7 +67,7 @@ Var JavascriptObject::NewInstance(RecyclableObject* function, CallInfo callInfo, } Var newObj = scriptContext->GetLibrary()->CreateObject(true); return isCtorSuperCall ? - JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), RecyclableObject::FromVar(newObj), nullptr, scriptContext) : + JavascriptOperators::OrdinaryCreateFromConstructor(VarTo(newTarget), VarTo(newObj), nullptr, scriptContext) : newObj; } @@ -152,9 +152,9 @@ BOOL JavascriptObject::ChangePrototype(RecyclableObject* object, RecyclableObjec Assert(JavascriptOperators::IsObject(object)); Assert(JavascriptOperators::IsObjectOrNull(newPrototype)); - if (JavascriptProxy::Is(object)) + if (VarIs(object)) { - JavascriptProxy* proxy = JavascriptProxy::FromVar(object); + JavascriptProxy* proxy = VarTo(object); CrossSite::ForceCrossSiteThunkOnPrototypeChain(newPrototype); return proxy->SetPrototypeTrap(newPrototype, shouldThrow, scriptContext); } @@ -207,7 +207,7 @@ BOOL JavascriptObject::ChangePrototype(RecyclableObject* object, RecyclableObjec // 8. Return true. bool isInvalidationOfInlineCacheNeeded = true; - DynamicObject * obj = DynamicObject::FromVar(object); + DynamicObject * obj = VarTo(object); // If this object was not prototype object, then no need to invalidate inline caches. // Simply assign it a new type so if this object used protoInlineCache in past, it will @@ -296,7 +296,7 @@ BOOL JavascriptObject::ChangePrototype(RecyclableObject* object, RecyclableObjec } // Set to new prototype - if (object->IsExternal() || (DynamicType::Is(object->GetTypeId()) && (DynamicObject::UnsafeFromVar(object))->IsCrossSiteObject())) + if (object->IsExternal() || (DynamicType::Is(object->GetTypeId()) && (UnsafeVarTo(object))->IsCrossSiteObject())) { CrossSite::ForceCrossSiteThunkOnPrototypeChain(newPrototype); } @@ -326,11 +326,11 @@ Var JavascriptObject::EntryIsPrototypeOf(RecyclableObject* function, CallInfo ca { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NullOrUndefined, _u("Object.prototype.isPrototypeOf")); } - RecyclableObject* value = RecyclableObject::FromVar(args[1]); + RecyclableObject* value = VarTo(args[1]); if (dynamicObject->GetTypeId() == TypeIds_GlobalObject) { - dynamicObject = RecyclableObject::FromVar(static_cast(dynamicObject)->ToThis()); + dynamicObject = VarTo(static_cast(dynamicObject)->ToThis()); } while (!JavascriptOperators::IsNull(value)) @@ -369,7 +369,7 @@ Var JavascriptObject::EntryToLocaleString(RecyclableObject* function, CallInfo c JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_NeedFunction, _u("Object.prototype.toLocaleString")); } - RecyclableObject* toStringFunc = RecyclableObject::FromVar(toStringVar); + RecyclableObject* toStringFunc = VarTo(toStringVar); if (toStringFunc == scriptContext->GetLibrary()->GetObjectToStringFunction()) { return ToStringHelper(thisValue, scriptContext); @@ -461,7 +461,7 @@ JavascriptString* JavascriptObject::ToStringTagHelper(Var thisArg, ScriptContext // 17. Return the String that is the result of concatenating "[object ", tag, and "]". auto buildToString = [&scriptContext](Var tag) { - JavascriptString *tagStr = JavascriptString::FromVar(tag); + JavascriptString *tagStr = VarTo(tag); const WCHAR objectStartString[9] = _u("[object "); const WCHAR objectEndString[1] = { _u(']') }; CompoundString *const cs = CompoundString::NewWithCharCapacity(_countof(objectStartString) @@ -473,7 +473,7 @@ JavascriptString* JavascriptObject::ToStringTagHelper(Var thisArg, ScriptContext return cs; }; - if (tag != nullptr && JavascriptString::Is(tag)) + if (tag != nullptr && VarIs(tag)) { return buildToString(tag); } @@ -572,7 +572,7 @@ Var JavascriptObject::ToStringHelper(Var thisArg, ScriptContext* scriptContext) // We first need to make sure we are in the right context. if (type == TypeIds_HostDispatch) { - RecyclableObject* hostDispatchObject = RecyclableObject::FromVar(thisArg); + RecyclableObject* hostDispatchObject = VarTo(thisArg); const DynamicObject* remoteObject = hostDispatchObject->GetRemoteObject(); if (!remoteObject) { @@ -691,7 +691,7 @@ BOOL JavascriptObject::GetOwnPropertyDescriptorHelper(RecyclableObject* obj, Pro if (obj->IsExternal()) { isPropertyDescriptorDefined = obj->HasOwnProperty(propertyId) ? - JavascriptOperators::GetOwnPropertyDescriptor(obj, propertyId, scriptContext, &propertyDescriptor) : + JavascriptOperators::GetOwnPropertyDescriptor(obj, propertyId, scriptContext, &propertyDescriptor) : FALSE; } else @@ -826,8 +826,8 @@ Var JavascriptObject::EntrySetPrototypeOf(RecyclableObject* function, CallInfo c #if ENABLE_COPYONACCESS_ARRAY JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray(args[1]); #endif - RecyclableObject* object = RecyclableObject::FromVar(args[1]); - RecyclableObject* newPrototype = RecyclableObject::FromVar(args[2]); + RecyclableObject* object = VarTo(args[1]); + RecyclableObject* newPrototype = VarTo(args[2]); // 5. Let status be O.[[SetPrototypeOf]](proto). // 6. ReturnIfAbrupt(status). @@ -860,7 +860,7 @@ Var JavascriptObject::EntrySeal(RecyclableObject* function, CallInfo callInfo, . } - RecyclableObject *object = RecyclableObject::FromVar(args[1]); + RecyclableObject *object = VarTo(args[1]); GlobalObject* globalObject = object->GetLibrary()->GetGlobalObject(); if (globalObject != object && globalObject && (globalObject->ToThis() == object)) @@ -892,7 +892,7 @@ Var JavascriptObject::EntryFreeze(RecyclableObject* function, CallInfo callInfo, return args[1]; } - RecyclableObject *object = RecyclableObject::FromVar(args[1]); + RecyclableObject *object = VarTo(args[1]); GlobalObject* globalObject = object->GetLibrary()->GetGlobalObject(); if (globalObject != object && globalObject && (globalObject->ToThis() == object)) @@ -924,7 +924,7 @@ Var JavascriptObject::EntryPreventExtensions(RecyclableObject* function, CallInf return args[1]; } - RecyclableObject *object = RecyclableObject::FromVar(args[1]); + RecyclableObject *object = VarTo(args[1]); GlobalObject* globalObject = object->GetLibrary()->GetGlobalObject(); if (globalObject != object && globalObject && (globalObject->ToThis() == object)) @@ -952,7 +952,7 @@ Var JavascriptObject::EntryIsSealed(RecyclableObject* function, CallInfo callInf return scriptContext->GetLibrary()->GetTrue(); } - RecyclableObject *object = RecyclableObject::FromVar(args[1]); + RecyclableObject *object = VarTo(args[1]); BOOL isSealed = object->IsSealed(); @@ -980,7 +980,7 @@ Var JavascriptObject::EntryIsFrozen(RecyclableObject* function, CallInfo callInf return scriptContext->GetLibrary()->GetTrue(); } - RecyclableObject *object = RecyclableObject::FromVar(args[1]); + RecyclableObject *object = VarTo(args[1]); BOOL isFrozen = object->IsFrozen(); @@ -1008,7 +1008,7 @@ Var JavascriptObject::EntryIsExtensible(RecyclableObject* function, CallInfo cal return scriptContext->GetLibrary()->GetFalse(); } - RecyclableObject *object = RecyclableObject::FromVar(args[1]); + RecyclableObject *object = VarTo(args[1]); BOOL isExtensible = object->IsExtensible(); GlobalObject* globalObject = object->GetLibrary()->GetGlobalObject(); @@ -1108,7 +1108,7 @@ Var JavascriptObject::GetValuesOrEntries(RecyclableObject* object, bool valuesTo for (uint32 i = 0, index = 0; i < length; i++) { nextKey = ownKeysResult->DirectGetItem(i); - Assert(JavascriptString::Is(nextKey)); + Assert(VarIs(nextKey)); PropertyDescriptor propertyDescriptor; @@ -1296,7 +1296,7 @@ Var JavascriptObject::EntryDefineProperty(RecyclableObject* function, CallInfo c #if ENABLE_COPYONACCESS_ARRAY JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray(args[1]); #endif - RecyclableObject* obj = RecyclableObject::FromVar(args[1]); + RecyclableObject* obj = VarTo(args[1]); // If the object is HostDispatch try to invoke the operation remotely if (obj->GetTypeId() == TypeIds_HostDispatch) @@ -1347,7 +1347,7 @@ Var JavascriptObject::EntryDefineProperties(RecyclableObject* function, CallInfo #if ENABLE_COPYONACCESS_ARRAY JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray(args[1]); #endif - RecyclableObject *object = RecyclableObject::FromVar(args[1]); + RecyclableObject *object = VarTo(args[1]); // If the object is HostDispatch try to invoke the operation remotely if (object->GetTypeId() == TypeIds_HostDispatch) @@ -1619,7 +1619,7 @@ void JavascriptObject::CopyDataPropertiesHelper(Var source, RecyclableObject* to JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray(from); #endif // if proxy, take slow path by calling [[OwnPropertyKeys]] on source - if (JavascriptProxy::Is(from)) + if (VarIs(from)) { CopyDataPropertiesForProxyObjects(from, to, excluded, scriptContext); } @@ -1631,8 +1631,8 @@ void JavascriptObject::CopyDataPropertiesHelper(Var source, RecyclableObject* to bool copied = false; if (tryCopy) { - DynamicObject* fromObj = JavascriptOperators::TryFromVar(from); - DynamicObject* toObj = JavascriptOperators::TryFromVar(to); + DynamicObject* fromObj = DynamicObject::TryVarToBaseDynamicObject(from); + DynamicObject* toObj = DynamicObject::TryVarToBaseDynamicObject(to); if (toObj && fromObj && toObj->GetType() == scriptContext->GetLibrary()->GetObjectType()) { copied = toObj->TryCopy(fromObj); @@ -1687,7 +1687,7 @@ void JavascriptObject::CopyDataPropertiesForGenericObjects(RecyclableObject* fro } if (!found) { - PropertyString * propertyString = PropertyString::TryFromVar(propertyName); + PropertyString * propertyString = JavascriptOperators::TryFromVar(propertyName); // If propertyName is a PropertyString* we can try getting the property from the inline cache to avoid having a full property lookup // @@ -1740,7 +1740,7 @@ void JavascriptObject::CopyDataPropertiesForProxyObjects(RecyclableObject* from, { PropertyDescriptor propertyDescriptor; nextKey = keys->DirectGetItem(j); - AssertMsg(JavascriptSymbol::Is(nextKey) || JavascriptString::Is(nextKey), "Invariant check during ownKeys proxy trap should make sure we only get property key here. (symbol or string primitives)"); + AssertMsg(VarIs(nextKey) || VarIs(nextKey), "Invariant check during ownKeys proxy trap should make sure we only get property key here. (symbol or string primitives)"); // Spec doesn't strictly call for us to use ToPropertyKey but since we know nextKey is already a symbol or string primitive, ToPropertyKey will be a nop and return us the propertyRecord JavascriptConversion::ToPropertyKey(nextKey, scriptContext, &propertyRecord, nullptr); propertyId = propertyRecord->GetPropertyId(); @@ -1795,7 +1795,7 @@ BOOL JavascriptObject::CreateDataProperty(RecyclableObject* obj, PropertyId key, newDesc.SetEnumerable(true); newDesc.SetConfigurable(true); - // 4. Return ? O.[[DefineOwnProperty]](P, newDesc). + // 4. Return ? O.[[DefineOwnProperty]](P, newDesc). return DefineOwnPropertyHelper(obj, key, newDesc, scriptContext); } @@ -1823,14 +1823,14 @@ Var JavascriptObject::EntryCreate(RecyclableObject* function, CallInfo callInfo, JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_NotObjectOrNull, _u("Object.create")); } - RecyclableObject* protoObj = RecyclableObject::FromVar(protoVar); + RecyclableObject* protoObj = VarTo(protoVar); DynamicObject* object = function->GetLibrary()->CreateObject(protoObj); JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_OBJECT(object)); #if ENABLE_DEBUG_CONFIG_OPTIONS if (Js::Configuration::Global.flags.IsEnabled(Js::autoProxyFlag)) { - object = DynamicObject::FromVar(JavascriptProxy::AutoProxyWrapper(object)); + object = VarTo(JavascriptProxy::AutoProxyWrapper(object)); } #endif @@ -1848,7 +1848,7 @@ Var JavascriptObject::EntryCreate(RecyclableObject* function, CallInfo callInfo, Var JavascriptObject::DefinePropertiesHelper(RecyclableObject *object, RecyclableObject* props, ScriptContext *scriptContext) { - if (JavascriptProxy::Is(props)) + if (VarIs(props)) { return DefinePropertiesHelperForProxyObjects(object, props, scriptContext); } @@ -1943,7 +1943,7 @@ Var JavascriptObject::DefinePropertiesHelperForGenericObjects(RecyclableObject * //ES5 15.2.3.7 Var JavascriptObject::DefinePropertiesHelperForProxyObjects(RecyclableObject *object, RecyclableObject* props, ScriptContext *scriptContext) { - Assert(JavascriptProxy::Is(props)); + Assert(VarIs(props)); //1. If Type(O) is not Object throw a TypeError exception. //2. Let props be ToObject(Properties). @@ -1982,7 +1982,7 @@ Var JavascriptObject::DefinePropertiesHelperForProxyObjects(RecyclableObject *ob { PropertyDescriptor propertyDescriptor; nextKey = keys->DirectGetItem(j); - AssertMsg(JavascriptSymbol::Is(nextKey) || JavascriptString::Is(nextKey), "Invariant check during ownKeys proxy trap should make sure we only get property key here. (symbol or string primitives)"); + AssertMsg(VarIs(nextKey) || VarIs(nextKey), "Invariant check during ownKeys proxy trap should make sure we only get property key here. (symbol or string primitives)"); JavascriptConversion::ToPropertyKey(nextKey, scriptContext, &propertyRecord, nullptr); propertyId = propertyRecord->GetPropertyId(); AssertMsg(propertyId != Constants::NoProperty, "DefinePropertiesHelper - OwnPropertyKeys returned a propertyId with value NoProperty."); @@ -2090,8 +2090,8 @@ void JavascriptObject::ModifyGetterSetterFuncName(const PropertyRecord * propert charcount_t propertyLength = propertyRecord->GetLength(); if (descriptor.GetterSpecified() - && Js::ScriptFunction::Is(descriptor.GetGetter()) - && _wcsicmp(Js::ScriptFunction::FromVar(descriptor.GetGetter())->GetFunctionProxy()->GetDisplayName(), _u("get")) == 0) + && Js::VarIs(descriptor.GetGetter()) + && _wcsicmp(Js::VarTo(descriptor.GetGetter())->GetFunctionProxy()->GetDisplayName(), _u("get")) == 0) { // modify to name.get const char16* finalName = ConstructName(propertyRecord, _u(".get"), scriptContext); @@ -2099,14 +2099,14 @@ void JavascriptObject::ModifyGetterSetterFuncName(const PropertyRecord * propert { FunctionProxy::SetDisplayNameFlags flags = (FunctionProxy::SetDisplayNameFlags) (FunctionProxy::SetDisplayNameFlagsDontCopy | FunctionProxy::SetDisplayNameFlagsRecyclerAllocated); - Js::ScriptFunction::FromVar(descriptor.GetGetter())->GetFunctionProxy()->SetDisplayName(finalName, + Js::VarTo(descriptor.GetGetter())->GetFunctionProxy()->SetDisplayName(finalName, propertyLength + 4 /*".get"*/, propertyLength + 1, flags); } } if (descriptor.SetterSpecified() - && Js::ScriptFunction::Is(descriptor.GetSetter()) - && _wcsicmp(Js::ScriptFunction::FromVar(descriptor.GetSetter())->GetFunctionProxy()->GetDisplayName(), _u("set")) == 0) + && Js::VarIs(descriptor.GetSetter()) + && _wcsicmp(Js::VarTo(descriptor.GetSetter())->GetFunctionProxy()->GetDisplayName(), _u("set")) == 0) { // modify to name.set const char16* finalName = ConstructName(propertyRecord, _u(".set"), scriptContext); @@ -2114,7 +2114,7 @@ void JavascriptObject::ModifyGetterSetterFuncName(const PropertyRecord * propert { FunctionProxy::SetDisplayNameFlags flags = (FunctionProxy::SetDisplayNameFlags) (FunctionProxy::SetDisplayNameFlagsDontCopy | FunctionProxy::SetDisplayNameFlagsRecyclerAllocated); - Js::ScriptFunction::FromVar(descriptor.GetSetter())->GetFunctionProxy()->SetDisplayName(finalName, + Js::VarTo(descriptor.GetSetter())->GetFunctionProxy()->SetDisplayName(finalName, propertyLength + 4 /*".set"*/, propertyLength + 1, flags); } } @@ -2143,7 +2143,7 @@ BOOL JavascriptObject::DefineOwnPropertyHelper(RecyclableObject* obj, PropertyId else if (DynamicObject::IsAnyTypedArray(obj)) { returnValue = JavascriptOperators::DefineOwnPropertyForTypedArray( - TypedArrayBase::FromVar(obj), propId, descriptor, throwOnError, scriptContext); + VarTo(obj), propId, descriptor, throwOnError, scriptContext); } // TODO: implement DefineOwnProperty for other object built-in exotic types. else @@ -2206,7 +2206,7 @@ void JavascriptObject::Restify(Var source, Var to, void* excludedStatic, void* e PropertyId id = propIdsStatic->elements[i]; excluded.Set(id); } - // If these two are equal, this means there were no computed properties + // If these two are equal, this means there were no computed properties // and the static array was passed in to indicate this if (propIdsStatic != propIdsComputed) { diff --git a/lib/Runtime/Library/JavascriptPromise.cpp b/lib/Runtime/Library/JavascriptPromise.cpp index c11624902d2..fafcaae1588 100644 --- a/lib/Runtime/Library/JavascriptPromise.cpp +++ b/lib/Runtime/Library/JavascriptPromise.cpp @@ -47,13 +47,13 @@ namespace Js { JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_NeedFunction, _u("Promise")); } - RecyclableObject* executor = RecyclableObject::FromVar(args[1]); + RecyclableObject* executor = VarTo(args[1]); // 3. Let promise be ? OrdinaryCreateFromConstructor(NewTarget, "%PromisePrototype%", <<[[PromiseState]], [[PromiseResult]], [[PromiseFulfillReactions]], [[PromiseRejectReactions]], [[PromiseIsHandled]] >>). JavascriptPromise* promise = library->CreatePromise(); if (isCtorSuperCall) { - JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), promise, library->GetPromisePrototype(), scriptContext); + JavascriptOperators::OrdinaryCreateFromConstructor(VarTo(newTarget), promise, library->GetPromisePrototype(), scriptContext); } JavascriptPromiseResolveOrRejectFunction* resolve; @@ -117,25 +117,6 @@ namespace Js *reject = library->CreatePromiseResolveOrRejectFunction(EntryResolveOrRejectFunction, promise, true, alreadyResolvedRecord); } - bool JavascriptPromise::Is(Var aValue) - { - return Js::JavascriptOperators::GetTypeId(aValue) == TypeIds_Promise; - } - - JavascriptPromise* JavascriptPromise::FromVar(Js::Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptPromise'"); - - return static_cast(aValue); - } - - JavascriptPromise* JavascriptPromise::UnsafeFromVar(Js::Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptPromise'"); - - return static_cast(aValue); - } - BOOL JavascriptPromise::GetDiagValueString(StringBuilder* stringBuilder, ScriptContext* requestContext) { stringBuilder->AppendCppLiteral(_u("[...]")); @@ -192,7 +173,7 @@ namespace Js // We know that constructor is an object at this point - further, we even know that it is a constructor - because NewPromiseCapability // would throw otherwise. That means we can safely cast constructor into a RecyclableObject* now and avoid having to perform ToObject // as part of the Invoke operation performed inside the loop below. - RecyclableObject* constructorObject = RecyclableObject::FromVar(constructor); + RecyclableObject* constructorObject = VarTo(constructor); uint32 index = 0; JavascriptArray* values = nullptr; @@ -220,7 +201,7 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedFunction); } - RecyclableObject* resolveFunc = RecyclableObject::FromVar(resolveVar); + RecyclableObject* resolveFunc = VarTo(resolveVar); ThreadContext * threadContext = scriptContext->GetThreadContext(); Var nextPromise = nullptr; @@ -251,7 +232,7 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedFunction); } - RecyclableObject* thenFunc = RecyclableObject::FromVar(thenVar); + RecyclableObject* thenFunc = VarTo(thenVar); BEGIN_SAFE_REENTRANT_CALL(threadContext) { @@ -330,7 +311,7 @@ namespace Js onRejected = undefinedVar; } - RecyclableObject* func = RecyclableObject::FromVar(funcVar); + RecyclableObject* func = VarTo(funcVar); BEGIN_SAFE_REENTRANT_CALL(scriptContext->GetThreadContext()) { @@ -381,7 +362,7 @@ namespace Js // We know that constructor is an object at this point - further, we even know that it is a constructor - because NewPromiseCapability // would throw otherwise. That means we can safely cast constructor into a RecyclableObject* now and avoid having to perform ToObject // as part of the Invoke operation performed inside the loop below. - RecyclableObject* constructorObject = RecyclableObject::FromVar(constructor); + RecyclableObject* constructorObject = VarTo(constructor); JavascriptExceptionObject* exception = nullptr; try @@ -398,7 +379,7 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedFunction); } - RecyclableObject* resolveFunc = RecyclableObject::FromVar(resolveVar); + RecyclableObject* resolveFunc = VarTo(resolveVar); ThreadContext * threadContext = scriptContext->GetThreadContext(); Var nextPromise = nullptr; @@ -425,7 +406,7 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedFunction); } - RecyclableObject* thenFunc = RecyclableObject::FromVar(thenVar); + RecyclableObject* thenFunc = VarTo(thenVar); BEGIN_SAFE_REENTRANT_CALL(threadContext) { @@ -521,7 +502,7 @@ namespace Js } // 3. If IsPromise(x) is true, - if (JavascriptPromise::Is(x)) + if (VarIs(x)) { // a. Let xConstructor be Get(x, "constructor"). Var xConstructor = JavascriptOperators::GetProperty((RecyclableObject*)x, PropertyIds::constructor, scriptContext); @@ -550,19 +531,19 @@ namespace Js AUTO_TAG_NATIVE_LIBRARY_ENTRY(function, callInfo, _u("Promise.prototype.then")); - if (args.Info.Count < 1 || !JavascriptPromise::Is(args[0])) + if (args.Info.Count < 1 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedPromise, _u("Promise.prototype.then")); } JavascriptLibrary* library = scriptContext->GetLibrary(); - JavascriptPromise* promise = JavascriptPromise::FromVar(args[0]); + JavascriptPromise* promise = VarTo(args[0]); RecyclableObject* rejectionHandler; RecyclableObject* fulfillmentHandler; if (args.Info.Count > 1 && JavascriptConversion::IsCallable(args[1])) { - fulfillmentHandler = RecyclableObject::FromVar(args[1]); + fulfillmentHandler = VarTo(args[1]); } else { @@ -571,7 +552,7 @@ namespace Js if (args.Info.Count > 2 && JavascriptConversion::IsCallable(args[2])) { - rejectionHandler = RecyclableObject::FromVar(args[2]); + rejectionHandler = VarTo(args[2]); } else { @@ -599,7 +580,7 @@ namespace Js } JavascriptLibrary* library = scriptContext->GetLibrary(); - RecyclableObject* promise = RecyclableObject::UnsafeFromVar(args[0]); + RecyclableObject* promise = UnsafeVarTo(args[0]); // 3. Let C be ? SpeciesConstructor(promise, %Promise%). RecyclableObject* constructor = JavascriptOperators::SpeciesConstructor(promise, scriptContext->GetLibrary()->GetPromiseConstructor(), scriptContext); // 4. Assert IsConstructor(C) @@ -607,7 +588,7 @@ namespace Js // 5. If IsCallable(onFinally) is false // a. Let thenFinally be onFinally - // b. Let catchFinally be onFinally + // b. Let catchFinally be onFinally // 6. Else, // a. Let thenFinally be a new built-in function object as defined in ThenFinally Function. // b. Let catchFinally be a new built-in function object as defined in CatchFinally Function. @@ -622,8 +603,8 @@ namespace Js if (JavascriptConversion::IsCallable(args[1])) { //note to avoid duplicating code the ThenFinallyFunction works as both thenFinally and catchFinally using a flag - thenFinally = library->CreatePromiseThenFinallyFunction(EntryThenFinallyFunction, RecyclableObject::FromVar(args[1]), constructor, false); - catchFinally = library->CreatePromiseThenFinallyFunction(EntryThenFinallyFunction, RecyclableObject::FromVar(args[1]), constructor, true); + thenFinally = library->CreatePromiseThenFinallyFunction(EntryThenFinallyFunction, VarTo(args[1]), constructor, false); + catchFinally = library->CreatePromiseThenFinallyFunction(EntryThenFinallyFunction, VarTo(args[1]), constructor, true); } else { @@ -645,7 +626,7 @@ namespace Js { JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_NeedFunction, _u("Promise.prototype.finally")); } - RecyclableObject* func = RecyclableObject::UnsafeFromVar(funcVar); + RecyclableObject* func = UnsafeVarTo(funcVar); BEGIN_SAFE_REENTRANT_CALL(scriptContext->GetThreadContext()) { @@ -666,10 +647,10 @@ namespace Js ARGUMENTS(args, callInfo); Assert(!(callInfo.Flags & CallFlags_New)); ScriptContext* scriptContext = function->GetScriptContext(); - + JavascriptLibrary* library = scriptContext->GetLibrary(); - JavascriptPromiseThenFinallyFunction* thenFinallyFunction = JavascriptPromiseThenFinallyFunction::FromVar(function); + JavascriptPromiseThenFinallyFunction* thenFinallyFunction = VarTo(function); // 1. Let onFinally be F.[[OnFinally]] // 2. Assert: IsCallable(onFinally)=true @@ -716,7 +697,7 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_NeedFunction, _u("Promise.prototype.finally")); } - RecyclableObject* func = RecyclableObject::FromVar(funcVar); + RecyclableObject* func = VarTo(funcVar); BEGIN_SAFE_REENTRANT_CALL(scriptContext->GetThreadContext()) { @@ -736,11 +717,11 @@ namespace Js ARGUMENTS(args, callInfo); Assert(!(callInfo.Flags & CallFlags_New)); - JavascriptPromiseThunkFinallyFunction* thunkFinallyFunction = JavascriptPromiseThunkFinallyFunction::FromVar(function); + JavascriptPromiseThunkFinallyFunction* thunkFinallyFunction = VarTo(function); if (!thunkFinallyFunction->GetShouldThrow()) { - return thunkFinallyFunction->GetValue(); + return thunkFinallyFunction->GetValue(); } else { @@ -769,7 +750,7 @@ namespace Js resolution = undefinedVar; } - JavascriptPromiseResolveOrRejectFunction* resolveOrRejectFunction = JavascriptPromiseResolveOrRejectFunction::FromVar(function); + JavascriptPromiseResolveOrRejectFunction* resolveOrRejectFunction = VarTo(function); if (resolveOrRejectFunction->IsAlreadyResolved()) { @@ -811,16 +792,16 @@ namespace Js resolution = selfResolutionError; isRejecting = true; } - else if (RecyclableObject::Is(resolution)) + else if (VarIs(resolution)) { try { - RecyclableObject* thenable = RecyclableObject::FromVar(resolution); + RecyclableObject* thenable = VarTo(resolution); Var then = JavascriptOperators::GetPropertyNoCache(thenable, Js::PropertyIds::then, scriptContext); if (JavascriptConversion::IsCallable(then)) { - JavascriptPromiseResolveThenableTaskFunction* resolveThenableTaskFunction = library->CreatePromiseResolveThenableTaskFunction(EntryResolveThenableTaskFunction, this, thenable, RecyclableObject::FromVar(then)); + JavascriptPromiseResolveThenableTaskFunction* resolveThenableTaskFunction = library->CreatePromiseResolveThenableTaskFunction(EntryResolveThenableTaskFunction, this, thenable, VarTo(then)); library->EnqueueTask(resolveThenableTaskFunction); @@ -897,7 +878,7 @@ namespace Js } } - JavascriptPromiseCapabilitiesExecutorFunction* capabilitiesExecutorFunction = JavascriptPromiseCapabilitiesExecutorFunction::FromVar(function); + JavascriptPromiseCapabilitiesExecutorFunction* capabilitiesExecutorFunction = VarTo(function); JavascriptPromiseCapability* promiseCapability = capabilitiesExecutorFunction->GetCapability(); if (!JavascriptOperators::IsUndefined(promiseCapability->GetResolve()) || !JavascriptOperators::IsUndefined(promiseCapability->GetReject())) @@ -921,7 +902,7 @@ namespace Js ScriptContext* scriptContext = function->GetScriptContext(); Var undefinedVar = scriptContext->GetLibrary()->GetUndefined(); - JavascriptPromiseReactionTaskFunction* reactionTaskFunction = JavascriptPromiseReactionTaskFunction::FromVar(function); + JavascriptPromiseReactionTaskFunction* reactionTaskFunction = VarTo(function); JavascriptPromiseReaction* reaction = reactionTaskFunction->GetReaction(); Var argument = reactionTaskFunction->GetArgument(); JavascriptPromiseCapability* promiseCapability = reaction->GetCapabilities(); @@ -934,13 +915,13 @@ namespace Js bool isPromiseRejectionHandled = true; if (scriptContext->IsScriptContextInDebugMode()) { - // only necessary to determine if false if debugger is attached. This way we'll + // only necessary to determine if false if debugger is attached. This way we'll // correctly break on exceptions raised in promises that result in uhandled rejection // notifications Var promiseVar = promiseCapability->GetPromise(); - if (JavascriptPromise::Is(promiseVar)) + if (VarIs(promiseVar)) { - JavascriptPromise* promise = JavascriptPromise::FromVar(promiseVar); + JavascriptPromise* promise = VarTo(promiseVar); isPromiseRejectionHandled = !promise->WillRejectionBeUnhandled(); } } @@ -984,10 +965,10 @@ namespace Js bool willBeUnhandled = !this->GetIsHandled(); if (!willBeUnhandled) { - // if this promise is handled, then we need to do a depth-first search over this promise's reject - // reactions. If we find a reaction that + // if this promise is handled, then we need to do a depth-first search over this promise's reject + // reactions. If we find a reaction that // - associated promise is "unhandled" (ie, it's never been "then'd") - // - AND its rejection handler is our default "thrower function" + // - AND its rejection handler is our default "thrower function" // then this promise results in an unhandled rejection path. JsUtil::Stack stack(&HeapAllocator::Instance); @@ -1007,15 +988,15 @@ namespace Js JavascriptPromiseReaction* reaction = pair.rejectReaction; Var promiseVar = reaction->GetCapabilities()->GetPromise(); - if (JavascriptPromise::Is(promiseVar)) + if (VarIs(promiseVar)) { - JavascriptPromise* p = JavascriptPromise::FromVar(promiseVar); + JavascriptPromise* p = VarTo(promiseVar); if (!p->GetIsHandled()) { RecyclableObject* handler = reaction->GetHandler(); - if (JavascriptFunction::Is(handler)) + if (VarIs(handler)) { - JavascriptFunction* func = JavascriptFunction::FromVar(handler); + JavascriptFunction* func = VarTo(handler); FunctionInfo* functionInfo = func->GetFunctionInfo(); #ifdef DEBUG @@ -1058,7 +1039,7 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedFunction); } - RecyclableObject* handlerFunc = RecyclableObject::FromVar(handler); + RecyclableObject* handlerFunc = VarTo(handler); BEGIN_SAFE_REENTRANT_CALL(scriptContext->GetThreadContext()) { @@ -1171,7 +1152,7 @@ namespace Js ScriptContext* scriptContext = function->GetScriptContext(); JavascriptLibrary* library = scriptContext->GetLibrary(); - JavascriptPromiseResolveThenableTaskFunction* resolveThenableTaskFunction = JavascriptPromiseResolveThenableTaskFunction::FromVar(function); + JavascriptPromiseResolveThenableTaskFunction* resolveThenableTaskFunction = VarTo(function); JavascriptPromise* promise = resolveThenableTaskFunction->GetPromise(); RecyclableObject* thenable = resolveThenableTaskFunction->GetThenable(); RecyclableObject* thenFunction = resolveThenableTaskFunction->GetThenFunction(); @@ -1187,7 +1168,7 @@ namespace Js bool isPromiseRejectionHandled = true; if (scriptContext->IsScriptContextInDebugMode()) { - // only necessary to determine if false if debugger is attached. This way we'll + // only necessary to determine if false if debugger is attached. This way we'll // correctly break on exceptions raised in promises that result in uhandled rejections isPromiseRejectionHandled = !promise->WillRejectionBeUnhandled(); } @@ -1279,7 +1260,7 @@ namespace Js x = undefinedVar; } - JavascriptPromiseAllResolveElementFunction* allResolveElementFunction = JavascriptPromiseAllResolveElementFunction::FromVar(function); + JavascriptPromiseAllResolveElementFunction* allResolveElementFunction = VarTo(function); if (allResolveElementFunction->IsAlreadyCalled()) { @@ -1331,8 +1312,8 @@ namespace Js resolve = args[1]; reject = args[2]; - Assert(JavascriptPromiseAsyncSpawnExecutorFunction::Is(function)); - JavascriptPromiseAsyncSpawnExecutorFunction* asyncSpawnExecutorFunction = JavascriptPromiseAsyncSpawnExecutorFunction::FromVar(function); + Assert(VarIs(function)); + JavascriptPromiseAsyncSpawnExecutorFunction* asyncSpawnExecutorFunction = VarTo(function); Var self = asyncSpawnExecutorFunction->GetTarget(); Var varCallArgs[] = { undefinedVar, self }; @@ -1349,7 +1330,7 @@ namespace Js { PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault); - JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction* asyncSpawnStepArgumentExecutorFunction = JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction::FromVar(function); + JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction* asyncSpawnStepArgumentExecutorFunction = VarTo(function); Var argument = asyncSpawnStepArgumentExecutorFunction->GetArgument(); JavascriptFunction* next = function->GetScriptContext()->GetLibrary()->EnsureGeneratorNextFunction(); @@ -1364,7 +1345,7 @@ namespace Js { PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault); - JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction* asyncSpawnStepArgumentExecutorFunction = JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction::FromVar(function); + JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction* asyncSpawnStepArgumentExecutorFunction = VarTo(function); JavascriptFunction* throw_ = function->GetScriptContext()->GetLibrary()->EnsureGeneratorThrowFunction(); BEGIN_SAFE_REENTRANT_CALL(function->GetScriptContext()->GetThreadContext()) { @@ -1389,7 +1370,7 @@ namespace Js argument = args[1]; } - JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction* asyncSpawnStepExecutorFunction = JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction::FromVar(function); + JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction* asyncSpawnStepExecutorFunction = VarTo(function); JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction* functionArg; JavascriptGenerator* gen = asyncSpawnStepExecutorFunction->GetGenerator(); Var reject = asyncSpawnStepExecutorFunction->GetReject(); @@ -1425,7 +1406,7 @@ namespace Js try { Var nextVar = CALL_FUNCTION(scriptContext->GetThreadContext(), nextFunction, CallInfo(CallFlags_Value, 1), undefinedVar); - next = RecyclableObject::FromVar(nextVar); + next = VarTo(nextVar); } catch (const JavascriptException& err) { @@ -1449,7 +1430,7 @@ namespace Js { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedFunction); } - CALL_FUNCTION(scriptContext->GetThreadContext(), RecyclableObject::FromVar(resolve), CallInfo(CallFlags_Value, 2), undefinedVar, value); + CALL_FUNCTION(scriptContext->GetThreadContext(), VarTo(resolve), CallInfo(CallFlags_Value, 2), undefinedVar, value); return; } @@ -1461,14 +1442,14 @@ namespace Js JavascriptFunction* promiseResolve = library->EnsurePromiseResolveFunction(); value = JavascriptOperators::GetProperty(next, PropertyIds::value, scriptContext); Var promiseVar = CALL_FUNCTION(scriptContext->GetThreadContext(), promiseResolve, CallInfo(CallFlags_Value, 2), library->GetPromiseConstructor(), value); - JavascriptPromise* promise = FromVar(promiseVar); + JavascriptPromise* promise = VarTo(promiseVar); Var promiseThen = JavascriptOperators::GetProperty(promise, PropertyIds::then, scriptContext); if (!JavascriptConversion::IsCallable(promiseThen)) { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedFunction); } - CALL_FUNCTION(scriptContext->GetThreadContext(), RecyclableObject::FromVar(promiseThen), CallInfo(CallFlags_Value, 3), promise, successFunction, failFunction); + CALL_FUNCTION(scriptContext->GetThreadContext(), VarTo(promiseThen), CallInfo(CallFlags_Value, 3), promise, successFunction, failFunction); END_SAFE_REENTRANT_REGION } @@ -1590,7 +1571,7 @@ namespace Js } AssertMsg(hasResolve == false && hasReject == false, "mismatched resolve/reject reaction counts"); promise->reactions->Reverse(); - + return promise; } #endif @@ -1603,7 +1584,7 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedFunction); } - RecyclableObject* constructorFunc = RecyclableObject::FromVar(constructor); + RecyclableObject* constructorFunc = VarTo(constructor); BEGIN_SAFE_REENTRANT_CALL(scriptContext->GetThreadContext()) { @@ -1681,12 +1662,10 @@ namespace Js : RuntimeFunction(type, functionInfo), promise(promise), isReject(isReject), alreadyResolvedWrapper(alreadyResolvedRecord) { } - bool JavascriptPromiseResolveOrRejectFunction::Is(Var var) + template <> bool VarIsImpl(RecyclableObject* obj) { - if (JavascriptFunction::Is(var)) + if (VarIs(obj)) { - JavascriptFunction* obj = JavascriptFunction::UnsafeFromVar(var); - return VirtualTableInfo::HasVirtualTable(obj) || VirtualTableInfo>::HasVirtualTable(obj); } @@ -1694,20 +1673,6 @@ namespace Js return false; } - JavascriptPromiseResolveOrRejectFunction* JavascriptPromiseResolveOrRejectFunction::FromVar(Var var) - { - AssertOrFailFast(JavascriptPromiseResolveOrRejectFunction::Is(var)); - - return static_cast(var); - } - - JavascriptPromiseResolveOrRejectFunction* JavascriptPromiseResolveOrRejectFunction::UnsafeFromVar(Var var) - { - Assert(JavascriptPromiseResolveOrRejectFunction::Is(var)); - - return static_cast(var); - } - JavascriptPromise* JavascriptPromiseResolveOrRejectFunction::GetPromise() { return this->promise; @@ -1768,12 +1733,10 @@ namespace Js : RuntimeFunction(type, functionInfo), generator(generator), target(target) { } - bool JavascriptPromiseAsyncSpawnExecutorFunction::Is(Var var) + template <> bool VarIsImpl(RecyclableObject* obj) { - if (JavascriptFunction::Is(var)) + if (VarIs(obj)) { - JavascriptFunction* obj = JavascriptFunction::UnsafeFromVar(var); - return VirtualTableInfo::HasVirtualTable(obj) || VirtualTableInfo>::HasVirtualTable(obj); } @@ -1781,21 +1744,6 @@ namespace Js return false; } - JavascriptPromiseAsyncSpawnExecutorFunction* JavascriptPromiseAsyncSpawnExecutorFunction::FromVar(Var var) - { - AssertOrFailFast(JavascriptPromiseAsyncSpawnExecutorFunction::Is(var)); - - return static_cast(var); - } - - JavascriptPromiseAsyncSpawnExecutorFunction* JavascriptPromiseAsyncSpawnExecutorFunction::UnsafeFromVar(Var var) - { - Assert(JavascriptPromiseAsyncSpawnExecutorFunction::Is(var)); - - return static_cast(var); - } - - JavascriptGenerator* JavascriptPromiseAsyncSpawnExecutorFunction::GetGenerator() { return this->generator; @@ -1838,12 +1786,10 @@ namespace Js : RuntimeFunction(type, functionInfo), generator(generator), argument(argument), resolve(resolve), reject(reject), isReject(isReject) { } - bool JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction::Is(Var var) + template <> bool VarIsImpl(RecyclableObject* obj) { - if (JavascriptFunction::Is(var)) + if (VarIs(obj)) { - JavascriptFunction* obj = JavascriptFunction::UnsafeFromVar(var); - return VirtualTableInfo::HasVirtualTable(obj) || VirtualTableInfo>::HasVirtualTable(obj); } @@ -1851,20 +1797,6 @@ namespace Js return false; } - JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction* JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction::FromVar(Var var) - { - AssertOrFailFast(JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction::Is(var)); - - return static_cast(var); - } - - JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction* JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction::UnsafeFromVar(Var var) - { - Assert(JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction::Is(var)); - - return static_cast(var); - } - JavascriptGenerator* JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction::GetGenerator() { return this->generator; @@ -1978,7 +1910,7 @@ namespace Js { alloc.SlabCommitArraySpace(depCount, maxDeps); } - else + else { alloc.SlabAbortArraySpace(maxDeps); } @@ -1999,12 +1931,10 @@ namespace Js : RuntimeFunction(type, functionInfo), capability(capability) { } - bool JavascriptPromiseCapabilitiesExecutorFunction::Is(Var var) + template <> bool VarIsImpl(RecyclableObject* obj) { - if (JavascriptFunction::Is(var)) + if (VarIs(obj)) { - JavascriptFunction* obj = JavascriptFunction::UnsafeFromVar(var); - return VirtualTableInfo::HasVirtualTable(obj) || VirtualTableInfo>::HasVirtualTable(obj); } @@ -2012,20 +1942,6 @@ namespace Js return false; } - JavascriptPromiseCapabilitiesExecutorFunction* JavascriptPromiseCapabilitiesExecutorFunction::FromVar(Var var) - { - AssertOrFailFast(JavascriptPromiseCapabilitiesExecutorFunction::Is(var)); - - return static_cast(var); - } - - JavascriptPromiseCapabilitiesExecutorFunction* JavascriptPromiseCapabilitiesExecutorFunction::UnsafeFromVar(Var var) - { - Assert(JavascriptPromiseCapabilitiesExecutorFunction::Is(var)); - - return static_cast(var); - } - JavascriptPromiseCapability* JavascriptPromiseCapabilitiesExecutorFunction::GetCapability() { return this->capability; @@ -2157,6 +2073,17 @@ namespace Js } #endif + template <> bool VarIsImpl(RecyclableObject* obj) + { + if (VarIs(obj)) + { + return VirtualTableInfo::HasVirtualTable(obj) + || VirtualTableInfo>::HasVirtualTable(obj); + } + + return false; + } + JavascriptPromiseReaction* JavascriptPromiseReactionTaskFunction::GetReaction() { return this->reaction; @@ -2217,6 +2144,38 @@ namespace Js } #endif + template <> bool VarIsImpl(RecyclableObject* obj) + { + if (VarIs(obj)) + { + return VirtualTableInfo::HasVirtualTable(obj) + || VirtualTableInfo>::HasVirtualTable(obj); + } + + return false; + } + + template <> bool VarIsImpl(RecyclableObject* obj) + { + if (VarIs(obj)) + { + return VirtualTableInfo::HasVirtualTable(obj) + || VirtualTableInfo>::HasVirtualTable(obj); + } + return false; + } + + template <> bool VarIsImpl(RecyclableObject* obj) + { + if (VarIs(obj)) + { + return VirtualTableInfo::HasVirtualTable(obj) + || VirtualTableInfo>::HasVirtualTable(obj); + } + + return false; + } + JavascriptPromise* JavascriptPromiseResolveThenableTaskFunction::GetPromise() { return this->promise; @@ -2258,12 +2217,10 @@ namespace Js : RuntimeFunction(type, functionInfo), index(index), values(values), capabilities(capabilities), remainingElementsWrapper(remainingElementsWrapper), alreadyCalled(false) { } - bool JavascriptPromiseAllResolveElementFunction::Is(Var var) + template <> bool VarIsImpl(RecyclableObject* obj) { - if (JavascriptFunction::Is(var)) + if (VarIs(obj)) { - JavascriptFunction* obj = JavascriptFunction::UnsafeFromVar(var); - return VirtualTableInfo::HasVirtualTable(obj) || VirtualTableInfo>::HasVirtualTable(obj); } @@ -2271,20 +2228,6 @@ namespace Js return false; } - JavascriptPromiseAllResolveElementFunction* JavascriptPromiseAllResolveElementFunction::FromVar(Var var) - { - AssertOrFailFast(JavascriptPromiseAllResolveElementFunction::Is(var)); - - return static_cast(var); - } - - JavascriptPromiseAllResolveElementFunction* JavascriptPromiseAllResolveElementFunction::UnsafeFromVar(Var var) - { - Assert(JavascriptPromiseAllResolveElementFunction::Is(var)); - - return static_cast(var); - } - JavascriptPromiseCapability* JavascriptPromiseAllResolveElementFunction::GetCapabilities() { return this->capabilities; diff --git a/lib/Runtime/Library/JavascriptPromise.h b/lib/Runtime/Library/JavascriptPromise.h index b004f6f262d..4d4c8570505 100644 --- a/lib/Runtime/Library/JavascriptPromise.h +++ b/lib/Runtime/Library/JavascriptPromise.h @@ -21,10 +21,6 @@ namespace Js JavascriptPromiseResolveOrRejectFunction(DynamicType* type); JavascriptPromiseResolveOrRejectFunction(DynamicType* type, FunctionInfo* functionInfo, JavascriptPromise* promise, bool isReject, JavascriptPromiseResolveOrRejectFunctionAlreadyResolvedWrapper* alreadyResolvedRecord); - inline static bool Is(Var var); - inline static JavascriptPromiseResolveOrRejectFunction* FromVar(Var var); - inline static JavascriptPromiseResolveOrRejectFunction* UnsafeFromVar(Var var); - JavascriptPromise* GetPromise(); bool IsRejectFunction(); bool IsAlreadyResolved(); @@ -44,6 +40,8 @@ namespace Js #endif }; + template <> bool VarIsImpl(RecyclableObject* obj); + class JavascriptPromiseAsyncSpawnExecutorFunction : public RuntimeFunction { protected: @@ -53,10 +51,6 @@ namespace Js public: JavascriptPromiseAsyncSpawnExecutorFunction(DynamicType* type, FunctionInfo* functionInfo, JavascriptGenerator* generator, Var target); - inline static bool Is(Var var); - inline static JavascriptPromiseAsyncSpawnExecutorFunction* FromVar(Var var); - inline static JavascriptPromiseAsyncSpawnExecutorFunction* UnsafeFromVar(Var var); - JavascriptGenerator* GetGenerator(); Var GetTarget(); @@ -73,6 +67,8 @@ namespace Js #endif }; + template <> bool VarIsImpl(RecyclableObject* obj); + class JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction : public RuntimeFunction { protected: @@ -82,10 +78,6 @@ namespace Js public: JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction(DynamicType* type, FunctionInfo* functionInfo, JavascriptGenerator* generator, Var argument, Var resolve = nullptr, Var reject = nullptr, bool isReject = false); - inline static bool Is(Var var); - inline static JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction* FromVar(Var var); - inline static JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction* UnsafeFromVar(Var var); - JavascriptGenerator* GetGenerator(); Var GetReject(); Var GetResolve(); @@ -108,6 +100,8 @@ namespace Js #endif }; + template <> bool VarIsImpl(RecyclableObject* obj); + class JavascriptPromiseCapabilitiesExecutorFunction : public RuntimeFunction { protected: @@ -117,10 +111,6 @@ namespace Js public: JavascriptPromiseCapabilitiesExecutorFunction(DynamicType* type, FunctionInfo* functionInfo, JavascriptPromiseCapability* capability); - inline static bool Is(Var var); - inline static JavascriptPromiseCapabilitiesExecutorFunction* FromVar(Var var); - inline static JavascriptPromiseCapabilitiesExecutorFunction* UnsafeFromVar(Var var); - JavascriptPromiseCapability* GetCapability(); private: @@ -135,6 +125,8 @@ namespace Js #endif }; + template <> bool VarIsImpl(RecyclableObject* obj); + class JavascriptPromiseResolveThenableTaskFunction : public RuntimeFunction { protected: @@ -146,26 +138,6 @@ namespace Js : RuntimeFunction(type, functionInfo), promise(promise), thenable(thenable), thenFunction(thenFunction) { } - inline static bool Is(Var var) - { - if (JavascriptFunction::Is(var)) - { - JavascriptFunction* obj = JavascriptFunction::UnsafeFromVar(var); - - return VirtualTableInfo::HasVirtualTable(obj) - || VirtualTableInfo>::HasVirtualTable(obj); - } - - return false; - } - - inline static JavascriptPromiseResolveThenableTaskFunction* FromVar(Var var) - { - AssertOrFailFast(JavascriptPromiseResolveThenableTaskFunction::Is(var)); - - return static_cast(var); - } - JavascriptPromise* GetPromise(); RecyclableObject* GetThenable(); RecyclableObject* GetThenFunction(); @@ -185,6 +157,8 @@ namespace Js #endif }; + template <> bool VarIsImpl(RecyclableObject* obj); + class JavascriptPromiseReactionTaskFunction : public RuntimeFunction { protected: @@ -196,26 +170,6 @@ namespace Js : RuntimeFunction(type, functionInfo), reaction(reaction), argument(argument) { } - inline static bool Is(Var var) - { - if (JavascriptFunction::Is(var)) - { - JavascriptFunction* obj = JavascriptFunction::UnsafeFromVar(var); - - return VirtualTableInfo::HasVirtualTable(obj) - || VirtualTableInfo>::HasVirtualTable(obj); - } - - return false; - } - - inline static JavascriptPromiseReactionTaskFunction* FromVar(Var var) - { - AssertOrFailFast(JavascriptPromiseReactionTaskFunction::Is(var)); - - return static_cast(var); - } - JavascriptPromiseReaction* GetReaction(); Var GetArgument(); @@ -232,6 +186,8 @@ namespace Js #endif }; + template <> bool VarIsImpl(RecyclableObject* obj); + class JavascriptPromiseThenFinallyFunction : public RuntimeFunction { protected: @@ -243,26 +199,6 @@ namespace Js : RuntimeFunction(type, functionInfo), OnFinally(OnFinally), Constructor(Constructor), shouldThrow(shouldThrow) { } - inline static bool Is(Var var) - { - if (JavascriptFunction::Is(var)) - { - JavascriptFunction* obj = JavascriptFunction::UnsafeFromVar(var); - - return VirtualTableInfo::HasVirtualTable(obj) - || VirtualTableInfo>::HasVirtualTable(obj); - } - - return false; - } - - inline static JavascriptPromiseThenFinallyFunction* FromVar(Var var) - { - AssertOrFailFast(JavascriptPromiseThenFinallyFunction::Is(var)); - - return static_cast(var); - } - inline bool GetShouldThrow() { return this->shouldThrow; } inline RecyclableObject* GetOnFinally() { return this->OnFinally; } inline RecyclableObject* GetConstructor() { return this->Constructor; } @@ -273,6 +209,8 @@ namespace Js Field(bool) shouldThrow; }; + template <> bool VarIsImpl(RecyclableObject* obj); + class JavascriptPromiseThunkFinallyFunction : public RuntimeFunction { protected: @@ -284,25 +222,6 @@ namespace Js : RuntimeFunction(type, functionInfo), value(value), shouldThrow(shouldThrow) { } - inline static bool Is(Var var) - { - if (JavascriptFunction::Is(var)) - { - JavascriptFunction* obj = JavascriptFunction::UnsafeFromVar(var); - - return VirtualTableInfo::HasVirtualTable(obj) - || VirtualTableInfo>::HasVirtualTable(obj); - } - return false; - } - - inline static JavascriptPromiseThunkFinallyFunction* FromVar(Var var) - { - AssertOrFailFast(JavascriptPromiseThunkFinallyFunction::Is(var)); - - return static_cast(var); - } - inline bool GetShouldThrow() { return this->shouldThrow; } inline Var GetValue() { return this->value; } @@ -311,6 +230,8 @@ namespace Js Field(bool) shouldThrow; }; + template <> bool VarIsImpl(RecyclableObject* obj); + struct JavascriptPromiseAllResolveElementFunctionRemainingElementsWrapper { Field(uint32) remainingElements; @@ -326,10 +247,6 @@ namespace Js JavascriptPromiseAllResolveElementFunction(DynamicType* type); JavascriptPromiseAllResolveElementFunction(DynamicType* type, FunctionInfo* functionInfo, uint32 index, JavascriptArray* values, JavascriptPromiseCapability* capabilities, JavascriptPromiseAllResolveElementFunctionRemainingElementsWrapper* remainingElementsWrapper); - inline static bool Is(Var var); - inline static JavascriptPromiseAllResolveElementFunction* FromVar(Var var); - inline static JavascriptPromiseAllResolveElementFunction* UnsafeFromVar(Var var); - JavascriptPromiseCapability* GetCapabilities(); uint32 GetIndex(); uint32 GetRemainingElements(); @@ -355,6 +272,8 @@ namespace Js #endif }; + template <> bool VarIsImpl(RecyclableObject* obj); + class JavascriptPromiseCapability : FinalizableObject { private: @@ -398,7 +317,7 @@ namespace Js //Do any additional marking that is needed for a TT snapshotable object void MarkVisitPtrs(TTD::SnapshotExtractor* extractor); - //Do the extraction + //Do the extraction void ExtractSnapPromiseCapabilityInto(TTD::NSSnapValues::SnapPromiseCapabilityInfo* snapPromiseCapability, JsUtil::List& depOnList, TTD::SlabAllocator& alloc); #endif }; @@ -440,7 +359,7 @@ namespace Js //Do any additional marking that is needed for a TT snapshotable object void MarkVisitPtrs(TTD::SnapshotExtractor* extractor); - //Do the extraction + //Do the extraction void ExtractSnapPromiseReactionInto(TTD::NSSnapValues::SnapPromiseReactionInfo* snapPromiseReaction, JsUtil::List& depOnList, TTD::SlabAllocator& alloc); #endif }; @@ -513,10 +432,6 @@ namespace Js static Var EntryJavascriptPromiseAsyncSpawnStepThrowExecutorFunction(RecyclableObject* function, CallInfo callInfo, ...); static Var EntryJavascriptPromiseAsyncSpawnCallStepExecutorFunction(RecyclableObject* function, CallInfo callInfo, ...); - static bool Is(Var aValue); - static JavascriptPromise* FromVar(Js::Var aValue); - static JavascriptPromise* UnsafeFromVar(Js::Var aValue); - static Var CreateRejectedPromise(Var resolution, ScriptContext* scriptContext, Var promiseConstructor = nullptr); static Var CreateResolvedPromise(Var resolution, ScriptContext* scriptContext, Var promiseConstructor = nullptr); static Var CreatePassThroughPromise(JavascriptPromise* sourcePromise, ScriptContext* scriptContext); @@ -585,4 +500,9 @@ namespace Js static JavascriptPromise* InitializePromise_TTD(ScriptContext* scriptContext, uint32 status, bool isHandled, Var result, SList& resolveReactions, SList& rejectReactions); #endif }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return Js::JavascriptOperators::GetTypeId(obj) == TypeIds_Promise; + } } diff --git a/lib/Runtime/Library/JavascriptProxy.cpp b/lib/Runtime/Library/JavascriptProxy.cpp index 07e3e04beb4..8e2424d8b57 100644 --- a/lib/Runtime/Library/JavascriptProxy.cpp +++ b/lib/Runtime/Library/JavascriptProxy.cpp @@ -6,16 +6,6 @@ namespace Js { - BOOL JavascriptProxy::Is(_In_ RecyclableObject* obj) - { - return JavascriptOperators::GetTypeId(obj) == TypeIds_Proxy; - } - - BOOL JavascriptProxy::Is(_In_ Var obj) - { - return JavascriptOperators::GetTypeId(obj) == TypeIds_Proxy; - } - bool JavascriptProxy::IsRevoked() const { return (target == nullptr); @@ -78,13 +68,13 @@ namespace Js { JavascriptError::ThrowTypeError(scriptContext, JSERR_InvalidProxyArgument, _u("target")); } - target = DynamicObject::FromVar(args[1]); + target = VarTo(args[1]); #if ENABLE_COPYONACCESS_ARRAY JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray(target); #endif - if (JavascriptProxy::Is(target)) + if (VarIs(target)) { - if (JavascriptProxy::FromVar(target)->target == nullptr) + if (VarTo(target)->target == nullptr) { JavascriptError::ThrowTypeError(scriptContext, JSERR_InvalidProxyArgument, _u("target")); } @@ -94,10 +84,10 @@ namespace Js { JavascriptError::ThrowTypeError(scriptContext, JSERR_InvalidProxyArgument, _u("handler")); } - handler = DynamicObject::FromVar(args[2]); - if (JavascriptProxy::Is(handler)) + handler = VarTo(args[2]); + if (VarIs(handler)) { - if (JavascriptProxy::FromVar(handler)->handler == nullptr) + if (VarTo(handler)->handler == nullptr) { JavascriptError::ThrowTypeError(scriptContext, JSERR_InvalidProxyArgument, _u("handler")); } @@ -110,7 +100,7 @@ namespace Js newProxy->GetDynamicType()->SetEntryPoint(JavascriptProxy::FunctionCallTrap); } return isCtorSuperCall ? - JavascriptProxy::FromVar(JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), newProxy, nullptr, scriptContext)) : + VarTo(JavascriptOperators::OrdinaryCreateFromConstructor(VarTo(newTarget), newProxy, nullptr, scriptContext)) : newProxy; } @@ -168,7 +158,7 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_InvalidProxyArgument, _u("")); } function->SetInternalProperty(Js::InternalPropertyIds::RevocableProxy, scriptContext->GetLibrary()->GetNull(), PropertyOperationFlags::PropertyOperation_Force, nullptr); - (JavascriptProxy::FromVar(revokableProxy))->RevokeObject(); + (VarTo(revokableProxy))->RevokeObject(); return scriptContext->GetLibrary()->GetUndefined(); } @@ -235,7 +225,7 @@ namespace Js Var propertyName = GetName(requestContext, propertyId); - Assert(JavascriptString::Is(propertyName) || JavascriptSymbol::Is(propertyName)); + Assert(VarIs(propertyName) || VarIs(propertyName)); //8. Let trapResultObj be the result of calling the[[Call]] internal method of trap with handler as the this value and a new List containing target and P. //9. ReturnIfAbrupt(trapResultObj). //10. If Type(trapResultObj) is neither Object nor Undefined, then throw a TypeError exception. @@ -590,7 +580,7 @@ namespace Js } return FALSE; } - + _Check_return_ _Success_(return) BOOL JavascriptProxy::GetAccessors(PropertyId propertyId, _Outptr_result_maybenull_ Var* getter, _Outptr_result_maybenull_ Var* setter, ScriptContext* requestContext) { PropertyDescriptor result; @@ -683,7 +673,7 @@ namespace Js } else { - // ES2017 Spec'd (9.1.9.1): + // ES2017 Spec'd (9.1.9.1): // If existingDescriptor is not undefined, then // If IsAccessorDescriptor(existingDescriptor) is true, return false. // If existingDescriptor.[[Writable]] is false, return false. @@ -1023,9 +1013,9 @@ namespace Js if (var) { // if (typeof key === "string") { - if (JavascriptString::Is(var)) + if (VarIs(var)) { - JavascriptString* propertyName = JavascriptString::FromVar(var); + JavascriptString* propertyName = VarTo(var); // let desc = Reflect.getOwnPropertyDescriptor(obj, key); Js::PropertyDescriptor desc; BOOL ret = JavascriptOperators::GetOwnPropertyDescriptor(proxy, propertyName, scriptContext, &desc); @@ -1037,7 +1027,7 @@ namespace Js // if (desc.enumerable) yield key; if (desc.IsEnumerable()) { - return JavascriptString::FromVar(CrossSite::MarshalVar( + return VarTo(CrossSite::MarshalVar( scriptContext, propertyName, propertyName->GetScriptContext())); } } @@ -1173,12 +1163,12 @@ namespace Js { return targetObj->IsExtensible(); } - + Var isExtensibleResult = threadContext->ExecuteImplicitCall(isExtensibleMethod, ImplicitCall_Accessor, [=]()->Js::Var { return CALL_FUNCTION(threadContext, isExtensibleMethod, CallInfo(CallFlags_Value, 2), handlerObj, targetObj); }); - + BOOL trapResult = JavascriptConversion::ToBoolean(isExtensibleResult, requestContext); BOOL targetIsExtensible = targetObj->IsExtensible(); if (trapResult != targetIsExtensible) @@ -1229,7 +1219,7 @@ namespace Js { return targetObj->PreventExtensions(); } - + //8. Let booleanTrapResult be ToBoolean(trapResult) //9. ReturnIfAbrupt(booleanTrapResult). //10. Let targetIsExtensible be the result of calling the[[IsExtensible]] internal method of target. @@ -1273,7 +1263,7 @@ namespace Js // at this time this is called from proxy only; when we extend this to other objects, we need to handle the other codepath. //7. Let keys be O.[[OwnPropertyKeys]](). //8. ReturnIfAbrupt(keys). - Assert(JavascriptProxy::Is(obj)); + Assert(VarIs(obj)); JavascriptArray* resultArray = JavascriptOperators::GetOwnPropertyKeys(obj, scriptContext); //9. Repeat for each element k of keys, @@ -1291,7 +1281,7 @@ namespace Js for (uint i = 0; i < resultArray->GetLength(); i++) { itemVar = resultArray->DirectGetItem(i); - AssertMsg(JavascriptSymbol::Is(itemVar) || JavascriptString::Is(itemVar), "Invariant check during ownKeys proxy trap should make sure we only get property key here. (symbol or string primitives)"); + AssertMsg(VarIs(itemVar) || VarIs(itemVar), "Invariant check during ownKeys proxy trap should make sure we only get property key here. (symbol or string primitives)"); JavascriptConversion::ToPropertyKey(itemVar, scriptContext, &propertyRecord, nullptr); PropertyId propertyId = propertyRecord->GetPropertyId(); if (JavascriptObject::GetOwnPropertyDescriptorHelper(obj, propertyId, scriptContext, propertyDescriptor)) @@ -1323,7 +1313,7 @@ namespace Js //5. If status is false, return false. // at this time this is called from proxy only; when we extend this to other objects, we need to handle the other codepath. - Assert(JavascriptProxy::Is(obj)); + Assert(VarIs(obj)); if (obj->PreventExtensions() == FALSE) return FALSE; @@ -1344,7 +1334,7 @@ namespace Js for (uint i = 0; i < resultArray->GetLength(); i++) { itemVar = resultArray->DirectGetItem(i); - AssertMsg(JavascriptSymbol::Is(itemVar) || JavascriptString::Is(itemVar), "Invariant check during ownKeys proxy trap should make sure we only get property key here. (symbol or string primitives)"); + AssertMsg(VarIs(itemVar) || VarIs(itemVar), "Invariant check during ownKeys proxy trap should make sure we only get property key here. (symbol or string primitives)"); JavascriptConversion::ToPropertyKey(itemVar, scriptContext, &propertyRecord, nullptr); PropertyId propertyId = propertyRecord->GetPropertyId(); JavascriptObject::DefineOwnPropertyHelper(obj, propertyId, propertyDescriptor, scriptContext); @@ -1372,7 +1362,7 @@ namespace Js for (uint i = 0; i < resultArray->GetLength(); i++) { itemVar = resultArray->DirectGetItem(i); - AssertMsg(JavascriptSymbol::Is(itemVar) || JavascriptString::Is(itemVar), "Invariant check during ownKeys proxy trap should make sure we only get property key here. (symbol or string primitives)"); + AssertMsg(VarIs(itemVar) || VarIs(itemVar), "Invariant check during ownKeys proxy trap should make sure we only get property key here. (symbol or string primitives)"); JavascriptConversion::ToPropertyKey(itemVar, scriptContext, &propertyRecord, nullptr); PropertyId propertyId = propertyRecord->GetPropertyId(); PropertyDescriptor propertyDescriptor; @@ -1481,14 +1471,14 @@ namespace Js if (nullptr == getPrototypeOfMethod || GetScriptContext()->IsHeapEnumInProgress()) { - return RecyclableObject::FromVar(JavascriptObject::GetPrototypeOf(targetObj, requestContext)); + return VarTo(JavascriptObject::GetPrototypeOf(targetObj, requestContext)); } - + Var getPrototypeOfResult = threadContext->ExecuteImplicitCall(getPrototypeOfMethod, ImplicitCall_Accessor, [=]()->Js::Var { return CALL_FUNCTION(threadContext, getPrototypeOfMethod, CallInfo(CallFlags_Value, 2), handlerObj, targetObj); }); - + TypeId prototypeTypeId = JavascriptOperators::GetTypeId(getPrototypeOfResult); if (!JavascriptOperators::IsObjectType(prototypeTypeId) && prototypeTypeId != TypeIds_Null) { @@ -1498,7 +1488,7 @@ namespace Js { JavascriptError::ThrowTypeError(requestContext, JSERR_InconsistentTrapResult, _u("getPrototypeOf")); } - return RecyclableObject::FromVar(getPrototypeOfResult); + return VarTo(getPrototypeOfResult); } RecyclableObject* JavascriptProxy::GetConfigurablePrototype(ScriptContext * requestContext) @@ -1679,7 +1669,7 @@ namespace Js return requestContext->GetLibrary()->GetObjectTypeDisplayString(); } // if exotic object has [[Call]] we should return "function", otherwise return "object" - if (JavascriptFunction::Is(this->target)) + if (VarIs(this->target)) { return requestContext->GetLibrary()->GetFunctionTypeDisplayString(); } @@ -1692,7 +1682,7 @@ namespace Js BOOL JavascriptProxy::GetOwnPropertyDescriptor(RecyclableObject* obj, PropertyId propertyId, ScriptContext* requestContext, PropertyDescriptor* propertyDescriptor) { - JavascriptProxy* proxy = JavascriptProxy::FromVar(obj); + JavascriptProxy* proxy = VarTo(obj); return proxy->GetPropertyDescriptorTrap(propertyId, propertyDescriptor, requestContext); } @@ -1710,7 +1700,7 @@ namespace Js return FALSE; } - JavascriptProxy* proxy = JavascriptProxy::FromVar(obj); + JavascriptProxy* proxy = VarTo(obj); //1. Assert: IsPropertyKey(P) is true. //2. Let handler be O.[[ProxyHandler]]. @@ -1877,12 +1867,12 @@ namespace Js //11. If booleanTrapResult is false, then return false. Var propertyName = GetName(requestContext, propertyId); - + Var setPropertyResult = threadContext->ExecuteImplicitCall(setMethod, ImplicitCall_Accessor, [=]()->Js::Var { return CALL_FUNCTION(threadContext, setMethod, CallInfo(CallFlags_Value, 5), handlerObj, targetObj, propertyName, newValue, receiver); }); - + BOOL setResult = JavascriptConversion::ToBoolean(setPropertyResult, requestContext); if (!setResult) { @@ -1955,14 +1945,14 @@ namespace Js { return nullptr; } - if (!JavascriptFunction::Is(varMethod)) + if (!VarIs(varMethod)) { JavascriptError::ThrowTypeError(requestContext, JSERR_NeedFunction, requestContext->GetPropertyName(methodId)->GetBuffer()); } - JavascriptFunction* function = JavascriptFunction::FromVar(varMethod); + JavascriptFunction* function = VarTo(varMethod); - return JavascriptFunction::FromVar(CrossSite::MarshalVar(requestContext, + return VarTo(CrossSite::MarshalVar(requestContext, function, function->GetScriptContext())); } @@ -1974,7 +1964,7 @@ namespace Js } if (propertyDescriptor.GetterSpecified()) { - return JavascriptOperators::CallGetter(RecyclableObject::FromVar(propertyDescriptor.GetGetter()), instance, requestContext); + return JavascriptOperators::CallGetter(VarTo(propertyDescriptor.GetGetter()), instance, requestContext); } Assert(FALSE); return requestContext->GetLibrary()->GetUndefined(); @@ -2028,8 +2018,8 @@ namespace Js RecyclableObject* JavascriptProxy::AutoProxyWrapper(Var obj) { - RecyclableObject* object = RecyclableObject::FromVar(obj); - if (!JavascriptOperators::IsObject(object) || JavascriptProxy::Is(object)) + RecyclableObject* object = VarTo(obj); + if (!JavascriptOperators::IsObject(object) || VarIs(object)) { return object; } @@ -2089,7 +2079,7 @@ namespace Js bool isNewCall = args.IsNewCall() || hasOverridingNewTarget; AssertMsg(args.Info.Count > 0, "Should always have implicit 'this'"); - if (!JavascriptProxy::Is(function)) + if (!VarIs(function)) { if (args.Info.Flags & CallFlags_New) { @@ -2102,7 +2092,7 @@ namespace Js } Var newTarget = nullptr; - JavascriptProxy* proxy = JavascriptProxy::FromVar(function); + JavascriptProxy* proxy = VarTo(function); Js::RecyclableObject *handlerObj = proxy->handler; Js::RecyclableObject *targetObj = proxy->target; @@ -2346,7 +2336,7 @@ namespace Js //12. ReturnIfAbrupt(extensibleTarget). //13. Let targetKeys be target.[[OwnPropertyKeys]](). //14. ReturnIfAbrupt(targetKeys). - + Var ownKeysResult = threadContext->ExecuteImplicitCall(ownKeysMethod, ImplicitCall_Accessor, [=]()->Js::Var { return CALL_FUNCTION(threadContext, ownKeysMethod, CallInfo(CallFlags_Value, 2), handlerObj, targetObj); @@ -2356,7 +2346,7 @@ namespace Js { JavascriptError::ThrowTypeError(requestContext, JSERR_InconsistentTrapResult, _u("ownKeys")); } - RecyclableObject* trapResultArray = RecyclableObject::FromVar(ownKeysResult); + RecyclableObject* trapResultArray = VarTo(ownKeysResult); //15. Assert: targetKeys is a List containing only String and Symbol values. //16. Let targetConfigurableKeys be an empty List. @@ -2484,7 +2474,7 @@ namespace Js for (uint32 i = 0; i < targetKeys->GetLength(); i++) { element = targetKeys->DirectGetItem(i); - AssertMsg(JavascriptSymbol::Is(element) || JavascriptString::Is(element), "Invariant check during ownKeys proxy trap should make sure we only get property key here. (symbol or string primitives)"); + AssertMsg(VarIs(element) || VarIs(element), "Invariant check during ownKeys proxy trap should make sure we only get property key here. (symbol or string primitives)"); JavascriptConversion::ToPropertyKey(element, requestContext, &propertyRecord, nullptr); propertyId = propertyRecord->GetPropertyId(); diff --git a/lib/Runtime/Library/JavascriptProxy.h b/lib/Runtime/Library/JavascriptProxy.h index b88d5b75010..c18dcb5c266 100644 --- a/lib/Runtime/Library/JavascriptProxy.h +++ b/lib/Runtime/Library/JavascriptProxy.h @@ -50,10 +50,6 @@ namespace Js JavascriptProxy(DynamicType * type); JavascriptProxy(DynamicType * type, ScriptContext * scriptContext, RecyclableObject* target, RecyclableObject* handler); - static BOOL Is(_In_ Var obj); - static BOOL Is(_In_ RecyclableObject* obj); - static JavascriptProxy* FromVar(Var obj) { AssertOrFailFast(Is(obj)); return static_cast(obj); } - static JavascriptProxy* UnsafeFromVar(Var obj) { Assert(Is(obj)); return static_cast(obj); } // before recursively calling something on 'target' use this helper in case there is nesting of proxies. // the proxies could be deep nested and cause SO when processed recursively. @@ -173,7 +169,7 @@ namespace Js for (uint32 i = 0; i < len; i++) { if (!JavascriptOperators::GetItem(trapResultArray, i, &element, scriptContext) || // missing - !(JavascriptString::Is(element) || JavascriptSymbol::Is(element))) // neither String nor Symbol + !(VarIs(element) || VarIs(element))) // neither String nor Symbol { JavascriptError::ThrowTypeError(scriptContext, JSERR_InconsistentTrapResult, _u("ownKeys")); } @@ -239,4 +235,9 @@ namespace Js virtual void ExtractSnapObjectDataInto(TTD::NSSnapObjects::SnapObject* objData, TTD::SlabAllocator& alloc) override; #endif }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_Proxy; + } } diff --git a/lib/Runtime/Library/JavascriptReflect.cpp b/lib/Runtime/Library/JavascriptReflect.cpp index afa606e7484..79adacbd45d 100644 --- a/lib/Runtime/Library/JavascriptReflect.cpp +++ b/lib/Runtime/Library/JavascriptReflect.cpp @@ -43,11 +43,11 @@ namespace Js BOOL defineResult; if (JavascriptOperators::GetTypeId(target) == TypeIds_HostDispatch) { - defineResult = RecyclableObject::FromVar(target)->InvokeBuiltInOperationRemotely(EntryDefineProperty, args, nullptr); + defineResult = VarTo(target)->InvokeBuiltInOperationRemotely(EntryDefineProperty, args, nullptr); } else { - defineResult = JavascriptObject::DefineOwnPropertyHelper(RecyclableObject::FromVar(target), propertyRecord->GetPropertyId(), propertyDescriptor, scriptContext, false); + defineResult = JavascriptObject::DefineOwnPropertyHelper(VarTo(target), propertyRecord->GetPropertyId(), propertyDescriptor, scriptContext, false); } return scriptContext->GetLibrary()->GetTrueOrFalse(defineResult); @@ -102,7 +102,7 @@ namespace Js Var receiver = args.Info.Count > 3 ? args[3] : target; - return JavascriptOperators::GetElementIHelper(RecyclableObject::FromVar(target), propertyKey, receiver, scriptContext); + return JavascriptOperators::GetElementIHelper(VarTo(target), propertyKey, receiver, scriptContext); } Var JavascriptReflect::EntryGetOwnPropertyDescriptor(RecyclableObject* function, CallInfo callInfo, ...) @@ -130,13 +130,13 @@ namespace Js if (JavascriptOperators::GetTypeId(target) == TypeIds_HostDispatch) { Var result; - if (RecyclableObject::FromVar(target)->InvokeBuiltInOperationRemotely(EntryGetOwnPropertyDescriptor, args, &result)) + if (VarTo(target)->InvokeBuiltInOperationRemotely(EntryGetOwnPropertyDescriptor, args, &result)) { return result; } } - return JavascriptObject::GetOwnPropertyDescriptorHelper(RecyclableObject::FromVar(target), propertyKey, scriptContext); + return JavascriptObject::GetOwnPropertyDescriptorHelper(VarTo(target), propertyKey, scriptContext); } Var JavascriptReflect::EntryGetPrototypeOf(RecyclableObject* function, CallInfo callInfo, ...) @@ -158,7 +158,7 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_NeedObject, _u("Reflect.getPrototypeOf")); } Var target = args[1]; - return JavascriptObject::GetPrototypeOf(RecyclableObject::FromVar(target), scriptContext); + return JavascriptObject::GetPrototypeOf(VarTo(target), scriptContext); } Var JavascriptReflect::EntryHas(RecyclableObject* function, CallInfo callInfo, ...) @@ -206,7 +206,7 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_NeedObject, _u("Reflect.iesExtensible")); } Var target = args[1]; - RecyclableObject *object = RecyclableObject::FromVar(target); + RecyclableObject *object = VarTo(target); BOOL isExtensible = object->IsExtensible(); GlobalObject* globalObject = object->GetLibrary()->GetGlobalObject(); @@ -261,7 +261,7 @@ namespace Js } Var target = args[1]; - RecyclableObject* targetObj = RecyclableObject::FromVar(target); + RecyclableObject* targetObj = VarTo(target); GlobalObject* globalObject = targetObj->GetLibrary()->GetGlobalObject(); if (globalObject != targetObj && globalObject && (globalObject->ToThis() == targetObj)) { @@ -296,7 +296,7 @@ namespace Js Var receiver = args.Info.Count > 4 ? args[4] : target; target = JavascriptOperators::ToObject(target, scriptContext); - BOOL result = JavascriptOperators::SetElementIHelper(receiver, RecyclableObject::FromVar(target), propertyKey, value, scriptContext, PropertyOperationFlags::PropertyOperation_None); + BOOL result = JavascriptOperators::SetElementIHelper(receiver, VarTo(target), propertyKey, value, scriptContext, PropertyOperationFlags::PropertyOperation_None); return scriptContext->GetLibrary()->GetTrueOrFalse(result); } @@ -326,8 +326,8 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_NotObjectOrNull, _u("Object.setPrototypeOf")); } - RecyclableObject* newPrototype = RecyclableObject::FromVar(args[2]); - BOOL changeResult = JavascriptObject::ChangePrototype(RecyclableObject::FromVar(target), newPrototype, /*validate*/false, scriptContext); + RecyclableObject* newPrototype = VarTo(args[2]); + BOOL changeResult = JavascriptObject::ChangePrototype(VarTo(target), newPrototype, /*validate*/false, scriptContext); return scriptContext->GetLibrary()->GetTrueOrFalse(changeResult); } @@ -359,7 +359,7 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_NeedArrayLike, _u("Reflect.apply")); } - return JavascriptFunction::ApplyHelper(RecyclableObject::FromVar(target), thisArgument, argArray, scriptContext); + return JavascriptFunction::ApplyHelper(VarTo(target), thisArgument, argArray, scriptContext); } static const int STACK_ARGS_ALLOCA_THRESHOLD = 8; @@ -402,10 +402,10 @@ namespace Js } } - RecyclableObject* thisArg = RecyclableObject::FromVar(undefinedValue); + RecyclableObject* thisArg = VarTo(undefinedValue); if (newTarget != nullptr) { - thisArg = JavascriptOperators::CreateFromConstructor(RecyclableObject::FromVar(newTarget), scriptContext); + thisArg = JavascriptOperators::CreateFromConstructor(VarTo(newTarget), scriptContext); } Var argArray = args.Info.Count > 2 ? args[2] : undefinedValue; @@ -415,6 +415,6 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_NeedArrayLike, _u("Reflect.construct")); } - return JavascriptFunction::ConstructHelper(RecyclableObject::FromVar(target), thisArg, newTarget, argArray, scriptContext); + return JavascriptFunction::ConstructHelper(VarTo(target), thisArg, newTarget, argArray, scriptContext); } } diff --git a/lib/Runtime/Library/JavascriptRegularExpression.cpp b/lib/Runtime/Library/JavascriptRegularExpression.cpp index 74f8102810f..31b8b80234f 100644 --- a/lib/Runtime/Library/JavascriptRegularExpression.cpp +++ b/lib/Runtime/Library/JavascriptRegularExpression.cpp @@ -71,11 +71,6 @@ using namespace Js; Assert(!ThreadContext::IsOnStack(instance->lastIndexVar)); } - bool JavascriptRegExp::Is(Var aValue) - { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_RegEx; - } - // IsRegExp in the spec. bool JavascriptRegExp::IsRegExpLike(Var aValue, ScriptContext* scriptContext) { @@ -87,7 +82,7 @@ using namespace Js; } Var symbolMatchProperty = JavascriptOperators::GetProperty( - RecyclableObject::FromVar(aValue), + VarTo(aValue), PropertyIds::_symbolMatch, scriptContext); if (!JavascriptOperators::IsUndefined(symbolMatchProperty)) @@ -96,21 +91,7 @@ using namespace Js; } } - return JavascriptRegExp::Is(aValue); - } - - JavascriptRegExp* JavascriptRegExp::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptRegExp'"); - - return static_cast(aValue); - } - - JavascriptRegExp* JavascriptRegExp::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptRegExp'"); - - return static_cast(aValue); + return VarIs(aValue); } CharCount JavascriptRegExp::GetLastIndexProperty(RecyclableObject* instance, ScriptContext* scriptContext) @@ -133,7 +114,7 @@ using namespace Js; { JavascriptOperators::SetProperty( instance, - RecyclableObject::FromVar(instance), + VarTo(instance), PropertyIds::lastIndex, lastIndex, scriptContext, @@ -199,7 +180,7 @@ using namespace Js; if (JavascriptOperators::GetTypeId(var) == TypeIds_HostDispatch) { TypeId remoteTypeId = TypeIds_Limit; - RecyclableObject* reclObj = RecyclableObject::UnsafeFromVar(var); + RecyclableObject* reclObj = UnsafeVarTo(var); if (reclObj->GetRemoteTypeId(&remoteTypeId) && remoteTypeId == TypeIds_RegEx) { return static_cast(reclObj->GetRemoteObject()); @@ -217,7 +198,7 @@ using namespace Js; JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedObject, varName); } - return RecyclableObject::FromVar(args[0]); + return VarTo(args[0]); } JavascriptString* JavascriptRegExp::GetFirstStringArg(Arguments& args, ScriptContext* scriptContext) @@ -272,7 +253,7 @@ using namespace Js; else if (JavascriptRegExp::IsRegExpLike(args[1], scriptContext)) { // JavascriptRegExp::IsRegExpLike() makes sure that args[1] is an Object. - RecyclableObject* regexLikeObj = RecyclableObject::FromVar(args[1]); + RecyclableObject* regexLikeObj = VarTo(args[1]); if (!(callInfo.Flags & CallFlags_New) && (callInfo.Count == 2 || JavascriptOperators::IsUndefinedObject(args[2])) && @@ -284,9 +265,9 @@ using namespace Js; return regexLikeObj; } - if (JavascriptRegExp::Is(regexLikeObj)) + if (VarIs(regexLikeObj)) { - JavascriptRegExp* source = JavascriptRegExp::FromVar(regexLikeObj); + JavascriptRegExp* source = VarTo(regexLikeObj); if (callInfo.Count > 2) { @@ -339,7 +320,7 @@ using namespace Js; regex->SetSplitPattern(splitPattern); return isCtorSuperCall ? - JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), regex, nullptr, scriptContext) : + JavascriptOperators::OrdinaryCreateFromConstructor(VarTo(newTarget), regex, nullptr, scriptContext) : regex; } @@ -347,9 +328,9 @@ using namespace Js; { JavascriptString * strBody; - if (JavascriptString::Is(aValue)) + if (VarIs(aValue)) { - strBody = JavascriptString::FromVar(aValue); + strBody = VarTo(aValue); } else if (JavascriptOperators::GetTypeId(aValue) == TypeIds_Undefined) { @@ -368,9 +349,9 @@ using namespace Js; JavascriptString * strOptions = nullptr; if (options != nullptr && !JavascriptOperators::IsUndefinedObject(options)) { - if (JavascriptString::Is(options)) + if (VarIs(options)) { - strOptions = JavascriptString::FromVar(options); + strOptions = VarTo(options); } else { @@ -398,9 +379,9 @@ using namespace Js; JIT_HELPER_REENTRANT_HEADER(Op_CoerseRegex); // This is called as helper from OpCode::CoerseRegEx. If aValue is regex pattern /a/, CreatePattern converts // it to pattern "/a/" instead of "a". So if we know that aValue is regex, then just return the same object - if (JavascriptRegExp::Is(aValue)) + if (VarIs(aValue)) { - return JavascriptRegExp::FromVar(aValue); + return VarTo(aValue); } else { @@ -574,9 +555,9 @@ using namespace Js; { pattern = scriptContext->GetLibrary()->GetEmptyRegexPattern(); } - else if (JavascriptRegExp::Is(args[1])) + else if (VarIs(args[1])) { - JavascriptRegExp* source = JavascriptRegExp::FromVar(args[1]); + JavascriptRegExp* source = VarTo(args[1]); //compile with a regular expression pattern = source->GetPattern(); splitPattern = source->GetSplitPattern(); @@ -590,9 +571,9 @@ using namespace Js; { //compile with a string JavascriptString * strBody; - if (JavascriptString::Is(args[1])) + if (VarIs(args[1])) { - strBody = JavascriptString::FromVar(args[1]); + strBody = VarTo(args[1]); } else if(JavascriptOperators::GetTypeId(args[1]) == TypeIds_Undefined) { @@ -611,9 +592,9 @@ using namespace Js; JavascriptString * strOptions = nullptr; if (callInfo.Count > 2 && !JavascriptOperators::IsUndefinedObject(args[2])) { - if (JavascriptString::Is(args[2])) + if (VarIs(args[2])) { - strOptions = JavascriptString::FromVar(args[2]); + strOptions = VarTo(args[2]); } else { @@ -796,9 +777,9 @@ using namespace Js; Var replaceValue = (args.Info.Count > 2) ? args[2] : scriptContext->GetLibrary()->GetUndefined(); - if (JavascriptFunction::Is(replaceValue)) + if (VarIs(replaceValue)) { - JavascriptFunction* replaceFunction = JavascriptFunction::FromVar(replaceValue); + JavascriptFunction* replaceFunction = VarTo(replaceValue); return RegexHelper::RegexReplaceFunction(scriptContext, thisObj, string, replaceFunction); } else @@ -839,7 +820,7 @@ using namespace Js; return JavascriptOperators::IsNull(result) ? TaggedInt::ToVarUnchecked(-1) - : JavascriptOperators::GetProperty(RecyclableObject::FromVar(result), PropertyIds::index, scriptContext); + : JavascriptOperators::GetProperty(VarTo(result), PropertyIds::index, scriptContext); } Var JavascriptRegExp::EntrySymbolSplit(RecyclableObject* function, CallInfo callInfo, ...) @@ -882,7 +863,7 @@ using namespace Js; Var exec = JavascriptOperators::GetProperty(thisObj, PropertyIds::exec, scriptContext); if (JavascriptConversion::IsCallable(exec)) { - RecyclableObject* execFn = RecyclableObject::UnsafeFromVar(exec); + RecyclableObject* execFn = UnsafeVarTo(exec); ThreadContext * threadContext = scriptContext->GetThreadContext(); Var result = threadContext->ExecuteImplicitCall(execFn, ImplicitCall_Accessor, [=]()->Js::Var { diff --git a/lib/Runtime/Library/JavascriptRegularExpression.h b/lib/Runtime/Library/JavascriptRegularExpression.h index bc03cd7c41c..7eb414c00cb 100644 --- a/lib/Runtime/Library/JavascriptRegularExpression.h +++ b/lib/Runtime/Library/JavascriptRegularExpression.h @@ -122,10 +122,7 @@ namespace Js this->lastIndexOrFlag = lastIndex; } - static bool Is(Var aValue); static bool IsRegExpLike(Var aValue, ScriptContext* scriptContext); - static JavascriptRegExp* FromVar(Var aValue); - static JavascriptRegExp* UnsafeFromVar(Var aValue); static JavascriptRegExp* CreateRegEx(const char16* pSource, CharCount sourceLen, UnifiedRegex::RegexFlags flags, ScriptContext *scriptContext); @@ -222,4 +219,9 @@ namespace Js } }; + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_RegEx; + } + } // namespace Js diff --git a/lib/Runtime/Library/JavascriptSet.cpp b/lib/Runtime/Library/JavascriptSet.cpp index 6e20f24e8cd..7d974236f4b 100644 --- a/lib/Runtime/Library/JavascriptSet.cpp +++ b/lib/Runtime/Library/JavascriptSet.cpp @@ -18,25 +18,6 @@ JavascriptSet* JavascriptSet::New(ScriptContext* scriptContext) return set; } -bool JavascriptSet::Is(Var aValue) -{ - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Set; -} - -JavascriptSet* JavascriptSet::FromVar(Var aValue) -{ - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptSet'"); - - return static_cast(aValue); -} - -JavascriptSet* JavascriptSet::UnsafeFromVar(Var aValue) -{ - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptSet'"); - - return static_cast(aValue); -} - JavascriptSet::SetDataList::Iterator JavascriptSet::GetIterator() { return this->list.GetIterator(); @@ -87,7 +68,7 @@ Var JavascriptSet::NewInstance(RecyclableObject* function, CallInfo callInfo, .. { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedFunction); } - adder = RecyclableObject::FromVar(adderVar); + adder = VarTo(adderVar); } if (iter != nullptr) @@ -102,7 +83,7 @@ Var JavascriptSet::NewInstance(RecyclableObject* function, CallInfo callInfo, .. } return isCtorSuperCall ? - JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), setObject, nullptr, scriptContext) : + JavascriptOperators::OrdinaryCreateFromConstructor(VarTo(newTarget), setObject, nullptr, scriptContext) : setObject; } @@ -188,7 +169,7 @@ Var JavascriptSet::EntryForEach(RecyclableObject* function, CallInfo callInfo, . { JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_NeedFunction, _u("Set.prototype.forEach")); } - RecyclableObject* callBackFn = RecyclableObject::FromVar(args[1]); + RecyclableObject* callBackFn = VarTo(args[1]); Var thisArg = (args.Info.Count > 2) ? args[2] : scriptContext->GetLibrary()->GetUndefined(); diff --git a/lib/Runtime/Library/JavascriptSet.h b/lib/Runtime/Library/JavascriptSet.h index 53fce640adf..b8609e31511 100644 --- a/lib/Runtime/Library/JavascriptSet.h +++ b/lib/Runtime/Library/JavascriptSet.h @@ -74,10 +74,6 @@ namespace Js static JavascriptSet* New(ScriptContext* scriptContext); - static bool Is(Var aValue); - static JavascriptSet* FromVar(Var aValue); - static JavascriptSet* UnsafeFromVar(Var aValue); - void Add(Var value); void Clear(); @@ -125,4 +121,9 @@ namespace Js static JavascriptSet* CreateForSnapshotRestore(ScriptContext* ctx); #endif }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_Set; + } } diff --git a/lib/Runtime/Library/JavascriptSetIterator.cpp b/lib/Runtime/Library/JavascriptSetIterator.cpp index c9454400e56..6fe4c8b8ede 100644 --- a/lib/Runtime/Library/JavascriptSetIterator.cpp +++ b/lib/Runtime/Library/JavascriptSetIterator.cpp @@ -15,26 +15,6 @@ namespace Js Assert(type->GetTypeId() == TypeIds_SetIterator); } - bool JavascriptSetIterator::Is(Var aValue) - { - TypeId typeId = JavascriptOperators::GetTypeId(aValue); - return typeId == TypeIds_SetIterator; - } - - JavascriptSetIterator* JavascriptSetIterator::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptSetIterator'"); - - return static_cast(aValue); - } - - JavascriptSetIterator* JavascriptSetIterator::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptSetIterator'"); - - return static_cast(aValue); - } - Var JavascriptSetIterator::EntryNext(RecyclableObject* function, CallInfo callInfo, ...) { PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault); @@ -47,12 +27,12 @@ namespace Js Var thisObj = args[0]; - if (!JavascriptSetIterator::Is(thisObj)) + if (!VarIs(thisObj)) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedSetIterator, _u("Set Iterator.prototype.next")); } - JavascriptSetIterator* iterator = JavascriptSetIterator::FromVar(thisObj); + JavascriptSetIterator* iterator = VarTo(thisObj); JavascriptSet* set = iterator->m_set; auto& setIterator = iterator->m_setIterator; diff --git a/lib/Runtime/Library/JavascriptSetIterator.h b/lib/Runtime/Library/JavascriptSetIterator.h index 4106f3245c8..a74b6e01b86 100644 --- a/lib/Runtime/Library/JavascriptSetIterator.h +++ b/lib/Runtime/Library/JavascriptSetIterator.h @@ -26,10 +26,6 @@ namespace Js public: JavascriptSetIterator(DynamicType* type, JavascriptSet* set, JavascriptSetIteratorKind kind); - static bool Is(Var aValue); - static JavascriptSetIterator* FromVar(Var aValue); - static JavascriptSetIterator* UnsafeFromVar(Var aValue); - class EntryInfo { public: @@ -41,4 +37,9 @@ namespace Js public: JavascriptSet* GetSetForHeapEnum() { return m_set; } }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_SetIterator; + } } // namespace Js diff --git a/lib/Runtime/Library/JavascriptString.cpp b/lib/Runtime/Library/JavascriptString.cpp index 79fa08ebf3c..ec27408fd98 100644 --- a/lib/Runtime/Library/JavascriptString.cpp +++ b/lib/Runtime/Library/JavascriptString.cpp @@ -160,7 +160,7 @@ namespace Js } return isCtorSuperCall ? - JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), RecyclableObject::UnsafeFromVar(result), nullptr, scriptContext) : + JavascriptOperators::OrdinaryCreateFromConstructor(VarTo(newTarget), UnsafeVarTo(result), nullptr, scriptContext) : result; } @@ -219,9 +219,9 @@ namespace Js return IsValidCharCount(idx) && idx < GetLength(); } - bool JavascriptString::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_String; + return JavascriptOperators::GetTypeId(obj) == TypeIds_String; } void JavascriptString::GetPropertyRecord(_Out_ Js::PropertyRecord const ** propertyRecord, bool dontLookupFromDictionary) @@ -240,20 +240,6 @@ namespace Js // Base string doesn't have enough room to keep this value, so do nothing } - JavascriptString* JavascriptString::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptString'"); - - return static_cast(aValue); - } - - JavascriptString* JavascriptString::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptString'"); - - return static_cast(aValue); - } - charcount_t JavascriptString::GetBufferLength(const char16 * content) { @@ -410,7 +396,7 @@ namespace Js if(!IsFinalized()) { - if(CompoundString::Is(this)) + if(VarIs(this)) { return ConcatDestructive_Compound(pstRight); } @@ -456,7 +442,7 @@ namespace Js JavascriptString* JavascriptString::ConcatDestructive_Compound(JavascriptString* pstRight) { - Assert(CompoundString::Is(this)); + Assert(VarIs(this)); Assert(pstRight); #ifdef PROFILE_STRINGS @@ -471,7 +457,7 @@ namespace Js Output::Flush(); } - CompoundString *const leftCs = CompoundString::FromVar(this); + CompoundString *const leftCs = VarTo(this); leftCs->PrepareForAppend(); leftCs->Append(pstRight); return this; @@ -567,7 +553,7 @@ namespace Js if(!pstLeft->IsFinalized()) { - if(CompoundString::Is(pstLeft)) + if(VarIs(pstLeft)) { return Concat_Compound(pstLeft, pstRight); } @@ -605,7 +591,7 @@ namespace Js JavascriptString* JavascriptString::Concat_Compound(JavascriptString * pstLeft, JavascriptString * pstRight) { Assert(pstLeft); - Assert(CompoundString::Is(pstLeft)); + Assert(VarIs(pstLeft)); Assert(pstRight); #ifdef PROFILE_STRINGS @@ -623,7 +609,7 @@ namespace Js // This is not a left-dead concat, but we can reuse available space in the left string // because it may be accessible by script code, append to a clone. const bool needAppend = pstRight->GetLength() != 0; - CompoundString *const leftCs = CompoundString::FromVar(pstLeft)->Clone(needAppend); + CompoundString *const leftCs = VarTo(pstLeft)->Clone(needAppend); if(needAppend) { leftCs->Append(pstRight); @@ -1661,13 +1647,13 @@ namespace Js // When the config is enabled, the operation is handled by a Symbol function (e.g. Symbol.replace). if (!scriptContext->GetConfig()->IsES6RegExSymbolsEnabled() - && JavascriptRegExp::Is(aValue)) + && VarIs(aValue)) { - *ppSearchRegEx = JavascriptRegExp::FromVar(aValue); + *ppSearchRegEx = VarTo(aValue); } - else if (JavascriptString::Is(aValue)) + else if (VarIs(aValue)) { - *ppSearchString = JavascriptString::FromVar(aValue); + *ppSearchString = VarTo(aValue); } else { @@ -1680,13 +1666,13 @@ namespace Js *ppReplaceFn = nullptr; *ppReplaceString = nullptr; - if (JavascriptFunction::Is(aValue)) + if (VarIs(aValue)) { - *ppReplaceFn = JavascriptFunction::FromVar(aValue); + *ppReplaceFn = VarTo(aValue); } - else if (JavascriptString::Is(aValue)) + else if (VarIs(aValue)) { - *ppReplaceString = JavascriptString::FromVar(aValue); + *ppReplaceString = VarTo(aValue); } else { @@ -1768,7 +1754,7 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_Invalid, varName); } - RecyclableObject* fnObj = RecyclableObject::UnsafeFromVar(fn); + RecyclableObject* fnObj = UnsafeVarTo(fn); return CallRegExFunction(fnObj, regExp, args, scriptContext); } @@ -1898,9 +1884,9 @@ namespace Js // When the config is enabled, the operation is handled by RegExp.prototype[@@split]. if (!scriptContext->GetConfig()->IsES6RegExSymbolsEnabled() - && JavascriptRegExp::Is(args[1])) + && VarIs(args[1])) { - return RegexHelper::RegexSplit(scriptContext, JavascriptRegExp::UnsafeFromVar(args[1]), input, limit, + return RegexHelper::RegexSplit(scriptContext, UnsafeVarTo(args[1]), input, limit, RegexHelper::IsResultNotUsed(callInfo.Flags)); } else @@ -2207,7 +2193,7 @@ namespace Js if (JavascriptOperators::GetTypeId(args[0]) == TypeIds_HostDispatch) { Var result; - if (RecyclableObject::UnsafeFromVar(args[0])->InvokeBuiltInOperationRemotely(EntryToString, args, &result)) + if (UnsafeVarTo(args[0])->InvokeBuiltInOperationRemotely(EntryToString, args, &result)) { return result; } @@ -2721,7 +2707,7 @@ namespace Js if (JavascriptOperators::GetTypeId(args[0]) == TypeIds_HostDispatch) { Var result; - if (RecyclableObject::UnsafeFromVar(args[0])->InvokeBuiltInOperationRemotely(EntryValueOf, args, &result)) + if (UnsafeVarTo(args[0])->InvokeBuiltInOperationRemotely(EntryValueOf, args, &result)) { return result; } @@ -3095,10 +3081,10 @@ namespace Js // bool JavascriptString::LessThan(Var aLeft, Var aRight) { - AssertMsg(JavascriptString::Is(aLeft) && JavascriptString::Is(aRight), "string LessThan"); + AssertMsg(VarIs(aLeft) && VarIs(aRight), "string LessThan"); - JavascriptString *leftString = JavascriptString::FromVar(aLeft); - JavascriptString *rightString = JavascriptString::FromVar(aRight); + JavascriptString *leftString = VarTo(aLeft); + JavascriptString *rightString = VarTo(aRight); if (JavascriptString::strcmp(leftString, rightString) < 0) { @@ -3113,20 +3099,20 @@ namespace Js Assert(pString); // 1. If Type(value) is String, return value. - if (JavascriptString::Is(aValue)) + if (VarIs(aValue)) { - *pString = JavascriptString::FromVar(aValue); + *pString = VarTo(aValue); return TRUE; } // 2. If Type(value) is Object and value has a [[StringData]] internal slot - else if ( JavascriptStringObject::Is(aValue)) + else if ( VarIs(aValue)) { - JavascriptStringObject* pStringObj = JavascriptStringObject::FromVar(aValue); + JavascriptStringObject* pStringObj = VarTo(aValue); // a. Let s be the value of value's [[StringData]] internal slot. // b. If s is not undefined, then return s. *pString = pStringObj->Unwrap(); - *pString = JavascriptString::FromVar(CrossSite::MarshalVar(scriptContext, + *pString = VarTo(CrossSite::MarshalVar(scriptContext, *pString, pStringObj->GetScriptContext())); return TRUE; } @@ -3174,8 +3160,8 @@ namespace Js // // pszProp = _u("href"); // pszTag = _u("a"); - // pThis = JavascriptString::FromVar(args[0]); - // pPropertyValue = JavascriptString::FromVar(args[1]); + // pThis = VarTo(args[0]); + // pPropertyValue = VarTo(args[1]); // // pResult = _u("[[pThis]]"); // diff --git a/lib/Runtime/Library/JavascriptString.h b/lib/Runtime/Library/JavascriptString.h index 72fdc9d971c..f199352abce 100644 --- a/lib/Runtime/Library/JavascriptString.h +++ b/lib/Runtime/Library/JavascriptString.h @@ -133,9 +133,6 @@ namespace Js virtual BOOL BufferEquals(__in_ecount(otherLength) LPCWSTR otherBuffer, __in charcount_t otherLength); char16* GetNormalizedString(PlatformAgnostic::UnicodeText::NormalizationForm, ArenaAllocator*, charcount_t&); - static bool Is(Var aValue); - static JavascriptString* FromVar(Var aValue); - static JavascriptString* UnsafeFromVar(Var aValue); static bool Equals(JavascriptString* aLeft, JavascriptString* aRight); static bool LessThan(Var aLeft, Var aRight); static bool IsNegZero(JavascriptString *string); @@ -358,6 +355,8 @@ namespace Js static Var CallRegExFunction(RecyclableObject* fnObj, Var regExp, Arguments& args, ScriptContext *scriptContext); }; + template <> bool VarIsImpl(RecyclableObject* obj); + template<> struct PropertyRecordStringHashComparer { diff --git a/lib/Runtime/Library/JavascriptStringIterator.cpp b/lib/Runtime/Library/JavascriptStringIterator.cpp index de9d18c745a..658b5b7f9e8 100644 --- a/lib/Runtime/Library/JavascriptStringIterator.cpp +++ b/lib/Runtime/Library/JavascriptStringIterator.cpp @@ -14,26 +14,6 @@ namespace Js Assert(type->GetTypeId() == TypeIds_StringIterator); } - bool JavascriptStringIterator::Is(Var aValue) - { - TypeId typeId = JavascriptOperators::GetTypeId(aValue); - return typeId == TypeIds_StringIterator; - } - - JavascriptStringIterator* JavascriptStringIterator::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptStringIterator'"); - - return static_cast(aValue); - } - - JavascriptStringIterator* JavascriptStringIterator::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptStringIterator'"); - - return static_cast(aValue); - } - Var JavascriptStringIterator::EntryNext(RecyclableObject* function, CallInfo callInfo, ...) { PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault); @@ -46,12 +26,12 @@ namespace Js Var thisObj = args[0]; - if (!JavascriptStringIterator::Is(thisObj)) + if (!VarIs(thisObj)) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedStringIterator, _u("String Iterator.prototype.next")); } - JavascriptStringIterator* iterator = JavascriptStringIterator::FromVar(thisObj); + JavascriptStringIterator* iterator = VarTo(thisObj); JavascriptString* string = iterator->m_string; if (string == nullptr) diff --git a/lib/Runtime/Library/JavascriptStringIterator.h b/lib/Runtime/Library/JavascriptStringIterator.h index bf3ae4b0f9f..f2087e8bc4f 100644 --- a/lib/Runtime/Library/JavascriptStringIterator.h +++ b/lib/Runtime/Library/JavascriptStringIterator.h @@ -19,10 +19,6 @@ namespace Js public: JavascriptStringIterator(DynamicType* type, JavascriptString* string); - static bool Is(Var aValue); - static JavascriptStringIterator* FromVar(Var aValue); - static JavascriptStringIterator* UnsafeFromVar(Var aValue); - class EntryInfo { public: @@ -34,4 +30,9 @@ namespace Js public: JavascriptString* GetStringForHeapEnum() { return m_string; } }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_StringIterator; + } } // namespace Js diff --git a/lib/Runtime/Library/JavascriptStringObject.cpp b/lib/Runtime/Library/JavascriptStringObject.cpp index 7740918fb2d..69a41f9a171 100644 --- a/lib/Runtime/Library/JavascriptStringObject.cpp +++ b/lib/Runtime/Library/JavascriptStringObject.cpp @@ -37,25 +37,6 @@ namespace Js } } - bool JavascriptStringObject::Is(Var aValue) - { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_StringObject; - } - - JavascriptStringObject* JavascriptStringObject::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptString'"); - - return static_cast(aValue); - } - - JavascriptStringObject* JavascriptStringObject::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptString'"); - - return static_cast(aValue); - } - void JavascriptStringObject::Initialize(JavascriptString* value) { Assert(this->value == nullptr); @@ -254,7 +235,7 @@ namespace Js if (scriptContext->IsNumericPropertyId(propertyId, &index)) { JavascriptString* str = this->InternalUnwrap(); - str = JavascriptString::FromVar(CrossSite::MarshalVar(requestContext, str, scriptContext)); + str = VarTo(CrossSite::MarshalVar(requestContext, str, scriptContext)); return JavascriptConversion::BooleanToPropertyQueryFlags(str->GetItemAt(index, value)); } @@ -365,7 +346,7 @@ namespace Js Var strObject = CrossSite::MarshalVar(requestContext, this->InternalUnwrap(), this->GetScriptContext()); - JavascriptString* str = JavascriptString::FromVar(strObject); + JavascriptString* str = VarTo(strObject); if (str->GetItemAt(index, value)) { return PropertyQueryFlags::Property_Found; @@ -420,7 +401,7 @@ namespace Js #if ENABLE_TTD void JavascriptStringObject::SetValue_TTD(Js::Var val) { - AssertMsg(val == nullptr || Js::JavascriptString::Is(val), "Only legal values!"); + AssertMsg(val == nullptr || Js::VarIs(val), "Only legal values!"); this->value = static_cast(val); } diff --git a/lib/Runtime/Library/JavascriptStringObject.h b/lib/Runtime/Library/JavascriptStringObject.h index bc87db3f714..aeb0266e6e9 100644 --- a/lib/Runtime/Library/JavascriptStringObject.h +++ b/lib/Runtime/Library/JavascriptStringObject.h @@ -27,9 +27,6 @@ namespace Js public: JavascriptStringObject(DynamicType * type); JavascriptStringObject(JavascriptString* value, DynamicType * type); - static bool Is(Var aValue); - static JavascriptStringObject* FromVar(Var aValue); - static JavascriptStringObject* UnsafeFromVar(Var aValue); void Initialize(JavascriptString* value); JavascriptString* Unwrap() { return InternalUnwrap(); } @@ -72,4 +69,9 @@ namespace Js virtual void ExtractSnapObjectDataInto(TTD::NSSnapObjects::SnapObject* objData, TTD::SlabAllocator& alloc) override; #endif }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_StringObject; + } } diff --git a/lib/Runtime/Library/JavascriptSymbol.cpp b/lib/Runtime/Library/JavascriptSymbol.cpp index dffe6a7662d..77e97e78eb2 100644 --- a/lib/Runtime/Library/JavascriptSymbol.cpp +++ b/lib/Runtime/Library/JavascriptSymbol.cpp @@ -11,25 +11,6 @@ namespace Js return &this->propertyRecordUsageCache; } - bool JavascriptSymbol::Is(Var aValue) - { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Symbol; - } - - JavascriptSymbol* JavascriptSymbol::FromVar(Js::Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptSymbol'"); - - return static_cast(aValue); - } - - JavascriptSymbol* JavascriptSymbol::UnsafeFromVar(Js::Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptSymbol'"); - - return static_cast(aValue); - } - Var JavascriptSymbol::NewInstance(RecyclableObject* function, CallInfo callInfo, ...) { PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault); @@ -73,13 +54,13 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (JavascriptSymbol::Is(args[0])) + if (VarIs(args[0])) { return args[0]; } - else if (JavascriptSymbolObject::Is(args[0])) + else if (VarIs(args[0])) { - JavascriptSymbolObject* obj = JavascriptSymbolObject::FromVar(args[0]); + JavascriptSymbolObject* obj = VarTo(args[0]); return CrossSite::MarshalVar(scriptContext, obj->Unwrap(), obj->GetScriptContext()); } else @@ -101,13 +82,13 @@ namespace Js const PropertyRecord* val; Var aValue = args[0]; - if (JavascriptSymbol::Is(aValue)) + if (VarIs(aValue)) { - val = JavascriptSymbol::FromVar(aValue)->GetValue(); + val = VarTo(aValue)->GetValue(); } - else if (JavascriptSymbolObject::Is(aValue)) + else if (VarIs(aValue)) { - val = JavascriptSymbolObject::FromVar(aValue)->GetValue(); + val = VarTo(aValue)->GetValue(); } else { @@ -170,12 +151,12 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count < 2 || !JavascriptSymbol::Is(args[1])) + if (args.Info.Count < 2 || !VarIs(args[1])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedSymbol, _u("Symbol.keyFor")); } - JavascriptSymbol* sym = JavascriptSymbol::FromVar(args[1]); + JavascriptSymbol* sym = VarTo(args[1]); const Js::PropertyRecord* symPropertyRecord = sym->GetValue(); const char16* key = symPropertyRecord->GetBuffer(); const charcount_t keyLength = symPropertyRecord->GetLength(); @@ -206,13 +187,13 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (JavascriptSymbol::Is(args[0])) + if (VarIs(args[0])) { return args[0]; } - else if (JavascriptSymbolObject::Is(args[0])) + else if (VarIs(args[0])) { - JavascriptSymbolObject* obj = JavascriptSymbolObject::FromVar(args[0]); + JavascriptSymbolObject* obj = VarTo(args[0]); return CrossSite::MarshalVar(scriptContext, obj->Unwrap(), obj->GetScriptContext()); } else @@ -233,7 +214,7 @@ namespace Js if (JavascriptOperators::GetTypeId(args[0]) == TypeIds_HostDispatch) { Var result; - if (RecyclableObject::FromVar(args[0])->InvokeBuiltInOperationRemotely(entryPoint, args, &result)) + if (VarTo(args[0])->InvokeBuiltInOperationRemotely(entryPoint, args, &result)) { return result; } @@ -266,12 +247,12 @@ namespace Js switch (typeId) { case TypeIds_Symbol: - *value = left == JavascriptSymbol::UnsafeFromVar(right); - Assert((left->GetValue() == JavascriptSymbol::UnsafeFromVar(right)->GetValue()) == *value); + *value = left == UnsafeVarTo(right); + Assert((left->GetValue() == UnsafeVarTo(right)->GetValue()) == *value); break; case TypeIds_SymbolObject: - *value = left == JavascriptSymbol::UnsafeFromVar(JavascriptSymbolObject::UnsafeFromVar(right)->Unwrap()); - Assert((left->GetValue() == JavascriptSymbolObject::UnsafeFromVar(right)->GetValue()) == *value); + *value = left == UnsafeVarTo(UnsafeVarTo(right)->Unwrap()); + Assert((left->GetValue() == UnsafeVarTo(right)->GetValue()) == *value); break; default: *value = FALSE; diff --git a/lib/Runtime/Library/JavascriptSymbol.h b/lib/Runtime/Library/JavascriptSymbol.h index 06595fb5c9f..50964d2729c 100644 --- a/lib/Runtime/Library/JavascriptSymbol.h +++ b/lib/Runtime/Library/JavascriptSymbol.h @@ -27,9 +27,6 @@ namespace Js static uint32 GetOffsetOfLdElemInlineCache() { return offsetof(JavascriptSymbol, propertyRecordUsageCache) + PropertyRecordUsageCache::GetOffsetOfLdElemInlineCache(); } static uint32 GetOffsetOfStElemInlineCache() { return offsetof(JavascriptSymbol, propertyRecordUsageCache) + PropertyRecordUsageCache::GetOffsetOfStElemInlineCache(); } static uint32 GetOffsetOfHitRate() { return offsetof(JavascriptSymbol, propertyRecordUsageCache) + PropertyRecordUsageCache::GetOffsetOfHitRate(); } - static bool Is(Var aValue); - static JavascriptSymbol* FromVar(Var aValue); - static JavascriptSymbol* UnsafeFromVar(Var aValue); class EntryInfo { @@ -65,4 +62,9 @@ namespace Js static BOOL Equals(JavascriptSymbol* left, Var right, BOOL* value, ScriptContext * requestContext); static Var TryInvokeRemotelyOrThrow(JavascriptMethod entryPoint, ScriptContext * scriptContext, Arguments & args, int32 errorCode, PCWSTR varName); }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_Symbol; + } } diff --git a/lib/Runtime/Library/JavascriptSymbolObject.cpp b/lib/Runtime/Library/JavascriptSymbolObject.cpp index d254bd3a7c1..2584b60b53d 100644 --- a/lib/Runtime/Library/JavascriptSymbolObject.cpp +++ b/lib/Runtime/Library/JavascriptSymbolObject.cpp @@ -12,25 +12,6 @@ namespace Js Assert(type->GetTypeId() == TypeIds_SymbolObject); } - bool JavascriptSymbolObject::Is(Var aValue) - { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_SymbolObject; - } - - JavascriptSymbolObject* JavascriptSymbolObject::FromVar(Js::Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptSymbolObject'"); - - return static_cast(aValue); - } - - JavascriptSymbolObject* JavascriptSymbolObject::UnsafeFromVar(Js::Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptSymbolObject'"); - - return static_cast(aValue); - } - Var JavascriptSymbolObject::Unwrap() const { return value; @@ -54,7 +35,7 @@ namespace Js #if ENABLE_TTD void JavascriptSymbolObject::SetValue_TTD(Js::Var val) { - AssertMsg(val == nullptr || Js::JavascriptSymbol::Is(val), "Only allowable values!"); + AssertMsg(val == nullptr || Js::VarIs(val), "Only allowable values!"); this->value = static_cast(val); } diff --git a/lib/Runtime/Library/JavascriptSymbolObject.h b/lib/Runtime/Library/JavascriptSymbolObject.h index 19f4ae2559d..6983b00a51b 100644 --- a/lib/Runtime/Library/JavascriptSymbolObject.h +++ b/lib/Runtime/Library/JavascriptSymbolObject.h @@ -16,9 +16,6 @@ namespace Js public: JavascriptSymbolObject(JavascriptSymbol* value, DynamicType * type); - static bool Is(Var aValue); - static JavascriptSymbolObject* FromVar(Js::Var aValue); - static JavascriptSymbolObject* UnsafeFromVar(Js::Var aValue); inline const PropertyRecord* GetValue() { @@ -44,4 +41,9 @@ namespace Js virtual void ExtractSnapObjectDataInto(TTD::NSSnapObjects::SnapObject* objData, TTD::SlabAllocator& alloc) override; #endif }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_SymbolObject; + } } diff --git a/lib/Runtime/Library/JavascriptTypedNumber.cpp b/lib/Runtime/Library/JavascriptTypedNumber.cpp index 76591918ac9..16ff9fdd37f 100644 --- a/lib/Runtime/Library/JavascriptTypedNumber.cpp +++ b/lib/Runtime/Library/JavascriptTypedNumber.cpp @@ -34,7 +34,7 @@ namespace Js JavascriptString* JavascriptTypedNumber<__int64>::ToString(Var value, ScriptContext* scriptContext) { char16 szBuffer[22]; - __int64 val = JavascriptTypedNumber<__int64>::FromVar(value)->GetValue(); + __int64 val = VarTo>(value)->GetValue(); int pos = TaggedInt::SignedToString(val, szBuffer, 22); return JavascriptString::NewCopyBuffer(szBuffer + pos, (_countof(szBuffer) - 1) - pos, scriptContext); } @@ -43,7 +43,7 @@ namespace Js JavascriptString* JavascriptTypedNumber::ToString(Var value, ScriptContext* scriptContext) { char16 szBuffer[22]; - unsigned __int64 val = JavascriptUInt64Number::FromVar(value)->GetValue(); + unsigned __int64 val = VarTo(value)->GetValue(); int pos = TaggedInt::UnsignedToString(val, szBuffer, 22); return JavascriptString::NewCopyBuffer(szBuffer + pos, (_countof(szBuffer) - 1) - pos, scriptContext); } diff --git a/lib/Runtime/Library/JavascriptTypedNumber.h b/lib/Runtime/Library/JavascriptTypedNumber.h index 0575918d075..1097610c768 100644 --- a/lib/Runtime/Library/JavascriptTypedNumber.h +++ b/lib/Runtime/Library/JavascriptTypedNumber.h @@ -31,23 +31,6 @@ namespace Js static Var ToVar(T nValue, ScriptContext* scriptContext); - static JavascriptTypedNumber* FromVar(Var value) - { - AssertOrFailFastMsg(JavascriptOperators::GetTypeId(value) == TypeIds_Int64Number || - JavascriptOperators::GetTypeId(value) == TypeIds_UInt64Number, "invalid typed number"); - - return static_cast*>(value); - }; - - static JavascriptTypedNumber* UnsafeFromVar(Var value) - { -#if DBG - AssertMsg(JavascriptOperators::GetTypeId(value) == TypeIds_Int64Number || - JavascriptOperators::GetTypeId(value) == TypeIds_UInt64Number, "invalid typed number"); -#endif - return static_cast*>(value); - }; - static JavascriptString* ToString(Var value, ScriptContext* scriptContext); Var ToJavascriptNumber() @@ -57,7 +40,7 @@ namespace Js RecyclableObject * CloneToScriptContext(ScriptContext* requestContext) override { - return RecyclableObject::FromVar(JavascriptTypedNumber::ToVar(this->GetValue(), requestContext)); + return VarTo(JavascriptTypedNumber::ToVar(this->GetValue(), requestContext)); } BOOL GetDiagTypeString(StringBuilder* stringBuilder, ScriptContext* requestContext) override @@ -75,4 +58,14 @@ namespace Js typedef JavascriptTypedNumber<__int64> JavascriptInt64Number; typedef JavascriptTypedNumber JavascriptUInt64Number; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_Int64Number; + } + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_UInt64Number; + } } diff --git a/lib/Runtime/Library/JavascriptTypedObjectSlotAccessorFunction.cpp b/lib/Runtime/Library/JavascriptTypedObjectSlotAccessorFunction.cpp deleted file mode 100644 index 8c77bf24bd7..00000000000 --- a/lib/Runtime/Library/JavascriptTypedObjectSlotAccessorFunction.cpp +++ /dev/null @@ -1,67 +0,0 @@ -//------------------------------------------------------------------------------------------------------- -// Copyright (C) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. -//------------------------------------------------------------------------------------------------------- -#include "RuntimeLibraryPch.h" - -#ifdef ENABLE_DOM_FAST_PATH -#include "Library\JavascriptTypedObjectSlotAccessorFunction.h" -namespace Js -{ - JavascriptTypedObjectSlotAccessorFunction::JavascriptTypedObjectSlotAccessorFunction(DynamicType* type, FunctionInfo* functionInfo, int allowedTypeId, PropertyId nameId) : - RuntimeFunction(type, functionInfo), - allowedTypeId(allowedTypeId) - { - DebugOnly(VerifyEntryPoint()); - SetFunctionNameId(Js::TaggedInt::ToVarUnchecked(nameId)); - } - - - bool JavascriptTypedObjectSlotAccessorFunction::Is(Var instance) - { - if (VirtualTableInfo::HasVirtualTable(instance) || - VirtualTableInfo>::HasVirtualTable(instance) ) - { - return true; - } - return false; - } - - - void JavascriptTypedObjectSlotAccessorFunction::ValidateThisInstance(Js::Var thisObj) - { - if (!InstanceOf(thisObj)) - { - Js::JavascriptError::ThrowTypeError(GetType()->GetScriptContext(), JSERR_FunctionArgument_NeedObject, _u("DOM object")); - } - } - - bool JavascriptTypedObjectSlotAccessorFunction::InstanceOf(Var thisObj) - { - int allowedTypeId = GetAllowedTypeId(); - TypeId typeId = Js::JavascriptOperators::GetTypeId(thisObj); - if (typeId == allowedTypeId) - { - return true; - } - Type* type = RecyclableObject::FromVar(thisObj)->GetType(); - if (ExternalTypeWithInheritedTypeIds::Is(type)) - { - return ((Js::ExternalTypeWithInheritedTypeIds*)type)->InstanceOf(); - } - return false; - } - - JavascriptTypedObjectSlotAccessorFunction* JavascriptTypedObjectSlotAccessorFunction::FromVar(Var instance) - { - Assert(Js::JavascriptTypedObjectSlotAccessorFunction::Is(instance)); - Assert((Js::JavascriptFunction::FromVar(instance)->GetFunctionInfo()->GetAttributes() & Js::FunctionBody::Attributes::NeedCrossSiteSecurityCheck) != 0); - return static_cast(instance); - } - - void JavascriptTypedObjectSlotAccessorFunction::ValidateThis(Js::JavascriptTypedObjectSlotAccessorFunction* func, Var thisObject) - { - func->ValidateThisInstance(thisObject); - } -} -#endif diff --git a/lib/Runtime/Library/JavascriptVariantDate.cpp b/lib/Runtime/Library/JavascriptVariantDate.cpp index bab70b7c749..cdfdb169aa6 100644 --- a/lib/Runtime/Library/JavascriptVariantDate.cpp +++ b/lib/Runtime/Library/JavascriptVariantDate.cpp @@ -6,25 +6,6 @@ namespace Js { - bool JavascriptVariantDate::Is(Var aValue) - { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_VariantDate; - } - - JavascriptVariantDate* JavascriptVariantDate::FromVar(Js::Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptVariantDate'"); - - return static_cast(aValue); - } - - JavascriptVariantDate* JavascriptVariantDate::UnsafeFromVar(Js::Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptVariantDate'"); - - return static_cast(aValue); - } - Var JavascriptVariantDate::GetTypeOfString(ScriptContext* requestContext) { return requestContext->GetLibrary()->GetVariantDateTypeDisplayString(); diff --git a/lib/Runtime/Library/JavascriptVariantDate.h b/lib/Runtime/Library/JavascriptVariantDate.h index 3d36b571837..0011802b79a 100644 --- a/lib/Runtime/Library/JavascriptVariantDate.h +++ b/lib/Runtime/Library/JavascriptVariantDate.h @@ -25,10 +25,6 @@ namespace Js public: JavascriptVariantDate(const double val, StaticType * type) : value(val), RecyclableObject(type) { } - static bool Is(Var aValue); - static JavascriptVariantDate* FromVar(Var aValue); - static JavascriptVariantDate* UnsafeFromVar(Var aValue); - // Used for making function calls to external objects requiring string params. JavascriptString* GetValueString(ScriptContext* scriptContext); @@ -55,4 +51,9 @@ namespace Js virtual RecyclableObject * CloneToScriptContext(ScriptContext* requestContext) override; virtual RecyclableObject* ToObject(ScriptContext* requestContext) override; }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_VariantDate; + } } diff --git a/lib/Runtime/Library/JavascriptWeakMap.cpp b/lib/Runtime/Library/JavascriptWeakMap.cpp index 61f5c8d6796..cdb4b0fbc35 100644 --- a/lib/Runtime/Library/JavascriptWeakMap.cpp +++ b/lib/Runtime/Library/JavascriptWeakMap.cpp @@ -12,25 +12,6 @@ namespace Js { } - bool JavascriptWeakMap::Is(Var aValue) - { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_WeakMap; - } - - JavascriptWeakMap* JavascriptWeakMap::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptWeakMap'"); - - return static_cast(aValue); - } - - JavascriptWeakMap* JavascriptWeakMap::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptWeakMap'"); - - return static_cast(RecyclableObject::UnsafeFromVar(aValue)); - } - JavascriptWeakMap::WeakMapKeyMap* JavascriptWeakMap::GetWeakMapKeyMapFromKey(RecyclableObject* key) const { AssertOrFailFast(DynamicType::Is(key->GetTypeId()) || JavascriptOperators::GetTypeId(key) == TypeIds_HostDispatch); @@ -114,7 +95,7 @@ namespace Js { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedFunction); } - adder = RecyclableObject::FromVar(adderVar); + adder = VarTo(adderVar); } if (iter != nullptr) @@ -127,7 +108,7 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedObject); } - RecyclableObject* obj = RecyclableObject::FromVar(nextItem); + RecyclableObject* obj = VarTo(nextItem); Var key = nullptr, value = nullptr; @@ -155,7 +136,7 @@ namespace Js #endif return isCtorSuperCall ? - JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), weakMapObject, nullptr, scriptContext) : + JavascriptOperators::OrdinaryCreateFromConstructor(VarTo(newTarget), weakMapObject, nullptr, scriptContext) : weakMapObject; } @@ -166,19 +147,19 @@ namespace Js ARGUMENTS(args, callInfo); ScriptContext* scriptContext = function->GetScriptContext(); - if (!JavascriptWeakMap::Is(args[0])) + if (!VarIs(args[0])) { JavascriptError::ThrowTypeErrorVar(scriptContext, JSERR_NeedObjectOfType, _u("WeakMap.prototype.delete"), _u("WeakMap")); } - JavascriptWeakMap* weakMap = JavascriptWeakMap::FromVar(args[0]); + JavascriptWeakMap* weakMap = VarTo(args[0]); Var key = (args.Info.Count > 1) ? args[1] : scriptContext->GetLibrary()->GetUndefined(); bool didDelete = false; if (JavascriptOperators::IsObject(key)) { - RecyclableObject* keyObj = RecyclableObject::FromVar(key); + RecyclableObject* keyObj = VarTo(key); didDelete = weakMap->Delete(keyObj); } @@ -207,12 +188,12 @@ namespace Js ARGUMENTS(args, callInfo); ScriptContext* scriptContext = function->GetScriptContext(); - if (!JavascriptWeakMap::Is(args[0])) + if (!VarIs(args[0])) { JavascriptError::ThrowTypeErrorVar(scriptContext, JSERR_NeedObjectOfType, _u("WeakMap.prototype.get"), _u("WeakMap")); } - JavascriptWeakMap* weakMap = JavascriptWeakMap::FromVar(args[0]); + JavascriptWeakMap* weakMap = VarTo(args[0]); Var key = (args.Info.Count > 1) ? args[1] : scriptContext->GetLibrary()->GetUndefined(); @@ -220,7 +201,7 @@ namespace Js Var value = nullptr; if (JavascriptOperators::IsObject(key)) { - RecyclableObject* keyObj = RecyclableObject::FromVar(key); + RecyclableObject* keyObj = VarTo(key); loaded = weakMap->Get(keyObj, &value); } @@ -248,19 +229,19 @@ namespace Js ARGUMENTS(args, callInfo); ScriptContext* scriptContext = function->GetScriptContext(); - if (!JavascriptWeakMap::Is(args[0])) + if (!VarIs(args[0])) { JavascriptError::ThrowTypeErrorVar(scriptContext, JSERR_NeedObjectOfType, _u("WeakMap.prototype.has"), _u("WeakMap")); } - JavascriptWeakMap* weakMap = JavascriptWeakMap::FromVar(args[0]); + JavascriptWeakMap* weakMap = VarTo(args[0]); Var key = (args.Info.Count > 1) ? args[1] : scriptContext->GetLibrary()->GetUndefined(); bool hasValue = false; if (JavascriptOperators::IsObject(key)) { - RecyclableObject* keyObj = RecyclableObject::FromVar(key); + RecyclableObject* keyObj = VarTo(key); hasValue = weakMap->Has(keyObj); } @@ -289,12 +270,12 @@ namespace Js ARGUMENTS(args, callInfo); ScriptContext* scriptContext = function->GetScriptContext(); - if (!JavascriptWeakMap::Is(args[0])) + if (!VarIs(args[0])) { JavascriptError::ThrowTypeErrorVar(scriptContext, JSERR_NeedObjectOfType, _u("WeakMap.prototype.set"), _u("WeakMap")); } - JavascriptWeakMap* weakMap = JavascriptWeakMap::FromVar(args[0]); + JavascriptWeakMap* weakMap = VarTo(args[0]); Var key = (args.Info.Count > 1) ? args[1] : scriptContext->GetLibrary()->GetUndefined(); Var value = (args.Info.Count > 2) ? args[2] : scriptContext->GetLibrary()->GetUndefined(); @@ -304,7 +285,7 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_WeakMapSetKeyNotAnObject, _u("WeakMap.prototype.set")); } - RecyclableObject* keyObj = RecyclableObject::FromVar(key); + RecyclableObject* keyObj = VarTo(key); #if ENABLE_TTD //In replay we need to pin the object (and will release at snapshot points) -- in record we don't need to do anything diff --git a/lib/Runtime/Library/JavascriptWeakMap.h b/lib/Runtime/Library/JavascriptWeakMap.h index 475ab30af35..c7d560e2aaa 100644 --- a/lib/Runtime/Library/JavascriptWeakMap.h +++ b/lib/Runtime/Library/JavascriptWeakMap.h @@ -67,10 +67,6 @@ namespace Js public: JavascriptWeakMap(DynamicType* type); - static bool Is(Var aValue); - static JavascriptWeakMap* FromVar(Var aValue); - static JavascriptWeakMap* UnsafeFromVar(Var aValue); - void Clear(); bool Delete(RecyclableObject* key); bool Get(RecyclableObject* key, Var* value) const; @@ -137,4 +133,9 @@ namespace Js virtual void ExtractSnapObjectDataInto(TTD::NSSnapObjects::SnapObject* objData, TTD::SlabAllocator& alloc) override; #endif }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_WeakMap; + } } diff --git a/lib/Runtime/Library/JavascriptWeakSet.cpp b/lib/Runtime/Library/JavascriptWeakSet.cpp index 1e41d191235..e9ba517c327 100644 --- a/lib/Runtime/Library/JavascriptWeakSet.cpp +++ b/lib/Runtime/Library/JavascriptWeakSet.cpp @@ -12,25 +12,6 @@ namespace Js { } - bool JavascriptWeakSet::Is(Var aValue) - { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_WeakSet; - } - - JavascriptWeakSet* JavascriptWeakSet::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptWeakSet'"); - - return static_cast(aValue); - } - - JavascriptWeakSet* JavascriptWeakSet::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptWeakSet'"); - - return static_cast(aValue); - } - Var JavascriptWeakSet::NewInstance(RecyclableObject* function, CallInfo callInfo, ...) { PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault); @@ -68,7 +49,7 @@ namespace Js { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedFunction); } - adder = RecyclableObject::FromVar(adderVar); + adder = VarTo(adderVar); } if (iter != nullptr) @@ -88,7 +69,7 @@ namespace Js #endif return isCtorSuperCall ? - JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), weakSetObject, nullptr, scriptContext) : + JavascriptOperators::OrdinaryCreateFromConstructor(VarTo(newTarget), weakSetObject, nullptr, scriptContext) : weakSetObject; } @@ -99,12 +80,12 @@ namespace Js ARGUMENTS(args, callInfo); ScriptContext* scriptContext = function->GetScriptContext(); - if (!JavascriptWeakSet::Is(args[0])) + if (!VarIs(args[0])) { JavascriptError::ThrowTypeErrorVar(scriptContext, JSERR_NeedObjectOfType, _u("WeakSet.prototype.add"), _u("WeakSet")); } - JavascriptWeakSet* weakSet = JavascriptWeakSet::FromVar(args[0]); + JavascriptWeakSet* weakSet = VarTo(args[0]); Var key = (args.Info.Count > 1) ? args[1] : scriptContext->GetLibrary()->GetUndefined(); @@ -115,7 +96,7 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_WeakMapSetKeyNotAnObject, _u("WeakSet.prototype.add")); } - RecyclableObject* keyObj = RecyclableObject::FromVar(key); + RecyclableObject* keyObj = VarTo(key); #if ENABLE_TTD //In replay we need to pin the object (and will release at snapshot points) -- in record we don't need to do anything @@ -137,19 +118,19 @@ namespace Js ARGUMENTS(args, callInfo); ScriptContext* scriptContext = function->GetScriptContext(); - if (!JavascriptWeakSet::Is(args[0])) + if (!VarIs(args[0])) { JavascriptError::ThrowTypeErrorVar(scriptContext, JSERR_NeedObjectOfType, _u("WeakSet.prototype.delete"), _u("WeakSet")); } - JavascriptWeakSet* weakSet = JavascriptWeakSet::FromVar(args[0]); + JavascriptWeakSet* weakSet = VarTo(args[0]); Var key = (args.Info.Count > 1) ? args[1] : scriptContext->GetLibrary()->GetUndefined(); bool didDelete = false; if (JavascriptOperators::IsObject(key) && JavascriptOperators::GetTypeId(key) != TypeIds_HostDispatch) { - RecyclableObject* keyObj = RecyclableObject::FromVar(key); + RecyclableObject* keyObj = VarTo(key); didDelete = weakSet->Delete(keyObj); } @@ -178,19 +159,19 @@ namespace Js ARGUMENTS(args, callInfo); ScriptContext* scriptContext = function->GetScriptContext(); - if (!JavascriptWeakSet::Is(args[0])) + if (!VarIs(args[0])) { JavascriptError::ThrowTypeErrorVar(scriptContext, JSERR_NeedObjectOfType, _u("WeakSet.prototype.has"), _u("WeakSet")); } - JavascriptWeakSet* weakSet = JavascriptWeakSet::FromVar(args[0]); + JavascriptWeakSet* weakSet = VarTo(args[0]); Var key = (args.Info.Count > 1) ? args[1] : scriptContext->GetLibrary()->GetUndefined(); bool hasValue = false; if (JavascriptOperators::IsObject(key) && JavascriptOperators::GetTypeId(key) != TypeIds_HostDispatch) { - RecyclableObject* keyObj = RecyclableObject::FromVar(key); + RecyclableObject* keyObj = VarTo(key); hasValue = weakSet->Has(keyObj); } diff --git a/lib/Runtime/Library/JavascriptWeakSet.h b/lib/Runtime/Library/JavascriptWeakSet.h index d4a2ce9228b..df2d3412f9c 100644 --- a/lib/Runtime/Library/JavascriptWeakSet.h +++ b/lib/Runtime/Library/JavascriptWeakSet.h @@ -25,10 +25,6 @@ namespace Js public: JavascriptWeakSet(DynamicType* type); - static bool Is(Var aValue); - static JavascriptWeakSet* FromVar(Var aValue); - static JavascriptWeakSet* UnsafeFromVar(Var aValue); - void Add(RecyclableObject* key); bool Delete(RecyclableObject* key); bool Has(RecyclableObject* key); @@ -69,4 +65,9 @@ namespace Js virtual void ExtractSnapObjectDataInto(TTD::NSSnapObjects::SnapObject* objData, TTD::SlabAllocator& alloc) override; #endif }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_WeakSet; + } } diff --git a/lib/Runtime/Library/JsBuiltInEngineInterfaceExtensionObject.cpp b/lib/Runtime/Library/JsBuiltInEngineInterfaceExtensionObject.cpp index 8105b355787..2d3dc1640f3 100644 --- a/lib/Runtime/Library/JsBuiltInEngineInterfaceExtensionObject.cpp +++ b/lib/Runtime/Library/JsBuiltInEngineInterfaceExtensionObject.cpp @@ -105,8 +105,8 @@ namespace Js JavascriptLibrary* library = scriptContext->GetLibrary(); JavascriptString * methodName = JavascriptString::NewWithSz(_u("ArrayIterator"), scriptContext); auto arrayIterator = JavascriptOperators::GetProperty(library->GetChakraLib(), JavascriptOperators::GetPropertyId(methodName, scriptContext), scriptContext); - library->arrayIteratorPrototype = DynamicObject::FromVar(JavascriptOperators::GetProperty(DynamicObject::FromVar(arrayIterator), PropertyIds::prototype, scriptContext)); - library->arrayIteratorPrototypeBuiltinNextFunction = JavascriptFunction::FromVar(JavascriptOperators::GetProperty(library->arrayIteratorPrototype, PropertyIds::next, scriptContext)); + library->arrayIteratorPrototype = VarTo(JavascriptOperators::GetProperty(VarTo(arrayIterator), PropertyIds::prototype, scriptContext)); + library->arrayIteratorPrototypeBuiltinNextFunction = VarTo(JavascriptOperators::GetProperty(library->arrayIteratorPrototype, PropertyIds::next, scriptContext)); } void JsBuiltInEngineInterfaceExtensionObject::InjectJsBuiltInLibraryCode(ScriptContext * scriptContext) @@ -254,15 +254,15 @@ namespace Js { EngineInterfaceObject_CommonFunctionProlog(function, callInfo); - AssertOrFailFast(args.Info.Count >= 3 && JavascriptString::Is(args.Values[1]) && ScriptFunction::Is(args.Values[2])); + AssertOrFailFast(args.Info.Count >= 3 && VarIs(args.Values[1]) && VarIs(args.Values[2])); JavascriptLibrary * library = scriptContext->GetLibrary(); - JavascriptString* methodName = JavascriptString::UnsafeFromVar(args.Values[1]); + JavascriptString* methodName = UnsafeVarTo(args.Values[1]); // chakra library functions, since they aren't public, can be constructors (__chakraLibrary.ArrayIterator is one) ScriptFunction* func = EngineInterfaceObject::CreateLibraryCodeScriptFunction( - ScriptFunction::UnsafeFromVar(args.Values[2]), + UnsafeVarTo(args.Values[2]), methodName, true /* isConstructor */, true /* isJsBuiltIn */, @@ -281,7 +281,7 @@ namespace Js { EngineInterfaceObject_CommonFunctionProlog(function, callInfo); - AssertOrFailFast(args.Info.Count == 3 && TaggedInt::Is(args.Values[1]) && ScriptFunction::Is(args.Values[2])); + AssertOrFailFast(args.Info.Count == 3 && TaggedInt::Is(args.Values[1]) && VarIs(args.Values[2])); JavascriptLibrary * library = scriptContext->GetLibrary(); @@ -323,7 +323,7 @@ FUNCTIONKIND_VALUES(VALUE) } ScriptFunction *func = EngineInterfaceObject::CreateLibraryCodeScriptFunction( - ScriptFunction::UnsafeFromVar(args.Values[2]), + UnsafeVarTo(args.Values[2]), fullName, false /* isConstructor */, true /* isJsBuiltIn */, @@ -394,11 +394,11 @@ FUNCTIONKIND_VALUES(VALUE) Var iterable = args.Values[1]; TypedArrayBase *typedArrayBase = nullptr; - Assert(!JavascriptArray::Is(iterable)); + Assert(!JavascriptArray::IsNonES5Array(iterable)); - if (TypedArrayBase::Is(iterable)) + if (VarIs(iterable)) { - typedArrayBase = TypedArrayBase::FromVar(iterable); + typedArrayBase = VarTo(iterable); if (typedArrayBase->IsDetachedBuffer()) { JavascriptError::ThrowTypeError(scriptContext, JSERR_DetachedTypedArray); @@ -427,14 +427,14 @@ FUNCTIONKIND_VALUES(VALUE) { EngineInterfaceObject_CommonFunctionProlog(function, callInfo); - DynamicObject* obj = DynamicObject::FromVar(args.Values[1]); + DynamicObject* obj = VarTo(args.Values[1]); unsigned propCount = TaggedInt::ToUInt32(args.Values[2]); Assert(callInfo.Count == 3 + propCount); for (unsigned i = 0; i < propCount; i++) { - JavascriptString *propName = JavascriptString::FromVar(args.Values[i + 3]); + JavascriptString *propName = VarTo(args.Values[i + 3]); obj->SetPropertyWithAttributes(JavascriptOperators::GetPropertyId(propName, scriptContext), scriptContext->GetLibrary()->GetNull(), PropertyWritable, nullptr); } @@ -477,7 +477,7 @@ FUNCTIONKIND_VALUES(VALUE) EngineInterfaceObject_CommonFunctionProlog(function, callInfo); AssertOrFailFast(args.Info.Count == 4); - RecyclableObject * obj = RecyclableObject::FromVar(args.Values[1]); + RecyclableObject * obj = VarTo(args.Values[1]); double index = JavascriptConversion::ToInteger(args.Values[2], scriptContext); AssertOrFailFast(index >= 0); JavascriptArray::BigIndex bigIndex(static_cast(index)); diff --git a/lib/Runtime/Library/LazyJSONString.cpp b/lib/Runtime/Library/LazyJSONString.cpp index eb5b1e62a6d..4f578005909 100644 --- a/lib/Runtime/Library/LazyJSONString.cpp +++ b/lib/Runtime/Library/LazyJSONString.cpp @@ -98,7 +98,7 @@ LazyJSONString::ReconstructObject(_In_ JSONObject* valueList) const { Var propertyValue = ReconstructVar(&entry.propertyValue); JavascriptString* propertyName = entry.propertyName; - PropertyString* propertyString = PropertyString::TryFromVar(propertyName); + PropertyString* propertyString = JavascriptOperators::TryFromVar(propertyName); PropertyValueInfo info; if (!propertyString || !propertyString->TrySetPropertyFromCache(obj, propertyValue, this->GetScriptContext(), PropertyOperation_None, &info)) { @@ -205,20 +205,9 @@ LazyJSONString::GetSz() return target; } -// static -bool -LazyJSONString::Is(Var var) -{ - return RecyclableObject::Is(var) && VirtualTableInfo::HasVirtualTable(RecyclableObject::FromVar(var)); -} - -// static -LazyJSONString* -LazyJSONString::TryFromVar(Var var) +template <> bool VarIsImpl(RecyclableObject* obj) { - return LazyJSONString::Is(var) - ? reinterpret_cast(var) - : nullptr; + return VirtualTableInfo::HasVirtualTable(obj); } } // namespace Js diff --git a/lib/Runtime/Library/LazyJSONString.h b/lib/Runtime/Library/LazyJSONString.h index 779a749bed8..12a651745ce 100644 --- a/lib/Runtime/Library/LazyJSONString.h +++ b/lib/Runtime/Library/LazyJSONString.h @@ -105,10 +105,6 @@ class LazyJSONString : public JavascriptString const char16* GetSz() override sealed; - static bool Is(Var var); - - static LazyJSONString* TryFromVar(Var var); - virtual VTableValue DummyVirtualFunctionToHinderLinkerICF() { return VTableValue::VtableLazyJSONString; @@ -116,4 +112,6 @@ class LazyJSONString : public JavascriptString }; // class LazyJSONString +template <> bool VarIsImpl(RecyclableObject* obj); + } // namespace Js diff --git a/lib/Runtime/Library/ModuleRoot.h b/lib/Runtime/Library/ModuleRoot.h index 61f2c8a3c58..1691c72ce15 100644 --- a/lib/Runtime/Library/ModuleRoot.h +++ b/lib/Runtime/Library/ModuleRoot.h @@ -50,7 +50,6 @@ namespace Js virtual BOOL DeleteRootProperty(PropertyId propertyId, PropertyOperationFlags flags) override; ModuleID GetModuleID() { return moduleID;} - static bool Is(Var aValue); protected: // For module binder, there is only one IDispatch* associated with the name provided diff --git a/lib/Runtime/Library/ObjectPrototypeObject.cpp b/lib/Runtime/Library/ObjectPrototypeObject.cpp index 8f7cfc90b31..5eb1cbe4748 100644 --- a/lib/Runtime/Library/ObjectPrototypeObject.cpp +++ b/lib/Runtime/Library/ObjectPrototypeObject.cpp @@ -80,8 +80,8 @@ namespace Js return scriptContext->GetLibrary()->GetUndefined(); } - RecyclableObject* object = RecyclableObject::FromVar(arg0); - RecyclableObject* newPrototype = RecyclableObject::FromVar(args[1]); + RecyclableObject* object = VarTo(arg0); + RecyclableObject* newPrototype = VarTo(args[1]); // 5. Let status be O.[[SetPrototypeOf]](proto). // 6. ReturnIfAbrupt(status). diff --git a/lib/Runtime/Library/PropertyString.cpp b/lib/Runtime/Library/PropertyString.cpp index f38641baf47..f3de61febf4 100644 --- a/lib/Runtime/Library/PropertyString.cpp +++ b/lib/Runtime/Library/PropertyString.cpp @@ -35,25 +35,11 @@ namespace Js return &this->propertyRecordUsageCache; } - /* static */ - bool PropertyString::Is(RecyclableObject * obj) + template <> bool VarIsImpl(RecyclableObject * obj) { return VirtualTableInfo::HasVirtualTable(obj); } - /* static */ - bool PropertyString::Is(Var var) - { - return RecyclableObject::Is(var) && PropertyString::Is(RecyclableObject::UnsafeFromVar(var)); - } - - PropertyString* PropertyString::UnsafeFromVar(Js::Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'PropertyString'"); - - return static_cast(aValue); - } - const void * PropertyString::GetOriginalStringReference() { // Property record is the allocation containing the string buffer diff --git a/lib/Runtime/Library/PropertyString.h b/lib/Runtime/Library/PropertyString.h index b229f57ac41..ad30aee35f7 100644 --- a/lib/Runtime/Library/PropertyString.h +++ b/lib/Runtime/Library/PropertyString.h @@ -58,11 +58,6 @@ class PropertyString : public JavascriptString static uint32 GetOffsetOfLdElemInlineCache() { return offsetof(PropertyString, propertyRecordUsageCache) + PropertyRecordUsageCache::GetOffsetOfLdElemInlineCache(); } static uint32 GetOffsetOfStElemInlineCache() { return offsetof(PropertyString, propertyRecordUsageCache) + PropertyRecordUsageCache::GetOffsetOfStElemInlineCache(); } static uint32 GetOffsetOfHitRate() { return offsetof(PropertyString, propertyRecordUsageCache) + PropertyRecordUsageCache::GetOffsetOfHitRate(); } - static bool Is(Var var); - static bool Is(RecyclableObject * var); - - template static PropertyString* TryFromVar(T var); - static PropertyString* UnsafeFromVar(Var aValue); #if ENABLE_TTD //Get the associated property id for this string if there is on (e.g. it is a propertystring otherwise return Js::PropertyIds::_none) @@ -75,16 +70,6 @@ class PropertyString : public JavascriptString } }; -// Templated so that the Is call dispatchs to different function depending -// on if argument is already a RecyclableObject* or only known to be a Var -// -// In case it is known to be a RecyclableObject*, the Is call skips that check -template inline -PropertyString * PropertyString::TryFromVar(T var) -{ - return PropertyString::Is(var) - ? reinterpret_cast(var) - : nullptr; -} +template <> bool VarIsImpl(RecyclableObject * obj); } // namespace Js diff --git a/lib/Runtime/Library/RegexHelper.cpp b/lib/Runtime/Library/RegexHelper.cpp index 86d004b5428..0db65e2ecf4 100644 --- a/lib/Runtime/Library/RegexHelper.cpp +++ b/lib/Runtime/Library/RegexHelper.cpp @@ -811,8 +811,8 @@ namespace Js if (captureIndex < numGroups && (captureIndex != 0)) { Var group = getGroup(captureIndex, nonMatchValue); - if (JavascriptString::Is(group)) - concatenated.Append(JavascriptString::UnsafeFromVar(group)); + if (VarIs(group)) + concatenated.Append(UnsafeVarTo(group)); else if (group != nonMatchValue) concatenated.Append(replace, substitutionOffset, offset - substitutionOffset); } @@ -1629,7 +1629,7 @@ namespace Js Js::Arguments(callInfo, args), scriptContext); }); - RecyclableObject* splitter = RecyclableObject::UnsafeFromVar(regEx); + RecyclableObject* splitter = UnsafeVarTo(regEx); JavascriptArray* arrayResult = scriptContext->GetLibrary()->CreateArray(); @@ -2366,7 +2366,7 @@ namespace Js // an Object or Null. RegExp algorithms have special conditions for when the result is Null, // so we can directly cast to RecyclableObject. Assert(!JavascriptOperators::IsNull(result)); - return RecyclableObject::UnsafeFromVar(result); + return UnsafeVarTo(result); } JavascriptString* RegexHelper::GetMatchStrFromResult(RecyclableObject* result, ScriptContext* scriptContext) diff --git a/lib/Runtime/Library/RootObjectBase.cpp b/lib/Runtime/Library/RootObjectBase.cpp index 87e5adc062f..b21b8c9107b 100644 --- a/lib/Runtime/Library/RootObjectBase.cpp +++ b/lib/Runtime/Library/RootObjectBase.cpp @@ -21,29 +21,6 @@ namespace Js DynamicObject(type, scriptContext), hostObject(nullptr), loadInlineCacheMap(nullptr), loadMethodInlineCacheMap(nullptr), storeInlineCacheMap(nullptr) {} - bool RootObjectBase::Is(Var var) - { - return RecyclableObject::Is(var) && RootObjectBase::Is(RecyclableObject::UnsafeFromVar(var)); - } - - bool RootObjectBase::Is(RecyclableObject* obj) - { - TypeId id = obj->GetTypeId(); - return id == TypeIds_GlobalObject || id == TypeIds_ModuleRoot; - } - - RootObjectBase * RootObjectBase::FromVar(Var var) - { - AssertOrFailFast(RootObjectBase::Is(var)); - return static_cast(var); - } - - RootObjectBase * RootObjectBase::UnsafeFromVar(Var var) - { - Assert(RootObjectBase::Is(var)); - return static_cast(var); - } - HostObjectBase * RootObjectBase::GetHostObject() const { Assert(hostObject == nullptr || Js::JavascriptOperators::GetTypeId(hostObject) == TypeIds_HostObject); diff --git a/lib/Runtime/Library/RootObjectBase.h b/lib/Runtime/Library/RootObjectBase.h index 22afe5fc074..d3d9a0c1067 100644 --- a/lib/Runtime/Library/RootObjectBase.h +++ b/lib/Runtime/Library/RootObjectBase.h @@ -54,11 +54,6 @@ namespace Js bool IsLetConstGlobal(PropertyId propertyId); #endif - static bool Is(Var var); - static bool Is(RecyclableObject * obj); - static RootObjectBase * FromVar(Var var); - static RootObjectBase * UnsafeFromVar(Var var); - protected: DEFINE_VTABLE_CTOR(RootObjectBase, DynamicObject); @@ -74,6 +69,12 @@ namespace Js Field(RootObjectInlineCacheMap *) storeInlineCacheMap; }; + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + TypeId id = obj->GetTypeId(); + return id == TypeIds_GlobalObject || id == TypeIds_ModuleRoot; + } + template void RootObjectBase::MapLetConstGlobals(Fn fn) diff --git a/lib/Runtime/Library/RuntimeFunction.cpp b/lib/Runtime/Library/RuntimeFunction.cpp index 0b8bea81377..a6a4cc97788 100644 --- a/lib/Runtime/Library/RuntimeFunction.cpp +++ b/lib/Runtime/Library/RuntimeFunction.cpp @@ -48,7 +48,7 @@ namespace Js } else { - retStr = JavascriptString::FromVar(this->functionNameId); + retStr = VarTo(this->functionNameId); } } return retStr; @@ -58,7 +58,7 @@ namespace Js RuntimeFunction::SetFunctionNameId(Var nameId) { Assert(functionNameId == NULL); - Assert(TaggedInt::Is(nameId) || Js::JavascriptString::Is(nameId)); + Assert(TaggedInt::Is(nameId) || Js::VarIs(nameId)); // We are only reference the propertyId, it needs to be tracked to stay alive Assert(!TaggedInt::Is(nameId) || this->GetScriptContext()->IsTrackedPropertyId(TaggedInt::ToInt32(nameId))); diff --git a/lib/Runtime/Library/SameValueComparer.h b/lib/Runtime/Library/SameValueComparer.h index e57c1e548bc..8edbd3e9e09 100644 --- a/lib/Runtime/Library/SameValueComparer.h +++ b/lib/Runtime/Library/SameValueComparer.h @@ -63,7 +63,7 @@ namespace Js case TypeIds_Int64Number: case TypeIds_UInt64Number: { - __int64 v = JavascriptInt64Number::FromVar(i)->GetValue(); + __int64 v = VarTo(i)->GetValue(); double d = (double) v; if (v != (__int64) d) { @@ -85,7 +85,7 @@ namespace Js case TypeIds_String: { - JavascriptString* v = JavascriptString::UnsafeFromVar(i); + JavascriptString* v = UnsafeVarTo(i); return JsUtil::CharacterBuffer::StaticGetHashCode(v->GetString(), v->GetLength()); } diff --git a/lib/Runtime/Library/ScriptFunction.cpp b/lib/Runtime/Library/ScriptFunction.cpp index 82ba2c44567..d6fd1c2a517 100644 --- a/lib/Runtime/Library/ScriptFunction.cpp +++ b/lib/Runtime/Library/ScriptFunction.cpp @@ -14,11 +14,11 @@ using namespace Js; JavascriptFunction(type, functionInfo) {} - bool ScriptFunctionBase::Is(Var func) + template <> bool Js::VarIsImpl(RecyclableObject* obj) { - if (JavascriptFunction::Is(func)) + if (VarIs(obj)) { - JavascriptFunction *function = JavascriptFunction::UnsafeFromVar(func); + JavascriptFunction *function = UnsafeVarTo(obj); return ScriptFunction::Test(function) || JavascriptGeneratorFunction::Test(function) || JavascriptAsyncFunction::Test(function); } @@ -26,18 +26,6 @@ using namespace Js; return false; } - ScriptFunctionBase * ScriptFunctionBase::FromVar(Var func) - { - AssertOrFailFast(ScriptFunctionBase::Is(func)); - return reinterpret_cast(func); - } - - ScriptFunctionBase * ScriptFunctionBase::UnsafeFromVar(Var func) - { - Assert(ScriptFunctionBase::Is(func)); - return reinterpret_cast(func); - } - ScriptFunction::ScriptFunction(FunctionProxy * proxy, ScriptFunctionType* deferredPrototypeType) : ScriptFunctionBase(deferredPrototypeType, proxy->GetFunctionInfo()), environment((FrameDisplay*)&NullFrameDisplay), cachedScopeObj(nullptr), @@ -160,28 +148,11 @@ using namespace Js; for (uint i = 0; i < length; i++) { Var scope = pDisplay->GetItem(i); - RecyclableObject *scopeObj = RecyclableObject::FromVar(scope); + RecyclableObject *scopeObj = VarTo(scope); scopeObj->InvalidateCachedScope(); } } - bool ScriptFunction::Is(Var func) - { - return JavascriptFunction::Is(func) && JavascriptFunction::UnsafeFromVar(func)->IsScriptFunction(); - } - - ScriptFunction * ScriptFunction::FromVar(Var func) - { - AssertOrFailFast(ScriptFunction::Is(func)); - return reinterpret_cast(func); - } - - ScriptFunction * ScriptFunction::UnsafeFromVar(Var func) - { - Assert(ScriptFunction::Is(func)); - return reinterpret_cast(func); - } - ProxyEntryPointInfo * ScriptFunction::GetEntryPointInfo() const { return this->GetScriptFunctionType()->GetEntryPointInfo(); @@ -523,7 +494,7 @@ using namespace Js; TTD::NSSnapObjects::StdExtractSetKindSpecificInfo(objData, ssfi); } - + // TODO: Fixup function definition - something funky w/ header file includes - cycles? void ScriptFunction::ExtractSnapObjectDataIntoSnapScriptFunctionInfo(/*TTD::NSSnapObjects::SnapScriptFunctionInfo* */ void* snapScriptFunctionInfo, TTD::SlabAllocator& alloc) { @@ -562,23 +533,6 @@ using namespace Js; ScriptFunction(proxy, deferredPrototypeType), m_moduleEnvironment(nullptr) {} - bool AsmJsScriptFunction::Is(Var func) - { - return ScriptFunction::Is(func) && ScriptFunction::UnsafeFromVar(func)->IsAsmJsFunction(); - } - - AsmJsScriptFunction* AsmJsScriptFunction::FromVar(Var func) - { - AssertOrFailFast(AsmJsScriptFunction::Is(func)); - return reinterpret_cast(func); - } - - AsmJsScriptFunction* AsmJsScriptFunction::UnsafeFromVar(Var func) - { - Assert(AsmJsScriptFunction::Is(func)); - return reinterpret_cast(func); - } - AsmJsScriptFunction * AsmJsScriptFunction::OP_NewAsmJsFunc(FrameDisplay *environment, FunctionInfoPtrPtr infoRef) { AssertMsg(infoRef != nullptr, "BYTE-CODE VERIFY: Must specify a valid function to create"); @@ -614,23 +568,6 @@ using namespace Js; Assert(!proxy->GetFunctionInfo()->HasComputedName()); } - bool WasmScriptFunction::Is(Var func) - { - return ScriptFunction::Is(func) && ScriptFunction::UnsafeFromVar(func)->IsWasmFunction(); - } - - WasmScriptFunction* WasmScriptFunction::FromVar(Var func) - { - AssertOrFailFast(WasmScriptFunction::Is(func)); - return reinterpret_cast(func); - } - - WasmScriptFunction* WasmScriptFunction::UnsafeFromVar(Var func) - { - Assert(WasmScriptFunction::Is(func)); - return reinterpret_cast(func); - } - WebAssemblyMemory* WasmScriptFunction::GetWebAssemblyMemory() const { return (WebAssemblyMemory*)PointerValue( @@ -642,23 +579,6 @@ using namespace Js; ScriptFunction(proxy, deferredPrototypeType) {} - bool ScriptFunctionWithInlineCache::Is(Var func) - { - return ScriptFunction::Is(func) && ScriptFunction::UnsafeFromVar(func)->GetHasInlineCaches(); - } - - ScriptFunctionWithInlineCache* ScriptFunctionWithInlineCache::FromVar(Var func) - { - AssertOrFailFast(ScriptFunctionWithInlineCache::Is(func)); - return reinterpret_cast(func); - } - - ScriptFunctionWithInlineCache* ScriptFunctionWithInlineCache::UnsafeFromVar(Var func) - { - Assert(ScriptFunctionWithInlineCache::Is(func)); - return reinterpret_cast(func); - } - InlineCache * ScriptFunctionWithInlineCache::GetInlineCache(uint index) { void** inlineCaches = this->GetInlineCaches(); @@ -817,9 +737,9 @@ using namespace Js; bool ScriptFunction::GetSymbolName(Var computedNameVar, const char16** symbolName, charcount_t* length) { - if (nullptr != computedNameVar && JavascriptSymbol::Is(computedNameVar)) + if (nullptr != computedNameVar && VarIs(computedNameVar)) { - const PropertyRecord* symbolRecord = JavascriptSymbol::FromVar(computedNameVar)->GetValue(); + const PropertyRecord* symbolRecord = VarTo(computedNameVar)->GetValue(); *symbolName = symbolRecord->GetBuffer(); *length = symbolRecord->GetLength(); return true; diff --git a/lib/Runtime/Library/ScriptFunction.h b/lib/Runtime/Library/ScriptFunction.h index 66d5275cbed..81b43af88d9 100644 --- a/lib/Runtime/Library/ScriptFunction.h +++ b/lib/Runtime/Library/ScriptFunction.h @@ -15,10 +15,6 @@ namespace Js DEFINE_VTABLE_CTOR(ScriptFunctionBase, JavascriptFunction); public: - static bool Is(Var func); - static ScriptFunctionBase * FromVar(Var func); - static ScriptFunctionBase * UnsafeFromVar(Var func); - virtual Var GetHomeObj() const = 0; virtual void SetHomeObj(Var homeObj) = 0; virtual void SetComputedNameVar(Var computedNameVar) = 0; @@ -26,6 +22,8 @@ namespace Js virtual bool IsAnonymousFunction() const = 0; }; + template <> bool VarIsImpl(RecyclableObject* obj); + template class FunctionWithComputedName : public BaseClass { @@ -78,10 +76,7 @@ namespace Js DEFINE_MARSHAL_OBJECT_TO_SCRIPT_CONTEXT(ScriptFunction); public: ScriptFunction(FunctionProxy * proxy, ScriptFunctionType* deferredPrototypeType); - static bool Is(Var func); inline static BOOL Test(JavascriptFunction *func) { return func->IsScriptFunction(); } - static ScriptFunction * FromVar(Var func); - static ScriptFunction * UnsafeFromVar(Var func); static ScriptFunction * OP_NewScFunc(FrameDisplay *environment, FunctionInfoPtrPtr infoRef); static ScriptFunction * OP_NewScFuncHomeObj(FrameDisplay *environment, FunctionInfoPtrPtr infoRef, Var homeObj); @@ -157,6 +152,11 @@ namespace Js } }; + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return VarIs(obj) && UnsafeVarTo(obj)->IsScriptFunction(); + } + typedef FunctionWithComputedName ScriptFunctionWithComputedName; typedef FunctionWithHomeObj ScriptFunctionWithHomeObj; @@ -165,9 +165,6 @@ namespace Js public: AsmJsScriptFunction(FunctionProxy * proxy, ScriptFunctionType* deferredPrototypeType); - static bool Is(Var func); - static AsmJsScriptFunction* FromVar(Var func); - static AsmJsScriptFunction* UnsafeFromVar(Var func); static AsmJsScriptFunction * OP_NewAsmJsFunc(FrameDisplay *environment, FunctionInfoPtrPtr infoRef); virtual bool IsAsmJsFunction() const override { return true; } @@ -185,6 +182,11 @@ namespace Js Field(Field(Var)*) m_moduleEnvironment; }; + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return VarIs(obj) && UnsafeVarTo(obj)->IsAsmJsFunction(); + } + typedef FunctionWithComputedName AsmJsScriptFunctionWithComputedName; #ifdef ENABLE_WASM @@ -193,10 +195,6 @@ namespace Js public: WasmScriptFunction(FunctionProxy * proxy, ScriptFunctionType* deferredPrototypeType); - static bool Is(Var func); - static WasmScriptFunction* FromVar(Var func); - static WasmScriptFunction* UnsafeFromVar(Var func); - void SetSignature(Wasm::WasmSignature * sig) { m_signature = sig; } Wasm::WasmSignature * GetSignature() const { return m_signature; } static uint32 GetOffsetOfSignature() { return offsetof(WasmScriptFunction, m_signature); } @@ -204,18 +202,22 @@ namespace Js WebAssemblyMemory* GetWebAssemblyMemory() const; virtual bool IsWasmFunction() const override { return true; } - protected: + protected: DEFINE_VTABLE_CTOR(WasmScriptFunction, AsmJsScriptFunction); DEFINE_MARSHAL_OBJECT_TO_SCRIPT_CONTEXT(WasmScriptFunction); private: Field(Wasm::WasmSignature *) m_signature; }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return VarIs(obj) && UnsafeVarTo(obj)->IsWasmFunction(); + } #else - class WasmScriptFunction + class WasmScriptFunction : public AsmJsScriptFunction { - public: - static bool Is(Var) { return false; } }; + template <> inline bool VarIsImpl(RecyclableObject* obj) { return false; } #endif class ScriptFunctionWithInlineCache : public ScriptFunction @@ -243,9 +245,6 @@ namespace Js public: ScriptFunctionWithInlineCache(FunctionProxy * proxy, ScriptFunctionType* deferredPrototypeType); - static bool Is(Var func); - static ScriptFunctionWithInlineCache * FromVar(Var func); - static ScriptFunctionWithInlineCache * UnsafeFromVar(Var func); void CreateInlineCache(); void AllocateInlineCache(); void ClearInlineCacheOnFunctionObject(); @@ -258,5 +257,10 @@ namespace Js virtual void Finalize(bool isShutdown) override; }; + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return VarIs(obj) && UnsafeVarTo(obj)->GetHasInlineCaches(); + } + typedef FunctionWithComputedName ScriptFunctionWithInlineCacheAndComputedName; } // namespace Js diff --git a/lib/Runtime/Library/SharedArrayBuffer.cpp b/lib/Runtime/Library/SharedArrayBuffer.cpp index 26c4e443c14..3fa17eb6d52 100644 --- a/lib/Runtime/Library/SharedArrayBuffer.cpp +++ b/lib/Runtime/Library/SharedArrayBuffer.cpp @@ -97,7 +97,7 @@ namespace Js RecyclableObject* newArr = scriptContext->GetLibrary()->CreateSharedArrayBuffer(byteLength); return isCtorSuperCall ? - JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), newArr, nullptr, scriptContext) : + JavascriptOperators::OrdinaryCreateFromConstructor(VarTo(newTarget), newArr, nullptr, scriptContext) : newArr; } @@ -111,12 +111,12 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !SharedArrayBuffer::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedSharedArrayBufferObject); } - SharedArrayBuffer* sharedArrayBuffer = SharedArrayBuffer::FromVar(args[0]); + SharedArrayBuffer* sharedArrayBuffer = VarTo(args[0]); return JavascriptNumber::ToVar(sharedArrayBuffer->GetByteLength(), scriptContext); } @@ -132,13 +132,13 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (!SharedArrayBuffer::Is(args[0])) + if (!VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedSharedArrayBufferObject); } JavascriptLibrary* library = scriptContext->GetLibrary(); - SharedArrayBuffer* currentBuffer = SharedArrayBuffer::FromVar(args[0]); + SharedArrayBuffer* currentBuffer = VarTo(args[0]); int64 currentLen = (int64)currentBuffer->GetByteLength(); int64 start = 0, end = 0; @@ -188,12 +188,12 @@ namespace Js return JavascriptOperators::NewScObject(constructor, Js::Arguments(constructorCallInfo, constructorArgs), scriptContext); }); - if (!SharedArrayBuffer::Is(newVar)) + if (!VarIs(newVar)) { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedSharedArrayBufferObject); } - newBuffer = SharedArrayBuffer::FromVar(newVar); + newBuffer = VarTo(newVar); if (newBuffer == currentBuffer) { @@ -233,25 +233,6 @@ namespace Js return args[0]; } - SharedArrayBuffer* SharedArrayBuffer::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "var must be an SharedArrayBuffer"); - - return static_cast(aValue); - } - - SharedArrayBuffer* SharedArrayBuffer::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "var must be an SharedArrayBuffer"); - - return static_cast(aValue); - } - - bool SharedArrayBuffer::Is(Var aValue) - { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_SharedArrayBuffer; - } - BYTE* SharedArrayBuffer::AllocBuffer(uint32 length, uint32 maxLength) { Unused(maxLength); // WebAssembly only @@ -365,7 +346,7 @@ namespace Js { sharedContents = contents; } - else + else { Js::Throw::FatalInternalError(); } @@ -374,6 +355,12 @@ namespace Js #endif } + SharedArrayBuffer * SharedArrayBuffer::GetAsSharedArrayBuffer() + { + AssertOrFailFast(VarIsCorrectType(this)); + return this; + } + CriticalSection SharedArrayBuffer::csSharedArrayBuffer; WaiterList *SharedArrayBuffer::GetWaiterList(uint index) @@ -402,7 +389,7 @@ namespace Js return nullptr; } - uint32 SharedArrayBuffer::GetByteLength() const + uint32 SharedArrayBuffer::GetByteLength() const { return sharedContents != nullptr ? sharedContents->bufferLength : 0; } @@ -564,18 +551,6 @@ namespace Js return result; } - bool WebAssemblySharedArrayBuffer::Is(Var aValue) - { - return SharedArrayBuffer::Is(aValue) && SharedArrayBuffer::FromVar(aValue)->IsWebAssemblyArrayBuffer(); - } - - WebAssemblySharedArrayBuffer* WebAssemblySharedArrayBuffer::FromVar(Var aValue) - { - AssertOrFailFast(WebAssemblySharedArrayBuffer::Is(aValue)); - return (WebAssemblySharedArrayBuffer*)aValue; - } - - bool WebAssemblySharedArrayBuffer::IsValidVirtualBufferLength(uint length) const { #if ENABLE_FAST_ARRAYBUFFER diff --git a/lib/Runtime/Library/SharedArrayBuffer.h b/lib/Runtime/Library/SharedArrayBuffer.h index 89a76569ad7..9d9f8d7e00e 100644 --- a/lib/Runtime/Library/SharedArrayBuffer.h +++ b/lib/Runtime/Library/SharedArrayBuffer.h @@ -73,10 +73,6 @@ namespace Js static Var EntryGetterByteLength(RecyclableObject* function, CallInfo callInfo, ...); static Var EntryGetterSymbolSpecies(RecyclableObject* function, CallInfo callInfo, ...); - static bool Is(Var aValue); - static SharedArrayBuffer* FromVar(Var aValue); - static SharedArrayBuffer* UnsafeFromVar(Var aValue); - virtual BOOL GetDiagTypeString(StringBuilder* stringBuilder, ScriptContext* requestContext) override; virtual BOOL GetDiagValueString(StringBuilder* stringBuilder, ScriptContext* requestContext) override; @@ -89,7 +85,7 @@ namespace Js virtual bool IsArrayBuffer() override { return false; } virtual bool IsSharedArrayBuffer() override { return true; } virtual ArrayBuffer * GetAsArrayBuffer() { return nullptr; } - virtual SharedArrayBuffer * GetAsSharedArrayBuffer() override { return SharedArrayBuffer::FromVar(this); } + virtual SharedArrayBuffer * GetAsSharedArrayBuffer() override; WaiterList *GetWaiterList(uint index); SharedContents *GetSharedContents() { return sharedContents; } @@ -115,6 +111,11 @@ namespace Js static CriticalSection csSharedArrayBuffer; }; + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_SharedArrayBuffer; + } + class JavascriptSharedArrayBuffer : public SharedArrayBuffer { protected: @@ -144,9 +145,6 @@ namespace Js static WebAssemblySharedArrayBuffer* Create(uint32 length, uint32 maxLength, DynamicType * type); static WebAssemblySharedArrayBuffer* Create(SharedContents *sharedContents, DynamicType * type); - static bool Is(Var aValue); - static WebAssemblySharedArrayBuffer* FromVar(Var aValue); - virtual bool IsValidVirtualBufferLength(uint length) const override; virtual bool IsWebAssemblyArrayBuffer() override { return true; } _Must_inspect_result_ bool GrowMemory(uint32 newBufferLength); @@ -160,6 +158,11 @@ namespace Js WebAssemblySharedArrayBuffer(SharedContents *sharedContents, DynamicType * type); void ValidateBuffer(); }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return VarIs(obj) && UnsafeVarTo(obj)->IsWebAssemblyArrayBuffer(); + } #endif // An agent can be viewed as a worker diff --git a/lib/Runtime/Library/StackScriptFunction.cpp b/lib/Runtime/Library/StackScriptFunction.cpp index 52f9a199417..96df65590bb 100644 --- a/lib/Runtime/Library/StackScriptFunction.cpp +++ b/lib/Runtime/Library/StackScriptFunction.cpp @@ -21,7 +21,7 @@ namespace Js } // Only script function can be on the stack - StackScriptFunction * stackScriptFunction = StackScriptFunction::FromVar(function); + StackScriptFunction * stackScriptFunction = VarTo(function); ScriptFunction * boxedFunction = stackScriptFunction->boxedScriptFunction; if (boxedFunction != nullptr) { @@ -58,26 +58,10 @@ namespace Js return function; } - ScriptFunction * boxed = StackScriptFunction::FromVar(function)->boxedScriptFunction; + ScriptFunction * boxed = VarTo(function)->boxedScriptFunction; return boxed ? boxed : function; } - StackScriptFunction * - StackScriptFunction::FromVar(Var var) - { - AssertOrFailFast(ScriptFunction::Is(var)); - Assert(ThreadContext::IsOnStack(var)); - return static_cast(var); - } - - StackScriptFunction * - StackScriptFunction::UnsafeFromVar(Var var) - { - Assert(ScriptFunction::Is(var)); - Assert(ThreadContext::IsOnStack(var)); - return static_cast(var); - } - ScriptFunction * StackScriptFunction::Box(StackScriptFunction *stackScriptFunction, void * returnAddress) { @@ -112,7 +96,7 @@ namespace Js if (functionRef != nullptr && ThreadContext::IsOnStack(*functionRef)) { - ScriptFunction * boxedScriptFunction = StackScriptFunction::FromVar(*functionRef)->boxedScriptFunction; + ScriptFunction * boxedScriptFunction = VarTo(*functionRef)->boxedScriptFunction; if (boxedScriptFunction != nullptr) { *functionRef = boxedScriptFunction; @@ -168,7 +152,7 @@ namespace Js continue; } - ScriptFunction * callerScriptFunction = ScriptFunction::FromVar(caller); + ScriptFunction * callerScriptFunction = VarTo(caller); FunctionBody * callerFunctionBody = callerScriptFunction->GetFunctionBody(); if (hasInlineeToBox || this->NeedBoxFrame(callerFunctionBody)) { @@ -391,7 +375,7 @@ namespace Js // Assert(ThreadContext::IsOnStack(callerScriptFunction)); if (ThreadContext::IsOnStack(callerScriptFunction)) { - boxedCaller = this->BoxStackFunction(StackScriptFunction::FromVar(callerScriptFunction)); + boxedCaller = this->BoxStackFunction(VarTo(callerScriptFunction)); walker.SetCurrentFunction(boxedCaller); InterpreterStackFrame * interpreterFrame = walker.GetCurrentInterpreterFrame(); @@ -507,7 +491,7 @@ namespace Js { this->ForEachStackNestedFunctionNative(walker, callerFunctionBody, [&](ScriptFunction *curr) { - StackScriptFunction * func = StackScriptFunction::FromVar(curr); + StackScriptFunction * func = VarTo(curr); // Need to check if we need the script function as the list of script function // include inlinee stack function that doesn't necessary need to be boxed if (this->NeedBoxScriptFunction(func)) @@ -607,7 +591,7 @@ namespace Js { do { - StackScriptFunction *func = StackScriptFunction::FromVar(curr); + StackScriptFunction *func = VarTo(curr); fn(func); curr = *(Js::Var *)(func + 1); } @@ -697,9 +681,9 @@ namespace Js for (uint i = 0; i < count; i++) { Js::Var slotValue = scopeSlots.Get(i); - if (ScriptFunction::Is(slotValue)) + if (VarIs(slotValue)) { - ScriptFunction * stackFunction = ScriptFunction::FromVar(slotValue); + ScriptFunction * stackFunction = VarTo(slotValue); slotValue = BoxStackFunction(stackFunction); } boxedScopeSlots.Set(i, slotValue); @@ -718,7 +702,7 @@ namespace Js return scriptFunction; } - StackScriptFunction * stackFunction = StackScriptFunction::FromVar(scriptFunction); + StackScriptFunction * stackFunction = VarTo(scriptFunction); ScriptFunction * boxedFunction = stackFunction->boxedScriptFunction; if (boxedFunction != nullptr) { diff --git a/lib/Runtime/Library/StackScriptFunction.h b/lib/Runtime/Library/StackScriptFunction.h index 0844e5f7153..71f0c471c30 100644 --- a/lib/Runtime/Library/StackScriptFunction.h +++ b/lib/Runtime/Library/StackScriptFunction.h @@ -26,7 +26,7 @@ namespace Js #if DBG static bool IsBoxed(Var var) { - return StackScriptFunction::FromVar(var)->boxedScriptFunction != nullptr; + return VarTo(var)->boxedScriptFunction != nullptr; } @@ -41,8 +41,6 @@ namespace Js } private: static ScriptFunction * Box(StackScriptFunction * stackScriptFunction, void * returnAddress); - static StackScriptFunction * FromVar(Var var); - static StackScriptFunction * UnsafeFromVar(Var var); struct BoxState { public: @@ -98,4 +96,14 @@ namespace Js return VTableValue::VtableStackScriptFunction; } }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + bool result = VarIs(obj); + if (result) + { + Assert(ThreadContext::IsOnStack(obj)); + } + return result; + } }; diff --git a/lib/Runtime/Library/ThrowErrorObject.cpp b/lib/Runtime/Library/ThrowErrorObject.cpp index 4b23b94803f..93b7362a349 100644 --- a/lib/Runtime/Library/ThrowErrorObject.cpp +++ b/lib/Runtime/Library/ThrowErrorObject.cpp @@ -17,7 +17,7 @@ namespace Js ARGUMENTS(args, callInfo); ScriptContext* scriptContext = function->GetScriptContext(); - ThrowErrorObject* throwErrorObject = ThrowErrorObject::FromVar(function); + ThrowErrorObject* throwErrorObject = VarTo(function); #ifdef ENABLE_SCRIPT_DEBUGGING bool useExceptionWrapper = @@ -52,23 +52,6 @@ namespace Js return RecyclerNew(recycler, ThrowErrorObject, type, error); } - bool ThrowErrorObject::Is(Var aValue) - { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Undefined; - } - - ThrowErrorObject* ThrowErrorObject::FromVar(Var aValue) - { - AssertOrFailFast(Is(aValue)); - return static_cast(aValue); - } - - ThrowErrorObject* ThrowErrorObject::UnsafeFromVar(Var aValue) - { - Assert(Is(aValue)); - return static_cast(aValue); - } - RecyclableObject* ThrowErrorObject::CreateThrowErrorObject(CreateErrorFunc createError, ScriptContext* scriptContext, int32 hCode, PCWSTR varName) { JavascriptLibrary* library = scriptContext->GetLibrary(); diff --git a/lib/Runtime/Library/ThrowErrorObject.h b/lib/Runtime/Library/ThrowErrorObject.h index 3b9cdc41ec0..f2bc6c3089e 100644 --- a/lib/Runtime/Library/ThrowErrorObject.h +++ b/lib/Runtime/Library/ThrowErrorObject.h @@ -22,9 +22,6 @@ namespace Js static Var DefaultEntryPoint(RecyclableObject* function, CallInfo callInfo, ...); static ThrowErrorObject* New(StaticType* type, JavascriptError* error, Recycler* recycler); - static bool Is(Var aValue); - static ThrowErrorObject* FromVar(Var aValue); - static ThrowErrorObject* UnsafeFromVar(Var aValue); static RecyclableObject* CreateThrowTypeErrorObject(ScriptContext* scriptContext, int32 hCode, PCWSTR varName); static RecyclableObject* CreateThrowTypeErrorObject(ScriptContext* scriptContext, int32 hCode, JavascriptString* varName); @@ -33,4 +30,9 @@ namespace Js typedef JavascriptError* (JavascriptLibrary::*CreateErrorFunc)(); static RecyclableObject* CreateThrowErrorObject(CreateErrorFunc createError, ScriptContext* scriptContext, int32 hCode, PCWSTR varName); }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_Undefined; + } } diff --git a/lib/Runtime/Library/TypedArray.cpp b/lib/Runtime/Library/TypedArray.cpp index 9c3bff99d65..a6ac7c28076 100644 --- a/lib/Runtime/Library/TypedArray.cpp +++ b/lib/Runtime/Library/TypedArray.cpp @@ -29,442 +29,176 @@ namespace Js INSTANTIATE_BUILT_IN_ENTRYPOINTS(Uint64Array) INSTANTIATE_BUILT_IN_ENTRYPOINTS(BoolArray) - template<> BOOL Uint8ClampedArray::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Uint8ClampedArray && - ( VirtualTableInfo::HasVirtualTable(aValue) || - VirtualTableInfo>::HasVirtualTable(aValue) + return JavascriptOperators::GetTypeId(obj) == TypeIds_Uint8ClampedArray && + ( VirtualTableInfo::HasVirtualTable(obj) || + VirtualTableInfo>::HasVirtualTable(obj) ); } - template<> BOOL Uint8Array::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Uint8Array && - ( VirtualTableInfo::HasVirtualTable(aValue) || - VirtualTableInfo>::HasVirtualTable(aValue) + return JavascriptOperators::GetTypeId(obj) == TypeIds_Uint8Array && + ( VirtualTableInfo::HasVirtualTable(obj) || + VirtualTableInfo>::HasVirtualTable(obj) ); } - template<> BOOL Int8Array::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Int8Array && - ( VirtualTableInfo::HasVirtualTable(aValue) || - VirtualTableInfo>::HasVirtualTable(aValue) + return JavascriptOperators::GetTypeId(obj) == TypeIds_Int8Array && + ( VirtualTableInfo::HasVirtualTable(obj) || + VirtualTableInfo>::HasVirtualTable(obj) ); } - template<> BOOL Int16Array::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Int16Array && - ( VirtualTableInfo::HasVirtualTable(aValue) || - VirtualTableInfo>::HasVirtualTable(aValue) + return JavascriptOperators::GetTypeId(obj) == TypeIds_Int16Array && + ( VirtualTableInfo::HasVirtualTable(obj) || + VirtualTableInfo>::HasVirtualTable(obj) ); } - template<> BOOL Uint16Array::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Uint16Array && - ( VirtualTableInfo::HasVirtualTable(aValue) || - VirtualTableInfo>::HasVirtualTable(aValue) + return JavascriptOperators::GetTypeId(obj) == TypeIds_Uint16Array && + ( VirtualTableInfo::HasVirtualTable(obj) || + VirtualTableInfo>::HasVirtualTable(obj) ); } - template<> BOOL Int32Array::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Int32Array && - ( VirtualTableInfo::HasVirtualTable(aValue) || - VirtualTableInfo>::HasVirtualTable(aValue) + return JavascriptOperators::GetTypeId(obj) == TypeIds_Int32Array && + ( VirtualTableInfo::HasVirtualTable(obj) || + VirtualTableInfo>::HasVirtualTable(obj) ); } - template<> BOOL Uint32Array::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Uint32Array && - ( VirtualTableInfo::HasVirtualTable(aValue) || - VirtualTableInfo>::HasVirtualTable(aValue) + return JavascriptOperators::GetTypeId(obj) == TypeIds_Uint32Array && + ( VirtualTableInfo::HasVirtualTable(obj) || + VirtualTableInfo>::HasVirtualTable(obj) ); } - template<> BOOL Float32Array::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Float32Array && - ( VirtualTableInfo::HasVirtualTable(aValue) || - VirtualTableInfo>::HasVirtualTable(aValue) + return JavascriptOperators::GetTypeId(obj) == TypeIds_Float32Array && + ( VirtualTableInfo::HasVirtualTable(obj) || + VirtualTableInfo>::HasVirtualTable(obj) ); } - template<> BOOL Float64Array::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Float64Array && - ( VirtualTableInfo::HasVirtualTable(aValue) || - VirtualTableInfo>::HasVirtualTable(aValue) + return JavascriptOperators::GetTypeId(obj) == TypeIds_Float64Array && + ( VirtualTableInfo::HasVirtualTable(obj) || + VirtualTableInfo>::HasVirtualTable(obj) ); } - template<> BOOL Int64Array::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Int64Array && - ( VirtualTableInfo::HasVirtualTable(aValue) || - VirtualTableInfo>::HasVirtualTable(aValue) + return JavascriptOperators::GetTypeId(obj) == TypeIds_Int64Array && + ( VirtualTableInfo::HasVirtualTable(obj) || + VirtualTableInfo>::HasVirtualTable(obj) ); } - template<> BOOL Uint64Array::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Uint64Array && - ( VirtualTableInfo::HasVirtualTable(aValue) || - VirtualTableInfo>::HasVirtualTable(aValue) + return JavascriptOperators::GetTypeId(obj) == TypeIds_Uint64Array && + ( VirtualTableInfo::HasVirtualTable(obj) || + VirtualTableInfo>::HasVirtualTable(obj) ); } - template<> BOOL BoolArray::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_BoolArray && - ( VirtualTableInfo::HasVirtualTable(aValue) || - VirtualTableInfo>::HasVirtualTable(aValue) + return JavascriptOperators::GetTypeId(obj) == TypeIds_BoolArray && + ( VirtualTableInfo::HasVirtualTable(obj) || + VirtualTableInfo>::HasVirtualTable(obj) ); } - template<> BOOL Uint8ClampedVirtualArray::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Uint8ClampedArray && - ( VirtualTableInfo::HasVirtualTable(aValue) || - VirtualTableInfo>::HasVirtualTable(aValue) + return JavascriptOperators::GetTypeId(obj) == TypeIds_Uint8ClampedArray && + ( VirtualTableInfo::HasVirtualTable(obj) || + VirtualTableInfo>::HasVirtualTable(obj) ); } - template<> BOOL Uint8VirtualArray::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Uint8Array && - ( VirtualTableInfo::HasVirtualTable(aValue) || - VirtualTableInfo>::HasVirtualTable(aValue) + return JavascriptOperators::GetTypeId(obj) == TypeIds_Uint8Array && + ( VirtualTableInfo::HasVirtualTable(obj) || + VirtualTableInfo>::HasVirtualTable(obj) ); } - template<> BOOL Int8VirtualArray::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Int8Array && - ( VirtualTableInfo::HasVirtualTable(aValue) || - VirtualTableInfo>::HasVirtualTable(aValue) + return JavascriptOperators::GetTypeId(obj) == TypeIds_Int8Array && + ( VirtualTableInfo::HasVirtualTable(obj) || + VirtualTableInfo>::HasVirtualTable(obj) ); } - template<> BOOL Int16VirtualArray::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Int16Array && - ( VirtualTableInfo::HasVirtualTable(aValue) || - VirtualTableInfo>::HasVirtualTable(aValue) + return JavascriptOperators::GetTypeId(obj) == TypeIds_Int16Array && + ( VirtualTableInfo::HasVirtualTable(obj) || + VirtualTableInfo>::HasVirtualTable(obj) ); } - template<> BOOL Uint16VirtualArray::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Uint16Array && - ( VirtualTableInfo::HasVirtualTable(aValue) || - VirtualTableInfo>::HasVirtualTable(aValue) + return JavascriptOperators::GetTypeId(obj) == TypeIds_Uint16Array && + ( VirtualTableInfo::HasVirtualTable(obj) || + VirtualTableInfo>::HasVirtualTable(obj) ); } - template<> BOOL Int32VirtualArray::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Int32Array && - ( VirtualTableInfo::HasVirtualTable(aValue) || - VirtualTableInfo>::HasVirtualTable(aValue) + return JavascriptOperators::GetTypeId(obj) == TypeIds_Int32Array && + ( VirtualTableInfo::HasVirtualTable(obj) || + VirtualTableInfo>::HasVirtualTable(obj) ); } - template<> BOOL Uint32VirtualArray::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Uint32Array && - ( VirtualTableInfo::HasVirtualTable(aValue) || - VirtualTableInfo>::HasVirtualTable(aValue) + return JavascriptOperators::GetTypeId(obj) == TypeIds_Uint32Array && + ( VirtualTableInfo::HasVirtualTable(obj) || + VirtualTableInfo>::HasVirtualTable(obj) ); } - template<> BOOL Float32VirtualArray::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Float32Array && - ( VirtualTableInfo::HasVirtualTable(aValue) || - VirtualTableInfo>::HasVirtualTable(aValue) + return JavascriptOperators::GetTypeId(obj) == TypeIds_Float32Array && + ( VirtualTableInfo::HasVirtualTable(obj) || + VirtualTableInfo>::HasVirtualTable(obj) ); } - template<> BOOL Float64VirtualArray::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Float64Array && - ( VirtualTableInfo::HasVirtualTable(aValue) || - VirtualTableInfo>::HasVirtualTable(aValue) + return JavascriptOperators::GetTypeId(obj) == TypeIds_Float64Array && + ( VirtualTableInfo::HasVirtualTable(obj) || + VirtualTableInfo>::HasVirtualTable(obj) ); } - template - TypedArray* TypedArray::FromVar(Var aValue) - { - AssertOrFailFastMsg(TypedArray::Is(aValue), "invalid TypedArray"); - return static_cast*>(aValue); - } - - template<> Uint8ClampedArray* Uint8ClampedArray::FromVar(Var aValue) - { - AssertOrFailFastMsg(Uint8ClampedArray::Is(aValue), "invalid Uint8ClampedArray"); - return static_cast(aValue); - } - - template<> Uint8Array* Uint8Array::FromVar(Var aValue) - { - AssertOrFailFastMsg(Uint8Array::Is(aValue), "invalid Uint8Array"); - return static_cast(aValue); - } - - template<> Int8Array* Int8Array::FromVar(Var aValue) - { - AssertOrFailFastMsg(Int8Array::Is(aValue), "invalid Int8Array"); - return static_cast(aValue); - } - - template<> Int16Array* Int16Array::FromVar(Var aValue) - { - AssertOrFailFastMsg(Int16Array::Is(aValue), "invalid Int16Array"); - return static_cast(aValue); - } - - template<> Uint16Array* Uint16Array::FromVar(Var aValue) - { - AssertOrFailFastMsg(Uint16Array::Is(aValue), "invalid Uint16Array"); - return static_cast(aValue); - } - - template<> Int32Array* Int32Array::FromVar(Var aValue) - { - AssertOrFailFastMsg(Int32Array::Is(aValue), "invalid Int32Array"); - return static_cast(aValue); - } - - template<> Uint32Array* Uint32Array::FromVar(Var aValue) - { - AssertOrFailFastMsg(Uint32Array::Is(aValue), "invalid Uint32Array"); - return static_cast(aValue); - } - - template<> Float32Array* Float32Array::FromVar(Var aValue) - { - AssertOrFailFastMsg(Float32Array::Is(aValue), "invalid Float32Array"); - return static_cast(aValue); - } - - template<> Float64Array* Float64Array::FromVar(Var aValue) - { - AssertOrFailFastMsg(Float64Array::Is(aValue), "invalid Float64Array"); - return static_cast(aValue); - } - - template<> Int64Array* Int64Array::FromVar(Var aValue) - { - AssertOrFailFastMsg(Int64Array::Is(aValue), "invalid Int64Array"); - return static_cast(aValue); - } - - template<> Uint64Array* Uint64Array::FromVar(Var aValue) - { - AssertOrFailFastMsg(Uint64Array::Is(aValue), "invalid Uint64Array"); - return static_cast(aValue); - } - - template<> Int8VirtualArray* Int8VirtualArray::FromVar(Var aValue) - { - AssertOrFailFastMsg(Int8VirtualArray::Is(aValue), "invalid Int8Array"); - return static_cast(aValue); - } - - template<> Uint8ClampedVirtualArray* Uint8ClampedVirtualArray::FromVar(Var aValue) - { - AssertOrFailFastMsg(Uint8ClampedVirtualArray::Is(aValue), "invalid Uint8ClampedArray"); - return static_cast(aValue); - } - - template<> Uint8VirtualArray* Uint8VirtualArray::FromVar(Var aValue) - { - AssertOrFailFastMsg(Uint8VirtualArray::Is(aValue), "invalid Uint8Array"); - return static_cast(aValue); - } - - template<> Int16VirtualArray* Int16VirtualArray::FromVar(Var aValue) - { - AssertOrFailFastMsg(Int16VirtualArray::Is(aValue), "invalid Int16Array"); - return static_cast(aValue); - } - - template<> Uint16VirtualArray* Uint16VirtualArray::FromVar(Var aValue) - { - AssertOrFailFastMsg(Uint16VirtualArray::Is(aValue), "invalid Uint16Array"); - return static_cast(aValue); - } - - template<> Int32VirtualArray* Int32VirtualArray::FromVar(Var aValue) - { - AssertOrFailFastMsg(Int32VirtualArray::Is(aValue), "invalid Int32Array"); - return static_cast(aValue); - } - - template<> Uint32VirtualArray* Uint32VirtualArray::FromVar(Var aValue) - { - AssertOrFailFastMsg(Uint32VirtualArray::Is(aValue), "invalid Uint32Array"); - return static_cast(aValue); - } - - template<> Float32VirtualArray* Float32VirtualArray::FromVar(Var aValue) - { - AssertOrFailFastMsg(Float32VirtualArray::Is(aValue), "invalid Float32Array"); - return static_cast(aValue); - } - - template<> Float64VirtualArray* Float64VirtualArray::FromVar(Var aValue) - { - AssertOrFailFastMsg(Float64VirtualArray::Is(aValue), "invalid Float64Array"); - return static_cast(aValue); - } - - template<> BoolArray* BoolArray::FromVar(Var aValue) - { - AssertOrFailFastMsg(BoolArray::Is(aValue), "invalid BoolArray"); - return static_cast(aValue); - } - - template - TypedArray* TypedArray::UnsafeFromVar(Var aValue) - { - AssertMsg(TypedArray::Is(aValue), "invalid TypedArray"); - return static_cast*>(aValue); - } - - template<> Uint8ClampedArray* Uint8ClampedArray::UnsafeFromVar(Var aValue) - { - AssertMsg(Uint8ClampedArray::Is(aValue), "invalid Uint8ClampedArray"); - return static_cast(aValue); - } - - template<> Uint8Array* Uint8Array::UnsafeFromVar(Var aValue) - { - AssertMsg(Uint8Array::Is(aValue), "invalid Uint8Array"); - return static_cast(aValue); - } - - template<> Int8Array* Int8Array::UnsafeFromVar(Var aValue) - { - AssertMsg(Int8Array::Is(aValue), "invalid Int8Array"); - return static_cast(aValue); - } - - template<> Int16Array* Int16Array::UnsafeFromVar(Var aValue) - { - AssertMsg(Int16Array::Is(aValue), "invalid Int16Array"); - return static_cast(aValue); - } - - template<> Uint16Array* Uint16Array::UnsafeFromVar(Var aValue) - { - AssertMsg(Uint16Array::Is(aValue), "invalid Uint16Array"); - return static_cast(aValue); - } - - template<> Int32Array* Int32Array::UnsafeFromVar(Var aValue) - { - AssertMsg(Int32Array::Is(aValue), "invalid Int32Array"); - return static_cast(aValue); - } - - template<> Uint32Array* Uint32Array::UnsafeFromVar(Var aValue) - { - AssertMsg(Uint32Array::Is(aValue), "invalid Uint32Array"); - return static_cast(aValue); - } - - template<> Float32Array* Float32Array::UnsafeFromVar(Var aValue) - { - AssertMsg(Float32Array::Is(aValue), "invalid Float32Array"); - return static_cast(aValue); - } - - template<> Float64Array* Float64Array::UnsafeFromVar(Var aValue) - { - AssertMsg(Float64Array::Is(aValue), "invalid Float64Array"); - return static_cast(aValue); - } - - template<> Int64Array* Int64Array::UnsafeFromVar(Var aValue) - { - AssertMsg(Int64Array::Is(aValue), "invalid Int64Array"); - return static_cast(aValue); - } - - template<> Uint64Array* Uint64Array::UnsafeFromVar(Var aValue) - { - AssertMsg(Uint64Array::Is(aValue), "invalid Uint64Array"); - return static_cast(aValue); - } - - template<> Int8VirtualArray* Int8VirtualArray::UnsafeFromVar(Var aValue) - { - AssertMsg(Int8VirtualArray::Is(aValue), "invalid Int8Array"); - return static_cast(aValue); - } - - template<> Uint8ClampedVirtualArray* Uint8ClampedVirtualArray::UnsafeFromVar(Var aValue) - { - AssertMsg(Uint8ClampedVirtualArray::Is(aValue), "invalid Uint8ClampedArray"); - return static_cast(aValue); - } - - template<> Uint8VirtualArray* Uint8VirtualArray::UnsafeFromVar(Var aValue) - { - AssertMsg(Uint8VirtualArray::Is(aValue), "invalid Uint8Array"); - return static_cast(aValue); - } - - template<> Int16VirtualArray* Int16VirtualArray::UnsafeFromVar(Var aValue) - { - AssertMsg(Int16VirtualArray::Is(aValue), "invalid Int16Array"); - return static_cast(aValue); - } - - template<> Uint16VirtualArray* Uint16VirtualArray::UnsafeFromVar(Var aValue) - { - AssertMsg(Uint16VirtualArray::Is(aValue), "invalid Uint16Array"); - return static_cast(aValue); - } - - template<> Int32VirtualArray* Int32VirtualArray::UnsafeFromVar(Var aValue) - { - AssertMsg(Int32VirtualArray::Is(aValue), "invalid Int32Array"); - return static_cast(aValue); - } - - template<> Uint32VirtualArray* Uint32VirtualArray::UnsafeFromVar(Var aValue) - { - AssertMsg(Uint32VirtualArray::Is(aValue), "invalid Uint32Array"); - return static_cast(aValue); - } - - template<> Float32VirtualArray* Float32VirtualArray::UnsafeFromVar(Var aValue) - { - AssertMsg(Float32VirtualArray::Is(aValue), "invalid Float32Array"); - return static_cast(aValue); - } - - template<> Float64VirtualArray* Float64VirtualArray::UnsafeFromVar(Var aValue) - { - AssertMsg(Float64VirtualArray::Is(aValue), "invalid Float64Array"); - return static_cast(aValue); - } - - template<> BoolArray* BoolArray::UnsafeFromVar(Var aValue) - { - AssertMsg(BoolArray::Is(aValue), "invalid BoolArray"); - return static_cast(aValue); - } - TypedArrayBase::TypedArrayBase(ArrayBufferBase* arrayBuffer, uint32 offSet, uint mappedLength, uint elementSize, DynamicType* type) : ArrayBufferParent(type, mappedLength, arrayBuffer), byteOffset(offSet), @@ -540,7 +274,7 @@ namespace Js } else { - if (TypedArrayBase::Is(firstArgument)) + if (VarIs(firstArgument)) { // Constructor(TypedArray array) typedArraySource = static_cast(firstArgument); @@ -555,11 +289,11 @@ namespace Js JavascriptError::ThrowRangeError(scriptContext, JSERR_InvalidTypedArrayLength); } } - else if (ArrayBufferBase::Is(firstArgument)) + else if (VarIs(firstArgument)) { // Constructor(ArrayBuffer buffer, // optional uint32 byteOffset, optional uint32 length) - arrayBuffer = ArrayBufferBase::FromVar(firstArgument); + arrayBuffer = VarTo(firstArgument); if (arrayBuffer->IsDetached()) { JavascriptError::ThrowTypeError(scriptContext, JSERR_DetachedTypedArray, _u("[TypedArray]")); @@ -571,18 +305,18 @@ namespace Js RecyclableObject* iteratorFn = JavascriptOperators::GetIteratorFunction(firstArgument, scriptContext, true /* optional */); if (iteratorFn != nullptr && (iteratorFn != scriptContext->GetLibrary()->EnsureArrayPrototypeValuesFunction() || - !JavascriptArray::Is(firstArgument) || JavascriptLibrary::ArrayIteratorPrototypeHasUserDefinedNext(scriptContext))) + !JavascriptArray::IsNonES5Array(firstArgument) || JavascriptLibrary::ArrayIteratorPrototypeHasUserDefinedNext(scriptContext))) { Var iterator = scriptContext->GetThreadContext()->ExecuteImplicitCall(iteratorFn, Js::ImplicitCall_Accessor, [=]()->Js::Var { - return CALL_FUNCTION(scriptContext->GetThreadContext(), iteratorFn, CallInfo(Js::CallFlags_Value, 1), RecyclableObject::FromVar(firstArgument)); + return CALL_FUNCTION(scriptContext->GetThreadContext(), iteratorFn, CallInfo(Js::CallFlags_Value, 1), VarTo(firstArgument)); }); if (!JavascriptOperators::IsObject(iterator)) { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedObject); } - return CreateNewInstanceFromIterator(RecyclableObject::FromVar(iterator), scriptContext, elementSize, pfnCreateTypedArray); + return CreateNewInstanceFromIterator(VarTo(iterator), scriptContext, elementSize, pfnCreateTypedArray); } if (!JavascriptConversion::ToObject(firstArgument, scriptContext, &jsArraySource)) @@ -742,7 +476,7 @@ namespace Js } #endif return isCtorSuperCall ? - JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), RecyclableObject::FromVar(object), nullptr, scriptContext) : + JavascriptOperators::OrdinaryCreateFromConstructor(VarTo(newTarget), VarTo(object), nullptr, scriptContext) : object; }; @@ -1123,29 +857,11 @@ namespace Js return IsSealed(); } - BOOL TypedArrayBase::Is(Var aValue) - { - TypeId typeId = JavascriptOperators::GetTypeId(aValue); - return Is(typeId); - } - BOOL TypedArrayBase::Is(TypeId typeId) { return typeId >= TypeIds_TypedArrayMin && typeId <= TypeIds_TypedArrayMax; } - TypedArrayBase* TypedArrayBase::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "must be a typed array"); - return static_cast(aValue); - } - - TypedArrayBase* TypedArrayBase::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "must be a typed array"); - return static_cast(aValue); - } - BOOL TypedArrayBase::IsDetachedTypedArray(Var aValue) { TypedArrayBase* arr = JavascriptOperators::TryFromVar(aValue); @@ -1175,11 +891,11 @@ namespace Js // - we cannot memmove to a uint8 clamped array from an int8 array, due to negatives rounding to 0 if (GetTypeId() == source->GetTypeId() || (GetBytesPerElement() == source->GetBytesPerElement() - && !((Uint8ClampedArray::Is(this) || Uint8ClampedVirtualArray::Is(this)) && (Int8Array::Is(source) || Int8VirtualArray::Is(source))) - && !Float32Array::Is(this) && !Float32Array::Is(source) - && !Float32VirtualArray::Is(this) && !Float32VirtualArray::Is(source) - && !Float64Array::Is(this) && !Float64Array::Is(source) - && !Float64VirtualArray::Is(this) && !Float64VirtualArray::Is(source))) + && !((VarIs(this) || VarIs(this)) && (VarIs(source) || VarIs(source))) + && !VarIs(this) && !VarIs(source) + && !VarIs(this) && !VarIs(source) + && !VarIs(this) && !VarIs(source) + && !VarIs(this) && !VarIs(source))) { const size_t offsetInBytes = offset * BYTES_PER_ELEMENT; memmove_s(buffer + offsetInBytes, @@ -1277,23 +993,23 @@ namespace Js HRESULT TypedArrayBase::GetBuffer(Var instance, ArrayBuffer** outBuffer, uint32* outOffset, uint32* outLength) { HRESULT hr = NOERROR; - if (Js::TypedArrayBase::Is(instance)) + if (Js::VarIs(instance)) { - Js::TypedArrayBase* typedArrayBase = Js::TypedArrayBase::FromVar(instance); + Js::TypedArrayBase* typedArrayBase = Js::VarTo(instance); *outBuffer = typedArrayBase->GetArrayBuffer()->GetAsArrayBuffer(); *outOffset = typedArrayBase->GetByteOffset(); *outLength = typedArrayBase->GetByteLength(); } - else if (Js::ArrayBuffer::Is(instance)) + else if (Js::VarIs(instance)) { - Js::ArrayBuffer* buffer = Js::ArrayBuffer::FromVar(instance); + Js::ArrayBuffer* buffer = Js::VarTo(instance); *outBuffer = buffer; *outOffset = 0; *outLength = buffer->GetByteLength(); } - else if (Js::DataView::Is(instance)) + else if (Js::VarIs(instance)) { - Js::DataView* dView = Js::DataView::FromVar(instance); + Js::DataView* dView = Js::VarTo(instance); *outBuffer = dView->GetArrayBuffer()->GetAsArrayBuffer(); *outOffset = dView->GetByteOffset(); *outLength = dView->GetLength(); @@ -1323,12 +1039,12 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !TypedArrayBase::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedTypedArray); } - TypedArrayBase* typedArray = TypedArrayBase::UnsafeFromVar(args[0]); + TypedArrayBase* typedArray = UnsafeVarTo(args[0]); ArrayBufferBase* arrayBuffer = typedArray->GetArrayBuffer(); if (arrayBuffer == nullptr) @@ -1348,12 +1064,12 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !TypedArrayBase::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedTypedArray); } - TypedArrayBase* typedArray = TypedArrayBase::UnsafeFromVar(args[0]); + TypedArrayBase* typedArray = UnsafeVarTo(args[0]); ArrayBufferBase* arrayBuffer = typedArray->GetArrayBuffer(); if (arrayBuffer == nullptr) @@ -1377,12 +1093,12 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !TypedArrayBase::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedTypedArray); } - TypedArrayBase* typedArray = TypedArrayBase::UnsafeFromVar(args[0]); + TypedArrayBase* typedArray = UnsafeVarTo(args[0]); ArrayBufferBase* arrayBuffer = typedArray->GetArrayBuffer(); if (arrayBuffer == nullptr) @@ -1406,12 +1122,12 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !TypedArrayBase::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedTypedArray); } - TypedArrayBase* typedArray = TypedArrayBase::UnsafeFromVar(args[0]); + TypedArrayBase* typedArray = UnsafeVarTo(args[0]); ArrayBufferBase* arrayBuffer = typedArray->GetArrayBuffer(); if (arrayBuffer == nullptr) @@ -1448,7 +1164,7 @@ namespace Js // 1. Let O be the this value. // 2. If Type(O) is not Object, return undefined. // 3. If O does not have a[[TypedArrayName]] internal slot, return undefined. - if (args.Info.Count == 0 || !TypedArrayBase::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { if (scriptContext->GetConfig()->IsES6ToStringTagEnabled()) { @@ -1519,7 +1235,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !TypedArrayBase::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedTypedArray); } @@ -1539,7 +1255,7 @@ namespace Js // This method is only called in pre-ES6 compat modes. In those modes, we need to throw an error // if the this argument is not the same type as our TypedArray template instance. - if (args.Info.Count == 0 || !TypedArray::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedTypedArray); } @@ -1549,7 +1265,7 @@ namespace Js Var TypedArrayBase::CommonSet(Arguments& args) { - TypedArrayBase* typedArrayBase = TypedArrayBase::FromVar(args[0]); + TypedArrayBase* typedArrayBase = VarTo(args[0]); ScriptContext* scriptContext = typedArrayBase->GetScriptContext(); uint32 offset = 0; if (args.Info.Count < 2) @@ -1600,7 +1316,7 @@ namespace Js Assert(!(callInfo.Flags & CallFlags_New)); CHAKRATEL_LANGSTATS_INC_BUILTINCOUNT(TypedArray_Prototype_subarray); - if (args.Info.Count == 0 || !TypedArrayBase::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedTypedArray); } @@ -1617,7 +1333,7 @@ namespace Js Var TypedArrayBase::CommonSubarray(Arguments& args) { - TypedArrayBase* typedArrayBase = TypedArrayBase::FromVar(args[0]); + TypedArrayBase* typedArrayBase = VarTo(args[0]); uint32 length = typedArrayBase->GetLength(); ScriptContext* scriptContext = typedArrayBase->GetScriptContext(); int32 begin = 0; @@ -1659,8 +1375,8 @@ namespace Js AssertOrFailFast(JavascriptOperators::IsConstructor(constructor)); bool isDefaultConstructor = constructor == defaultConstructor; - newTypedArray = RecyclableObject::FromVar(JavascriptOperators::NewObjectCreationHelper_ReentrancySafe(constructor, isDefaultConstructor, scriptContext->GetThreadContext(), [=]()->Js::Var - { + newTypedArray = VarTo(JavascriptOperators::NewObjectCreationHelper_ReentrancySafe(constructor, isDefaultConstructor, scriptContext->GetThreadContext(), [=]()->Js::Var + { Js::Var constructorArgs[] = { constructor, buffer, JavascriptNumber::ToVar(beginByteOffset, scriptContext), JavascriptNumber::ToVar(newLength, scriptContext) }; Js::CallInfo constructorCallInfo(Js::CallFlags_New, _countof(constructorArgs)); return TypedArrayBase::TypedArrayCreate(constructor, &Js::Arguments(constructorCallInfo, constructorArgs), newLength, scriptContext); @@ -1693,7 +1409,7 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedFunction, _u("[TypedArray].from")); } - RecyclableObject* constructor = RecyclableObject::FromVar(args[0]); + RecyclableObject* constructor = VarTo(args[0]); bool isDefaultConstructor = JavascriptLibrary::IsTypedArrayConstructor(constructor, scriptContext); RecyclableObject* items = nullptr; @@ -1708,12 +1424,12 @@ namespace Js if (args.Info.Count >= 3) { - if (!JavascriptFunction::Is(args[2])) + if (!VarIs(args[2])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_NeedFunction, _u("[TypedArray].from")); } - mapFn = JavascriptFunction::FromVar(args[2]); + mapFn = VarTo(args[2]); if (args.Info.Count >= 4) { @@ -1760,7 +1476,7 @@ namespace Js if (!newTypedArrayBase) { - newArr = JavascriptOperators::TryFromVar(newObj); + newArr = JavascriptArray::TryVarToNonES5Array(newObj); } for (uint32 k = 0; k < len; k++) @@ -1806,7 +1522,7 @@ namespace Js if (!itemsTypedArrayBase) { - itemsArray = JavascriptOperators::TryFromVar(items); + itemsArray = JavascriptArray::TryVarToNonES5Array(items); } newObj = JavascriptOperators::NewObjectCreationHelper_ReentrancySafe(constructor, isDefaultConstructor, scriptContext->GetThreadContext(), [=]()->Js::Var @@ -1821,7 +1537,7 @@ namespace Js if (!newTypedArrayBase) { - newArr = JavascriptOperators::TryFromVar(newObj); + newArr = JavascriptArray::TryVarToNonES5Array(newObj); } for (uint32 k = 0; k < len; k++) @@ -1921,7 +1637,7 @@ namespace Js Assert(!JavascriptOperators::IsUndefinedOrNull(scriptFunction)); Assert(JavascriptConversion::IsCallable(scriptFunction)); - RecyclableObject* function = RecyclableObject::FromVar(scriptFunction); + RecyclableObject* function = VarTo(scriptFunction); Var chakraLibObj = JavascriptOperators::OP_GetProperty(library->GetGlobalObject(), PropertyIds::__chakraLibrary, scriptContext); Var argsIt[] = { chakraLibObj, args[0], TaggedInt::ToVarUnchecked((int)kind) }; @@ -1999,7 +1715,7 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_NeedFunction, _u("[TypedArray].prototype.filter")); } - RecyclableObject* callBackFn = RecyclableObject::FromVar(args[1]); + RecyclableObject* callBackFn = VarTo(args[1]); Var thisArg = nullptr; if (args.Info.Count > 2) @@ -2056,7 +1772,7 @@ namespace Js AssertOrFailFast(JavascriptOperators::IsConstructor(constructor)); bool isDefaultConstructor = constructor == defaultConstructor; - newObj = RecyclableObject::FromVar(JavascriptOperators::NewObjectCreationHelper_ReentrancySafe(constructor, isDefaultConstructor, scriptContext->GetThreadContext(), [=]()->Js::Var + newObj = VarTo(JavascriptOperators::NewObjectCreationHelper_ReentrancySafe(constructor, isDefaultConstructor, scriptContext->GetThreadContext(), [=]()->Js::Var { Js::Var constructorArgs[] = { constructor, JavascriptNumber::ToVar(captured, scriptContext) }; Js::CallInfo constructorCallInfo(Js::CallFlags_New, _countof(constructorArgs)); @@ -2138,7 +1854,7 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_NeedFunction, _u("[TypedArray].prototype.forEach")); } - RecyclableObject* callBackFn = RecyclableObject::FromVar(args[1]); + RecyclableObject* callBackFn = VarTo(args[1]); Var thisArg; if (args.Info.Count > 2) @@ -2439,7 +2155,7 @@ namespace Js void **contextArray = (void **)context; if (contextArray[1] != nullptr) { - RecyclableObject* compFn = RecyclableObject::FromVar(contextArray[1]); + RecyclableObject* compFn = VarTo(contextArray[1]); ScriptContext* scriptContext = compFn->GetScriptContext(); Var undefined = scriptContext->GetLibrary()->GetUndefined(); double dblResult; @@ -2454,7 +2170,7 @@ namespace Js } END_SAFE_REENTRANT_CALL - Assert(TypedArrayBase::Is(contextArray[0])); + Assert(VarIs(contextArray[0])); if (TypedArrayBase::IsDetachedTypedArray(contextArray[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_DetachedTypedArray, _u("[TypedArray].prototype.sort")); @@ -2535,7 +2251,7 @@ namespace Js JavascriptError::ThrowTypeError(scriptContext, JSERR_FunctionArgument_NeedFunction, _u("[TypedArray].prototype.sort")); } - compareFn = RecyclableObject::FromVar(args[1]); + compareFn = VarTo(args[1]); } // Get the elements comparison function for the type of this TypedArray @@ -2632,12 +2348,12 @@ namespace Js Assert(lengthRef); Assert(typeIdRef); - if(!RecyclableObject::Is(var)) + if(!VarIs(var)) { return false; } - const TypeId typeId = RecyclableObject::FromVar(var)->GetTypeId(); + const TypeId typeId = VarTo(var)->GetTypeId(); switch(typeId) { case TypeIds_Int8Array: @@ -2650,7 +2366,7 @@ namespace Js case TypeIds_Float32Array: case TypeIds_Float64Array: Assert(ValueType::FromTypeId(typeId,false).IsOptimizedTypedArray()); - *lengthRef = FromVar(var)->GetLength(); + *lengthRef = VarTo(var)->GetLength(); *typeIdRef = typeId; return true; } @@ -2705,9 +2421,9 @@ namespace Js else { double dIndexValue = 0; - if (JavascriptString::Is(index)) + if (VarIs(index)) { - if (JavascriptConversion::CanonicalNumericIndexString(JavascriptString::FromVar(index), &dIndexValue, GetScriptContext())) + if (JavascriptConversion::CanonicalNumericIndexString(VarTo(index), &dIndexValue, GetScriptContext())) { if (JavascriptNumber::IsNegZero(dIndexValue)) { @@ -3600,9 +3316,9 @@ namespace Js return arr; } - BOOL CharArray::Is(Var value) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(value) == Js::TypeIds_CharArray; + return JavascriptOperators::GetTypeId(obj) == Js::TypeIds_CharArray; } Var CharArray::EntrySet(RecyclableObject* function, CallInfo callInfo, ...) @@ -3623,18 +3339,6 @@ namespace Js JavascriptError::ThrowTypeError(GetScriptContext(), JSERR_This_NeedTypedArray); } - inline CharArray* CharArray::FromVar(Var aValue) - { - AssertOrFailFastMsg(CharArray::Is(aValue), "invalid CharArray"); - return static_cast(aValue); - } - - inline CharArray* CharArray::UnsafeFromVar(Var aValue) - { - AssertMsg(CharArray::Is(aValue), "invalid CharArray"); - return static_cast(aValue); - } - inline BOOL CharArray::DirectSetItem(__in uint32 index, __in Js::Var value) { ScriptContext* scriptContext = GetScriptContext(); diff --git a/lib/Runtime/Library/TypedArray.h b/lib/Runtime/Library/TypedArray.h index 3c06dfa4d1b..6b56bc3dfb8 100644 --- a/lib/Runtime/Library/TypedArray.h +++ b/lib/Runtime/Library/TypedArray.h @@ -130,10 +130,7 @@ namespace Js virtual BOOL InitProperty(Js::PropertyId propertyId, Js::Var value, PropertyOperationFlags flags = PropertyOperation_None, Js::PropertyValueInfo* info = NULL) override; virtual BOOL SetPropertyWithAttributes(PropertyId propertyId, Var value, PropertyAttributes attributes, PropertyValueInfo* info, PropertyOperationFlags flags = PropertyOperation_None, SideEffects possibleSideEffects = SideEffects_Any) override; - static BOOL Is(Var aValue); static BOOL Is(TypeId typeId); - static TypedArrayBase* FromVar(Var aValue); - static TypedArrayBase* UnsafeFromVar(Var aValue); // Returns false if this is not a TypedArray or it's not detached static BOOL IsDetachedTypedArray(Var aValue); static HRESULT GetBuffer(Var aValue, ArrayBuffer** outBuffer, uint32* outOffset, uint32* outLength); @@ -217,6 +214,11 @@ namespace Js #endif }; + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return TypedArrayBase::Is(JavascriptOperators::GetTypeId(obj)); + } + template class TypedArray; @@ -272,9 +274,6 @@ namespace Js Var Subarray(uint32 begin, uint32 end); - static BOOL Is(Var aValue); - static TypedArray* FromVar(Var aValue); - static TypedArray* UnsafeFromVar(Var aValue); static BOOL HasVirtualTableInfo(Var aValue) { return VirtualTableInfo>::HasVirtualTable(aValue) || VirtualTableInfo>>::HasVirtualTable(aValue); @@ -552,11 +551,8 @@ namespace Js static Var Create(ArrayBufferBase* arrayBuffer, uint32 byteOffSet, uint32 mappedLength, JavascriptLibrary* javascriptLibrary); static Var NewInstance(RecyclableObject* function, CallInfo callInfo, ...); - static BOOL Is(Var aValue); Var Subarray(uint32 begin, uint32 end); - static CharArray* FromVar(Var aValue); - static CharArray* UnsafeFromVar(Var aValue); virtual BOOL DirectSetItem(__in uint32 index, __in Js::Var value) override; virtual BOOL DirectSetItemNoSet(__in uint32 index, __in Js::Var value) override; @@ -587,6 +583,7 @@ namespace Js } }; + template <> bool VarIsImpl(RecyclableObject* obj); template TypedArray::TypedArray(ArrayBufferBase* arrayBuffer, uint32 byteOffset, uint32 mappedLength, DynamicType* type) : diff --git a/lib/Runtime/Library/UriHelper.cpp b/lib/Runtime/Library/UriHelper.cpp index 26de3321344..838df90a14b 100644 --- a/lib/Runtime/Library/UriHelper.cpp +++ b/lib/Runtime/Library/UriHelper.cpp @@ -19,9 +19,9 @@ namespace Js else { - if (JavascriptString::Is(args[1])) + if (VarIs(args[1])) { - strURI = JavascriptString::FromVar(args[1]); + strURI = VarTo(args[1]); } else { @@ -267,9 +267,9 @@ namespace Js else { - if (JavascriptString::Is(args[1])) + if (VarIs(args[1])) { - strURI = JavascriptString::FromVar(args[1]); + strURI = VarTo(args[1]); } else { diff --git a/lib/Runtime/Library/WabtInterface.cpp b/lib/Runtime/Library/WabtInterface.cpp index 4129a752f1c..52ee5422c56 100644 --- a/lib/Runtime/Library/WabtInterface.cpp +++ b/lib/Runtime/Library/WabtInterface.cpp @@ -111,7 +111,7 @@ Js::Var WabtInterface::EntryConvertWast2Wasm(RecyclableObject* function, CallInf Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count < 2 || !JavascriptString::Is(args[1])) + if (args.Info.Count < 2 || !VarIs(args[1])) { JavascriptError::ThrowTypeError(scriptContext, WASMERR_NeedBufferSource); } @@ -123,7 +123,7 @@ Js::Var WabtInterface::EntryConvertWast2Wasm(RecyclableObject* function, CallInf { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedObject, _u("config")); } - DynamicObject * configObject = JavascriptObject::FromVar(args[2]); + DynamicObject * configObject = VarTo(args[2]); Js::Var isSpecVar = JavascriptOperators::OP_GetProperty(configObject, PropertyIds::spec, scriptContext); isSpecText = JavascriptConversion::ToBool(isSpecVar, scriptContext); diff --git a/lib/Runtime/Library/WebAssembly.cpp b/lib/Runtime/Library/WebAssembly.cpp index 933c9a893a9..051df9add1c 100644 --- a/lib/Runtime/Library/WebAssembly.cpp +++ b/lib/Runtime/Library/WebAssembly.cpp @@ -92,9 +92,9 @@ Var WebAssembly::EntryInstantiate(RecyclableObject* function, CallInfo callInfo, importObject = args[2]; } - if (WebAssemblyModule::Is(args[1])) + if (VarIs(args[1])) { - resultObject = WebAssemblyInstance::CreateInstance(WebAssemblyModule::FromVar(args[1]), importObject); + resultObject = WebAssemblyInstance::CreateInstance(VarTo(args[1]), importObject); } else { @@ -227,7 +227,7 @@ Var WebAssembly::EntryQueryResponse(RecyclableObject* function, CallInfo callInf JavascriptError::ThrowTypeError(scriptContext, WASMERR_NeedResponse); } - RecyclableObject* arrayBufferFunc = RecyclableObject::FromVar(arrayBufferProp); + RecyclableObject* arrayBufferFunc = VarTo(arrayBufferProp); Var arrayBufferRes = nullptr; BEGIN_SAFE_REENTRANT_CALL(scriptContext->GetThreadContext()) { @@ -236,7 +236,7 @@ Var WebAssembly::EntryQueryResponse(RecyclableObject* function, CallInfo callInf END_SAFE_REENTRANT_CALL // Make sure res.arrayBuffer() is a Promise - if (!JavascriptPromise::Is(arrayBufferRes)) + if (!VarIs(arrayBufferRes)) { JavascriptError::ThrowTypeError(scriptContext, WASMERR_NeedResponse); } @@ -245,11 +245,11 @@ Var WebAssembly::EntryQueryResponse(RecyclableObject* function, CallInfo callInf bool WebAssembly::IsResponseObject(Var responseObject, ScriptContext* scriptContext) { - if (!RecyclableObject::Is(responseObject)) + if (!VarIs(responseObject)) { return false; } - TypeId typeId = RecyclableObject::FromVar(responseObject)->GetTypeId(); + TypeId typeId = VarTo(responseObject)->GetTypeId(); if (!CONFIG_FLAG(WasmIgnoreResponse)) { return scriptContext->IsWellKnownHostType(typeId) && typeId != TypeIds_Undefined; @@ -271,13 +271,13 @@ Var WebAssembly::TryResolveResponse(RecyclableObject* function, Var thisArg, Var // We already have a response object, query it now responsePromise = CALL_ENTRYPOINT_NOASSERT(EntryQueryResponse, function, Js::CallInfo(CallFlags_Value, 2), thisArg, responseArg); } - else if (JavascriptPromise::Is(responseArg)) + else if (VarIs(responseArg)) { JavascriptPromise* promise = (JavascriptPromise*)responseArg; // Wait until this promise resolves and then try to query the response object (if it's a response object) responsePromise = JavascriptPromise::CreateThenPromise(promise, library->GetWebAssemblyQueryResponseFunction(), library->GetThrowerFunction(), scriptContext); } - if (responsePromise && !JavascriptPromise::Is(responsePromise)) + if (responsePromise && !VarIs(responsePromise)) { AssertMsg(UNREACHED, "How did we end up with something other than a promise here ?"); JavascriptError::ThrowTypeError(scriptContext, WASMERR_NeedResponse); diff --git a/lib/Runtime/Library/WebAssemblyEnvironment.cpp b/lib/Runtime/Library/WebAssemblyEnvironment.cpp index aced3bcb9c2..edf06d3e11e 100644 --- a/lib/Runtime/Library/WebAssemblyEnvironment.cpp +++ b/lib/Runtime/Library/WebAssemblyEnvironment.cpp @@ -62,11 +62,11 @@ T* WebAssemblyEnvironment::GetVarElement(Field(Var)* ptr, uint32 index, uint32 m Var varFunc = *functionPtr; if (varFunc) { - if (!T::Is(varFunc)) + if (!VarIs(varFunc)) { Js::Throw::InternalError(); } - return T::FromVar(varFunc); + return VarTo(varFunc); } return nullptr; } @@ -75,7 +75,7 @@ template void WebAssemblyEnvironment::SetVarElement(Field(Var)* ptr, T* val, uint32 index, uint32 maxCount) { if (index >= maxCount || - !T::Is(val)) + !VarIsCorrectType(val)) { Js::Throw::InternalError(); } diff --git a/lib/Runtime/Library/WebAssemblyInstance.cpp b/lib/Runtime/Library/WebAssemblyInstance.cpp index 8db7c14a210..2201d84ab13 100644 --- a/lib/Runtime/Library/WebAssemblyInstance.cpp +++ b/lib/Runtime/Library/WebAssemblyInstance.cpp @@ -41,29 +41,6 @@ WebAssemblyInstance::WebAssemblyInstance(WebAssemblyModule * wasmModule, Dynamic { } -/* static */ -bool -WebAssemblyInstance::Is(Var value) -{ - return JavascriptOperators::GetTypeId(value) == TypeIds_WebAssemblyInstance; -} - -/* static */ -WebAssemblyInstance * -WebAssemblyInstance::FromVar(Var value) -{ - AssertOrFailFast(WebAssemblyInstance::Is(value)); - return static_cast(value); -} - -/* static */ -WebAssemblyInstance * -WebAssemblyInstance::UnsafeFromVar(Var value) -{ - Assert(WebAssemblyInstance::Is(value)); - return static_cast(value); -} - // Implements "new WebAssembly.Instance(moduleObject [, importObject])" as described here: // https://github.com/WebAssembly/design/blob/master/JS.md#webassemblyinstance-constructor Var @@ -84,11 +61,11 @@ WebAssemblyInstance::NewInstance(RecyclableObject* function, CallInfo callInfo, JavascriptError::ThrowTypeError(scriptContext, JSERR_ClassConstructorCannotBeCalledWithoutNew, _u("WebAssembly.Instance")); } - if (args.Info.Count < 2 || !WebAssemblyModule::Is(args[1])) + if (args.Info.Count < 2 || !VarIs(args[1])) { JavascriptError::ThrowTypeError(scriptContext, WASMERR_NeedModule); } - WebAssemblyModule * module = WebAssemblyModule::FromVar(args[1]); + WebAssemblyModule * module = VarTo(args[1]); Var importObject = scriptContext->GetLibrary()->GetUndefined(); if (args.Info.Count >= 3) @@ -109,14 +86,14 @@ WebAssemblyInstance::GetterExports(RecyclableObject* function, CallInfo callInfo Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !WebAssemblyInstance::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, WASMERR_NeedInstanceObject); } - WebAssemblyInstance* instance = WebAssemblyInstance::FromVar(args[0]); + WebAssemblyInstance* instance = VarTo(args[0]); Js::Var exports = instance->m_exports; - if (!exports || !DynamicObject::Is(exports)) + if (!exports || !DynamicObject::IsBaseDynamicObject(exports)) { Assert(UNREACHED); exports = scriptContext->GetLibrary()->GetUndefined(); @@ -284,7 +261,7 @@ Var WebAssemblyInstance::CreateExportObject(WebAssemblyModule * wasmModule, Scri JavascriptOperators::OP_SetProperty(exportsNamespace, propertyRecord->GetPropertyId(), obj, scriptContext); } } - DynamicObject::FromVar(exportsNamespace)->PreventExtensions(); + VarTo(exportsNamespace)->PreventExtensions(); return exportsNamespace; } @@ -311,7 +288,7 @@ void WebAssemblyInstance::LoadImports( { case Wasm::ExternalKinds::Function: { - if (!JavascriptFunction::Is(prop)) + if (!VarIs(prop)) { JavascriptError::ThrowWebAssemblyLinkErrorVar(ctx, WASMERR_InvalidImport, import->modName, import->importName, _u("Function")); } @@ -319,10 +296,10 @@ void WebAssemblyInstance::LoadImports( Assert(wasmModule->GetFunctionIndexType(counter) == Wasm::FunctionIndexTypes::ImportThunk); env->SetImportedFunction(counter, prop); - if (WasmScriptFunction::Is(prop)) + if (VarIs(prop)) { Assert(env->GetWasmFunction(counter) == nullptr); - WasmScriptFunction* func = WasmScriptFunction::FromVar(prop); + WasmScriptFunction* func = VarTo(prop); if (!wasmModule->GetWasmFunctionInfo(counter)->GetSignature()->IsEquivalent(func->GetSignature())) { char16 temp[2048] = { 0 }; @@ -344,11 +321,11 @@ void WebAssemblyInstance::LoadImports( Assert(wasmModule->HasMemoryImport()); if (wasmModule->HasMemoryImport()) { - if (!WebAssemblyMemory::Is(prop)) + if (!VarIs(prop)) { JavascriptError::ThrowWebAssemblyLinkErrorVar(ctx, WASMERR_InvalidImport, import->modName, import->importName, _u("WebAssembly.Memory")); } - WebAssemblyMemory * mem = WebAssemblyMemory::FromVar(prop); + WebAssemblyMemory * mem = VarTo(prop); if (mem->GetInitialLength() < wasmModule->GetMemoryInitSize()) { @@ -375,11 +352,11 @@ void WebAssemblyInstance::LoadImports( Assert(wasmModule->HasTableImport()); if (wasmModule->HasTableImport()) { - if (!WebAssemblyTable::Is(prop)) + if (!VarIs(prop)) { JavascriptError::ThrowWebAssemblyLinkErrorVar(ctx, WASMERR_InvalidImport, import->modName, import->importName, _u("WebAssembly.Table")); } - WebAssemblyTable * table = WebAssemblyTable::FromVar(prop); + WebAssemblyTable * table = VarTo(prop); if (table->GetInitialLength() < wasmModule->GetTableInitSize()) { diff --git a/lib/Runtime/Library/WebAssemblyInstance.h b/lib/Runtime/Library/WebAssemblyInstance.h index a60f363e212..eaed68f47f9 100644 --- a/lib/Runtime/Library/WebAssemblyInstance.h +++ b/lib/Runtime/Library/WebAssemblyInstance.h @@ -25,10 +25,6 @@ namespace Js static Var NewInstance(RecyclableObject* function, CallInfo callInfo, ...); static Var GetterExports(RecyclableObject* function, CallInfo callInfo, ...); - static bool Is(Var aValue); - static WebAssemblyInstance * FromVar(Var aValue); - static WebAssemblyInstance * UnsafeFromVar(Var aValue); - static WebAssemblyInstance * CreateInstance(WebAssemblyModule * module, Var importObject); private: WebAssemblyInstance(WebAssemblyModule * wasmModule, DynamicType * type); @@ -45,5 +41,9 @@ namespace Js Field(Js::Var) m_exports; }; + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_WebAssemblyInstance; + } } // namespace Js #endif diff --git a/lib/Runtime/Library/WebAssemblyMemory.cpp b/lib/Runtime/Library/WebAssemblyMemory.cpp index 43e3e8fd3c5..bcc37f8ce54 100644 --- a/lib/Runtime/Library/WebAssemblyMemory.cpp +++ b/lib/Runtime/Library/WebAssemblyMemory.cpp @@ -40,29 +40,6 @@ _Must_inspect_result_ bool WebAssemblyMemory::AreLimitsValid(uint32 initial, uin return initBytes <= bufferLength && bufferLength <= maxBytes; } -/* static */ -bool -WebAssemblyMemory::Is(Var value) -{ - return JavascriptOperators::GetTypeId(value) == TypeIds_WebAssemblyMemory; -} - -/* static */ -WebAssemblyMemory * -WebAssemblyMemory::FromVar(Var value) -{ - AssertOrFailFast(WebAssemblyMemory::Is(value)); - return static_cast(value); -} - -/* static */ -WebAssemblyMemory * -WebAssemblyMemory::UnsafeFromVar(Var value) -{ - Assert(WebAssemblyMemory::Is(value)); - return static_cast(value); -} - Var WebAssemblyMemory::NewInstance(RecyclableObject* function, CallInfo callInfo, ...) { @@ -85,7 +62,7 @@ WebAssemblyMemory::NewInstance(RecyclableObject* function, CallInfo callInfo, .. { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedObject, _u("memoryDescriptor")); } - DynamicObject * memoryDescriptor = JavascriptObject::FromVar(args[1]); + DynamicObject * memoryDescriptor = VarTo(args[1]); Var initVar = JavascriptOperators::OP_GetProperty(memoryDescriptor, PropertyIds::initial, scriptContext); uint32 initial = WebAssembly::ToNonWrappingUint32(initVar, scriptContext); @@ -126,13 +103,13 @@ WebAssemblyMemory::EntryGrow(RecyclableObject* function, CallInfo callInfo, ...) Assert(!(callInfo.Flags & CallFlags_New)); - if (!WebAssemblyMemory::Is(args[0])) + if (!VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, WASMERR_NeedMemoryObject); } - WebAssemblyMemory* memory = WebAssemblyMemory::FromVar(args[0]); - Assert(ArrayBufferBase::Is(memory->m_buffer)); + WebAssemblyMemory* memory = VarTo(args[0]); + Assert(VarIsCorrectType(memory->m_buffer)); Var deltaVar = scriptContext->GetLibrary()->GetUndefined(); if (args.Info.Count >= 2) @@ -281,13 +258,13 @@ WebAssemblyMemory::EntryGetterBuffer(RecyclableObject* function, CallInfo callIn Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !WebAssemblyMemory::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, WASMERR_NeedMemoryObject); } - WebAssemblyMemory* memory = WebAssemblyMemory::FromVar(args[0]); - Assert(ArrayBufferBase::Is(memory->m_buffer)); + WebAssemblyMemory* memory = VarTo(args[0]); + Assert(VarIsCorrectType(memory->m_buffer)); return CrossSite::MarshalVar(scriptContext, memory->m_buffer); } @@ -376,7 +353,7 @@ WebAssemblyMemory::GetCurrentMemoryPages() const #ifdef ENABLE_WASM_THREADS bool WebAssemblyMemory::IsSharedMemory() const { - return WebAssemblySharedArrayBuffer::Is(m_buffer); + return VarIs(m_buffer); } #endif diff --git a/lib/Runtime/Library/WebAssemblyMemory.h b/lib/Runtime/Library/WebAssemblyMemory.h index dbb551216b7..353f69bcf61 100644 --- a/lib/Runtime/Library/WebAssemblyMemory.h +++ b/lib/Runtime/Library/WebAssemblyMemory.h @@ -27,10 +27,6 @@ namespace Js static Var EntryGrow(RecyclableObject* function, CallInfo callInfo, ...); static Var EntryGetterBuffer(RecyclableObject* function, CallInfo callInfo, ...); - static bool Is(Var aValue); - static WebAssemblyMemory * FromVar(Var aValue); - static WebAssemblyMemory * UnsafeFromVar(Var aValue); - static WebAssemblyMemory * CreateMemoryObject(uint32 initial, uint32 maximum, bool isShared, ScriptContext * scriptContext); static WebAssemblyMemory * CreateForExistingBuffer(uint32 initial, uint32 maximum, uint32 currentByteLength, ScriptContext * scriptContext); #ifdef ENABLE_WASM_THREADS @@ -64,4 +60,8 @@ namespace Js #endif }; + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_WebAssemblyMemory; + } } // namespace Js diff --git a/lib/Runtime/Library/WebAssemblyModule.cpp b/lib/Runtime/Library/WebAssemblyModule.cpp index 328aa0b1b7d..fc399396094 100644 --- a/lib/Runtime/Library/WebAssemblyModule.cpp +++ b/lib/Runtime/Library/WebAssemblyModule.cpp @@ -46,29 +46,6 @@ WebAssemblyModule::WebAssemblyModule(Js::ScriptContext* scriptContext, const byt m_reader = Anew(m_alloc, Wasm::WasmBinaryReader, m_alloc, this, binaryBuffer, binaryBufferLength); } -/* static */ -bool -WebAssemblyModule::Is(Var value) -{ - return JavascriptOperators::GetTypeId(value) == TypeIds_WebAssemblyModule; -} - -/* static */ -WebAssemblyModule * -WebAssemblyModule::FromVar(Var value) -{ - AssertOrFailFast(WebAssemblyModule::Is(value)); - return static_cast(value); -} - -/* static */ -WebAssemblyModule * -WebAssemblyModule::UnsafeFromVar(Var value) -{ - Assert(WebAssemblyModule::Is(value)); - return static_cast(value); -} - /* static */ Var WebAssemblyModule::NewInstance(RecyclableObject* function, CallInfo callInfo, ...) @@ -92,7 +69,7 @@ WebAssemblyModule::NewInstance(RecyclableObject* function, CallInfo callInfo, .. { JavascriptError::ThrowTypeError(scriptContext, WASMERR_NeedBufferSource); } - + WebAssemblySource src(args[1], true, scriptContext); return CreateModule(scriptContext, &src); } @@ -108,11 +85,11 @@ WebAssemblyModule::EntryExports(RecyclableObject* function, CallInfo callInfo, . Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count < 2 || !WebAssemblyModule::Is(args[1])) + if (args.Info.Count < 2 || !VarIs(args[1])) { JavascriptError::ThrowTypeError(scriptContext, WASMERR_NeedModule); } - WebAssemblyModule * module = WebAssemblyModule::FromVar(args[1]); + WebAssemblyModule * module = VarTo(args[1]); Var exportArray = JavascriptOperators::NewJavascriptArrayNoArg(scriptContext); @@ -140,12 +117,12 @@ WebAssemblyModule::EntryImports(RecyclableObject* function, CallInfo callInfo, . Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count < 2 || !WebAssemblyModule::Is(args[1])) + if (args.Info.Count < 2 || !VarIs(args[1])) { JavascriptError::ThrowTypeError(scriptContext, WASMERR_NeedModule); } - WebAssemblyModule * module = WebAssemblyModule::FromVar(args[1]); + WebAssemblyModule * module = VarTo(args[1]); Var importArray = JavascriptOperators::NewJavascriptArrayNoArg(scriptContext); for (uint32 i = 0; i < module->GetImportCount(); ++i) @@ -175,18 +152,18 @@ Var WebAssemblyModule::EntryCustomSections(RecyclableObject* function, CallInfo Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count < 2 || !WebAssemblyModule::Is(args[1])) + if (args.Info.Count < 2 || !VarIs(args[1])) { JavascriptError::ThrowTypeError(scriptContext, WASMERR_NeedModule); } Var sectionNameVar = args.Info.Count > 2 ? args[2] : scriptContext->GetLibrary()->GetUndefined(); - WebAssemblyModule * module = WebAssemblyModule::FromVar(args[1]); + WebAssemblyModule * module = VarTo(args[1]); Var customSections = nullptr; // C++ compiler optimizations can optimize away the sectionName variable while still keeping a reference to the underlying // character buffer sectionNameBuf. The character buffer itself is managed by the recycler; however; we may move past the // start of the character buffer while doing the comparison in memcmp. If a GC happens during CreateArrayBuffer, the character - // buffer can get collected as we don't have a reference to the start of the buffer on the stack anymore. To avoid this we need + // buffer can get collected as we don't have a reference to the start of the buffer on the stack anymore. To avoid this we need // to pin sectionName. ENTER_PINNED_SCOPE(JavascriptString, sectionName); sectionName = JavascriptConversion::ToString(sectionNameVar, scriptContext); diff --git a/lib/Runtime/Library/WebAssemblyModule.h b/lib/Runtime/Library/WebAssemblyModule.h index f196e765590..ff413f581bd 100644 --- a/lib/Runtime/Library/WebAssemblyModule.h +++ b/lib/Runtime/Library/WebAssemblyModule.h @@ -49,10 +49,6 @@ class WebAssemblyModule : public DynamicObject static Var EntryImports(RecyclableObject* function, CallInfo callInfo, ...); static Var EntryCustomSections(RecyclableObject* function, CallInfo callInfo, ...); - static bool Is(Var aValue); - static WebAssemblyModule * FromVar(Var aValue); - static WebAssemblyModule * UnsafeFromVar(Var aValue); - static WebAssemblyModule * CreateModule( ScriptContext* scriptContext, class WebAssemblySource* src); @@ -205,5 +201,10 @@ class WebAssemblyModule : public DynamicObject FieldNoBarrier(ArenaAllocator*) m_alloc; }; +template <> inline bool VarIsImpl(RecyclableObject* obj) +{ + return JavascriptOperators::GetTypeId(obj) == TypeIds_WebAssemblyModule; +} + } // namespace Js #endif diff --git a/lib/Runtime/Library/WebAssemblyTable.cpp b/lib/Runtime/Library/WebAssemblyTable.cpp index 079923f9344..099d9d5bcd1 100644 --- a/lib/Runtime/Library/WebAssemblyTable.cpp +++ b/lib/Runtime/Library/WebAssemblyTable.cpp @@ -21,29 +21,6 @@ WebAssemblyTable::WebAssemblyTable( { } -/* static */ -bool -WebAssemblyTable::Is(Var value) -{ - return JavascriptOperators::GetTypeId(value) == TypeIds_WebAssemblyTable; -} - -/* static */ -WebAssemblyTable * -WebAssemblyTable::FromVar(Var value) -{ - AssertOrFailFast(WebAssemblyTable::Is(value)); - return static_cast(value); -} - -/* static */ -WebAssemblyTable * -WebAssemblyTable::UnsafeFromVar(Var value) -{ - Assert(WebAssemblyTable::Is(value)); - return static_cast(value); -} - Var WebAssemblyTable::NewInstance(RecyclableObject* function, CallInfo callInfo, ...) { @@ -66,7 +43,7 @@ WebAssemblyTable::NewInstance(RecyclableObject* function, CallInfo callInfo, ... { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedObject, _u("tableDescriptor")); } - DynamicObject * tableDescriptor = JavascriptObject::FromVar(args[1]); + DynamicObject * tableDescriptor = VarTo(args[1]); Var elementVar = JavascriptOperators::OP_GetProperty(tableDescriptor, PropertyIds::element, scriptContext); if (!JavascriptOperators::StrictEqualString(elementVar, scriptContext->GetLibrary()->CreateStringFromCppLiteral(_u("anyfunc")))) @@ -96,11 +73,11 @@ WebAssemblyTable::EntryGetterLength(RecyclableObject* function, CallInfo callInf Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !WebAssemblyTable::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, WASMERR_NeedTableObject); } - WebAssemblyTable * table = WebAssemblyTable::FromVar(args[0]); + WebAssemblyTable * table = VarTo(args[0]); return JavascriptNumber::ToVar(table->m_currentLength, scriptContext); } @@ -114,11 +91,11 @@ WebAssemblyTable::EntryGrow(RecyclableObject* function, CallInfo callInfo, ...) Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !WebAssemblyTable::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, WASMERR_NeedTableObject); } - WebAssemblyTable * table = WebAssemblyTable::FromVar(args[0]); + WebAssemblyTable * table = VarTo(args[0]); uint32 oldLength = table->m_currentLength; Var deltaVar = args.Info.Count >= 2 ? args[1] : scriptContext->GetLibrary()->GetUndefined(); @@ -151,11 +128,11 @@ WebAssemblyTable::EntryGet(RecyclableObject* function, CallInfo callInfo, ...) Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !WebAssemblyTable::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, WASMERR_NeedTableObject); } - WebAssemblyTable * table = WebAssemblyTable::FromVar(args[0]); + WebAssemblyTable * table = VarTo(args[0]); Var indexVar = scriptContext->GetLibrary()->GetUndefined(); if (args.Info.Count >= 2) @@ -185,11 +162,11 @@ WebAssemblyTable::EntrySet(RecyclableObject* function, CallInfo callInfo, ...) Assert(!(callInfo.Flags & CallFlags_New)); - if (args.Info.Count == 0 || !WebAssemblyTable::Is(args[0])) + if (args.Info.Count == 0 || !VarIs(args[0])) { JavascriptError::ThrowTypeError(scriptContext, WASMERR_NeedTableObject); } - WebAssemblyTable * table = WebAssemblyTable::FromVar(args[0]); + WebAssemblyTable * table = VarTo(args[0]); if (args.Info.Count < 3) { @@ -197,12 +174,12 @@ WebAssemblyTable::EntrySet(RecyclableObject* function, CallInfo callInfo, ...) } Var indexVar = args[1]; Var value = args[2]; - + if (JavascriptOperators::IsNull(value)) { value = nullptr; } - else if (!WasmScriptFunction::Is(args[2])) + else if (!VarIs(args[2])) { JavascriptError::ThrowTypeError(scriptContext, WASMERR_NeedWebAssemblyFunc); } @@ -237,7 +214,7 @@ void WebAssemblyTable::DirectSetValue(uint index, Var val) { Assert(index < m_currentLength); - Assert(!val || WasmScriptFunction::Is(val)); + Assert(!val || VarIs(val)); m_values[index] = val; } @@ -246,7 +223,7 @@ WebAssemblyTable::DirectGetValue(uint index) const { Assert(index < m_currentLength); Var val = m_values[index]; - Assert(!val || WasmScriptFunction::Is(val)); + Assert(!val || VarIs(val)); return val; } diff --git a/lib/Runtime/Library/WebAssemblyTable.h b/lib/Runtime/Library/WebAssemblyTable.h index 6f97e4e46a8..8b68ac7f405 100644 --- a/lib/Runtime/Library/WebAssemblyTable.h +++ b/lib/Runtime/Library/WebAssemblyTable.h @@ -31,10 +31,6 @@ namespace Js static Var EntryGet(RecyclableObject* function, CallInfo callInfo, ...); static Var EntrySet(RecyclableObject* function, CallInfo callInfo, ...); - static bool Is(Var aValue); - static WebAssemblyTable * FromVar(Var aValue); - static WebAssemblyTable * UnsafeFromVar(Var aValue); - static WebAssemblyTable * Create(uint32 initial, uint32 maximum, ScriptContext * scriptContext); uint32 GetCurrentLength() const; @@ -54,4 +50,9 @@ namespace Js Field(Field(Var)*) m_values; #endif }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_WebAssemblyTable; + } } diff --git a/lib/Runtime/Math/JavascriptMath.cpp b/lib/Runtime/Math/JavascriptMath.cpp index 45026ad29a1..75d6169dca8 100644 --- a/lib/Runtime/Math/JavascriptMath.cpp +++ b/lib/Runtime/Math/JavascriptMath.cpp @@ -226,7 +226,7 @@ using namespace Js; } else if (typeLeft == TypeIds_String) { - return JavascriptString::Concat(JavascriptString::UnsafeFromVar(aLeft), JavascriptString::UnsafeFromVar(aRight)); + return JavascriptString::Concat(UnsafeVarTo(aLeft), UnsafeVarTo(aRight)); } } else if(typeLeft == TypeIds_Number && typeRight == TypeIds_Integer) @@ -307,8 +307,8 @@ using namespace Js; { if( typeRight == TypeIds_String ) { - JavascriptString* leftString = JavascriptString::UnsafeFromVar(aLeft); - JavascriptString* rightString = JavascriptString::UnsafeFromVar(aRight); + JavascriptString* leftString = UnsafeVarTo(aLeft); + JavascriptString* rightString = UnsafeVarTo(aRight); return JavascriptString::Concat(leftString, rightString); } break; @@ -374,13 +374,13 @@ using namespace Js; JIT_HELPER_REENTRANT_HEADER(Op_AddLeftDead); if (JavascriptOperators::GetTypeId(aLeft) == TypeIds_String) { - JavascriptString* leftString = JavascriptString::UnsafeFromVar(aLeft); + JavascriptString* leftString = UnsafeVarTo(aLeft); JavascriptString* rightString; TypeId rightType = JavascriptOperators::GetTypeId(aRight); switch(rightType) { case TypeIds_String: - rightString = JavascriptString::UnsafeFromVar(aRight); + rightString = UnsafeVarTo(aRight); StringCommon: return leftString->ConcatDestructive(rightString); @@ -433,12 +433,12 @@ using namespace Js; // If either side is a string, then the result is also a string if (JavascriptOperators::GetTypeId(primLeft) == TypeIds_String) { - JavascriptString* stringLeft = JavascriptString::UnsafeFromVar(primLeft); + JavascriptString* stringLeft = UnsafeVarTo(primLeft); JavascriptString* stringRight = nullptr; if (JavascriptOperators::GetTypeId(primRight) == TypeIds_String) { - stringRight = JavascriptString::UnsafeFromVar(primRight); + stringRight = UnsafeVarTo(primRight); } else { @@ -455,7 +455,7 @@ using namespace Js; if (JavascriptOperators::GetTypeId(primRight) == TypeIds_String) { JavascriptString* stringLeft = JavascriptConversion::ToString(primLeft, scriptContext); - JavascriptString* stringRight = JavascriptString::UnsafeFromVar(primRight); + JavascriptString* stringRight = UnsafeVarTo(primRight); if(leftIsDead) { @@ -993,7 +993,7 @@ using namespace Js; TypeId typeId = JavascriptOperators::GetTypeId(arrayArg); if (!JavascriptNativeArray::Is(typeId) && !(TypedArrayBase::Is(typeId) && typeId != TypeIds_CharArray && typeId != TypeIds_BoolArray)) { - if (JavascriptArray::IsVarArray(typeId) && JavascriptArray::UnsafeFromVar(arrayArg)->GetLength() == 0) + if (JavascriptArray::IsVarArray(typeId) && UnsafeVarTo(arrayArg)->GetLength() == 0) { return scriptContext->GetLibrary()->GetNegativeInfinite(); } @@ -1010,7 +1010,7 @@ using namespace Js; #if ENABLE_COPYONACCESS_ARRAY JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray(arrayArg); #endif - JavascriptNativeArray * argsArray = JavascriptNativeArray::UnsafeFromVar(arrayArg); + JavascriptNativeArray * argsArray = UnsafeVarTo(arrayArg); uint len = argsArray->GetLength(); if (len == 0) { @@ -1031,7 +1031,7 @@ using namespace Js; } else { - TypedArrayBase * argsArray = TypedArrayBase::UnsafeFromVar(arrayArg); + TypedArrayBase * argsArray = UnsafeVarTo(arrayArg); uint len = argsArray->GetLength(); if (len == 0) { @@ -1066,7 +1066,7 @@ using namespace Js; TypeId typeId = JavascriptOperators::GetTypeId(arrayArg); if (!JavascriptNativeArray::Is(typeId) && !(TypedArrayBase::Is(typeId) && typeId != TypeIds_CharArray && typeId != TypeIds_BoolArray)) { - if (JavascriptArray::Is(typeId) && JavascriptArray::UnsafeFromVar(arrayArg)->GetLength() == 0) + if (JavascriptArray::IsNonES5Array(typeId) && UnsafeVarTo(arrayArg)->GetLength() == 0) { return scriptContext->GetLibrary()->GetPositiveInfinite(); } @@ -1083,7 +1083,7 @@ using namespace Js; #if ENABLE_COPYONACCESS_ARRAY JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray(arrayArg); #endif - JavascriptNativeArray * argsArray = JavascriptNativeArray::UnsafeFromVar(arrayArg); + JavascriptNativeArray * argsArray = UnsafeVarTo(arrayArg); uint len = argsArray->GetLength(); if (len == 0) { @@ -1104,7 +1104,7 @@ using namespace Js; } else { - TypedArrayBase * argsArray = TypedArrayBase::UnsafeFromVar(arrayArg); + TypedArrayBase * argsArray = UnsafeVarTo(arrayArg); uint len = argsArray->GetLength(); if (len == 0) { diff --git a/lib/Runtime/Math/JavascriptMath.inl b/lib/Runtime/Math/JavascriptMath.inl index 1a53d4d8074..4fdce77d457 100644 --- a/lib/Runtime/Math/JavascriptMath.inl +++ b/lib/Runtime/Math/JavascriptMath.inl @@ -169,8 +169,8 @@ namespace Js inline double JavascriptMath::Add_Helper(Var aLeft, Var aRight, ScriptContext* scriptContext) { - AssertMsg( !JavascriptString::Is(aLeft), "Strings should have been handled already" ); - AssertMsg( !JavascriptString::Is(aRight), "Strings should have been handled already" ); + AssertMsg( !VarIs(aLeft), "Strings should have been handled already" ); + AssertMsg( !VarIs(aRight), "Strings should have been handled already" ); double dblLeft = JavascriptConversion::ToNumber(aLeft, scriptContext); double dblRight = JavascriptConversion::ToNumber(aRight, scriptContext); diff --git a/lib/Runtime/Runtime.h b/lib/Runtime/Runtime.h index 967607477fa..e7150946df2 100644 --- a/lib/Runtime/Runtime.h +++ b/lib/Runtime/Runtime.h @@ -557,7 +557,6 @@ enum tagDEBUG_EVENT_INFO_TYPE #include "Language/JavascriptConversion.inl" #include "Types/RecyclableObject.inl" #include "Types/DynamicObject.inl" -#include "Library/JavascriptBoolean.inl" #include "Library/JavascriptArray.inl" #include "Library/SparseArraySegment.inl" #include "Library/JavascriptNumber.inl" diff --git a/lib/Runtime/Types/ActivationObject.cpp b/lib/Runtime/Types/ActivationObject.cpp index 1a1e9a6e937..95888cf1178 100644 --- a/lib/Runtime/Types/ActivationObject.cpp +++ b/lib/Runtime/Types/ActivationObject.cpp @@ -8,7 +8,7 @@ namespace Js { - bool ActivationObject::Is(void* instance) + template <> bool VarIsImpl(RecyclableObject* instance) { return VirtualTableInfo::HasVirtualTable(instance) || VirtualTableInfo::HasVirtualTable(instance) || @@ -170,6 +170,11 @@ namespace Js } #endif + template <> bool VarIsImpl(RecyclableObject* instance) + { + return VirtualTableInfo::HasVirtualTable(instance); + } + BOOL PseudoActivationObject::InitPropertyScoped(PropertyId propertyId, Var value) { // eval, etc., should not create function properties on something like a "catch" scope @@ -204,6 +209,11 @@ namespace Js } #endif + template <> bool VarIsImpl(RecyclableObject* instance) + { + return VirtualTableInfo::HasVirtualTable(instance); + } + #if ENABLE_TTD TTD::NSSnapObjects::SnapObjectType ConsoleScopeActivationObject::GetSnapTag_TTD() const { @@ -217,6 +227,12 @@ namespace Js #endif + template <> bool VarIsImpl(RecyclableObject* instance) + { + return VirtualTableInfo::HasVirtualTable(instance) + || VirtualTableInfo>::HasVirtualTable(instance); + } + /* static */ const PropertyId * ActivationObjectEx::GetCachedScopeInfo(const PropertyIdArray *propIds) { @@ -309,4 +325,10 @@ namespace Js TTDAssert(false, "Not implemented yet!!!"); } #endif + + template <> bool VarIsImpl(RecyclableObject* instance) + { + return VirtualTableInfo::HasVirtualTable(instance) || + VirtualTableInfo>::HasVirtualTable(instance); + } }; diff --git a/lib/Runtime/Types/ActivationObject.h b/lib/Runtime/Types/ActivationObject.h index e0548ea0bd1..7b1a549fdf5 100644 --- a/lib/Runtime/Types/ActivationObject.h +++ b/lib/Runtime/Types/ActivationObject.h @@ -33,7 +33,6 @@ namespace Js virtual BOOL DeleteItem(uint32 index, PropertyOperationFlags flags) override; virtual BOOL GetDiagValueString(StringBuilder* stringBuilder, ScriptContext* requestContext) override; virtual BOOL GetDiagTypeString(StringBuilder* stringBuilder, ScriptContext* requestContext) override; - static bool Is(void* instance); #if ENABLE_TTD public: @@ -42,6 +41,8 @@ namespace Js #endif }; + template <> bool VarIsImpl(RecyclableObject* instance); + // A block-ActivationObject is a scope for an ES6 block that should only receive block-scoped inits, // including function, let, and const. class BlockActivationObject : public ActivationObject @@ -56,15 +57,6 @@ namespace Js virtual BOOL EnsureNoRedeclProperty(PropertyId propertyId) override; virtual BOOL InitPropertyScoped(PropertyId propertyId, Var value) override; virtual BOOL InitFuncScoped(PropertyId propertyId, Var value) override; - static bool Is(void* instance) - { - return VirtualTableInfo::HasVirtualTable(instance); - } - static BlockActivationObject* FromVar(Var value) - { - AssertOrFailFast(BlockActivationObject::Is(value)); - return static_cast(DynamicObject::FromVar(value)); - } BlockActivationObject* Clone(ScriptContext *scriptContext); @@ -75,6 +67,8 @@ namespace Js #endif }; + template <> bool VarIsImpl(RecyclableObject* instance); + // A pseudo-ActivationObject is a scope like a "catch" scope that shouldn't receive var inits. class PseudoActivationObject : public ActivationObject { @@ -88,10 +82,6 @@ namespace Js virtual BOOL EnsureNoRedeclProperty(PropertyId propertyId) override; virtual BOOL InitFuncScoped(PropertyId propertyId, Var value) override; virtual BOOL InitPropertyScoped(PropertyId propertyId, Var value) override; - static bool Is(void* instance) - { - return VirtualTableInfo::HasVirtualTable(instance); - } #if ENABLE_TTD public: @@ -100,6 +90,8 @@ namespace Js #endif }; + template <> bool VarIsImpl(RecyclableObject* instance); + class ConsoleScopeActivationObject : public ActivationObject { private: @@ -114,12 +106,6 @@ namespace Js AssertMsg(false, "ConsoleScopeActivationObject::DummyVirtualFunc function should never be called"); } - static bool Is(void* instance) - { - return VirtualTableInfo::HasVirtualTable(instance) - || VirtualTableInfo>::HasVirtualTable(instance); - } - #if ENABLE_TTD public: virtual TTD::NSSnapObjects::SnapObjectType GetSnapTag_TTD() const override; @@ -127,6 +113,8 @@ namespace Js #endif }; + template <> bool VarIsImpl(RecyclableObject* instance); + class ActivationObjectEx : public ActivationObject { private: @@ -208,18 +196,6 @@ namespace Js static byte ExtraSlotCount() { return 4; } - static bool Is(void* instance) - { - return VirtualTableInfo::HasVirtualTable(instance) || - VirtualTableInfo>::HasVirtualTable(instance); - } - - static ActivationObjectEx * FromVar(Var instance) - { - AssertOrFailFast(Is(instance)); - return reinterpret_cast(instance); - } - private: Field(ScriptFunction *) parentFunc; Field(uint) cachedFuncCount; @@ -234,4 +210,6 @@ namespace Js virtual void ExtractSnapObjectDataInto(TTD::NSSnapObjects::SnapObject* objData, TTD::SlabAllocator& alloc) override; #endif }; + + template <> bool VarIsImpl(RecyclableObject* instance); }; diff --git a/lib/Runtime/Types/DeferredTypeHandler.cpp b/lib/Runtime/Types/DeferredTypeHandler.cpp index a3648adc637..3e9757f1b17 100644 --- a/lib/Runtime/Types/DeferredTypeHandler.cpp +++ b/lib/Runtime/Types/DeferredTypeHandler.cpp @@ -43,7 +43,7 @@ namespace Js if (functionProxy && !isProto && typeHandler->GetMayBecomeShared() && !CrossSite::IsThunk(instance->GetType()->GetEntryPoint()) && !PHASE_OFF1(ShareFuncTypesPhase)) { Assert(!functionProxy->GetUndeferredFunctionType()); - functionProxy->SetUndeferredFunctionType(ScriptFunction::UnsafeFromVar(instance)->GetScriptFunctionType()); + functionProxy->SetUndeferredFunctionType(UnsafeVarTo(instance)->GetScriptFunctionType()); instance->ShareType(); } } diff --git a/lib/Runtime/Types/DictionaryTypeHandler.cpp b/lib/Runtime/Types/DictionaryTypeHandler.cpp index 6c6d2a53938..a156938658b 100644 --- a/lib/Runtime/Types/DictionaryTypeHandler.cpp +++ b/lib/Runtime/Types/DictionaryTypeHandler.cpp @@ -290,7 +290,7 @@ namespace Js { return false; } - + if (entry->mustBeWritable && (!(descriptor->Attributes & PropertyWritable) || descriptor->IsOrMayBecomeFixed())) { return false; @@ -434,7 +434,7 @@ namespace Js { // PropertyAttributes is only one byte so it can't carry out data about whether this is an accessor. // Accessors must be cached differently than normal properties, so if we want to cache this we must - // do so here rather than in the caller. However, caching here would require passing originalInstance and + // do so here rather than in the caller. However, caching here would require passing originalInstance and // requestContext through a wide variety of call paths to this point (like we do for GetProperty), for // very little improvement. For now, just block caching this case. PropertyValueInfo::SetNoCache(info, instance); @@ -476,7 +476,7 @@ namespace Js BOOL DictionaryTypeHandlerBase::GetRootProperty(DynamicObject* instance, Var originalInstance, PropertyId propertyId, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) { - AssertMsg(RootObjectBase::Is(instance), "Instance must be a root object!"); + AssertMsg(VarIs(instance), "Instance must be a root object!"); return GetProperty_Internal(instance, originalInstance, propertyId, value, info, requestContext); } @@ -493,7 +493,7 @@ namespace Js DictionaryPropertyDescriptor* descriptor, Var* value, PropertyValueInfo* info, PropertyType propertyT, ScriptContext* requestContext) { bool const isLetConstGlobal = (descriptor->Attributes & PropertyLetConstGlobal) != 0; - AssertMsg(!isLetConstGlobal || RootObjectBase::Is(instance), "object must be a global object if letconstglobal is set"); + AssertMsg(!isLetConstGlobal || VarIs(instance), "object must be a global object if letconstglobal is set"); if (allowLetConstGlobal) { // GetRootProperty: false if not global @@ -524,7 +524,7 @@ namespace Js CacheOperators::CachePropertyReadForGetter(info, originalInstance, propertyT, requestContext); PropertyValueInfo::SetNoCache(info, instance); // we already cached getter, so we don't have to do it once more - RecyclableObject* func = RecyclableObject::UnsafeFromVar(instance->GetSlot(descriptor->GetGetterPropertyIndex())); + RecyclableObject* func = UnsafeVarTo(instance->GetSlot(descriptor->GetGetterPropertyIndex())); *value = JavascriptOperators::CallGetter(func, originalInstance, requestContext); return true; } @@ -613,7 +613,7 @@ namespace Js template DescriptorFlags DictionaryTypeHandlerBase::GetRootSetter(DynamicObject* instance, PropertyId propertyId, Var* setterValue, PropertyValueInfo* info, ScriptContext* requestContext) { - AssertMsg(RootObjectBase::Is(instance), "Instance must be a root object!"); + AssertMsg(VarIs(instance), "Instance must be a root object!"); return GetSetter_Internal(instance, propertyId, setterValue, info, requestContext); } @@ -693,7 +693,7 @@ namespace Js template BOOL DictionaryTypeHandlerBase::SetRootProperty(DynamicObject* instance, PropertyId propertyId, Var value, PropertyOperationFlags flags, PropertyValueInfo* info) { - AssertMsg(RootObjectBase::Is(instance), "Instance must be a root object!"); + AssertMsg(VarIs(instance), "Instance must be a root object!"); return SetProperty_Internal(instance, propertyId, value, flags, info); } template @@ -756,7 +756,7 @@ namespace Js Assert(value != nullptr); // We don't want fixed properties on external objects. See DynamicObject::ResetObject for more information. Assert(!instance->IsExternal()); - descriptor->SetIsFixed((JavascriptFunction::Is(value) ? ShouldFixMethodProperties() : (ShouldFixDataProperties() && CheckHeuristicsForFixedDataProps(instance, propertyId, value)))); + descriptor->SetIsFixed(VarIs(value) ? ShouldFixMethodProperties() : (ShouldFixDataProperties() && CheckHeuristicsForFixedDataProps(instance, propertyId, value))); } } } @@ -781,7 +781,7 @@ namespace Js } else if (descriptor->GetSetterPropertyIndex() != NoSlots) { - RecyclableObject* func = RecyclableObject::FromVar(instance->GetSlot(descriptor->GetSetterPropertyIndex())); + RecyclableObject* func = VarTo(instance->GetSlot(descriptor->GetSetterPropertyIndex())); JavascriptOperators::CallSetter(func, instance, value, NULL); // Wait for the setter to return before setting up the inline cache info, as the setter may change @@ -1002,7 +1002,7 @@ namespace Js template BOOL DictionaryTypeHandlerBase::DeleteRootProperty(DynamicObject* instance, PropertyId propertyId, PropertyOperationFlags propertyOperationFlags) { - AssertMsg(RootObjectBase::Is(instance), "Instance must be a root object!"); + AssertMsg(VarIs(instance), "Instance must be a root object!"); return DeleteProperty_Internal(instance, propertyId, propertyOperationFlags); } @@ -1179,7 +1179,7 @@ namespace Js { if (!descriptor->HasNonLetConstGlobal()) { - AssertMsg(RootObjectBase::Is(instance), "object must be a global object if letconstglobal is set"); + AssertMsg(VarIs(instance), "object must be a global object if letconstglobal is set"); return true; } @@ -1209,7 +1209,7 @@ namespace Js { if (!descriptor->HasNonLetConstGlobal()) { - AssertMsg(RootObjectBase::Is(instance), "object must be a global object if letconstglobal is set"); + AssertMsg(VarIs(instance), "object must be a global object if letconstglobal is set"); return !(descriptor->Attributes & PropertyConst); } return descriptor->Attributes & PropertyWritable; @@ -1238,7 +1238,7 @@ namespace Js { if (!descriptor->HasNonLetConstGlobal()) { - AssertMsg(RootObjectBase::Is(instance), "object must be a global object if letconstglobal is set"); + AssertMsg(VarIs(instance), "object must be a global object if letconstglobal is set"); return true; } return descriptor->Attributes & PropertyConfigurable; @@ -1272,7 +1272,7 @@ namespace Js if (!descriptor->HasNonLetConstGlobal()) { - AssertMsg(RootObjectBase::Is(instance), "object must be a global object if letconstglobal is set"); + AssertMsg(VarIs(instance), "object must be a global object if letconstglobal is set"); return false; } @@ -1317,7 +1317,7 @@ namespace Js if (!descriptor->HasNonLetConstGlobal()) { - AssertMsg(RootObjectBase::Is(instance), "object must be a global object if letconstglobal is set"); + AssertMsg(VarIs(instance), "object must be a global object if letconstglobal is set"); return false; } @@ -1359,7 +1359,7 @@ namespace Js if (!descriptor->HasNonLetConstGlobal()) { - AssertMsg(RootObjectBase::Is(instance), "object must be a global object if letconstglobal is set"); + AssertMsg(VarIs(instance), "object must be a global object if letconstglobal is set"); return false; } @@ -1452,7 +1452,7 @@ namespace Js #if DBG else { - AssertMsg(RootObjectBase::Is(instance), "instance needs to be global object when letconst global is set"); + AssertMsg(VarIs(instance), "instance needs to be global object when letconst global is set"); } #endif } @@ -1895,7 +1895,7 @@ namespace Js #if DEBUG Var ctor = JavascriptOperators::GetProperty(instance, PropertyIds::constructor, scriptContext); #endif - AssertMsg(RootObjectBase::Is(instance) || JavascriptFunction::IsBuiltinProperty(instance, propertyId) || + AssertMsg(VarIs(instance) || JavascriptFunction::IsBuiltinProperty(instance, propertyId) || // ValidateAndApplyPropertyDescriptor says to preserve Configurable and Enumerable flags // For InitRootFld, which is equivalent to @@ -2176,7 +2176,7 @@ namespace Js Assert(value != nullptr); // We don't want fixed properties on external objects. See DynamicObject::ResetObject for more information. Assert(!instance->IsExternal()); - newDescriptor.SetIsFixed((JavascriptFunction::Is(value) ? ShouldFixMethodProperties() : (ShouldFixDataProperties() & CheckHeuristicsForFixedDataProps(instance, propertyRecord, value)))); + newDescriptor.SetIsFixed(VarIs(value) ? ShouldFixMethodProperties() : (ShouldFixDataProperties() & CheckHeuristicsForFixedDataProps(instance, propertyRecord, value))); } } #endif @@ -2328,7 +2328,7 @@ namespace Js template DynamicTypeHandler* DictionaryTypeHandlerBase::ConvertToTypeWithItemAttributes(DynamicObject* instance) { - return JavascriptArray::Is(instance) ? ConvertToES5ArrayType(instance) : this; + return JavascriptArray::IsNonES5Array(instance) ? ConvertToES5ArrayType(instance) : this; } template @@ -2378,7 +2378,7 @@ namespace Js // Because DictionaryTypeHandlers are never shared we should always have a property value if the handler // says it's initialized. Assert(value != nullptr); - descriptor->SetIsFixed((JavascriptFunction::Is(value) ? ShouldFixMethodProperties() : (ShouldFixDataProperties() && CheckHeuristicsForFixedDataProps(instance, propertyRecord, value)))); + descriptor->SetIsFixed(VarIs(value) ? ShouldFixMethodProperties() : (ShouldFixDataProperties() && CheckHeuristicsForFixedDataProps(instance, propertyRecord, value))); } else if (descriptor->GetIsAccessor()) { @@ -2579,7 +2579,7 @@ namespace Js { Assert(!IsInternalPropertyId(propertyRecord->GetPropertyId())); Var value = localSingletonInstance->GetSlot(dataSlot); - if (value && ((IsFixedMethodProperty(propertyType) && JavascriptFunction::Is(value)) || IsFixedDataProperty(propertyType))) + if (value && ((IsFixedMethodProperty(propertyType) && VarIs(value)) || IsFixedDataProperty(propertyType))) { *pProperty = value; if (markAsUsed) @@ -2621,7 +2621,7 @@ namespace Js { Assert(!IsInternalPropertyId(propertyRecord->GetPropertyId())); Var value = localSingletonInstance->GetSlot(accessorSlot); - if (value && IsFixedAccessorProperty(propertyType) && JavascriptFunction::Is(value)) + if (value && IsFixedAccessorProperty(propertyType) && VarIs(value)) { *pAccessor = value; if (markAsUsed) diff --git a/lib/Runtime/Types/DynamicObject.cpp b/lib/Runtime/Types/DynamicObject.cpp index 1a8d438c192..012b23d8e43 100644 --- a/lib/Runtime/Types/DynamicObject.cpp +++ b/lib/Runtime/Types/DynamicObject.cpp @@ -118,9 +118,9 @@ namespace Js // While the objectArray can be any array type, a DynamicObject that is created on the // stack will only have one of these three types (as these are also the only array types // that can be allocated on the stack). - Assert(Js::JavascriptArray::Is(instance->GetObjectArrayOrFlagsAsArray()) - || Js::JavascriptNativeIntArray::Is(instance->GetObjectArrayOrFlagsAsArray()) - || Js::JavascriptNativeFloatArray::Is(instance->GetObjectArrayOrFlagsAsArray()) + Assert(Js::JavascriptArray::IsNonES5Array(instance->GetObjectArrayOrFlagsAsArray()) + || Js::VarIs(instance->GetObjectArrayOrFlagsAsArray()) + || Js::VarIs(instance->GetObjectArrayOrFlagsAsArray()) ); // Since a deep copy was requested for this DynamicObject, deep copy the object array as well @@ -128,7 +128,7 @@ namespace Js } else { - // Otherwise, assert that there is either + // Otherwise, assert that there is either // - no object array to deep copy // - an object array, but no deep copy needed // - data in the objectArray member, but it is inline slot data @@ -149,25 +149,21 @@ namespace Js return NewObject(recycler, type); } - bool DynamicObject::Is(Var aValue) + bool DynamicObject::IsBaseDynamicObject(Var aValue) { - return RecyclableObject::Is(aValue) && (RecyclableObject::UnsafeFromVar(aValue)->GetTypeId() == TypeIds_Object); + return VarIs(aValue) && (UnsafeVarTo(aValue)->GetTypeId() == TypeIds_Object); } - DynamicObject* DynamicObject::FromVar(Var aValue) + DynamicObject* DynamicObject::TryVarToBaseDynamicObject(Var aValue) { - RecyclableObject* obj = RecyclableObject::FromVar(aValue); - AssertMsg(obj->DbgIsDynamicObject(), "Ensure instance is actually a DynamicObject"); - AssertOrFailFast(DynamicType::Is(obj->GetTypeId())); - return static_cast(obj); + return IsBaseDynamicObject(aValue) ? UnsafeVarTo(aValue) : nullptr; } - DynamicObject* DynamicObject::UnsafeFromVar(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - RecyclableObject* obj = RecyclableObject::UnsafeFromVar(aValue); - AssertMsg(obj->DbgIsDynamicObject(), "Ensure instance is actually a DynamicObject"); - Assert(DynamicType::Is(obj->GetTypeId())); - return static_cast(obj); + bool result = DynamicType::Is(obj->GetTypeId()); + Assert(result == obj->DbgIsDynamicObject()); + return result; } ArrayObject* DynamicObject::EnsureObjectArray() @@ -218,7 +214,7 @@ namespace Js // Check if a typeId is of any array type (JavascriptArray or ES5Array). bool DynamicObject::IsAnyArrayTypeId(TypeId typeId) { - return JavascriptArray::Is(typeId) || typeId == TypeIds_ES5Array; + return JavascriptArray::IsNonES5Array(typeId) || typeId == TypeIds_ES5Array; } // Check if a Var is either a JavascriptArray* or ES5Array*. @@ -227,6 +223,11 @@ namespace Js return IsAnyArrayTypeId(JavascriptOperators::GetTypeId(aValue)); } + bool DynamicObject::IsAnyArray(DynamicObject* obj) + { + return IsAnyArrayTypeId(JavascriptOperators::GetTypeId(obj)); + } + BOOL DynamicObject::HasObjectArrayItem(uint32 index) { return HasObjectArray() && GetObjectArrayOrFlagsAsArray()->HasItem(index); @@ -977,7 +978,7 @@ namespace Js { return false; } - if (HasObjectArray() || (JavascriptArray::Is(this) && JavascriptArray::FromVar(this)->GetLength() != 0)) + if (HasObjectArray() || (JavascriptArray::IsNonES5Array(this) && VarTo(this)->GetLength() != 0)) { return false; } diff --git a/lib/Runtime/Types/DynamicObject.h b/lib/Runtime/Types/DynamicObject.h index 4eaa6b016c8..f25585644ca 100644 --- a/lib/Runtime/Types/DynamicObject.h +++ b/lib/Runtime/Types/DynamicObject.h @@ -145,9 +145,11 @@ namespace Js public: static DynamicObject * New(Recycler * recycler, DynamicType * type); - static bool Is(Var aValue); - static DynamicObject* FromVar(Var value); - static DynamicObject* UnsafeFromVar(Var value); + // Return whether the type is exactly DynamicObject, not some subclass (for more inclusive check use VarIs) + static bool IsBaseDynamicObject(Var aValue); + + // Returns the object if it is exactly DynamicObject, not some subclass. Otherwise returns null. + static DynamicObject* TryVarToBaseDynamicObject(Var aValue); void EnsureSlots(int oldCount, int newCount, ScriptContext * scriptContext, DynamicTypeHandler * newTypeHandler = nullptr); void EnsureSlots(int newCount, ScriptContext *scriptContext); @@ -186,6 +188,7 @@ namespace Js // Check if a Var is either a JavascriptArray* or ES5Array*. static bool IsAnyArray(const Var aValue); + static bool IsAnyArray(DynamicObject* obj); // Check if a Var is a typedarray. static bool IsAnyTypedArray(const Var aValue); @@ -386,4 +389,6 @@ namespace Js } }; + + template <> bool VarIsImpl(RecyclableObject* obj); } // namespace Js diff --git a/lib/Runtime/Types/DynamicObjectPropertyEnumerator.cpp b/lib/Runtime/Types/DynamicObjectPropertyEnumerator.cpp index e6a9953304a..b68863d5e11 100644 --- a/lib/Runtime/Types/DynamicObjectPropertyEnumerator.cpp +++ b/lib/Runtime/Types/DynamicObjectPropertyEnumerator.cpp @@ -198,7 +198,7 @@ namespace Js if (propertyStringName) { - PropertyString* propertyString = PropertyString::TryFromVar(propertyStringName); + PropertyString* propertyString = JavascriptOperators::TryFromVar(propertyStringName); if (propertyString != nullptr) { Assert(enumeratedCount < this->initialPropertyCount); diff --git a/lib/Runtime/Types/DynamicType.cpp b/lib/Runtime/Types/DynamicType.cpp index 89f4337f2bd..ac6d26629f2 100644 --- a/lib/Runtime/Types/DynamicType.cpp +++ b/lib/Runtime/Types/DynamicType.cpp @@ -449,7 +449,7 @@ namespace Js { if (JavascriptConversion::IsCallable(toPrimitiveFunction)) { - RecyclableObject* toStringFunction = RecyclableObject::FromVar(toPrimitiveFunction); + RecyclableObject* toStringFunction = VarTo(toPrimitiveFunction); ThreadContext * threadContext = requestContext->GetThreadContext(); Var aResult = threadContext->ExecuteImplicitCall(toStringFunction, ImplicitCall_ToPrimitive, [=]() -> Js::Var diff --git a/lib/Runtime/Types/ES5ArrayTypeHandler.cpp b/lib/Runtime/Types/ES5ArrayTypeHandler.cpp index 7f0e3d195ec..62dc0fda8ae 100644 --- a/lib/Runtime/Types/ES5ArrayTypeHandler.cpp +++ b/lib/Runtime/Types/ES5ArrayTypeHandler.cpp @@ -230,7 +230,7 @@ namespace Js template void ES5ArrayTypeHandlerBase::SetInstanceTypeHandler(DynamicObject* instance, bool hasChanged) { - Assert(JavascriptArray::Is(instance)); + Assert(JavascriptArray::IsNonES5Array(instance)); if (this->GetFlags() & DynamicTypeHandler::IsPrototypeFlag) { // We have ES5 array has array/object prototype, we can't use array fast path for set @@ -243,7 +243,7 @@ namespace Js #if ENABLE_COPYONACCESS_ARRAY JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray(instance); #endif - JavascriptArray * arrayInstance = JavascriptArray::EnsureNonNativeArray(JavascriptArray::FromVar(instance)); + JavascriptArray * arrayInstance = JavascriptArray::EnsureNonNativeArray(VarTo(instance)); #if DBG bool doneConversion = false; Js::Type* oldType = arrayInstance->GetType(); @@ -404,7 +404,7 @@ namespace Js } else if (descriptor->Setter) { - RecyclableObject* func = RecyclableObject::FromVar(descriptor->Setter); + RecyclableObject* func = VarTo(descriptor->Setter); // TODO : request context JavascriptOperators::CallSetter(func, instance, value, NULL); } @@ -478,7 +478,7 @@ namespace Js } else if (descriptor->Setter) { - RecyclableObject* func = RecyclableObject::FromVar(descriptor->Setter); + RecyclableObject* func = VarTo(descriptor->Setter); // TODO : request context JavascriptOperators::CallSetter(func, instance, value, NULL); } @@ -687,7 +687,7 @@ namespace Js if (descriptor->Getter) { - RecyclableObject* func = RecyclableObject::FromVar(descriptor->Getter); + RecyclableObject* func = VarTo(descriptor->Getter); *value = Js::JavascriptOperators::CallGetter(func, originalInstance, requestContext); } else @@ -712,7 +712,7 @@ namespace Js return None; } - if (HasDataItem(ES5Array::FromVar(instance), index)) + if (HasDataItem(VarTo(instance), index)) { // not a setter but shadows return (descriptor->Attributes & PropertyWritable) ? WritableData : Data; @@ -723,7 +723,7 @@ namespace Js return Accessor; } } - else if (HasDataItem(ES5Array::FromVar(instance), index)) + else if (HasDataItem(VarTo(instance), index)) { return (GetDataItemAttributes() & PropertyWritable) ? WritableData : Data; } @@ -767,7 +767,7 @@ namespace Js uint32 index; if (scriptContext->IsNumericPropertyId(propertyId, &index)) { - return GetItem(ES5Array::FromVar(instance), instance, index, value, requestContext); + return GetItem(VarTo(instance), instance, index, value, requestContext); } return __super::GetProperty(instance, originalInstance, propertyId, value, info, requestContext); @@ -813,7 +813,7 @@ namespace Js uint32 index; if (scriptContext->IsNumericPropertyId(propertyId, &index)) { - return DeleteItem(ES5Array::FromVar(instance), instance, index, flags); + return DeleteItem(VarTo(instance), instance, index, flags); } return __super::DeleteProperty(instance, propertyId, flags); @@ -822,49 +822,49 @@ namespace Js template BOOL ES5ArrayTypeHandlerBase::HasItem(DynamicObject* instance, uint32 index) { - return HasItem(ES5Array::FromVar(instance), index); + return HasItem(VarTo(instance), index); } template BOOL ES5ArrayTypeHandlerBase::SetItem(DynamicObject* instance, uint32 index, Var value, PropertyOperationFlags flags) { - return SetItem(ES5Array::FromVar(instance), instance, index, value, flags); + return SetItem(VarTo(instance), instance, index, value, flags); } template BOOL ES5ArrayTypeHandlerBase::SetItemWithAttributes(DynamicObject* instance, uint32 index, Var value, PropertyAttributes attributes) { - return SetItemWithAttributes(ES5Array::FromVar(instance), instance, index, value, attributes); + return SetItemWithAttributes(VarTo(instance), instance, index, value, attributes); } template BOOL ES5ArrayTypeHandlerBase::SetItemAttributes(DynamicObject* instance, uint32 index, PropertyAttributes attributes) { - return SetItemAttributes(ES5Array::FromVar(instance), instance, index, attributes); + return SetItemAttributes(VarTo(instance), instance, index, attributes); } template BOOL ES5ArrayTypeHandlerBase::SetItemAccessors(DynamicObject* instance, uint32 index, Var getter, Var setter) { - return SetItemAccessors(ES5Array::FromVar(instance), instance, index, getter, setter); + return SetItemAccessors(VarTo(instance), instance, index, getter, setter); } template BOOL ES5ArrayTypeHandlerBase::DeleteItem(DynamicObject* instance, uint32 index, PropertyOperationFlags flags) { - return DeleteItem(ES5Array::FromVar(instance), instance, index, flags); + return DeleteItem(VarTo(instance), instance, index, flags); } template BOOL ES5ArrayTypeHandlerBase::GetItem(DynamicObject* instance, Var originalInstance, uint32 index, Var* value, ScriptContext* requestContext) { - return GetItem(ES5Array::FromVar(instance), instance, originalInstance, index, value, requestContext); + return GetItem(VarTo(instance), instance, originalInstance, index, value, requestContext); } template DescriptorFlags ES5ArrayTypeHandlerBase::GetItemSetter(DynamicObject* instance, uint32 index, Var* setterValue, ScriptContext* requestContext) { - return GetItemSetter(ES5Array::FromVar(instance), instance, index, setterValue, requestContext); + return GetItemSetter(VarTo(instance), instance, index, setterValue, requestContext); } template @@ -1047,7 +1047,7 @@ namespace Js } else { - if (!HasDataItem(ES5Array::FromVar(instance), index)) + if (!HasDataItem(VarTo(instance), index)) { return false; } @@ -1166,7 +1166,7 @@ namespace Js uint32 index; if (scriptContext->IsNumericPropertyId(propertyId, &index)) { - return GetItemAccessors(ES5Array::FromVar(instance), instance, index, getter, setter); + return GetItemAccessors(VarTo(instance), instance, index, getter, setter); } return __super::GetAccessors(instance, propertyId, getter, setter); @@ -1190,7 +1190,7 @@ namespace Js template BOOL ES5ArrayTypeHandlerBase::FreezeImpl(DynamicObject* instance, bool isConvertedType) { - ES5Array* arr = ES5Array::FromVar(instance); + ES5Array* arr = VarTo(instance); for (int i = 0; i < indexPropertyMap->Count(); i++) { @@ -1245,7 +1245,7 @@ namespace Js // Check data item not in map if (this->GetDataItemAttributes() & PropertyConfigurable) { - if (HasAnyDataItemNotInMap(ES5Array::FromVar(instance))) + if (HasAnyDataItemNotInMap(VarTo(instance))) { return false; } @@ -1308,7 +1308,7 @@ namespace Js return false; } - return IsObjectArrayFrozen(ES5Array::FromVar(instance)); + return IsObjectArrayFrozen(VarTo(instance)); } template @@ -1319,7 +1319,7 @@ namespace Js uint32 index; if (scriptContext->IsNumericPropertyId(propertyId, &index)) { - return SetItemAttributes(ES5Array::FromVar(instance), instance, index, attributes); + return SetItemAttributes(VarTo(instance), instance, index, attributes); } return __super::SetAttributes(instance, propertyId, attributes); diff --git a/lib/Runtime/Types/JavascriptEnumerator.cpp b/lib/Runtime/Types/JavascriptEnumerator.cpp index c4531c344b3..61746a9ff5d 100644 --- a/lib/Runtime/Types/JavascriptEnumerator.cpp +++ b/lib/Runtime/Types/JavascriptEnumerator.cpp @@ -11,22 +11,8 @@ namespace Js Assert(scriptContext != NULL); } - bool JavascriptEnumerator::Is(Var aValue) + template <> bool VarIsImpl(RecyclableObject* obj) { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_Enumerator; - } - - JavascriptEnumerator* JavascriptEnumerator::FromVar(Var aValue) - { - AssertOrFailFastMsg(Is(aValue), "Ensure var is actually a 'JavascriptEnumerator'"); - - return static_cast(aValue); - } - - JavascriptEnumerator* JavascriptEnumerator::UnsafeFromVar(Var aValue) - { - AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptEnumerator'"); - - return static_cast(aValue); + return JavascriptOperators::GetTypeId(obj) == TypeIds_Enumerator; } } diff --git a/lib/Runtime/Types/JavascriptEnumerator.h b/lib/Runtime/Types/JavascriptEnumerator.h index 312c036f29a..87a76a14355 100644 --- a/lib/Runtime/Types/JavascriptEnumerator.h +++ b/lib/Runtime/Types/JavascriptEnumerator.h @@ -37,10 +37,7 @@ namespace Js { // as a reference and then remove it. If you have already made the edits before // seeing this comment please just consolidate the changes. virtual JavascriptString * MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) = 0; - - - static bool Is(Var aValue); - static JavascriptEnumerator* FromVar(Var varValue); - static JavascriptEnumerator* UnsafeFromVar(Var varValue); }; + + template <> bool VarIsImpl(RecyclableObject* obj); } diff --git a/lib/Runtime/Types/NullTypeHandler.cpp b/lib/Runtime/Types/NullTypeHandler.cpp index 2188242687b..7318978aaba 100644 --- a/lib/Runtime/Types/NullTypeHandler.cpp +++ b/lib/Runtime/Types/NullTypeHandler.cpp @@ -318,7 +318,7 @@ namespace Js DynamicTypeHandler* NullTypeHandlerBase::ConvertToTypeWithItemAttributes(DynamicObject* instance) { - return JavascriptArray::Is(instance) ? + return JavascriptArray::IsNonES5Array(instance) ? ConvertToES5ArrayType(instance) : ConvertToDictionaryType(instance); } diff --git a/lib/Runtime/Types/PathTypeHandler.cpp b/lib/Runtime/Types/PathTypeHandler.cpp index 57630b75237..02174de8b07 100644 --- a/lib/Runtime/Types/PathTypeHandler.cpp +++ b/lib/Runtime/Types/PathTypeHandler.cpp @@ -2420,7 +2420,7 @@ namespace Js #ifdef PROFILE_TYPES instance->GetScriptContext()->convertPathToDictionaryItemAttributesCount++; #endif - return JavascriptArray::Is(instance) ? + return JavascriptArray::IsNonES5Array(instance) ? ConvertToES5ArrayType(instance) : ConvertToDictionaryType(instance); } @@ -3123,7 +3123,7 @@ namespace Js if (ShouldFixAnyProperties() && CanBeSingletonInstance(instance)) { bool markAsFixed = !isNonFixed && !IsInternalPropertyId(propertyId) && - (JavascriptFunction::Is(value) ? ShouldFixMethodProperties() || ShouldFixAccessorProperties() : + (VarIs(value) ? ShouldFixMethodProperties() || ShouldFixAccessorProperties() : (ShouldFixDataProperties() && CheckHeuristicsForFixedDataProps(instance, propertyRecord, propertyId, value))); // Mark the newly added field as fixed and prevent population of inline caches. @@ -3261,7 +3261,7 @@ namespace Js } Var value = this->GetTypePath()->GetSingletonFixedFieldAt(index, GetPathLength(), requestContext); - if (value && ((IsFixedMethodProperty(propertyType) && JavascriptFunction::Is(value)) || IsFixedDataProperty(propertyType))) + if (value && ((IsFixedMethodProperty(propertyType) && VarIs(value)) || IsFixedDataProperty(propertyType))) { *pProperty = value; if (markAsUsed) @@ -3680,7 +3680,8 @@ namespace Js Assert(setters != nullptr); PathTypeSetterSlotIndex setterSlot = setters[propertyIndex]; Assert(setterSlot != NoSetterSlot && setterSlot < GetPathLength()); - *setterValue = DynamicObject::FromVar(instance)->GetSlot(setterSlot); + AssertOrFailFast(VarIsCorrectType(instance)); + *setterValue = instance->GetSlot(setterSlot); PropertyValueInfo::Set(info, instance, setterSlot, ObjectSlotAttributesToPropertyAttributes(attr), InlineCacheSetterFlag); return Accessor; } @@ -3761,7 +3762,7 @@ namespace Js CacheOperators::CachePropertyReadForGetter(info, originalInstance, propertyId, requestContext); PropertyValueInfo::SetNoCache(info, instance); // we already cached getter, so we don't have to do it once more - RecyclableObject* func = RecyclableObject::UnsafeFromVar(instance->GetSlot(index)); + RecyclableObject* func = UnsafeVarTo(instance->GetSlot(index)); *value = JavascriptOperators::CallGetter(func, originalInstance, requestContext); return true; } @@ -3803,7 +3804,7 @@ namespace Js if (attributes[index] & ObjectSlotAttr_Accessor) { Assert(setters[index] != Constants::NoSlot); - RecyclableObject* func = RecyclableObject::FromVar(instance->GetSlot(setters[index])); + RecyclableObject* func = VarTo(instance->GetSlot(setters[index])); JavascriptOperators::CallSetter(func, instance, value, NULL); // Wait for the setter to return before setting up the inline cache info, as the setter may change diff --git a/lib/Runtime/Types/RecyclableObject.cpp b/lib/Runtime/Types/RecyclableObject.cpp index 41f15dc31bc..2376ecd9851 100644 --- a/lib/Runtime/Types/RecyclableObject.cpp +++ b/lib/Runtime/Types/RecyclableObject.cpp @@ -33,8 +33,8 @@ namespace Js // Make sure the given prop and usage cache match Assert( prop == nullptr && propertyRecordUsageCache == nullptr || - JavascriptSymbol::Is(prop) && JavascriptSymbol::UnsafeFromVar(prop)->GetPropertyRecordUsageCache() == propertyRecordUsageCache || - PropertyString::Is(prop) && PropertyString::UnsafeFromVar(prop)->GetPropertyRecordUsageCache() == propertyRecordUsageCache); + VarIs(prop) && UnsafeVarTo(prop)->GetPropertyRecordUsageCache() == propertyRecordUsageCache || + VarIs(prop) && UnsafeVarTo(prop)->GetPropertyRecordUsageCache() == propertyRecordUsageCache); info->prop = prop; info->propertyRecordUsageCache = propertyRecordUsageCache; @@ -184,7 +184,7 @@ namespace Js { if (DynamicType::Is(this->GetTypeId())) { - DynamicObject* dynamicThis = DynamicObject::UnsafeFromVar(this); + DynamicObject* dynamicThis = UnsafeVarTo(this); dynamicThis->SetIsPrototype(); // Call the DynamicObject::SetIsPrototype } } @@ -193,7 +193,7 @@ namespace Js { if (DynamicType::Is(this->GetTypeId())) { - DynamicObject* obj = DynamicObject::UnsafeFromVar(this); + DynamicObject* obj = UnsafeVarTo(this); return obj->GetTypeHandler()->GetHasOnlyWritableDataProperties() && (!obj->HasObjectArray() || obj->GetObjectArrayOrFlagsAsArray()->HasOnlyWritableDataProperties()); } @@ -205,7 +205,7 @@ namespace Js { if (DynamicType::Is(this->GetTypeId())) { - DynamicObject* obj = DynamicObject::UnsafeFromVar(this); + DynamicObject* obj = UnsafeVarTo(this); return obj->GetTypeHandler()->GetHasSpecialProperties() || (obj->HasObjectArray() && obj->GetObjectArrayOrFlagsAsArray()->HasAnySpecialProperties()); } @@ -217,7 +217,7 @@ namespace Js { if (DynamicType::Is(this->GetTypeId())) { - DynamicObject* obj = DynamicObject::UnsafeFromVar(this); + DynamicObject* obj = UnsafeVarTo(this); obj->GetTypeHandler()->ClearWritableDataOnlyDetectionBit(); if (obj->HasObjectArray()) { @@ -230,7 +230,7 @@ namespace Js { if (DynamicType::Is(this->GetTypeId())) { - DynamicObject* obj = DynamicObject::UnsafeFromVar(this); + DynamicObject* obj = UnsafeVarTo(this); return obj->GetTypeHandler()->IsWritableDataOnlyDetectionBitSet() || (obj->HasObjectArray() && obj->GetObjectArrayOrFlagsAsArray()->IsWritableDataOnlyDetectionBitSet()); } @@ -259,7 +259,7 @@ namespace Js case TypeIds_Null: return requestContext->GetLibrary()->GetNull(); case TypeIds_Number: - return RecyclableObject::FromVar(JavascriptNumber::CloneToScriptContext(this, requestContext)); + return VarTo(JavascriptNumber::CloneToScriptContext(this, requestContext)); default: AssertMsg(FALSE, "shouldn't clone for other types"); Js::JavascriptError::ThrowError(requestContext, VBSERR_InternalError); @@ -324,9 +324,9 @@ namespace Js } RecyclableObject* RecyclableObject::GetThisObjectOrUnWrap() { - if (WithScopeObject::Is(this)) + if (VarIs(this)) { - return WithScopeObject::FromVar(this)->GetWrappedObject(); + return VarTo(this)->GetWrappedObject(); } return this; } @@ -537,7 +537,7 @@ namespace Js goto ReturnTrue; default: // Falsy objects are == null and == undefined. - *value = RecyclableObject::FromVar(aRight)->GetType()->IsFalsy(); + *value = VarTo(aRight)->GetType()->IsFalsy(); return TRUE; } case TypeIds_Integer: @@ -554,7 +554,7 @@ namespace Js case TypeIds_Int64Number: { int leftValue = TaggedInt::ToInt32(aLeft); - __int64 rightValue = JavascriptInt64Number::FromVar(aRight)->GetValue(); + __int64 rightValue = VarTo(aRight)->GetValue(); *value = leftValue == rightValue; Assert(!(*value)); // currently it cannot be true. more for future extension if we allow arithmetic calculation return TRUE; @@ -562,7 +562,7 @@ namespace Js case TypeIds_UInt64Number: { __int64 leftValue = TaggedInt::ToInt32(aLeft); - unsigned __int64 rightValue = JavascriptInt64Number::FromVar(aRight)->GetValue(); + unsigned __int64 rightValue = VarTo(aRight)->GetValue(); // TODO: yongqu to review whether we need to check for neg value *value = (/*leftValue >= 0 && */(unsigned __int64)leftValue == rightValue); Assert(!(*value)); // currently it cannot be true. more for future extension if we allow arithmetic calculation @@ -586,27 +586,27 @@ namespace Js { case TypeIds_Integer: { - __int64 leftValue = JavascriptInt64Number::FromVar(aLeft)->GetValue(); + __int64 leftValue = VarTo(aLeft)->GetValue(); int rightValue = TaggedInt::ToInt32(aRight); *value = leftValue == rightValue; Assert(!(*value)); // currently it cannot be true. more for future extension if we allow arithmetic calculation return TRUE; } case TypeIds_Number: - dblLeft = (double)JavascriptInt64Number::FromVar(aLeft)->GetValue(); + dblLeft = (double)VarTo(aLeft)->GetValue(); dblRight = JavascriptNumber::GetValue(aRight); goto CompareDoubles; case TypeIds_Int64Number: { - __int64 leftValue = JavascriptInt64Number::FromVar(aLeft)->GetValue(); - __int64 rightValue = JavascriptInt64Number::FromVar(aRight)->GetValue(); + __int64 leftValue = VarTo(aLeft)->GetValue(); + __int64 rightValue = VarTo(aRight)->GetValue(); *value = leftValue == rightValue; return TRUE; } case TypeIds_UInt64Number: { - __int64 leftValue = JavascriptInt64Number::FromVar(aLeft)->GetValue(); - unsigned __int64 rightValue = JavascriptInt64Number::FromVar(aRight)->GetValue(); + __int64 leftValue = VarTo(aLeft)->GetValue(); + unsigned __int64 rightValue = VarTo(aRight)->GetValue(); // TODO: yongqu to review whether we need to check for neg value *value = (/* leftValue >= 0 && */(unsigned __int64)leftValue == rightValue); return TRUE; @@ -618,7 +618,7 @@ namespace Js { case TypeIds_Integer: { - unsigned __int64 leftValue = JavascriptUInt64Number::FromVar(aLeft)->GetValue(); + unsigned __int64 leftValue = VarTo(aLeft)->GetValue(); __int64 rightValue = TaggedInt::ToInt32(aRight); // TODO: yongqu to review whether we need to check for neg value *value = rightValue >= 0 && leftValue == (unsigned __int64)rightValue; @@ -626,21 +626,21 @@ namespace Js return TRUE; } case TypeIds_Number: - dblLeft = (double)JavascriptUInt64Number::FromVar(aLeft)->GetValue(); + dblLeft = (double)VarTo(aLeft)->GetValue(); dblRight = JavascriptNumber::GetValue(aRight); goto CompareDoubles; case TypeIds_Int64Number: { - unsigned __int64 leftValue = JavascriptUInt64Number::FromVar(aLeft)->GetValue(); - __int64 rightValue = JavascriptInt64Number::FromVar(aRight)->GetValue(); + unsigned __int64 leftValue = VarTo(aLeft)->GetValue(); + __int64 rightValue = VarTo(aRight)->GetValue(); // TODO: yongqu to review whether we need to check for neg value *value = (/* rightValue >= 0 && */leftValue == (unsigned __int64)rightValue); return TRUE; } case TypeIds_UInt64Number: { - unsigned __int64 leftValue = JavascriptUInt64Number::FromVar(aLeft)->GetValue(); - unsigned __int64 rightValue = JavascriptInt64Number::FromVar(aRight)->GetValue(); + unsigned __int64 leftValue = VarTo(aLeft)->GetValue(); + unsigned __int64 rightValue = VarTo(aRight)->GetValue(); *value = leftValue == rightValue; return TRUE; } @@ -678,7 +678,7 @@ namespace Js case TypeIds_Symbol: goto ReturnFalse; case TypeIds_String: - *value = JavascriptString::Equals(JavascriptString::UnsafeFromVar(aLeft), JavascriptString::UnsafeFromVar(aRight)); + *value = JavascriptString::Equals(UnsafeVarTo(aLeft), UnsafeVarTo(aRight)); return TRUE; case TypeIds_Number: case TypeIds_Integer: @@ -697,7 +697,7 @@ namespace Js case TypeIds_Symbol: goto ReturnFalse; case TypeIds_Boolean: - *value = JavascriptBoolean::FromVar(aLeft)->GetValue() == JavascriptBoolean::FromVar(aRight)->GetValue(); + *value = VarTo(aLeft)->GetValue() == VarTo(aRight)->GetValue(); return TRUE; case TypeIds_Number: case TypeIds_Integer: @@ -722,11 +722,11 @@ namespace Js goto ReturnFalse; case TypeIds_Symbol: *value = (aLeft == aRight); - Assert((JavascriptSymbol::UnsafeFromVar(aLeft)->GetValue() == JavascriptSymbol::UnsafeFromVar(aRight)->GetValue()) == *value); + Assert((UnsafeVarTo(aLeft)->GetValue() == UnsafeVarTo(aRight)->GetValue()) == *value); return TRUE; case TypeIds_SymbolObject: - *value = (aLeft == JavascriptSymbolObject::UnsafeFromVar(aRight)->Unwrap()); - Assert((JavascriptSymbol::UnsafeFromVar(aLeft)->GetValue() == JavascriptSymbolObject::UnsafeFromVar(aRight)->GetValue()) == *value); + *value = (aLeft == UnsafeVarTo(aRight)->Unwrap()); + Assert((UnsafeVarTo(aLeft)->GetValue() == UnsafeVarTo(aRight)->GetValue()) == *value); return TRUE; default: goto RedoRight; diff --git a/lib/Runtime/Types/RecyclableObject.h b/lib/Runtime/Types/RecyclableObject.h index c57465ad4a1..f39b5e00101 100644 --- a/lib/Runtime/Types/RecyclableObject.h +++ b/lib/Runtime/Types/RecyclableObject.h @@ -249,9 +249,6 @@ namespace Js { virtual RecyclableObject* GetPrototypeSpecial(); public: - static bool Is(Var aValue); - static RecyclableObject* FromVar(Var varValue); - static RecyclableObject* UnsafeFromVar(Var varValue); RecyclableObject(Type * type); #if DBG_EXTRAFIELD // This dtor should only be call when OOM occurs and RecyclableObject ctor has completed @@ -467,4 +464,80 @@ namespace Js { int GetHeapEnumValidationCookie() { return m_heapEnumValidationCookie; } #endif }; + + // DO specialize this method; DON'T call it directly (use VarIs instead) + // Return whether the given RecyclableObject is of the template parameter's type. + // Generally, subclasses of RecyclableObject should only need to provide + // a specialization for VarIsImpl(RecyclableObject*), and the other conversion + // functions should take care of themselves. + template bool VarIsImpl(RecyclableObject* obj); + + template <> inline bool VarIsImpl(RecyclableObject* obj) { return true; } + + // Return whether the given Var is of the template parameter's type. + template bool VarIs(U* obj) + { + // ChakraFull can't include type_traits, but ChakraCore does include it for debug builds +#if DBG && !defined(NTBUILD) + static_assert(!std::is_same::value, "Check should be unnecessary - did you prematurely cast?"); + static_assert(std::is_base_of::value, "VarIs/VarTo should only downcast!"); +#endif + return VarIsImpl(obj); + } + + // Return whether the given Var is of the template parameter's type. + template bool VarIs(Var aValue) + { + AssertMsg(aValue != nullptr, "VarIs: aValue is null"); + +#if INT32VAR + bool isRecyclableObject = (((uintptr_t)aValue) >> VarTag_Shift) == 0; +#else + bool isRecyclableObject = (((uintptr_t)aValue) & AtomTag) == AtomTag_Object; +#endif + + return isRecyclableObject && VarIsImpl(reinterpret_cast(aValue)); + } + + // Validate that the object is actually the type that the type system thinks it is. + // This should only be used for extremely defensive assertions; if you find code + // relying on this behavior for correctness, then it's cause for concern. + template bool VarIsCorrectType(T* obj) + { + return VarIsImpl(obj); + } + template bool VarIsCorrectType(WriteBarrierPtr obj) + { + return VarIsImpl(obj); + } + + CompileAssertMsg(AtomTag_Object == 0, "Ensure GC objects do not need to be marked"); + + // Cast the input parameter to another type, or crash if the cast is invalid. + template T* VarTo(U* obj) + { + AssertOrFailFast(VarIs(obj)); + return static_cast(obj); + } + + // Cast the input parameter to another type, or crash if the cast is invalid. + template T* VarTo(Var aValue) + { + AssertOrFailFast(VarIs(aValue)); + return reinterpret_cast(aValue); + } + + // Cast the input parameter to another type. In debug builds only, assert that the cast is valid. + template T* UnsafeVarTo(U* obj) + { + Assert(VarIs(obj)); + return static_cast(obj); + } + + // Cast the input parameter to another type. In debug builds only, assert that the cast is valid. + template T* UnsafeVarTo(Var aValue) + { + Assert(VarIs(aValue)); + return reinterpret_cast(aValue); + } } diff --git a/lib/Runtime/Types/RecyclableObject.inl b/lib/Runtime/Types/RecyclableObject.inl index 95770afef0d..9c41a6ee14d 100644 --- a/lib/Runtime/Types/RecyclableObject.inl +++ b/lib/Runtime/Types/RecyclableObject.inl @@ -7,39 +7,6 @@ namespace Js { // These function needs to be in INL file for static lib -#if INT32VAR - inline bool RecyclableObject::Is(Var aValue) - { - AssertMsg(aValue != nullptr, "RecyclableObject::Is aValue is null"); - - return (((uintptr_t)aValue) >> VarTag_Shift) == 0; - } -#else - inline bool RecyclableObject::Is(Var aValue) - { - AssertMsg(aValue != nullptr, "RecyclableObject::Is aValue is null"); - - return (((uintptr_t)aValue) & AtomTag) == AtomTag_Object; - } -#endif - - inline RecyclableObject* RecyclableObject::FromVar(const Js::Var aValue) - { - AssertMsg(AtomTag_Object == 0, "Ensure GC objects do not need to be marked"); - AssertMsg(Is(aValue), "Ensure instance is a RecyclableObject"); - AssertOrFailFastMsg(!TaggedNumber::Is(aValue), "Tagged value being used as RecyclableObject"); - - return reinterpret_cast(aValue); - } - - inline RecyclableObject* RecyclableObject::UnsafeFromVar(const Js::Var aValue) - { - AssertMsg(AtomTag_Object == 0, "Ensure GC objects do not need to be marked"); - AssertMsg(Is(aValue), "Ensure instance is a RecyclableObject"); - AssertMsg(!TaggedNumber::Is(aValue), "Tagged value being used as RecyclableObject"); - - return reinterpret_cast(aValue); - } inline TypeId RecyclableObject::GetTypeId() const { diff --git a/lib/Runtime/Types/SimpleDictionaryTypeHandler.cpp b/lib/Runtime/Types/SimpleDictionaryTypeHandler.cpp index 17e370c684e..b9659b397d4 100644 --- a/lib/Runtime/Types/SimpleDictionaryTypeHandler.cpp +++ b/lib/Runtime/Types/SimpleDictionaryTypeHandler.cpp @@ -88,7 +88,7 @@ namespace Js const PropertyRecord* TMapKey_ConvertKey_TTD(ThreadContext* threadContext, JavascriptString* key) { PropertyRecord const * propertyRecord; - PropertyString * propertyString = PropertyString::TryFromVar(key); + PropertyString * propertyString = JavascriptOperators::TryFromVar(key); if (propertyString != nullptr) { propertyString->GetPropertyRecord(&propertyRecord); @@ -104,7 +104,7 @@ namespace Js bool TPropertyKey_IsInternalPropertyId(JavascriptString* key) { // WARNING: This will return false for PropertyStrings that are actually InternalPropertyIds - Assert(!PropertyString::Is(key) || !IsInternalPropertyId(((PropertyString*)key)->GetPropertyId())); + Assert(!VarIs(key) || !IsInternalPropertyId(((PropertyString*)key)->GetPropertyId())); return false; } @@ -1122,7 +1122,7 @@ namespace Js template BOOL SimpleDictionaryTypeHandlerBase::GetRootProperty(DynamicObject* instance, Var originalInstance, PropertyId propertyId, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) { - AssertMsg(RootObjectBase::Is(instance), "Instance must be a root object!"); + AssertMsg(VarIs(instance), "Instance must be a root object!"); return GetProperty_Internal(instance, originalInstance, propertyId, value, info, requestContext); } @@ -1277,7 +1277,7 @@ namespace Js template BOOL SimpleDictionaryTypeHandlerBase::SetRootProperty(DynamicObject* instance, PropertyId propertyId, Var value, PropertyOperationFlags flags, PropertyValueInfo* info) { - AssertMsg(RootObjectBase::Is(instance), "Instance must be a root object!"); + AssertMsg(VarIs(instance), "Instance must be a root object!"); return SetProperty_Internal(instance, propertyId, value, flags, info); } @@ -1399,7 +1399,7 @@ namespace Js Assert(value != nullptr); // We don't want fixed properties on external objects. See DynamicObject::ResetObject for more information. Assert(!instance->IsExternal()); - descriptor->isFixed = (JavascriptFunction::Is(value) ? ShouldFixMethodProperties() : (ShouldFixDataProperties() && CheckHeuristicsForFixedDataProps(instance, propertyId, value))); + descriptor->isFixed = (VarIs(value) ? ShouldFixMethodProperties() : (ShouldFixDataProperties() && CheckHeuristicsForFixedDataProps(instance, propertyId, value))); } } } @@ -1444,7 +1444,7 @@ namespace Js template DescriptorFlags SimpleDictionaryTypeHandlerBase::GetRootSetter(DynamicObject* instance, PropertyId propertyId, Var* setterValue, PropertyValueInfo* info, ScriptContext* requestContext) { - AssertMsg(RootObjectBase::Is(instance), "Instance must be a root object!"); + AssertMsg(VarIs(instance), "Instance must be a root object!"); return GetSetter_Internal(instance, propertyId, setterValue, info, requestContext); } @@ -1652,7 +1652,7 @@ namespace Js template BOOL SimpleDictionaryTypeHandlerBase::DeleteRootProperty(DynamicObject* instance, PropertyId propertyId, PropertyOperationFlags propertyOperationFlags) { - AssertMsg(RootObjectBase::Is(instance), "Instance must be a root object!"); + AssertMsg(VarIs(instance), "Instance must be a root object!"); return DeleteProperty_Internal(instance, propertyId, propertyOperationFlags); } @@ -1833,7 +1833,7 @@ namespace Js { if (descriptor->Attributes & PropertyLetConstGlobal) { - AssertMsg(RootObjectBase::Is(instance), "Instance must be a root object!"); + AssertMsg(VarIs(instance), "Instance must be a root object!"); return true; } return descriptor->Attributes & PropertyConfigurable; @@ -2450,7 +2450,7 @@ namespace Js Assert(value != nullptr); // We don't want fixed properties on external objects. See DynamicObject::ResetObject for more information. Assert(!instance->IsExternal()); - descriptor->isFixed = (JavascriptFunction::Is(value) ? ShouldFixMethodProperties() : (ShouldFixDataProperties() && CheckHeuristicsForFixedDataProps(instance, propertyId, value))); + descriptor->isFixed = (VarIs(value) ? ShouldFixMethodProperties() : (ShouldFixDataProperties() && CheckHeuristicsForFixedDataProps(instance, propertyId, value))); } } } @@ -2709,7 +2709,7 @@ namespace Js bool markAsInitialized = ((flags & PropertyOperation_PreInit) == 0); bool markAsFixed = markAsInitialized && !TPropertyKey_IsInternalPropertyId(propertyKey) && (flags & (PropertyOperation_NonFixedValue | PropertyOperation_SpecialValue)) == 0 && typeHandler->singletonInstance != nullptr && typeHandler->singletonInstance->Get() == instance - && (JavascriptFunction::Is(value) ? ShouldFixMethodProperties() : (ShouldFixDataProperties() && CheckHeuristicsForFixedDataProps(instance, propertyKey, value))); + && (VarIs(value) ? ShouldFixMethodProperties() : (ShouldFixDataProperties() && CheckHeuristicsForFixedDataProps(instance, propertyKey, value))); #else bool markAsInitialized = true; bool markAsFixed = false; @@ -2836,7 +2836,7 @@ namespace Js template DynamicTypeHandler* SimpleDictionaryTypeHandlerBase::ConvertToTypeWithItemAttributes(DynamicObject* instance) { - return JavascriptArray::Is(instance) ? + return JavascriptArray::IsNonES5Array(instance) ? ConvertToES5ArrayType(instance) : ConvertToDictionaryType(instance); } @@ -2890,7 +2890,7 @@ namespace Js // saravind:If the instance is used by a CrossSiteObject, then we are conservative and do not mark any field as fixed in that instance. // We need to relax this in the future and support fixed fields for Cross Site Context usage - descriptor->isFixed = (JavascriptFunction::Is(value) ? ShouldFixMethodProperties() : (ShouldFixDataProperties() && CheckHeuristicsForFixedDataProps(instance, propertyKey, value))); + descriptor->isFixed = (VarIs(value) ? ShouldFixMethodProperties() : (ShouldFixDataProperties() && CheckHeuristicsForFixedDataProps(instance, propertyKey, value))); // Since we have a new type we can clear all used as fixed bits. That's because any instance field loads // will have been invalidated by the type transition, and there are no proto fields loads from this object @@ -3149,7 +3149,7 @@ namespace Js AssertMsg(!(descriptor->Attributes & PropertyLetConstGlobal), "can't have fixed global let/const"); Assert(!IsInternalPropertyId(propertyRecord->GetPropertyId())); Var value = localSingletonInstance->GetSlot(descriptor->propertyIndex); - if (value && ((IsFixedMethodProperty(propertyType) && JavascriptFunction::Is(value)) || IsFixedDataProperty(propertyType))) + if (value && ((IsFixedMethodProperty(propertyType) && VarIs(value)) || IsFixedDataProperty(propertyType))) { *pProperty = value; if (markAsUsed) diff --git a/lib/Runtime/Types/SimpleTypeHandler.cpp b/lib/Runtime/Types/SimpleTypeHandler.cpp index 381f963faec..aaee074fa61 100644 --- a/lib/Runtime/Types/SimpleTypeHandler.cpp +++ b/lib/Runtime/Types/SimpleTypeHandler.cpp @@ -131,7 +131,7 @@ namespace Js Assert(value != nullptr || IsInternalPropertyId(descriptors[i].Id->GetPropertyId())); #if ENABLE_FIXED_FIELDS bool markAsFixed = allowFixedFields && !IsInternalPropertyId(descriptors[i].Id->GetPropertyId()) && - (JavascriptFunction::Is(value) ? ShouldFixMethodProperties() : false); + (VarIs(value) ? ShouldFixMethodProperties() : false); #else bool markAsFixed = false; #endif @@ -160,15 +160,15 @@ namespace Js Assert(!CrossSite::IsThunk(instance->GetType()->GetEntryPoint())); ScriptContext *scriptContext = instance->GetScriptContext(); - PathTypeHandlerBase* newTypeHandler = + PathTypeHandlerBase* newTypeHandler = PathTypeHandlerNoAttr::New( - scriptContext, - scriptContext->GetLibrary()->GetRootPath(), - 0, - static_cast(this->GetSlotCapacity()), - this->GetInlineSlotCapacity(), - this->GetOffsetOfInlineSlots(), - true, + scriptContext, + scriptContext->GetLibrary()->GetRootPath(), + 0, + static_cast(this->GetSlotCapacity()), + this->GetInlineSlotCapacity(), + this->GetOffsetOfInlineSlots(), + true, false); newTypeHandler->SetMayBecomeShared(); @@ -188,7 +188,7 @@ namespace Js #if ENABLE_FIXED_FIELDS #ifdef SUPPORT_FIXED_FIELDS_ON_PATH_TYPES bool markAsFixed = !IsInternalPropertyId(propertyId) && - (JavascriptFunction::Is(value) ? ShouldFixMethodProperties() : false); + (VarIs(value) ? ShouldFixMethodProperties() : false); newTypeHandler->InitializePath(instance, i, newTypeHandler->GetPathLength(), scriptContext, [=]() { return markAsFixed; }); #endif #endif @@ -1139,7 +1139,7 @@ namespace Js template DynamicTypeHandler* SimpleTypeHandler::ConvertToTypeWithItemAttributes(DynamicObject* instance) { - return JavascriptArray::Is(instance) ? + return JavascriptArray::IsNonES5Array(instance) ? ConvertToES5ArrayType(instance) : ConvertToDictionaryType(instance); } diff --git a/lib/Runtime/Types/SpreadArgument.cpp b/lib/Runtime/Types/SpreadArgument.cpp index 39e10212efc..ac50243db83 100644 --- a/lib/Runtime/Types/SpreadArgument.cpp +++ b/lib/Runtime/Types/SpreadArgument.cpp @@ -6,23 +6,6 @@ #include "Types/SpreadArgument.h" namespace Js { - bool SpreadArgument::Is(Var aValue) - { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_SpreadArgument; - } - - SpreadArgument* SpreadArgument::FromVar(Var aValue) - { - AssertOrFailFast(SpreadArgument::Is(aValue)); - return static_cast(aValue); - } - - SpreadArgument* SpreadArgument::UnsafeFromVar(Var aValue) - { - Assert(SpreadArgument::Is(aValue)); - return static_cast(aValue); - } - SpreadArgument::SpreadArgument(Var iterator, bool useDirectCall, DynamicType * type) : DynamicObject(type), iteratorIndices(nullptr) { @@ -32,9 +15,9 @@ namespace Js if (useDirectCall) { - if (JavascriptArray::Is(iterator)) + if (JavascriptArray::IsNonES5Array(iterator)) { - JavascriptArray *array = JavascriptArray::FromVar(iterator); + JavascriptArray *array = VarTo(iterator); if (!array->HasNoMissingValues()) { AssertAndFailFast(); @@ -56,9 +39,9 @@ namespace Js Assert(length == array->GetLength()); } } - else if (TypedArrayBase::Is(iterator)) + else if (VarIs(iterator)) { - TypedArrayBase *typedArray = TypedArrayBase::UnsafeFromVar(iterator); + TypedArrayBase *typedArray = UnsafeVarTo(iterator); if (typedArray->IsDetachedBuffer()) { @@ -84,10 +67,10 @@ namespace Js Assert(false); } } - else if (RecyclableObject::Is(iterator)) + else if (VarIs(iterator)) { Var nextItem; - while (JavascriptOperators::IteratorStepAndValue(RecyclableObject::FromVar(iterator), scriptContext, &nextItem)) + while (JavascriptOperators::IteratorStepAndValue(VarTo(iterator), scriptContext, &nextItem)) { if (iteratorIndices == nullptr) { diff --git a/lib/Runtime/Types/SpreadArgument.h b/lib/Runtime/Types/SpreadArgument.h index b2d1a0ab028..c744d091333 100644 --- a/lib/Runtime/Types/SpreadArgument.h +++ b/lib/Runtime/Types/SpreadArgument.h @@ -18,9 +18,6 @@ namespace Js DEFINE_MARSHAL_OBJECT_TO_SCRIPT_CONTEXT(SpreadArgument); public: - static bool Is(Var aValue); - static SpreadArgument* FromVar(Var value); - static SpreadArgument* UnsafeFromVar(Var value); SpreadArgument(Var iterator, bool useDirectCall, DynamicType * type); const Var* GetArgumentSpread() const { return iteratorIndices ? iteratorIndices->GetBuffer() : nullptr; } uint GetArgumentSpreadCount() const { return iteratorIndices ? iteratorIndices->Count() : 0; } @@ -73,4 +70,9 @@ namespace Js virtual BOOL GetDiagValueString(StringBuilder* stringBuilder, ScriptContext* requestContext) override { AssertAndFailFast(); return FALSE; }; virtual Var GetTypeOfString(ScriptContext * requestContext) override { AssertAndFailFast(); return RecyclableObject::GetTypeOfString(requestContext); }; }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_SpreadArgument; + } } diff --git a/lib/Runtime/Types/StaticType.cpp b/lib/Runtime/Types/StaticType.cpp index 4fa5c9616c3..b95e1b16863 100644 --- a/lib/Runtime/Types/StaticType.cpp +++ b/lib/Runtime/Types/StaticType.cpp @@ -35,7 +35,7 @@ namespace Js valueStr = scriptContext->GetIntegerString(this); break; case TypeIds_Boolean: - valueStr = JavascriptBoolean::FromVar(this)->GetValue() ? + valueStr = VarTo(this)->GetValue() ? GetLibrary()->GetTrueDisplayString() : GetLibrary()->GetFalseDisplayString(); break; @@ -43,7 +43,7 @@ namespace Js valueStr = JavascriptNumber::ToStringRadix10(JavascriptNumber::GetValue(this), scriptContext); break; case TypeIds_String: - valueStr = JavascriptString::FromVar(this); + valueStr = VarTo(this); break; default: valueStr = GetLibrary()->GetUndefinedDisplayString(); diff --git a/lib/Runtime/Types/TypeHandler.cpp b/lib/Runtime/Types/TypeHandler.cpp index f7782be93ff..45938c2d516 100644 --- a/lib/Runtime/Types/TypeHandler.cpp +++ b/lib/Runtime/Types/TypeHandler.cpp @@ -439,14 +439,14 @@ using namespace Js; LPCWSTR fixedPropertyResultType = nullptr; bool log = false; - if (pProperty && *pProperty && ((Js::JavascriptFunction::Is(*pProperty) && (PHASE_VERBOSE_TRACE1(Js::FixedMethodsPhase) || PHASE_VERBOSE_TESTTRACE1(Js::FixedMethodsPhase))) || + if (pProperty && *pProperty && ((Js::VarIs(*pProperty) && (PHASE_VERBOSE_TRACE1(Js::FixedMethodsPhase) || PHASE_VERBOSE_TESTTRACE1(Js::FixedMethodsPhase))) || ((PHASE_VERBOSE_TRACE1(Js::UseFixedDataPropsPhase) || PHASE_VERBOSE_TESTTRACE1(Js::UseFixedDataPropsPhase))) )) { if(*pProperty == nullptr) { fixedPropertyResultType = _u("null"); } - else if (Js::JavascriptFunction::Is(*pProperty)) + else if (Js::VarIs(*pProperty)) { fixedPropertyResultType = _u("function"); } diff --git a/lib/Runtime/Types/TypePropertyCache.cpp b/lib/Runtime/Types/TypePropertyCache.cpp index ab66d8a53e5..3673bdde787 100644 --- a/lib/Runtime/Types/TypePropertyCache.cpp +++ b/lib/Runtime/Types/TypePropertyCache.cpp @@ -205,8 +205,7 @@ namespace Js #if DBG const PropertyIndex typeHandlerPropertyIndex = - DynamicObject - ::FromVar(propertyObject) + VarTo(propertyObject) ->GetDynamicType() ->GetTypeHandler() ->InlineOrAuxSlotIndexToPropertyIndex(propertyIndex, isInlineSlot); @@ -221,8 +220,8 @@ namespace Js { *propertyValue = isInlineSlot - ? DynamicObject::FromVar(propertyObject)->GetInlineSlot(propertyIndex) - : DynamicObject::FromVar(propertyObject)->GetAuxSlot(propertyIndex); + ? VarTo(propertyObject)->GetInlineSlot(propertyIndex) + : VarTo(propertyObject)->GetAuxSlot(propertyIndex); } if(propertyObject->GetScriptContext() == requestContext) @@ -236,7 +235,7 @@ namespace Js CacheOperators::Cache( false, - DynamicObject::FromVar(propertyObject), + VarTo(propertyObject), false, propertyObject->GetType(), nullptr, @@ -402,8 +401,7 @@ namespace Js #endif Assert( ( - DynamicObject - ::FromVar(object) + VarTo(object) ->GetDynamicType() ->GetTypeHandler() ->InlineOrAuxSlotIndexToPropertyIndex(propertyIndex, isInlineSlot) @@ -418,18 +416,18 @@ namespace Js if(isInlineSlot) { - DynamicObject::FromVar(object)->SetInlineSlot(SetSlotArguments(propertyId, propertyIndex, propertyValue)); + VarTo(object)->SetInlineSlot(SetSlotArguments(propertyId, propertyIndex, propertyValue)); } else { - DynamicObject::FromVar(object)->SetAuxSlot(SetSlotArguments(propertyId, propertyIndex, propertyValue)); + VarTo(object)->SetAuxSlot(SetSlotArguments(propertyId, propertyIndex, propertyValue)); } if(objectScriptContext == requestContext) { CacheOperators::Cache( false, - DynamicObject::FromVar(object), + VarTo(object), false, object->GetType(), nullptr, diff --git a/lib/Runtime/Types/WithScopeObject.cpp b/lib/Runtime/Types/WithScopeObject.cpp index ad0d8c094a0..cc1b8794bfd 100644 --- a/lib/Runtime/Types/WithScopeObject.cpp +++ b/lib/Runtime/Types/WithScopeObject.cpp @@ -6,23 +6,6 @@ namespace Js { - bool WithScopeObject::Is(Var aValue) - { - return JavascriptOperators::GetTypeId(aValue) == TypeIds_WithScopeObject; - } - - WithScopeObject* WithScopeObject::FromVar(Var aValue) - { - AssertOrFailFast(WithScopeObject::Is(aValue)); - return static_cast(aValue); - } - - WithScopeObject* WithScopeObject::UnsafeFromVar(Var aValue) - { - Assert(WithScopeObject::Is(aValue)); - return static_cast(aValue); - } - PropertyQueryFlags WithScopeObject::HasPropertyQuery(PropertyId propertyId, _Inout_opt_ PropertyValueInfo* info) { return JavascriptConversion::BooleanToPropertyQueryFlags(JavascriptOperators::HasPropertyUnscopables(wrappedObject, propertyId)); diff --git a/lib/Runtime/Types/WithScopeObject.h b/lib/Runtime/Types/WithScopeObject.h index f616c8d0e36..ae113f6a2bf 100644 --- a/lib/Runtime/Types/WithScopeObject.h +++ b/lib/Runtime/Types/WithScopeObject.h @@ -25,9 +25,6 @@ namespace Js public: WithScopeObject(RecyclableObject *wrappedObject, StaticType * type) : RecyclableObject(type), wrappedObject(wrappedObject) {} - static bool Is(Var aValue); - static WithScopeObject* FromVar(Var value); - static WithScopeObject* UnsafeFromVar(Var value); RecyclableObject *GetWrappedObject() { return wrappedObject; } virtual PropertyQueryFlags HasPropertyQuery(PropertyId propertyId, _Inout_opt_ PropertyValueInfo* info) override; virtual BOOL HasOwnProperty(PropertyId propertyId) override; @@ -77,4 +74,9 @@ namespace Js virtual BOOL GetDiagValueString(StringBuilder* stringBuilder, ScriptContext* requestContext) override { UNWRAP_FAILFAST(); return FALSE; }; virtual Var GetTypeOfString(ScriptContext * requestContext) override { UNWRAP_FAILFAST(); return RecyclableObject::GetTypeOfString(requestContext); }; }; + + template <> inline bool VarIsImpl(RecyclableObject* obj) + { + return JavascriptOperators::GetTypeId(obj) == TypeIds_WithScopeObject; + } } // namespace Js