ArenaLiteralString* ArenaLiteralString::New(StaticType* type, const char16* content, charcount_t charLength, Recycler* recycler) { return RecyclerNew(recycler, ArenaLiteralString, type, content, charLength); }
void ModuleNamespace::Initialize() { ScriptContext* scriptContext = moduleRecord->GetRealm()->GetScriptContext(); Recycler* recycler = scriptContext->GetRecycler(); SourceTextModuleRecord* sourceTextModuleRecord = static_cast<SourceTextModuleRecord*>(moduleRecord); JavascriptLibrary* library = GetLibrary(); if (scriptContext->GetConfig()->IsES6ToStringTagEnabled()) { DynamicObject::SetPropertyWithAttributes(PropertyIds::_symbolToStringTag, library->GetModuleTypeDisplayString(), PropertyConfigurable, nullptr); } DynamicType* type = library->CreateFunctionWithLengthType(&EntryInfo::SymbolIterator); RuntimeFunction* iteratorFunction = RecyclerNewEnumClass(scriptContext->GetRecycler(), library->EnumFunctionClass, RuntimeFunction, type, &EntryInfo::SymbolIterator); DynamicObject::SetPropertyWithAttributes(PropertyIds::_symbolIterator, iteratorFunction, PropertyBuiltInMethodDefaults, nullptr); ModuleImportOrExportEntryList* localExportList = sourceTextModuleRecord->GetLocalExportEntryList(); // We don't have a type handler that can handle ModuleNamespace object. We have properties that could be aliased // like {export foo as foo1, foo2, foo3}, and external properties as reexport from current module. The problem with aliasing // is that multiple propertyId can be associated with one slotIndex. We need to build from PropertyMap directly here. // there is one instance of ModuleNamespace per module file; we can always use the BigPropertyIndex for security. propertyMap = RecyclerNew(recycler, SimplePropertyDescriptorMap, recycler, sourceTextModuleRecord->GetLocalExportCount()); if (localExportList != nullptr) { localExportList->Map([=](ModuleImportOrExportEntry exportEntry) { PropertyId exportNameId = exportEntry.exportName->GetPropertyId(); PropertyId localNameId = exportEntry.localName->GetPropertyId(); const Js::PropertyRecord* exportNameRecord = scriptContext->GetThreadContext()->GetPropertyName(exportNameId); ModuleNameRecord* importRecord = nullptr; AssertMsg(exportNameId != Js::Constants::NoProperty, "should have been initialized already"); // ignore local exports that are actually indirect exports. if (sourceTextModuleRecord->GetImportEntryList() == nullptr || (sourceTextModuleRecord->ResolveImport(localNameId, &importRecord) && importRecord == nullptr)) { BigPropertyIndex index = sourceTextModuleRecord->GetLocalExportSlotIndexByExportName(exportNameId); Assert((uint)index < sourceTextModuleRecord->GetLocalExportCount()); SimpleDictionaryPropertyDescriptor<BigPropertyIndex> propertyDescriptor = { index, PropertyModuleNamespaceDefault }; propertyMap->Add(exportNameRecord, propertyDescriptor); } }); } // update the local slot to use the storage for local exports. SetNSSlotsForModuleNS(sourceTextModuleRecord->GetLocalExportSlots()); // For items that are not in the local export list, we need to resolve them to get it ExportedNames* exportedNames = sourceTextModuleRecord->GetExportedNames(nullptr); ModuleNameRecord* moduleNameRecord = nullptr; #if DBG uint unresolvableExportsCount = 0; uint localExportCount = 0; #endif if (exportedNames != nullptr) { exportedNames->Map([&](PropertyId propertyId) { if (!moduleRecord->ResolveExport(propertyId, nullptr, nullptr, &moduleNameRecord)) { // ignore ambigious resolution. #if DBG unresolvableExportsCount++; #endif return; } // non-ambiguous resolution. if (moduleNameRecord == nullptr) { JavascriptError::ThrowSyntaxError(scriptContext, JSERR_ResolveExportFailed, scriptContext->GetPropertyName(propertyId)->GetBuffer()); } if (moduleNameRecord->module == moduleRecord) { // skip local exports as they are covered in the localExportSlots. #if DBG localExportCount++; #endif return; } Assert(moduleNameRecord->module != moduleRecord); this->AddUnambiguousNonLocalExport(propertyId, moduleNameRecord); }); } #if DBG uint totalExportCount = exportedNames != nullptr ? exportedNames->Count() : 0; uint unambiguousNonLocalCount = (this->GetUnambiguousNonLocalExports() != nullptr) ? this->GetUnambiguousNonLocalExports()->Count() : 0; Assert(totalExportCount == localExportCount + unambiguousNonLocalCount + unresolvableExportsCount); #endif BOOL result = this->PreventExtensions(); Assert(result); }
StaticType * StaticType::New(ScriptContext* scriptContext, TypeId typeId, RecyclableObject* prototype, JavascriptMethod entryPoint) { return RecyclerNew(scriptContext->GetRecycler(), StaticType, scriptContext, typeId, prototype, entryPoint); }
LiteralString* LiteralString::CreateEmptyString(StaticType* type) { return RecyclerNew(type->GetScriptContext()->GetRecycler(), LiteralString, type, _u(""), 0); }
DynamicType* DynamicObject::DuplicateType() { return RecyclerNew(GetRecycler(), DynamicType, this->GetDynamicType()); }
BOOL JavascriptStringObject::GetEnumerator(BOOL enumNonEnumerable, Var* enumerator, ScriptContext * requestContext, bool preferSnapshotSemantics, bool enumSymbols) { *enumerator = RecyclerNew(GetScriptContext()->GetRecycler(), JavascriptStringObjectEnumerator, this, requestContext, enumNonEnumerable, enumSymbols); return true; }
bfi->ArgArray[i] = this->boundArgs[i]; //Primitive kinds always inflated first so we only need to deal with complex kinds as depends on if(TTD::JsSupport::IsVarComplexKind(this->boundArgs[i])) { depArray[depCount] = TTD_CONVERT_VAR_TO_PTR_ID(this->boundArgs[i]); depCount++; } } } alloc.SlabCommitArraySpace<TTD_PTR_ID>(depCount, depCount + bfi->ArgCount); TTD::NSSnapObjects::StdExtractSetKindSpecificInfo<TTD::NSSnapObjects::SnapBoundFunctionInfo*, TTD::NSSnapObjects::SnapObjectType::SnapBoundFunctionObject>(objData, bfi, alloc, depCount, depArray); } BoundFunction* BoundFunction::InflateBoundFunction( ScriptContext* ctx, RecyclableObject* function, Var bThis, uint32 ct, Field(Var)* args) { BoundFunction* res = RecyclerNew(ctx->GetRecycler(), BoundFunction, ctx->GetLibrary()->GetBoundFunctionType()); res->boundThis = bThis; res->count = ct; res->boundArgs = args; res->targetFunction = function; return res; } #endif } // namespace Js
// // Create scope info for a deferred child to refer to its parent ParseableFunctionInfo. // ScopeInfo* ScopeInfo::FromParent(FunctionBody* parent) { return RecyclerNew(parent->GetScriptContext()->GetRecycler(), // Alloc with ParseableFunctionInfo ScopeInfo, parent, 0); }
Js::DynamicType* JsrtExternalObject::DuplicateType() { return RecyclerNew(this->GetScriptContext()->GetRecycler(), JsrtExternalType, this->GetExternalType()); }
ConcatStringBuilder* ConcatStringBuilder::New(ScriptContext* scriptContext, int initialSlotCount) { Assert(scriptContext); return RecyclerNew(scriptContext->GetRecycler(), ConcatStringBuilder, scriptContext, initialSlotCount); }
DynamicType * DynamicType::New(ScriptContext* scriptContext, TypeId typeId, RecyclableObject* prototype, JavascriptMethod entryPoint, DynamicTypeHandler * typeHandler, bool isLocked, bool isShared) { return RecyclerNew(scriptContext->GetRecycler(), DynamicType, scriptContext, typeId, prototype, entryPoint, typeHandler, isLocked, isShared); }
ThrowErrorObject* ThrowErrorObject::New(StaticType* type, JavascriptError* error, Recycler* recycler) { return RecyclerNew(recycler, ThrowErrorObject, type, error); }
JavascriptEnumerator * ES5Array::GetIndexEnumerator(EnumeratorFlags flags, ScriptContext* requestContext) { // ES5Array does not support compat mode, ignore preferSnapshotSemantics return RecyclerNew(GetScriptContext()->GetRecycler(), ES5ArrayIndexEnumerator, this, flags, requestContext); }
DynamicType* ES5Array::DuplicateType() { return RecyclerNew(GetScriptContext()->GetRecycler(), ES5ArrayType, this->GetDynamicType()); }
Var JavascriptMap::NewInstance(RecyclableObject* function, CallInfo callInfo, ...) { PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault); ARGUMENTS(args, callInfo); ScriptContext* scriptContext = function->GetScriptContext(); JavascriptLibrary* library = scriptContext->GetLibrary(); AUTO_TAG_NATIVE_LIBRARY_ENTRY(function, callInfo, _u("Map")); Var newTarget = callInfo.Flags & CallFlags_NewTarget ? args.Values[args.Info.Count] : args[0]; bool isCtorSuperCall = (callInfo.Flags & CallFlags_New) && newTarget != nullptr && !JavascriptOperators::IsUndefined(newTarget); Assert(isCtorSuperCall || !(callInfo.Flags & CallFlags_New) || args[0] == nullptr); CHAKRATEL_LANGSTATS_INC_BUILTINCOUNT(MapCount); JavascriptMap* mapObject = nullptr; if (callInfo.Flags & CallFlags_New) { mapObject = library->CreateMap(); } else { JavascriptError::ThrowTypeErrorVar(scriptContext, JSERR_NeedObjectOfType, _u("Map"), _u("Map")); } Assert(mapObject != nullptr); Var iterable = (args.Info.Count > 1) ? args[1] : library->GetUndefined(); RecyclableObject* iter = nullptr; RecyclableObject* adder = nullptr; if (JavascriptConversion::CheckObjectCoercible(iterable, scriptContext)) { iter = JavascriptOperators::GetIterator(iterable, scriptContext); Var adderVar = JavascriptOperators::GetProperty(mapObject, PropertyIds::set, scriptContext); if (!JavascriptConversion::IsCallable(adderVar)) { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedFunction); } adder = RecyclableObject::FromVar(adderVar); } if (mapObject->map != nullptr) { JavascriptError::ThrowTypeErrorVar(scriptContext, JSERR_ObjectIsAlreadyInitialized, _u("Map"), _u("Map")); } mapObject->map = RecyclerNew(scriptContext->GetRecycler(), MapDataMap, scriptContext->GetRecycler()); if (iter != nullptr) { Var undefined = library->GetUndefined(); JavascriptOperators::DoIteratorStepAndValue(iter, scriptContext, [&](Var nextItem) { if (!JavascriptOperators::IsObject(nextItem)) { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedObject); } RecyclableObject* obj = RecyclableObject::FromVar(nextItem); Var key, value; if (!JavascriptOperators::GetItem(obj, 0u, &key, scriptContext)) { key = undefined; } if (!JavascriptOperators::GetItem(obj, 1u, &value, scriptContext)) { value = undefined; } // CONSIDER: if adder is the default built-in, fast path it and skip the JS call? CALL_FUNCTION(adder, CallInfo(CallFlags_Value, 3), mapObject, key, value); }); } return isCtorSuperCall ? JavascriptOperators::OrdinaryCreateFromConstructor(RecyclableObject::FromVar(newTarget), mapObject, nullptr, scriptContext) : mapObject; }