Пример #1
0
 BOOL JavascriptBoolean::GetDiagValueString(StringBuilder<ArenaAllocator>* stringBuilder, ScriptContext* requestContext)
 {
     if (this->GetValue())
     {
         JavascriptString* trueDisplayString = GetLibrary()->GetTrueDisplayString();
         stringBuilder->Append(trueDisplayString->GetString(), trueDisplayString->GetLength());
     }
     else
     {
         JavascriptString* falseDisplayString = GetLibrary()->GetFalseDisplayString();
         stringBuilder->Append(falseDisplayString->GetString(), falseDisplayString->GetLength());
     }
     return TRUE;
 }
void CProjectWizardData::UseDefaultLibraries ()
{
	int i;

    for (i = 0; i < GetLibraryCount (); ++i)
        UseLibrary (i, (GetLibrary (i)->GetSubSystemDefault () & m_subSystems) != 0);
}
Пример #3
0
void
Library::Finalize(JSContext* cx, JSObject* obj)
{
  // unload the library
  PRLibrary* library = GetLibrary(cx, obj);
  if (library)
    PR_UnloadLibrary(library);
}
Пример #4
0
    Var ES5ArrayEnumerator::GetCurrentValue()
    {
        if (!doneArray && index != JavascriptArray::InvalidIndex)
        {
            Var element;
            if (arrayObject->GetItem(originalInstance, index, &element, GetScriptContext()))
            {
                return element;
            }
            return GetLibrary()->GetUndefined();
        }
        else if (!doneObject)
        {
            return objectEnumerator->GetCurrentValue();
        }

        return GetLibrary()->GetUndefined();
    }
