예제 #1
0
EncodedTiValue JSC_HOST_CALL functionProtoFuncApply(TiExcState* exec)
{
    TiValue thisValue = exec->hostThisValue();
    CallData callData;
    CallType callType = getCallData(thisValue, callData);
    if (callType == CallTypeNone)
        return throwVMTypeError(exec);

    TiValue array = exec->argument(1);

    MarkedArgumentBuffer applyArgs;
    if (!array.isUndefinedOrNull()) {
        if (!array.isObject())
            return throwVMTypeError(exec);
        if (asObject(array)->classInfo() == &Arguments::s_info)
            asArguments(array)->fillArgList(exec, applyArgs);
        else if (isTiArray(&exec->globalData(), array))
            asArray(array)->fillArgList(exec, applyArgs);
        else if (asObject(array)->inherits(&TiArray::s_info)) {
            unsigned length = asArray(array)->get(exec, exec->propertyNames().length).toUInt32(exec);
            for (unsigned i = 0; i < length; ++i)
                applyArgs.append(asArray(array)->get(exec, i));
        } else
            return throwVMTypeError(exec);
    }

    return TiValue::encode(call(exec, thisValue, callType, callData, exec->argument(0), applyArgs));
}
예제 #2
0
JSValue JSC_HOST_CALL functionProtoFuncApply(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
{
    CallData callData;
    CallType callType = thisValue.getCallData(callData);
    if (callType == CallTypeNone)
        return throwError(exec, TypeError);

    JSValue array = args.at(1);

    MarkedArgumentBuffer applyArgs;
    if (!array.isUndefinedOrNull()) {
        if (!array.isObject())
            return throwError(exec, TypeError);
        if (asObject(array)->classInfo() == &Arguments::info)
            asArguments(array)->fillArgList(exec, applyArgs);
        else if (isJSArray(&exec->globalData(), array))
            asArray(array)->fillArgList(exec, applyArgs);
        else if (asObject(array)->inherits(&JSArray::info)) {
            unsigned length = asArray(array)->get(exec, exec->propertyNames().length).toUInt32(exec);
            for (unsigned i = 0; i < length; ++i)
                applyArgs.append(asArray(array)->get(exec, i));
        } else
            return throwError(exec, TypeError);
    }

    return call(exec, thisValue, callType, callData, args.at(0), applyArgs);
}
EncodedJSValue JSC_HOST_CALL functionProtoFuncApply(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    CallData callData;
    CallType callType = getCallData(thisValue, callData);
    if (callType == CallTypeNone)
        return throwVMTypeError(exec);

    JSValue array = exec->argument(1);

    MarkedArgumentBuffer applyArgs;
    if (!array.isUndefinedOrNull()) {
        if (!array.isObject())
            return throwVMTypeError(exec);
        if (asObject(array)->classInfo() == &Arguments::s_info) {
            if (asArguments(array)->length(exec) > Arguments::MaxArguments)
                return JSValue::encode(throwStackOverflowError(exec));
            asArguments(array)->fillArgList(exec, applyArgs);
        } else if (isJSArray(array)) {
            if (asArray(array)->length() > Arguments::MaxArguments)
                return JSValue::encode(throwStackOverflowError(exec));
            asArray(array)->fillArgList(exec, applyArgs);
        } else {
            unsigned length = asObject(array)->get(exec, exec->propertyNames().length).toUInt32(exec);
            if (length > Arguments::MaxArguments)
                return JSValue::encode(throwStackOverflowError(exec));

            for (unsigned i = 0; i < length; ++i)
                applyArgs.append(asObject(array)->get(exec, i));
        }
    }
    
    return JSValue::encode(call(exec, thisValue, callType, callData, exec->argument(0), applyArgs));
}
예제 #4
0
bool VirtualValue::operator==(const VirtualValue& that) const
{
   if ( mKind == that.mKind )
   {
      switch ( mKind )
      {
         case eEmpty:
            return true;

         case eNumber:
            return asNumber() == that.asNumber();

         case eReal:
            return asReal() == that.asReal();

         case eChar:
            return asChar() == that.asChar();

         case eBool:
            return asBoolean() == that.asBoolean();

         case eString:
            return asString() == that.asString();

         case eObject:
            return &asObject() == &that.asObject();

         case eArray:
            return &asArray() == &that.asArray();
      }
   }

   return false;
}
static CryptoKeyUsageBitmap cryptoKeyUsagesFromJSValue(ExecState& state, ThrowScope& scope, JSValue value)
{
    if (!isJSArray(value)) {
        throwTypeError(&state, scope);
        return { };
    }

    CryptoKeyUsageBitmap result = 0;
    JSArray* array = asArray(value);
    for (unsigned i = 0; i < array->length(); ++i) {
        auto usageString = array->getIndex(&state, i).toWTFString(&state);
        RETURN_IF_EXCEPTION(scope, { });
        if (usageString == "encrypt")
            result |= CryptoKeyUsageEncrypt;
        else if (usageString == "decrypt")
            result |= CryptoKeyUsageDecrypt;
        else if (usageString == "sign")
            result |= CryptoKeyUsageSign;
        else if (usageString == "verify")
            result |= CryptoKeyUsageVerify;
        else if (usageString == "deriveKey")
            result |= CryptoKeyUsageDeriveKey;
        else if (usageString == "deriveBits")
            result |= CryptoKeyUsageDeriveBits;
        else if (usageString == "wrapKey")
            result |= CryptoKeyUsageWrapKey;
        else if (usageString == "unwrapKey")
            result |= CryptoKeyUsageUnwrapKey;
    }
    return result;
}
예제 #6
0
static inline void putByVal(ExecState* exec, JSValue baseValue, uint32_t index, JSValue value)
{
    JSGlobalData* globalData = &exec->globalData();

    if (isJSArray(baseValue)) {
        JSArray* array = asArray(baseValue);
        if (array->canSetIndex(index)) {
            array->setIndex(*globalData, index, value);
            return;
        }

        JSArray::putByIndex(array, exec, index, value, strict);
        return;
    }

    if (isJSByteArray(baseValue) && asByteArray(baseValue)->canAccessIndex(index)) {
        JSByteArray* byteArray = asByteArray(baseValue);
        // FIXME: the JITstub used to relink this to an optimized form!
        if (value.isInt32()) {
            byteArray->setIndex(index, value.asInt32());
            return;
        }

        if (value.isNumber()) {
            byteArray->setIndex(index, value.asNumber());
            return;
        }
    }

    baseValue.putByIndex(exec, index, value, strict);
}
JSValue JSInspectorFrontendHost::showContextMenu(ExecState* execState, const ArgList& args)
{
    if (args.size() < 2)
        return jsUndefined();

    Event* event = toEvent(args.at(0));

    JSArray* array = asArray(args.at(1));
    Vector<ContextMenuItem*> items;

    for (size_t i = 0; i < array->length(); ++i) {
        JSObject* item = asObject(array->getIndex(i));
        JSValue label = item->get(execState, Identifier(execState, "label"));
        JSValue id = item->get(execState, Identifier(execState, "id"));
        if (label.isUndefined() || id.isUndefined())
            items.append(new ContextMenuItem(SeparatorType, ContextMenuItemTagNoAction, String()));
        else {
            ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + id.toInt32(execState));
            items.append(new ContextMenuItem(ActionType, typedId, label.toString(execState)));
        }
    }

    impl()->showContextMenu(event, items);
    return jsUndefined();
}
static void populateContextMenuItems(ExecState* exec, JSArray* array, ContextMenu& menu)
{
    for (size_t i = 0; i < array->length(); ++i) {
        JSObject* item = asObject(array->getIndex(exec, i));
        JSValue label = item->get(exec, Identifier::fromString(exec, "label"));
        JSValue type = item->get(exec, Identifier::fromString(exec, "type"));
        JSValue id = item->get(exec, Identifier::fromString(exec, "id"));
        JSValue enabled = item->get(exec, Identifier::fromString(exec, "enabled"));
        JSValue checked = item->get(exec, Identifier::fromString(exec, "checked"));
        JSValue subItems = item->get(exec, Identifier::fromString(exec, "subItems"));
        if (!type.isString())
            continue;

        String typeString = type.toWTFString(exec);
        if (typeString == "separator") {
            ContextMenuItem item(SeparatorType, ContextMenuItemTagNoAction, String());
            menu.appendItem(item);
        } else if (typeString == "subMenu" && subItems.inherits(JSArray::info())) {
            ContextMenu subMenu;
            JSArray* subItemsArray = asArray(subItems);
            populateContextMenuItems(exec, subItemsArray, subMenu);
            ContextMenuItem item(SubmenuType, ContextMenuItemTagNoAction, label.toWTFString(exec), &subMenu);
            menu.appendItem(item);
        } else {
            ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + id.toInt32(exec));
            ContextMenuItem menuItem((typeString == "checkbox" ? CheckableActionType : ActionType), typedId, label.toWTFString(exec));
            if (!enabled.isUndefined())
                menuItem.setEnabled(enabled.toBoolean(exec));
            if (!checked.isUndefined())
                menuItem.setChecked(checked.toBoolean(exec));
            menu.appendItem(menuItem);
        }
    }
}
예제 #9
0
static inline EncodedJSValue getByVal(ExecState* exec, JSCell* base, uint32_t index)
{
    // FIXME: the JIT used to handle these in compiled code!
    if (isJSArray(base) && asArray(base)->canGetIndex(index))
        return JSValue::encode(asArray(base)->getIndex(index));

    // FIXME: the JITstub used to relink this to an optimized form!
    if (isJSString(base) && asString(base)->canGetIndex(index))
        return JSValue::encode(asString(base)->getIndex(exec, index));

    // FIXME: the JITstub used to relink this to an optimized form!
    if (isJSByteArray(base) && asByteArray(base)->canAccessIndex(index))
        return JSValue::encode(asByteArray(base)->getIndex(exec, index));

    return JSValue::encode(JSValue(base).get(exec, index));
}
예제 #10
0
파일: MarkStack.cpp 프로젝트: 13W/phantomjs
inline void MarkStack::visitChildren(JSCell* cell)
{
    ASSERT(Heap::isMarked(cell));
    if (cell->structure()->typeInfo().type() < CompoundType) {
        cell->JSCell::visitChildren(*this);
        return;
    }

    if (!cell->structure()->typeInfo().overridesVisitChildren()) {
        ASSERT(cell->isObject());
#ifdef NDEBUG
        asObject(cell)->visitChildrenDirect(*this);
#else
        ASSERT(!m_isCheckingForDefaultMarkViolation);
        m_isCheckingForDefaultMarkViolation = true;
        cell->visitChildren(*this);
        ASSERT(m_isCheckingForDefaultMarkViolation);
        m_isCheckingForDefaultMarkViolation = false;
#endif
        return;
    }
    if (cell->vptr() == m_jsArrayVPtr) {
        asArray(cell)->visitChildrenDirect(*this);
        return;
    }
    cell->visitChildren(*this);
}
예제 #11
0
bool Item::isCallable() const
{
   if ( isClass() || isFunction() || isMethod() )
      return true;

   if( isObject() )
   {
      return asObjectSafe()->hasProperty( OVERRIDE_OP_CALL );
   }

   //a bit more complex: a callable array...
   if( type() == FLC_ITEM_ARRAY )
   {
      CoreArray& arr = *asArray();
      if ( arr.length() > 0 )
      {
         // avoid infinite recursion.
         // even if arr[0] is not an array, the check is harmless, as we check by ptr value.
         return arr[0].asArray() != &arr && arr[0].isCallable();
      }
   }

   // in all the other cases, the item is not callable
   return false;
}
예제 #12
0
bool Item::methodize( const Item &self )
{
   Item *data = dereference();

   switch( data->type() )
   {
      case FLC_ITEM_FUNC:
      {
         data->setMethod( self, data->asFunction() );
      }
      return true;

      case FLC_ITEM_ARRAY:
      {
         CoreArray& arr = *asArray();
         // even if arr[0] is not an array, the check is harmless, as we check by ptr value.
         if ( arr.canBeMethod() && arr.length() > 0 && arr[0].asArray() != &arr && arr[0].isCallable() )
         {
            data->setMethod( self, &arr );
            return true;
         }
      }
      return false;
   }

   return false;
}
예제 #13
0
static bool cryptoKeyUsagesFromJSValue(ExecState* exec, JSValue value, CryptoKeyUsage& result)
{
    if (!isJSArray(value)) {
        throwTypeError(exec);
        return false;
    }

    result = 0;

    JSArray* array = asArray(value);
    for (size_t i = 0; i < array->length(); ++i) {
        JSValue element = array->getIndex(exec, i);
        String usageString = element.toString(exec)->value(exec);
        if (exec->hadException())
            return false;
        if (usageString == "encrypt")
            result |= CryptoKeyUsageEncrypt;
        else if (usageString == "decrypt")
            result |= CryptoKeyUsageDecrypt;
        else if (usageString == "sign")
            result |= CryptoKeyUsageSign;
        else if (usageString == "verify")
            result |= CryptoKeyUsageVerify;
        else if (usageString == "deriveKey")
            result |= CryptoKeyUsageDeriveKey;
        else if (usageString == "deriveBits")
            result |= CryptoKeyUsageDeriveBits;
        else if (usageString == "wrapKey")
            result |= CryptoKeyUsageWrapKey;
        else if (usageString == "unwrapKey")
            result |= CryptoKeyUsageUnwrapKey;
    }
    return true;
}
예제 #14
0
static RefPtr<InspectorValue> jsToInspectorValue(ExecState* scriptState, JSValue value, int maxDepth)
{
    if (!value) {
        ASSERT_NOT_REACHED();
        return nullptr;
    }

    if (!maxDepth)
        return nullptr;

    maxDepth--;

    if (value.isNull() || value.isUndefined())
        return InspectorValue::null();
    if (value.isBoolean())
        return InspectorValue::create(value.asBoolean());
    if (value.isNumber() && value.isDouble())
        return InspectorValue::create(value.asNumber());
    if (value.isNumber() && value.isMachineInt())
        return InspectorValue::create(static_cast<int>(value.asMachineInt()));
    if (value.isString())
        return InspectorValue::create(value.getString(scriptState));

    if (value.isObject()) {
        if (isJSArray(value)) {
            Ref<InspectorArray> inspectorArray = InspectorArray::create();
            JSArray* array = asArray(value);
            unsigned length = array->length();
            for (unsigned i = 0; i < length; i++) {
                JSValue element = array->getIndex(scriptState, i);
                RefPtr<InspectorValue> elementValue = jsToInspectorValue(scriptState, element, maxDepth);
                if (!elementValue)
                    return nullptr;
                inspectorArray->pushValue(WTFMove(elementValue));
            }
            return WTFMove(inspectorArray);
        }
        Ref<InspectorObject> inspectorObject = InspectorObject::create();
        JSObject* object = value.getObject();
        PropertyNameArray propertyNames(scriptState, PropertyNameMode::Strings);
        object->methodTable()->getOwnPropertyNames(object, scriptState, propertyNames, EnumerationMode());
        for (size_t i = 0; i < propertyNames.size(); i++) {
            const Identifier& name = propertyNames[i];
            JSValue propertyValue = object->get(scriptState, name);
            RefPtr<InspectorValue> inspectorValue = jsToInspectorValue(scriptState, propertyValue, maxDepth);
            if (!inspectorValue)
                return nullptr;
            inspectorObject->setValue(name.string(), WTFMove(inspectorValue));
        }
        return WTFMove(inspectorObject);
    }

    ASSERT_NOT_REACHED();
    return nullptr;
}
예제 #15
0
LinkedList reverse(LinkedList list) {
	LinkedList reversed_list = createList();
	void *as_array = (int *)calloc(list.length, SIZE_OF_ADDRESS);
	asArray(list, as_array, list.length);
	as_array += SIZE_OF_ADDRESS*(list.length-1);
	for (int i = 0; i < list.length; ++i){
		addToList(&reversed_list, *(void **)as_array);
		as_array -= SIZE_OF_ADDRESS;
	}
	return reversed_list;
}
예제 #16
0
static PassRefPtr<InspectorValue> jsToInspectorValue(ScriptState* scriptState, JSValue value, int maxDepth)
{
    if (!value) {
        ASSERT_NOT_REACHED();
        return 0;
    }

    if (!maxDepth)
        return 0;
    maxDepth--;

    if (value.isNull() || value.isUndefined())
        return InspectorValue::null();
    if (value.isBoolean())
        return InspectorBasicValue::create(value.asBoolean());
    if (value.isNumber())
        return InspectorBasicValue::create(value.asNumber());
    if (value.isString()) {
        String s = value.getString(scriptState);
        return InspectorString::create(String(s.characters(), s.length()));
    }
    if (value.isObject()) {
        if (isJSArray(value)) {
            RefPtr<InspectorArray> inspectorArray = InspectorArray::create();
            JSArray* array = asArray(value);
            unsigned length = array->length();
            for (unsigned i = 0; i < length; i++) {
                // FIXME: What if the array is in sparse mode? https://bugs.webkit.org/show_bug.cgi?id=95610
                JSValue element = array->getIndexQuickly(i);
                RefPtr<InspectorValue> elementValue = jsToInspectorValue(scriptState, element, maxDepth);
                if (!elementValue)
                    return 0;
                inspectorArray->pushValue(elementValue);
            }
            return inspectorArray;
        }
        RefPtr<InspectorObject> inspectorObject = InspectorObject::create();
        JSObject* object = value.getObject();
        PropertyNameArray propertyNames(scriptState);
        object->methodTable()->getOwnPropertyNames(object, scriptState, propertyNames, ExcludeDontEnumProperties);
        for (size_t i = 0; i < propertyNames.size(); i++) {
            const Identifier& name =  propertyNames[i];
            JSValue propertyValue = object->get(scriptState, name);
            RefPtr<InspectorValue> inspectorValue = jsToInspectorValue(scriptState, propertyValue, maxDepth);
            if (!inspectorValue)
                return 0;
            inspectorObject->setValue(String(name.characters(), name.length()), inspectorValue);
        }
        return inspectorObject;
    }
    ASSERT_NOT_REACHED();
    return 0;
}
예제 #17
0
void test_for_asArray() {
    LinkedList list = createList();
    int num[10] = {32,43,223,54,76,7,45,3,4,23};
    for (int i = 0; i < 10; ++i) {
        add_to_list(&list,&num[i]);
    };
    void *arr[10];
    assert(asArray(list,arr,5)==5);
    for (int i = 0; i < 5; ++i) {
        assert(*(int *)arr[i]==num[i]);
    }
};
예제 #18
0
void test_as_array() {
  LinkedList list = createList();
  int arr[5] = {2, 3, 9, 6, 1};
  for (size_t i = 0; i < 5; i++) {
    add_to_list(&list, &arr[i]);
  }
  void *arr_ads = (void *)calloc(2, 8);
  int count = asArray(list, arr_ads, 2);
  for (size_t i = 0; i < count; i++) {
    assert(**(int **)arr_ads == arr[i]);
    arr_ads += 8;
  }
};
예제 #19
0
void test_as_array_char() {
  LinkedList list = createList();
  char arr[5] = {'S', 'A', 'R', 'A', 'N'};
  for (size_t i = 0; i < 5; i++) {
    add_to_list(&list, &arr[i]);
  }
  void *arr_ads = (void *)calloc(2, 8);
  char count = asArray(list, arr_ads, 2);
  for (size_t i = 0; i < count; i++) {
    assert(**(char **)arr_ads == arr[i]);
    arr_ads += 8;
  }
};
예제 #20
0
void test_as_array_double() {
  LinkedList list = createList();
  double arr[5] = {2.21, 3.223, 9.434, 6.54, 1.5454};
  for (size_t i = 0; i < 5; i++) {
    add_to_list(&list, &arr[i]);
  }
  void *arr_ads = (void *)calloc(2, 8);
  double count = asArray(list, arr_ads, 2);
  for (size_t i = 0; i < count; i++) {
    assert(**(double **)arr_ads == arr[i]);
    arr_ads += 8;
  }
};
예제 #21
0
void test_asArray_copies_address_of_all_the_values_to_the_destination_given_and_returns_the_count_of_copied_values () {
	LinkedList list = createList();
	int array[] = {1,2,3,4,5,6};

	for (int i = 0; i < 6; ++i){
		addToList(&list, &array[i]);
	}

	void *dest = (int *)calloc(6,8);

	int countOfCopied = asArray(list, dest, 6);
	assert(countOfCopied == 6);
}
예제 #22
0
static PassRefPtr<InspectorValue> jsToInspectorValue(ScriptState* scriptState, JSValue value)
{
    if (!value) {
        ASSERT_NOT_REACHED();
        return 0;
    }
    if (value.isNull() || value.isUndefined())
        return InspectorValue::null();
    if (value.isBoolean())
        return InspectorBasicValue::create(value.getBoolean());
    if (value.isNumber())
        return InspectorBasicValue::create(value.uncheckedGetNumber());
    if (value.isString()) {
        UString s = value.getString(scriptState);
        return InspectorString::create(String(s.characters(), s.length()));
    }
    if (value.isObject()) {
        if (isJSArray(&scriptState->globalData(), value)) {
            RefPtr<InspectorArray> inspectorArray = InspectorArray::create();
            JSArray* array = asArray(value);
            unsigned length = array->length();
            for (unsigned i = 0; i < length; i++) {
                JSValue element = array->getIndex(i);
                RefPtr<InspectorValue> elementValue = jsToInspectorValue(scriptState, element);
                if (!elementValue) {
                    ASSERT_NOT_REACHED();
                    elementValue = InspectorValue::null();
                }
                inspectorArray->pushValue(elementValue);
            }
            return inspectorArray;
        }
        RefPtr<InspectorObject> inspectorObject = InspectorObject::create();
        JSObject* object = value.getObject();
        PropertyNameArray propertyNames(scriptState);
        object->getOwnPropertyNames(scriptState, propertyNames);
        for (size_t i = 0; i < propertyNames.size(); i++) {
            const Identifier& name =  propertyNames[i];
            JSValue propertyValue = object->get(scriptState, name);
            RefPtr<InspectorValue> inspectorValue = jsToInspectorValue(scriptState, propertyValue);
            if (!inspectorValue) {
                ASSERT_NOT_REACHED();
                inspectorValue = InspectorValue::null();
            }
            inspectorObject->setValue(String(name.characters(), name.length()), inspectorValue);
        }
        return inspectorObject;
    }
    ASSERT_NOT_REACHED();
    return 0;
}
예제 #23
0
EncodedTiValue operationGetByVal(TiExcState* exec, EncodedTiValue encodedBase, EncodedTiValue encodedProperty)
{
    TiValue baseValue = TiValue::decode(encodedBase);
    TiValue property = TiValue::decode(encodedProperty);

    if (LIKELY(baseValue.isCell())) {
        TiCell* base = baseValue.asCell();

        if (property.isUInt32()) {
            TiGlobalData* globalData = &exec->globalData();
            uint32_t i = property.asUInt32();

            // FIXME: the JIT used to handle these in compiled code!
            if (isTiArray(globalData, base) && asArray(base)->canGetIndex(i))
                return TiValue::encode(asArray(base)->getIndex(i));

            // FIXME: the JITstub used to relink this to an optimized form!
            if (isTiString(globalData, base) && asString(base)->canGetIndex(i))
                return TiValue::encode(asString(base)->getIndex(exec, i));

            // FIXME: the JITstub used to relink this to an optimized form!
            if (isTiArrayArray(globalData, base) && asByteArray(base)->canAccessIndex(i))
                return TiValue::encode(asByteArray(base)->getIndex(exec, i));

            return TiValue::encode(baseValue.get(exec, i));
        }

        if (property.isString()) {
            Identifier propertyName(exec, asString(property)->value(exec));
            PropertySlot slot(base);
            if (base->fastGetOwnPropertySlot(exec, propertyName, slot))
                return TiValue::encode(slot.getValue(exec, propertyName));
        }
    }

    Identifier ident(exec, property.toString(exec));
    return TiValue::encode(baseValue.get(exec, ident));
}
예제 #24
0
void test_for_asArray_it_can_test_for_int(){
  Linked_list list=createList();
  int _1st=23,_2nd =24,_3rd=25;
  add_to_list(&list,&_1st);
  add_to_list(&list,&_2nd);
  add_to_list(&list,&_3rd);
  void *array[3];
  assert(asArray(list,array,3)==3);
  Element e1,e2,e3;
  assert(TYPEINT(array[0])==23);
  assert(TYPEINT(array[1])==24);
  assert(TYPEINT(array[2])==25);

}
예제 #25
0
void test_for_asArray_it_can_test_for_float(){
  Linked_list list=createList();
  float _1st=23.50,_2nd =24.5,_3rd=25.00;
  add_to_list(&list,&_1st);
  add_to_list(&list,&_2nd);
  add_to_list(&list,&_3rd);
  void *array[3];
  assert(asArray(list,array,3)==3);
  Element e1,e2,e3;
  assert(TYPEFLOAT(array[0])==23.50);
  assert(TYPEFLOAT(array[1])==24.5);
  assert(TYPEFLOAT(array[2])==25.00);

}
예제 #26
0
void test_for_asArray_it_can_test_for_double(){
  Linked_list list=createList();
  double _1st=239876890.532468798435168480,_2nd =2455.85585,_3rd=2585.6576854346900;
  add_to_list(&list,&_1st);
  add_to_list(&list,&_2nd);
  add_to_list(&list,&_3rd);
  void *array[3];
  assert(asArray(list,array,3)==3);
  Element e1,e2,e3;
  assert(TYPEDOUBLE(array[0])==_1st);
  assert(TYPEDOUBLE(array[1])==_2nd);
  assert(TYPEDOUBLE(array[2])==_3rd);

}
예제 #27
0
PassRefPtr<DOMStringList> toDOMStringList(ExecState* exec, JSValue value)
{
    if (value.inherits(&JSDOMStringList::s_info))
        return jsCast<JSDOMStringList*>(asObject(value))->impl();

    if (!isJSArray(value))
        return 0;

    JSArray* array = asArray(value);
    RefPtr<DOMStringList> stringList = DOMStringList::create();
    for (unsigned i = 0; i < array->length(); ++i)
        stringList->append(array->getIndex(exec, i).toString(exec)->value(exec));

    return stringList.release();
}
예제 #28
0
ALWAYS_INLINE static void operationPutByValInternal(TiExcState* exec, EncodedTiValue encodedBase, EncodedTiValue encodedProperty, EncodedTiValue encodedValue)
{
    TiGlobalData* globalData = &exec->globalData();

    TiValue baseValue = TiValue::decode(encodedBase);
    TiValue property = TiValue::decode(encodedProperty);
    TiValue value = TiValue::decode(encodedValue);

    if (LIKELY(property.isUInt32())) {
        uint32_t i = property.asUInt32();

        if (isTiArray(globalData, baseValue)) {
            TiArray* jsArray = asArray(baseValue);
            if (jsArray->canSetIndex(i)) {
                jsArray->setIndex(*globalData, i, value);
                return;
            }

            jsArray->TiArray::put(exec, i, value);
            return;
        }

        if (isTiArrayArray(globalData, baseValue) && asByteArray(baseValue)->canAccessIndex(i)) {
            TiArrayArray* jsByteArray = asByteArray(baseValue);
            // FIXME: the JITstub used to relink this to an optimized form!
            if (value.isInt32()) {
                jsByteArray->setIndex(i, value.asInt32());
                return;
            }

            double dValue = 0;
            if (value.getNumber(dValue)) {
                jsByteArray->setIndex(i, dValue);
                return;
            }
        }

        baseValue.put(exec, i, value);
        return;
    }

    // Don't put to an object if toString throws an exception.
    Identifier ident(exec, property.toString(exec));
    if (!globalData->exception) {
        PutPropertySlot slot(strict);
        baseValue.put(exec, ident, value, slot);
    }
}
예제 #29
0
void test_asArray(){
	LinkedList list = createList();
	int number = 12, number2 = 33, number3 = 23;
	add_to_list(&list, &number);
	add_to_list(&list, &number2);
	add_to_list(&list, &number3);

	int a[10];
	void *arr_ptr = &a;
	int maxLength = 2;

	int length_of_arr = asArray(list, arr_ptr, maxLength);
	assert(maxLength == 2);

	print_arr(arr_ptr,2);
};
예제 #30
0
void test_asArray(){
	LinkedList list = createList();
	int num = 10,num1 = 9,num2 = 8,num3 = 7;
	int arr[] = {10,9,8,7};
	add_to_list(&list,&num);
	add_to_list(&list,&num1);
	add_to_list(&list,&num2);
	add_to_list(&list,&num3);
	void *array =calloc(4,5);
	int result = asArray(list,array,5);
	assert(4==result);
	for(int i=0;i<result;i++){
		assert(arr[i]==**(int **)array);
		array+=8;
	}
}