DynamicObject * DynamicObject::BoxStackInstance(DynamicObject * instance) { Assert(ThreadContext::IsOnStack(instance)); // On the stack, the we reserved a pointer before the object as to store the boxed value DynamicObject ** boxedInstanceRef = ((DynamicObject **)instance) - 1; DynamicObject * boxedInstance = *boxedInstanceRef; if (boxedInstance) { return boxedInstance; } size_t inlineSlotsSize = instance->GetTypeHandler()->GetInlineSlotsSize(); if (inlineSlotsSize) { boxedInstance = RecyclerNewPlusZ(instance->GetRecycler(), inlineSlotsSize, DynamicObject, instance); } else { boxedInstance = RecyclerNew(instance->GetRecycler(), DynamicObject, instance); } *boxedInstanceRef = boxedInstance; return boxedInstance; }
// // Create scope info for an outer scope. // ScopeInfo* ScopeInfo::FromScope(ByteCodeGenerator* byteCodeGenerator, FunctionBody* parent, Scope* scope, ScriptContext *scriptContext) { int count = scope->Count(); // Add argsPlaceHolder which includes same name args and destructuring patterns on parameters AddSlotCount(count, scope->GetFunc()->argsPlaceHolderSlotCount); AddSlotCount(count, scope->GetFunc()->thisScopeSlot != Js::Constants::NoRegister ? 1 : 0); AddSlotCount(count, scope->GetFunc()->newTargetScopeSlot != Js::Constants::NoRegister ? 1 : 0); ScopeInfo* scopeInfo = RecyclerNewPlusZ(scriptContext->GetRecycler(), count * sizeof(SymbolInfo), ScopeInfo, parent, count); scopeInfo->isDynamic = scope->GetIsDynamic(); scopeInfo->isObject = scope->GetIsObject(); scopeInfo->mustInstantiate = scope->GetMustInstantiate(); scopeInfo->isCached = (scope->GetFunc()->GetBodyScope() == scope) && scope->GetFunc()->GetHasCachedScope(); scopeInfo->isGlobalEval = scope->GetScopeType() == ScopeType_GlobalEvalBlock; scopeInfo->canMergeWithBodyScope = scope->GetCanMergeWithBodyScope(); scopeInfo->hasLocalInClosure = scope->GetHasOwnLocalInClosure(); TRACE_BYTECODE(_u("\nSave ScopeInfo: %s parent: %s #symbols: %d %s\n"), scope->GetFunc()->name, parent->GetDisplayName(), count, scopeInfo->isObject ? _u("isObject") : _u("")); MapSymbolData mapSymbolData = { byteCodeGenerator, scope->GetFunc() }; scope->ForEachSymbol([&mapSymbolData, scopeInfo, scope](Symbol * sym) { Assert(scope == sym->GetScope()); scopeInfo->SaveSymbolInfo(sym, &mapSymbolData); }); return scopeInfo; }
// // Clone a ScopeInfo object // ScopeInfo *ScopeInfo::CloneFor(ParseableFunctionInfo *body) { auto count = this->symbolCount; auto symbolsSize = count * sizeof(SymbolInfo); auto scopeInfo = RecyclerNewPlusZ(parent->GetScriptContext()->GetRecycler(), symbolsSize, ScopeInfo, parent, count); scopeInfo->isDynamic = this->isDynamic; scopeInfo->isObject = this->isObject; scopeInfo->mustInstantiate = this->mustInstantiate; scopeInfo->isCached = this->isCached; scopeInfo->isGlobalEval = this->isGlobalEval; if (funcExprScopeInfo) { scopeInfo->funcExprScopeInfo = funcExprScopeInfo->CloneFor(body); } if (paramScopeInfo) { scopeInfo->paramScopeInfo = paramScopeInfo->CloneFor(body); } memcpy_s(scopeInfo->symbols, symbolsSize, this->symbols, symbolsSize); return scopeInfo; }
PropertyString* PropertyString::New(StaticType* type, const Js::PropertyRecord* propertyRecord, Recycler *recycler) { PropertyString * propertyString = RecyclerNewPlusZ(recycler, sizeof(PropertyCache), PropertyString, type, propertyRecord); propertyString->propCache = (PropertyCache*)(propertyString + 1); return propertyString; }