nsresult
sbLocalDatabaseMediaListBase::GetFilteredPropertiesForNewItem(sbIPropertyArray* aProperties,
                                                              sbIPropertyArray** _retval)
{
  NS_ASSERTION(aProperties, "aProperties is null");
  NS_ASSERTION(_retval, "_retval is null");

  nsresult rv;
  nsCOMPtr<sbIMutablePropertyArray> mutableArray =
    do_CreateInstance(SB_MUTABLEPROPERTYARRAY_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<sbILibrary> library;
  rv = GetLibrary(getter_AddRefs(library));
  NS_ENSURE_SUCCESS(rv, rv);

  PRBool hasContentType = PR_FALSE;
  PRUint32 length;
  rv = aProperties->GetLength(&length);
  NS_ENSURE_SUCCESS(rv, rv);

  for (PRUint32 i = 0; i < length; i++) {
    nsCOMPtr<sbIProperty> property;
    rv = aProperties->GetPropertyAt(i, getter_AddRefs(property));
    NS_ENSURE_SUCCESS(rv, rv);

    nsString id;
    rv = property->GetId(id);
    NS_ENSURE_SUCCESS(rv, rv);

    // We never want these properties to be copied to a new item.
    if (mFilteredProperties.GetEntry(id)) {
      continue;
    }

    nsString value;
    rv = property->GetValue(value);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = mutableArray->AppendProperty(id, value);
    NS_ENSURE_SUCCESS(rv, rv);

    if (id.EqualsLiteral(SB_PROPERTY_CONTENTTYPE)) {
      hasContentType = PR_TRUE;
    }
  }

  if (!hasContentType) {
    // no content type given; assume audio
    rv = mutableArray->AppendProperty(NS_LITERAL_STRING(SB_PROPERTY_CONTENTTYPE),
                                      NS_LITERAL_STRING("audio"));
  }

  NS_ADDREF(*_retval = mutableArray);
  return NS_OK;
}
Пример #6
0
CStdString OfflineDocIDResolver::GetOnlineLibrary( const CStdString& sDocID, const CStdString &sOfflineLibrary) const
{
    CStdString sOfflineLib = _T("_") + sOfflineLibrary;
    CStdString sLib = GetLibrary(sDocID);
    sLib.MakeLower();
    sOfflineLib.MakeLower();
    sLib.Replace(sOfflineLib, _T(""));

    return sLib;
}
 Var ModuleNamespace::GetNextProperty(BigPropertyIndex& index)
 {
     PropertyId propertyId;
     Var result = GetLibrary()->GetUndefined();
     BOOL retVal = FALSE;
     if (this->FindNextProperty(index, nullptr, &propertyId, nullptr))
     {
         retVal = this->GetProperty(this, propertyId, &result, nullptr, GetScriptContext());
         Assert(retVal);
     }
     return result;
 }
Пример #8
0
 JavascriptString* BoundFunction::GetDisplayNameImpl() const
 {
     JavascriptString* displayName = GetLibrary()->GetEmptyString();
     if (targetFunction != nullptr)
     {
         Var value = JavascriptOperators::GetProperty(targetFunction, PropertyIds::name, targetFunction->GetScriptContext());
         if (JavascriptString::Is(value))
         {
             displayName = JavascriptString::FromVar(value);
         }
     }
     return LiteralString::Concat(LiteralString::NewCopySz(_u("bound "), this->GetScriptContext()), displayName);
 }
Пример #9
0
void ColladaObject::GetProgramElement(VECPROGRAMELEM& vecProgram) const
{
	VECLIBRARYELEM vecLib;
	GetLibrary( vecLib, LibraryElement::TYPE_PROGRAM );

	for( VECLIBRARYELEM::const_iterator it = vecLib.begin(); it != vecLib.end(); ++it )
	{
		for( unsigned int i = 0;  i < (*it)->GetCount(); i++ )
		{
			vecProgram.push_back( (ProgramElement*)(*it)->GetElement( i ) );
		}
	}
}
Пример #10
0
void ColladaObject::GetMaterialElement(VECMATERIALELEM& vecMaterial) const
{
	VECLIBRARYELEM vecLib;
	GetLibrary( vecLib, LibraryElement::TYPE_MATERIAL );

	for( VECLIBRARYELEM::const_iterator it = vecLib.begin(); it != vecLib.end(); ++it )
	{
		for( unsigned int i = 0;  i < (*it)->GetCount(); i++ )
		{
			vecMaterial.push_back( (MaterialElement*)(*it)->GetElement( i ) );
		}
	}
}
Пример #11
0
void ColladaObject::GetLightElement(VECLIGHTELEM& vecLight) const
{
	VECLIBRARYELEM vecLib;
	GetLibrary( vecLib, LibraryElement::TYPE_LIGHT );

	for( VECLIBRARYELEM::const_iterator it = vecLib.begin(); it != vecLib.end(); ++it )
	{
		for( unsigned int i = 0;  i < (*it)->GetCount(); i++ )
		{
			vecLight.push_back( (LightElement*)(*it)->GetElement( i ) );
		}
	}
}
Пример #12
0
void ColladaObject::GetControllerElement(VECCONTROLLERELEM& vecController) const
{
	VECLIBRARYELEM vecLib;
	GetLibrary( vecLib, LibraryElement::TYPE_CONTROLLER );

	for( VECLIBRARYELEM::const_iterator it = vecLib.begin(); it != vecLib.end(); ++it )
	{
		for( unsigned int i = 0;  i < (*it)->GetCount(); i++ )
		{
			vecController.push_back( (ControllerElement*)(*it)->GetElement( i ) );
		}
	}
}
Пример #13
0
void ColladaObject::GetAnimationElement(VECANIMATIONELEM& vecAnimation) const
{
	VECLIBRARYELEM vecLib;
	GetLibrary( vecLib, LibraryElement::TYPE_ANIMATION );

	for( VECLIBRARYELEM::const_iterator it = vecLib.begin(); it != vecLib.end(); ++it )
	{
		for( unsigned int i = 0; i < (*it)->GetCount(); i++ )
		{
			vecAnimation.push_back( (AnimationElement*)(*it)->GetElement( i ) );
		}
	}
}
Пример #14
0
    Var ES5ArrayEnumerator::GetCurrentIndex()
    {
        if (!doneArray && index != JavascriptArray::InvalidIndex)
        {
            return arrayObject->GetScriptContext()->GetIntegerString(index);
        }
        else if (!doneObject)
        {
            return objectEnumerator->GetCurrentIndex();
        }

        return GetLibrary()->GetUndefined();
    }
Пример #15
0
void ColladaObject::GetTextureElement(VECTEXTUREELEM& vecTexture) const
{
	VECLIBRARYELEM vecLib;
	GetLibrary( vecLib, LibraryElement::TYPE_TEXTURE );

	for( VECLIBRARYELEM::const_iterator it = vecLib.begin(); it != vecLib.end(); ++it )
	{
		for( unsigned int i = 0;  i < (*it)->GetCount(); i++ )
		{
			vecTexture.push_back( (TextureElement*)(*it)->GetElement( i ) );
		}
	}
}
    JavascriptStringObject::JavascriptStringObject(JavascriptString* value, DynamicType * type)
        : DynamicObject(type), value(value)
    {
        Assert(type->GetTypeId() == TypeIds_StringObject);

        this->GetTypeHandler()->ClearHasOnlyWritableDataProperties(); // length is non-writable
        if(GetTypeHandler()->GetFlags() & DynamicTypeHandler::IsPrototypeFlag)
        {
            // No need to invalidate store field caches for non-writable properties here. Since this type is just being created, it cannot represent
            // an object that is already a prototype. If it becomes a prototype and then we attempt to add a property to an object derived from this
            // object, then we will check if this property is writable, and only if it is will we do the fast path for add property.
            GetLibrary()->GetTypesWithOnlyWritablePropertyProtoChainCache()->Clear();
        }
    }
Пример #17
0
    BOOL RecyclableObject::GetDiagValueString(StringBuilder<ArenaAllocator>* stringBuilder, ScriptContext* requestContext)
    {
        ENTER_PINNED_SCOPE(JavascriptString, valueStr);
        ScriptContext *scriptContext = GetScriptContext();

        switch(GetTypeId())
        {
        case TypeIds_Undefined:
            valueStr = GetLibrary()->GetUndefinedDisplayString();
            break;
        case TypeIds_Null:
            valueStr = GetLibrary()->GetNullDisplayString();
            break;
        case TypeIds_Integer:
            valueStr = scriptContext->GetIntegerString(this);
            break;
        case TypeIds_Boolean:
            valueStr = JavascriptBoolean::FromVar(this)->GetValue() ?
                           GetLibrary()->GetTrueDisplayString()
                         : GetLibrary()->GetFalseDisplayString();
            break;
        case TypeIds_Number:
            valueStr = JavascriptNumber::ToStringRadix10(JavascriptNumber::GetValue(this), scriptContext);
            break;
        case TypeIds_String:
            valueStr = JavascriptString::FromVar(this);
            break;
        default:
            valueStr = GetLibrary()->GetUndefinedDisplayString();
        }

        stringBuilder->Append(valueStr->GetString(), valueStr->GetLength());

        LEAVE_PINNED_SCOPE();

        return TRUE;
    }
Пример #18
0
bool JniInvocation::Init(const char* library) {
#ifdef __ANDROID__
  char buffer[PROPERTY_VALUE_MAX];
#else
  char* buffer = NULL;
#endif
  library = GetLibrary(library, buffer);

  handle_ = dlopen(library, RTLD_NOW);
  if (handle_ == NULL) {
    if (strcmp(library, kLibraryFallback) == 0) {
      // Nothing else to try.
      ALOGE("Failed to dlopen %s: %s", library, dlerror());
      return false;
    }
    // Note that this is enough to get something like the zygote
    // running, we can't property_set here to fix this for the future
    // because we are root and not the system user. See
    // RuntimeInit.commonInit for where we fix up the property to
    // avoid future fallbacks. http://b/11463182
    ALOGW("Falling back from %s to %s after dlopen error: %s",
          library, kLibraryFallback, dlerror());
    library = kLibraryFallback;
    handle_ = dlopen(library, RTLD_NOW);
    if (handle_ == NULL) {
      ALOGE("Failed to dlopen %s: %s", library, dlerror());
      return false;
    }
  }
  if (!FindSymbol(reinterpret_cast<void**>(&JNI_GetDefaultJavaVMInitArgs_),
                  "JNI_GetDefaultJavaVMInitArgs")) {
    return false;
  }
  if (!FindSymbol(reinterpret_cast<void**>(&JNI_CreateJavaVM_),
                  "JNI_CreateJavaVM")) {
    return false;
  }
  if (!FindSymbol(reinterpret_cast<void**>(&JNI_GetCreatedJavaVMs_),
                  "JNI_GetCreatedJavaVMs")) {
    return false;
  }
  return true;
}
 // enumeration order: symbol first; local exports next; nonlocal exports last.
 Var ModuleNamespaceEnumerator::MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes)
 {
     Var undefined = GetLibrary()->GetUndefined();
     Var result = undefined;
     if (attributes != nullptr)
     {
         // all the attribute should have the same setting here in namespace object.
         *attributes = PropertyModuleNamespaceDefault;
     }
     if (!doneWithSymbol)
     {
         result = symbolEnumerator.MoveAndGetNext(propertyId, attributes);
         if (result == nullptr)
         {
             doneWithSymbol = true;
         }
         else
         {
             return result;
         }
     }
     if (!this->doneWithLocalExports)
     {
         currentLocalMapIndex++;
         JavascriptString* propertyString = nullptr;
         if (!nsObject->FindNextProperty(currentLocalMapIndex, &propertyString, &propertyId, attributes, this->GetScriptContext()))
         {
             // we are done with the object part; 
             this->doneWithLocalExports = true;
         }
         else
         {
             return propertyString;
         }
     }
     if (this->nonLocalMap != nullptr && (currentNonLocalMapIndex + 1 < nonLocalMap->Count()))
     {
         currentNonLocalMapIndex++;
         result = this->GetScriptContext()->GetPropertyString(this->nonLocalMap->GetKeyAt(currentNonLocalMapIndex));
         return result;
     }
     return nullptr;
 }
Пример #20
0
STDAPI GetRealProcAddress(LPCSTR pwszProcName, VOID** ppv)
{
    if(!ppv) 
    { 
        return E_POINTER; 
    } 

    HMODULE hLib = GetLibrary(LIB_mscorwks);
    if(hLib == NULL)
    {
        return HRESULT_FROM_GetLastError();
    }

    *ppv = (void*) GetProcAddress(hLib,pwszProcName);
    if(*ppv == NULL)
    {
        return HRESULT_FROM_GetLastError();
    }
    return S_OK;
}
Пример #21
0
ISystemModule *SystemWrapper::GetModule(char *interfacename, char *library, char *instancename)
{
	ISystemModule *module = FindModule(interfacename, instancename);
	if (module) {
		return module;
	}

	library_t *lib = GetLibrary(library);
	if (!lib) {
		return nullptr;
	}

	module = (ISystemModule *)lib->createInterfaceFn(interfacename, nullptr);
	if (!module) {
		DPrintf("ERROR! System::GetModule: interface \"%s\" not found in library %s.\n", interfacename, lib->name);
		return nullptr;
	}

	AddModule(module, instancename);
	return module;
}
Пример #22
0
CStdString OfflineDocIDResolver::ResolveToOfflineDocID(const CStdString &sDocID) const
{
    CStdString sDocNum  = GetDocNum( sDocID );
    CStdString sVersion = GetVersion( sDocID );
    CStdString sLibrary = GetLibrary( sDocID );

    CStdString sOfflineDocNum;
    CStdString sOfflineLibrary;

    if(!GetOfflineDocumentInfo(GetLibraryToSearch(sDocID), sDocNum, sOfflineDocNum, sOfflineLibrary))
        return sDocID;

    CStdString sNewDocID(_T("powerdocs://"));
    sNewDocID += sLibrary;
    sNewDocID += _T("_");
    sNewDocID += sOfflineLibrary;
    sNewDocID += _T("/") + sOfflineDocNum;
    sNewDocID += _T("/") + sVersion;

    return sNewDocID;
}
Пример #23
0
    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);
    }
Пример #24
0
 Recycler *
 Type::GetRecycler() const
 {
     return GetLibrary()->GetRecycler();
 }
Пример #25
0
 ScriptContext *
 Type::GetScriptContext() const
 {
     return GetLibrary()->GetScriptContext();
 }
Пример #26
0
    PolymorphicInlineCache * PropertyString::CreateBiggerPolymorphicInlineCache(bool isLdElem)
    {
        PolymorphicInlineCache * polymorphicInlineCache = isLdElem ? GetLdElemInlineCache() : GetStElemInlineCache();
        Assert(polymorphicInlineCache && polymorphicInlineCache->CanAllocateBigger());
        uint16 polymorphicInlineCacheSize = polymorphicInlineCache->GetSize();
        uint16 newPolymorphicInlineCacheSize = PolymorphicInlineCache::GetNextSize(polymorphicInlineCacheSize);
        Assert(newPolymorphicInlineCacheSize > polymorphicInlineCacheSize);
        PolymorphicInlineCache * newPolymorphicInlineCache = ScriptContextPolymorphicInlineCache::New(newPolymorphicInlineCacheSize, GetLibrary());
        polymorphicInlineCache->CopyTo(this->propertyRecord->GetPropertyId(), GetScriptContext(), newPolymorphicInlineCache);
        if (isLdElem)
        {
            this->ldElemInlineCache = newPolymorphicInlineCache;
        }
        else
        {
            this->stElemInlineCache = newPolymorphicInlineCache;
        }
#ifdef ENABLE_DEBUG_CONFIG_OPTIONS
        if (PHASE_VERBOSE_TRACE1(Js::PolymorphicInlineCachePhase) || PHASE_TRACE1(PropertyStringCachePhase))
        {
            Output::Print(_u("PropertyString '%s' : Bigger PIC, oldSize = %d, newSize = %d\n"), GetString(), polymorphicInlineCacheSize, newPolymorphicInlineCacheSize);
        }
#endif
        return newPolymorphicInlineCache;
    }
void CProjectWizardData::UseLibrary (int i, bool bUse)
{
    GetLibrary (i)->SetSelectFlag (bUse);
}
Пример #28
0
JSBool
Library::Declare(JSContext* cx, uintN argc, jsval* vp)
{
  JSObject* obj = JS_THIS_OBJECT(cx, vp);
  if (!obj || !IsLibrary(cx, obj)) {
    JS_ReportError(cx, "not a library");
    return JS_FALSE;
  }

  PRLibrary* library = GetLibrary(cx, obj);
  if (!library) {
    JS_ReportError(cx, "library not open");
    return JS_FALSE;
  }

  // We allow two API variants:
  // 1) library.declare(name, abi, returnType, argType1, ...)
  //    declares a function with the given properties, and resolves the symbol
  //    address in the library.
  // 2) library.declare(name, type)
  //    declares a symbol of 'type', and resolves it. The object that comes
  //    back will be of type 'type', and will point into the symbol data.
  //    This data will be both readable and writable via the usual CData
  //    accessors. If 'type' is a PointerType to a FunctionType, the result will
  //    be a function pointer, as with 1). 
  if (argc < 2) {
    JS_ReportError(cx, "declare requires at least two arguments");
    return JS_FALSE;
  }

  jsval* argv = JS_ARGV(cx, vp);
  if (!JSVAL_IS_STRING(argv[0])) {
    JS_ReportError(cx, "first argument must be a string");
    return JS_FALSE;
  }

  JSObject* fnObj = NULL;
  JSObject* typeObj;
  js::AutoObjectRooter root(cx);
  bool isFunction = argc > 2;
  if (isFunction) {
    // Case 1).
    // Create a FunctionType representing the function.
    fnObj = FunctionType::CreateInternal(cx,
              argv[1], argv[2], &argv[3], argc - 3);
    if (!fnObj)
      return JS_FALSE;
    root.setObject(fnObj);

    // Make a function pointer type.
    typeObj = PointerType::CreateInternal(cx, fnObj);
    if (!typeObj)
      return JS_FALSE;
    root.setObject(typeObj);

  } else {
    // Case 2).
    if (JSVAL_IS_PRIMITIVE(argv[1]) ||
        !CType::IsCType(cx, JSVAL_TO_OBJECT(argv[1])) ||
        !CType::IsSizeDefined(cx, JSVAL_TO_OBJECT(argv[1]))) {
      JS_ReportError(cx, "second argument must be a type of defined size");
      return JS_FALSE;
    }

    typeObj = JSVAL_TO_OBJECT(argv[1]);
    if (CType::GetTypeCode(cx, typeObj) == TYPE_pointer) {
      fnObj = PointerType::GetBaseType(cx, typeObj);
      isFunction = fnObj && CType::GetTypeCode(cx, fnObj) == TYPE_function;
    }
  }

  void* data;
  PRFuncPtr fnptr;
  JSString* nameStr = JSVAL_TO_STRING(argv[0]);
  AutoCString symbol;
  if (isFunction) {
    // Build the symbol, with mangling if necessary.
    FunctionType::BuildSymbolName(cx, nameStr, fnObj, symbol);
    AppendString(symbol, "\0");

    // Look up the function symbol.
    fnptr = PR_FindFunctionSymbol(library, symbol.begin());
    if (!fnptr) {
      JS_ReportError(cx, "couldn't find function symbol in library");
      return JS_FALSE;
    }
    data = &fnptr;

  } else {
    // 'typeObj' is another data type. Look up the data symbol.
    AppendString(symbol, nameStr);
    AppendString(symbol, "\0");

    data = PR_FindSymbol(library, symbol.begin());
    if (!data) {
      JS_ReportError(cx, "couldn't find symbol in library");
      return JS_FALSE;
    }
  }

  JSObject* result = CData::Create(cx, typeObj, obj, data, isFunction);
  if (!result)
    return JS_FALSE;

  JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(result));

  // Seal the CData object, to prevent modification of the function pointer.
  // This permanently associates this object with the library, and avoids
  // having to do things like reset SLOT_REFERENT when someone tries to
  // change the pointer value.
  // XXX This will need to change when bug 541212 is fixed -- CData::ValueSetter
  // could be called on a sealed object.
  if (isFunction && !JS_FreezeObject(cx, result))
    return JS_FALSE;

  return JS_TRUE;
}
Пример #29
0
bool
Library::Declare(JSContext* cx, unsigned argc, Value* vp)
{
  CallArgs args = CallArgsFromVp(argc, vp);
  RootedObject obj(cx, JS_THIS_OBJECT(cx, vp));
  if (!obj)
    return false;
  if (!IsLibrary(obj)) {
    JS_ReportErrorASCII(cx, "not a library");
    return false;
  }

  PRLibrary* library = GetLibrary(obj);
  if (!library) {
    JS_ReportErrorASCII(cx, "library not open");
    return false;
  }

  // We allow two API variants:
  // 1) library.declare(name, abi, returnType, argType1, ...)
  //    declares a function with the given properties, and resolves the symbol
  //    address in the library.
  // 2) library.declare(name, type)
  //    declares a symbol of 'type', and resolves it. The object that comes
  //    back will be of type 'type', and will point into the symbol data.
  //    This data will be both readable and writable via the usual CData
  //    accessors. If 'type' is a PointerType to a FunctionType, the result will
  //    be a function pointer, as with 1).
  if (args.length() < 2) {
    JS_ReportErrorASCII(cx, "declare requires at least two arguments");
    return false;
  }

  if (!args[0].isString()) {
    JS_ReportErrorASCII(cx, "first argument must be a string");
    return false;
  }

  RootedObject fnObj(cx, nullptr);
  RootedObject typeObj(cx);
  bool isFunction = args.length() > 2;
  if (isFunction) {
    // Case 1).
    // Create a FunctionType representing the function.
    fnObj = FunctionType::CreateInternal(cx, args[1], args[2],
                                         HandleValueArray::subarray(args, 3, args.length() - 3));
    if (!fnObj)
      return false;

    // Make a function pointer type.
    typeObj = PointerType::CreateInternal(cx, fnObj);
    if (!typeObj)
      return false;
  } else {
    // Case 2).
    if (args[1].isPrimitive() ||
        !CType::IsCType(args[1].toObjectOrNull()) ||
        !CType::IsSizeDefined(args[1].toObjectOrNull())) {
      JS_ReportErrorASCII(cx, "second argument must be a type of defined size");
      return false;
    }

    typeObj = args[1].toObjectOrNull();
    if (CType::GetTypeCode(typeObj) == TYPE_pointer) {
      fnObj = PointerType::GetBaseType(typeObj);
      isFunction = fnObj && CType::GetTypeCode(fnObj) == TYPE_function;
    }
  }

  void* data;
  PRFuncPtr fnptr;
  RootedString nameStr(cx, args[0].toString());
  AutoCString symbol;
  if (isFunction) {
    // Build the symbol, with mangling if necessary.
    FunctionType::BuildSymbolName(nameStr, fnObj, symbol);
    AppendString(symbol, "\0");

    // Look up the function symbol.
    fnptr = PR_FindFunctionSymbol(library, symbol.begin());
    if (!fnptr) {
      JS_ReportErrorASCII(cx, "couldn't find function symbol in library");
      return false;
    }
    data = &fnptr;

  } else {
    // 'typeObj' is another data type. Look up the data symbol.
    AppendString(symbol, nameStr);
    AppendString(symbol, "\0");

    data = PR_FindSymbol(library, symbol.begin());
    if (!data) {
      JS_ReportErrorASCII(cx, "couldn't find symbol in library");
      return false;
    }
  }

  RootedObject result(cx, CData::Create(cx, typeObj, obj, data, isFunction));
  if (!result)
    return false;

  if (isFunction)
    JS_SetReservedSlot(result, SLOT_FUNNAME, StringValue(nameStr));

  args.rval().setObject(*result);

  // Seal the CData object, to prevent modification of the function pointer.
  // This permanently associates this object with the library, and avoids
  // having to do things like reset SLOT_REFERENT when someone tries to
  // change the pointer value.
  // XXX This will need to change when bug 541212 is fixed -- CData::ValueSetter
  // could be called on a sealed object.
  if (isFunction && !JS_FreezeObject(cx, result))
    return false;

  return true;
}
int LibraryDetectionManager::LoadXmlDoc( TiXmlDocument& Doc )
{
    int loaded = 0;
    for ( TiXmlElement* Elem = Doc.FirstChildElement("library");
          Elem;
          Elem = Elem->NextSiblingElement("library") )
    {
        // Load the version of this set
        int version = 0;
        if ( Elem->QueryIntAttribute( "version", &version ) != TIXML_SUCCESS )
            version = 0;

        // Load shortcode
        wxString ShortCode = wxString(Elem->Attribute("short_code"),wxConvUTF8);
        if ( ShortCode.IsEmpty() )
            continue;

        // Load name
        wxString Name = wxString( Elem->Attribute("name"), wxConvUTF8 );
        if ( Name.IsEmpty() )
            continue;

        // Check if we already have setting of this library
        // I'm to lazy to firbid const_cast here ;)
        LibraryDetectionConfigSet* OldSet = const_cast< LibraryDetectionConfigSet* > ( GetLibrary( ShortCode ) );
        LibraryDetectionConfigSet* NewSet = 0;

        if ( OldSet )
        {
            // There are detection settings yet, we override only when there's newer
            // or same version already
            if ( OldSet->Version > version )
                continue; // We do not upgrade

            OldSet->Categories.Clear();
            OldSet->Configurations.clear();
            OldSet->LibraryName.Clear();
            NewSet = OldSet;
        }
        else
        {
            NewSet = new LibraryDetectionConfigSet;
            Libraries.Add( NewSet );
        }

        // Setup configuration set
        NewSet->ShortCode = ShortCode;
        NewSet->Version = version;
        NewSet->LibraryName = Name;

        // Read categories of library
        for ( TiXmlAttribute* attr = Elem->FirstAttribute();
              attr;
              attr = attr->Next() )
        {
//            if ( !strncasecmp(attr->Name(),"category",8) )
            if ( !strncmp(attr->Name(),"category",8) )
                NewSet->Categories.Add( wxString( attr->Value(),wxConvUTF8 ) );
        }

        // Check if there's corresponding pkg-config entry
        if ( IsPkgConfigEntry(ShortCode) )
        {
            LibraryDetectionConfig Config;
            Config.PkgConfigVar = ShortCode;
            Config.Description = NewSet->LibraryName + _T(" (pkg-config)");
            LibraryDetectionFilter Filter;
            Filter.Type = LibraryDetectionFilter::PkgConfig;
            Filter.Value = ShortCode;
            Config.Filters.push_back(Filter);
            loaded += AddConfig(Config,NewSet) ? 1 : 0;
        }

        // Load libraries
        LibraryDetectionConfig Initial;
        loaded += LoadXml( Elem, Initial, NewSet );
    }
    return loaded;
}