Example #1
0
bool JSFunction::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor, bool throwException)
{
    JSFunction* thisObject = jsCast<JSFunction*>(object);
    if (thisObject->isHostFunction())
        return Base::defineOwnProperty(object, exec, propertyName, descriptor, throwException);

    if (propertyName == exec->propertyNames().prototype) {
        // Make sure prototype has been reified, such that it can only be overwritten
        // following the rules set out in ECMA-262 8.12.9.
        PropertySlot slot;
        thisObject->methodTable()->getOwnPropertySlot(thisObject, exec, propertyName, slot);
        thisObject->m_allocationProfile.clear();
        thisObject->m_allocationProfileWatchpoint.notifyWrite();
        return Base::defineOwnProperty(object, exec, propertyName, descriptor, throwException);
    }

    bool valueCheck;
    if (propertyName == exec->propertyNames().arguments) {
        if (thisObject->jsExecutable()->isStrictMode()) {
            if (!Base::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor))
                thisObject->putDirectAccessor(exec, propertyName, thisObject->globalObject()->throwTypeErrorGetterSetter(exec), DontDelete | DontEnum | Accessor);
            return Base::defineOwnProperty(object, exec, propertyName, descriptor, throwException);
        }
        valueCheck = !descriptor.value() || sameValue(exec, descriptor.value(), exec->interpreter()->retrieveArgumentsFromVMCode(exec, thisObject));
    } else if (propertyName == exec->propertyNames().caller) {
        if (thisObject->jsExecutable()->isStrictMode()) {
            if (!Base::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor))
                thisObject->putDirectAccessor(exec, propertyName, thisObject->globalObject()->throwTypeErrorGetterSetter(exec), DontDelete | DontEnum | Accessor);
            return Base::defineOwnProperty(object, exec, propertyName, descriptor, throwException);
        }
        valueCheck = !descriptor.value() || sameValue(exec, descriptor.value(), exec->interpreter()->retrieveCallerFromVMCode(exec, thisObject));
    } else if (propertyName == exec->propertyNames().length)
        valueCheck = !descriptor.value() || sameValue(exec, descriptor.value(), jsNumber(thisObject->jsExecutable()->parameterCount()));
    else if (propertyName == exec->propertyNames().name)
        valueCheck = !descriptor.value() || sameValue(exec, descriptor.value(), thisObject->jsExecutable()->nameValue());
    else
        return Base::defineOwnProperty(object, exec, propertyName, descriptor, throwException);
     
    if (descriptor.configurablePresent() && descriptor.configurable()) {
        if (throwException)
            throwError(exec, createTypeError(exec, ASCIILiteral("Attempting to configurable attribute of unconfigurable property.")));
        return false;
    }
    if (descriptor.enumerablePresent() && descriptor.enumerable()) {
        if (throwException)
            throwError(exec, createTypeError(exec, ASCIILiteral("Attempting to change enumerable attribute of unconfigurable property.")));
        return false;
    }
    if (descriptor.isAccessorDescriptor()) {
        if (throwException)
            throwError(exec, createTypeError(exec, ASCIILiteral("Attempting to change access mechanism for an unconfigurable property.")));
        return false;
    }
    if (descriptor.writablePresent() && descriptor.writable()) {
        if (throwException)
            throwError(exec, createTypeError(exec, ASCIILiteral("Attempting to change writable attribute of unconfigurable property.")));
        return false;
    }
    if (!valueCheck) {
        if (throwException)
            throwError(exec, createTypeError(exec, ASCIILiteral("Attempting to change value of a readonly property.")));
        return false;
    }
    return true;
}
// void texImage2DHTML(in unsigned long target, in unsigned long level, in HTMLImageElement image);
JSValue JSCanvasRenderingContext3D::texImage2D(ExecState* exec, const ArgList& args)
{ 
    if (args.size() < 3)
        return throwError(exec, SyntaxError);

    ExceptionCode ec = 0;
    CanvasRenderingContext3D* context = static_cast<CanvasRenderingContext3D*>(impl());    
    unsigned target = args.at(0).toInt32(exec);
    if (exec->hadException())    
        return jsUndefined();
        
    unsigned level = args.at(1).toInt32(exec);
    if (exec->hadException())    
        return jsUndefined();
    
    if (args.size() > 5) {
        // This must be the bare array case.
        if (args.size() != 9)
            return throwError(exec, SyntaxError);
            
        unsigned internalformat = args.at(2).toInt32(exec);
        if (exec->hadException())    
            return jsUndefined();

        unsigned width = args.at(3).toInt32(exec);
        if (exec->hadException())    
            return jsUndefined();

        unsigned height = args.at(4).toInt32(exec);
        if (exec->hadException())    
            return jsUndefined();

        unsigned border = args.at(5).toInt32(exec);
        if (exec->hadException())    
            return jsUndefined();

        unsigned format = args.at(6).toInt32(exec);
        if (exec->hadException())    
            return jsUndefined();

        unsigned type = args.at(7).toInt32(exec);
        if (exec->hadException())    
            return jsUndefined();

        CanvasArray* array = toCanvasArray(args.at(8));
        if (exec->hadException())    
            return jsUndefined();
            
        if (!array)
            return throwError(exec, TypeError);
        
        // FIXME: Need to check to make sure CanvasArray is a CanvasByteArray or CanvasShortArray,
        // depending on the passed type parameter.
        
        context->texImage2D(target, level, internalformat, width, height, border, format, type, array, ec);
        return jsUndefined();
    }
    
    // The image parameter can be a <img> or <canvas> element.
    JSValue value = args.at(2);
    if (!value.isObject())
        return throwError(exec, TypeError);
    JSObject* o = asObject(value);
    
    bool flipY = (args.size() > 3) ? args.at(3).toBoolean(exec) : false;
    bool premultiplyAlpha = (args.size() > 4) ? args.at(3).toBoolean(exec) : false;
    
    if (o->inherits(&JSHTMLImageElement::s_info)) {
        HTMLImageElement* imgElt = static_cast<HTMLImageElement*>(static_cast<JSHTMLElement*>(o)->impl());
        context->texImage2D(target, level, imgElt, flipY, premultiplyAlpha, ec);
    } else if (o->inherits(&JSHTMLCanvasElement::s_info)) {
        HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(static_cast<JSHTMLElement*>(o)->impl());
        context->texImage2D(target, level, canvas, flipY, premultiplyAlpha, ec);
    } else {
        setDOMException(exec, TYPE_MISMATCH_ERR);
    }
    
    return jsUndefined();    
}
JSValue* JSCSSStyleDeclarationPrototypeFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
{
    if (!thisObj->inherits(&JSCSSStyleDeclaration::info))
      return throwError(exec, TypeError);

    CSSStyleDeclaration* imp = static_cast<CSSStyleDeclaration*>(static_cast<JSCSSStyleDeclaration*>(thisObj)->impl());

    switch (id) {
    case JSCSSStyleDeclaration::GetPropertyValueFuncNum: {
        String propertyName = args[0]->toString(exec);


        KJS::JSValue* result = jsStringOrNull(imp->getPropertyValue(propertyName));
        return result;
    }
    case JSCSSStyleDeclaration::GetPropertyCSSValueFuncNum: {
        String propertyName = args[0]->toString(exec);


        KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->getPropertyCSSValue(propertyName)));
        return result;
    }
    case JSCSSStyleDeclaration::RemovePropertyFuncNum: {
        ExceptionCode ec = 0;
        String propertyName = args[0]->toString(exec);


        KJS::JSValue* result = jsStringOrNull(imp->removeProperty(propertyName, ec));
        setDOMException(exec, ec);
        return result;
    }
    case JSCSSStyleDeclaration::GetPropertyPriorityFuncNum: {
        String propertyName = args[0]->toString(exec);


        KJS::JSValue* result = jsStringOrNull(imp->getPropertyPriority(propertyName));
        return result;
    }
    case JSCSSStyleDeclaration::SetPropertyFuncNum: {
        ExceptionCode ec = 0;
        String propertyName = args[0]->toString(exec);
        String value = valueToStringWithNullCheck(exec, args[1]);
        String priority = args[2]->toString(exec);

        imp->setProperty(propertyName, value, priority, ec);
        setDOMException(exec, ec);
        return jsUndefined();
    }
    case JSCSSStyleDeclaration::ItemFuncNum: {
        bool indexOk;
        unsigned index = args[0]->toInt32(exec, indexOk);
        if (!indexOk) {
            setDOMException(exec, TYPE_MISMATCH_ERR);
            return jsUndefined();
        }


        KJS::JSValue* result = jsStringOrNull(imp->item(index));
        return result;
    }
    case JSCSSStyleDeclaration::GetPropertyShorthandFuncNum: {
        String propertyName = args[0]->toString(exec);


        KJS::JSValue* result = jsStringOrNull(imp->getPropertyShorthand(propertyName));
        return result;
    }
    case JSCSSStyleDeclaration::IsPropertyImplicitFuncNum: {
        String propertyName = args[0]->toString(exec);


        KJS::JSValue* result = jsBoolean(imp->isPropertyImplicit(propertyName));
        return result;
    }
    }
    return 0;
}
JSValue JSC_HOST_CALL regExpProtoFuncExec(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
{
    if (!thisValue.isObject(&RegExpObject::info))
        return throwError(exec, TypeError);
    return asRegExpObject(thisValue)->exec(exec, args);
}
Example #5
0
void parseConfigFile(int fd, struct s_initconfig *cs) {
	char line[CONFPARSER_LINEBUF_SIZE+1];
	char c;
	int linepos = 0;
	int linectr = 0;
	int waiteol = 0;
	int rc;
	int readlen;
    
    strcpy(cs->tapname,"");
    strcpy(cs->ifconfig4,"");
    strcpy(cs->ifconfig6,"");
    strcpy(cs->upcmd,"");
    strcpy(cs->sourceip,"");
    strcpy(cs->sourceport,"");
    strcpy(cs->userstr,"");
    strcpy(cs->groupstr,"");
    strcpy(cs->chrootstr,"");
    strcpy(cs->networkname,"PEERVPN");
    strcpy(cs->engines,"");
    strcpy(cs->pidfile, "");
    strcpy(cs->privatekey, "/var/run/peervpn.pem");
    
    cs->password_len = 0;
    cs->enablepidfile = 0;
    cs->enableeth = 1;
    cs->enablendpcache = 0;
    cs->enablevirtserv = 0;
    cs->enablerelay = 0;
    cs->enableindirect = 0;
    cs->enableconsole = 0;
    cs->enableseccomp = 0;
    cs->forceseccomp = 0;
    cs->daemonize = 0;
    cs->enableprivdrop = 1;
    cs->enableipv4 = 1;
    cs->enableipv6 = 1;
    cs->enablenat64clat = 0;
    cs->enablesyslog = 0;
    cs->sockmark = 0;
    cs->enablepidfile = 0;
    cs->initpeerscount = 0;
    
	do {
		readlen = read(fd,&c,1);
		if(!(readlen > 0)) {
			c = '\n';
		}
		if(c == '\n') {
			linectr++;
			while(linepos > 0) {
				if(isWhitespaceChar(line[linepos-1])) {
					linepos--;
				}
				else {
					break;
				}
			}
			line[linepos] = '\0';
			rc = parseConfigLine(line,linepos,cs);
			if(rc < 0) {
				printf("error: config file parse error at line %d!\n", linectr); 
				throwError(NULL);
			}
			if(rc == 0) break;
			linepos = 0;
			waiteol = 0;
		}
		else {
			if((!waiteol) && (!(linepos == 0 && isWhitespaceChar(c)))) {
				if(parseConfigIsEOLChar(c)) {
					line[linepos] = '\0';
					waiteol = 1;
				}
				else {
					if(linepos < (CONFPARSER_LINEBUF_SIZE)) {
						line[linepos] = c;
						linepos++;
					}
					else {
						line[linepos] = '\0';
						waiteol = 1;
					}
				}
			}
		}
	}
	while(readlen > 0);
}
Example #6
0
void WorkerScriptController::setException(const ScriptValue& exception)
{
    throwError(*exception.v8Value());
}
KJS::Value QDirImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args )
{
    JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() );
    if ( !op ) {
        kdWarning() << "QDirImp::call() failed, not a JSOpaqueProxy" << endl;
        return KJS::Value();
    }

    if ( op->typeName() != "QDir" ) {
        kdWarning() << "QDirImp::call() failed, type is " << op->typeName() << endl;
	return KJS::Value();
    }

    instance =  op->toNative<QDir>();

    switch( mid ) {

    case Method_setPath_7:
        return setPath_7( exec, self, args );
        break;

    case Method_path_8:
        return path_8( exec, self, args );
        break;

    case Method_absPath_9:
        return absPath_9( exec, self, args );
        break;

    case Method_canonicalPath_10:
        return canonicalPath_10( exec, self, args );
        break;

    case Method_dirName_11:
        return dirName_11( exec, self, args );
        break;

    case Method_filePath_12:
        return filePath_12( exec, self, args );
        break;

    case Method_absFilePath_13:
        return absFilePath_13( exec, self, args );
        break;

    case Method_cd_14:
        return cd_14( exec, self, args );
        break;

    case Method_cdUp_15:
        return cdUp_15( exec, self, args );
        break;

    case Method_nameFilter_16:
        return nameFilter_16( exec, self, args );
        break;

    case Method_setNameFilter_17:
        return setNameFilter_17( exec, self, args );
        break;

    case Method_filter_18:
        return filter_18( exec, self, args );
        break;

    case Method_setFilter_19:
        return setFilter_19( exec, self, args );
        break;

    case Method_sorting_20:
        return sorting_20( exec, self, args );
        break;

    case Method_setSorting_21:
        return setSorting_21( exec, self, args );
        break;

    case Method_matchAllDirs_22:
        return matchAllDirs_22( exec, self, args );
        break;

    case Method_setMatchAllDirs_23:
        return setMatchAllDirs_23( exec, self, args );
        break;

    case Method_count_24:
        return count_24( exec, self, args );
        break;

    case Method_encodedEntryList_26:
        return encodedEntryList_26( exec, self, args );
        break;

    case Method_encodedEntryList_27:
        return encodedEntryList_27( exec, self, args );
        break;

    case Method_entryList_28:
        return entryList_28( exec, self, args );
        break;

    case Method_entryList_29:
        return entryList_29( exec, self, args );
        break;

    case Method_entryInfoList_30:
        return entryInfoList_30( exec, self, args );
        break;

    case Method_entryInfoList_31:
        return entryInfoList_31( exec, self, args );
        break;

    case Method_mkdir_32:
        return mkdir_32( exec, self, args );
        break;

    case Method_rmdir_33:
        return rmdir_33( exec, self, args );
        break;

    case Method_isReadable_34:
        return isReadable_34( exec, self, args );
        break;

    case Method_exists_35:
        return exists_35( exec, self, args );
        break;

    case Method_isRoot_36:
        return isRoot_36( exec, self, args );
        break;

    case Method_isRelative_37:
        return isRelative_37( exec, self, args );
        break;

    case Method_convertToAbs_38:
        return convertToAbs_38( exec, self, args );
        break;

    case Method_remove_41:
        return remove_41( exec, self, args );
        break;

    case Method_rename_42:
        return rename_42( exec, self, args );
        break;

    case Method_exists_43:
        return exists_43( exec, self, args );
        break;

    case Method_refresh_44:
        return refresh_44( exec, self, args );
        break;

    case Method_convertSeparators_45:
        return convertSeparators_45( exec, self, args );
        break;

    case Method_drives_46:
        return drives_46( exec, self, args );
        break;

    case Method_separator_47:
        return separator_47( exec, self, args );
        break;

    case Method_setCurrent_48:
        return setCurrent_48( exec, self, args );
        break;

    case Method_current_49:
        return current_49( exec, self, args );
        break;

    case Method_home_50:
        return home_50( exec, self, args );
        break;

    case Method_root_51:
        return root_51( exec, self, args );
        break;

    case Method_currentDirPath_52:
        return currentDirPath_52( exec, self, args );
        break;

    case Method_homeDirPath_53:
        return homeDirPath_53( exec, self, args );
        break;

    case Method_rootDirPath_54:
        return rootDirPath_54( exec, self, args );
        break;

    case Method_match_55:
        return match_55( exec, self, args );
        break;

    case Method_match_56:
        return match_56( exec, self, args );
        break;

    case Method_cleanDirPath_57:
        return cleanDirPath_57( exec, self, args );
        break;

    case Method_isRelativePath_58:
        return isRelativePath_58( exec, self, args );
        break;

    default:
        break;
    }

    QString msg = i18n( "QDirImp has no method with id '%1'." ).arg( mid );
    return throwError(exec, msg,KJS::ReferenceError);
}
Example #8
0
JSObject* throwOutOfMemoryError(ExecState* exec)
{
    return throwError(exec, createOutOfMemoryError(exec->lexicalGlobalObject()));
}
Example #9
0
JSObject* throwStackOverflowError(ExecState* exec)
{
    return throwError(exec, createStackOverflowError(exec));
}
Example #10
0
bool TiObject::defineOwnProperty(TiExcState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor, bool throwException)
{
    // If we have a new property we can just put it on normally
    PropertyDescriptor current;
    if (!getOwnPropertyDescriptor(exec, propertyName, current))
        return putDescriptor(exec, this, propertyName, descriptor, descriptor.attributes(), jsUndefined());

    if (descriptor.isEmpty())
        return true;

    if (current.equalTo(descriptor))
        return true;

    // Filter out invalid changes
    if (!current.configurable()) {
        if (descriptor.configurable()) {
            if (throwException)
                throwError(exec, TypeError, "Attempting to configurable attribute of unconfigurable property.");
            return false;
        }
        if (descriptor.enumerablePresent() && descriptor.enumerable() != current.enumerable()) {
            if (throwException)
                throwError(exec, TypeError, "Attempting to change enumerable attribute of unconfigurable property.");
            return false;
        }
    }

    // A generic descriptor is simply changing the attributes of an existing property
    if (descriptor.isGenericDescriptor()) {
        if (!current.attributesEqual(descriptor)) {
            deleteProperty(exec, propertyName);
            putDescriptor(exec, this, propertyName, descriptor, current.attributesWithOverride(descriptor), current.value());
        }
        return true;
    }

    // Changing between a normal property or an accessor property
    if (descriptor.isDataDescriptor() != current.isDataDescriptor()) {
        if (!current.configurable()) {
            if (throwException)
                throwError(exec, TypeError, "Attempting to change access mechanism for an unconfigurable property.");
            return false;
        }
        deleteProperty(exec, propertyName);
        return putDescriptor(exec, this, propertyName, descriptor, current.attributesWithOverride(descriptor), current.value() ? current.value() : jsUndefined());
    }

    // Changing the value and attributes of an existing property
    if (descriptor.isDataDescriptor()) {
        if (!current.configurable()) {
            if (!current.writable() && descriptor.writable()) {
                if (throwException)
                    throwError(exec, TypeError, "Attempting to change writable attribute of unconfigurable property.");
                return false;
            }
            if (!current.writable()) {
                if (descriptor.value() || !TiValue::strictEqual(current.value(), descriptor.value())) {
                    if (throwException)
                        throwError(exec, TypeError, "Attempting to change value of a readonly property.");
                    return false;
                }
            }
        } else if (current.attributesEqual(descriptor)) {
            if (!descriptor.value())
                return true;
            PutPropertySlot slot;
            put(exec, propertyName, descriptor.value(), slot);
            if (exec->hadException())
                return false;
            return true;
        }
        deleteProperty(exec, propertyName);
        return putDescriptor(exec, this, propertyName, descriptor, current.attributesWithOverride(descriptor), current.value());
    }

    // Changing the accessor functions of an existing accessor property
    ASSERT(descriptor.isAccessorDescriptor());
    if (!current.configurable()) {
        if (descriptor.setterPresent() && !(current.setter() && TiValue::strictEqual(current.setter(), descriptor.setter()))) {
            if (throwException)
                throwError(exec, TypeError, "Attempting to change the setter of an unconfigurable property.");
            return false;
        }
        if (descriptor.getterPresent() && !(current.getter() && TiValue::strictEqual(current.getter(), descriptor.getter()))) {
            if (throwException)
                throwError(exec, TypeError, "Attempting to change the getter of an unconfigurable property.");
            return false;
        }
    }
    TiValue accessor = getDirect(propertyName);
    if (!accessor)
        return false;
    GetterSetter* getterSetter = asGetterSetter(accessor);
    if (current.attributesEqual(descriptor)) {
        if (descriptor.setter())
            getterSetter->setSetter(asObject(descriptor.setter()));
        if (descriptor.getter())
            getterSetter->setGetter(asObject(descriptor.getter()));
        return true;
    }
    deleteProperty(exec, propertyName);
    unsigned attrs = current.attributesWithOverride(descriptor);
    if (descriptor.setter())
        attrs |= Setter;
    if (descriptor.getter())
        attrs |= Getter;
    putDirect(propertyName, getterSetter, attrs);
    return true;
}
Example #11
0
/* Encrypts or decrypts a string. result should be freed with free() when done */
SECStatus
doCrypto(JNIEnv* jenv, const char *path, const char *value, char** result, bool encrypt)
{
    SECStatus rv;
    PK11SlotInfo *slot;
    if (!initialized) {
      LOG("Initialize crypto in %s\n", path);
      rv = f_NSS_Initialize(path, "", "", "secmod.db", NSS_INIT_NOROOTINIT);
      if (rv != SECSuccess) {
          throwError(jenv, "NSS_Initialize");
          return rv;
      }
      initialized = true;
    }

    slot = f_PK11_GetInternalKeySlot();
    if (!slot) {
      throwError(jenv, "PK11_GetInternalKeySlot");
      return SECFailure;
    }

    if (f_PK11_NeedUserInit(slot)) {
      LOG("Initializing key3.db with default blank password.\n");
      rv = f_PK11_InitPin(slot, nullptr, nullptr);
      if (rv != SECSuccess) {
        throwError(jenv, "PK11_InitPin");
        return rv;
      }
    }

    SECItem request;
    SECItem reply;

    reply.data = 0;
    reply.len = 0;

    if (encrypt) {
      // This can print sensitive data. Uncomment if you need it.
      // LOG("Encrypting: %s\n", value);
      request.data = (unsigned char*)value;
      request.len = strlen(value);

      SECItem keyid;
      keyid.data = 0;
      keyid.len = 0;
      rv = f_PK11SDR_Encrypt(&keyid, &request, &reply, nullptr);

      if (rv != SECSuccess) {
        throwError(jenv, "PK11SDR_Encrypt");
        goto done;
      }

      rv = encode(reply.data, reply.len, result);
      if (rv != SECSuccess) {
          throwError(jenv, "encode");
          goto done;
      }
      LOG("Encrypted: %s\n", *result);
    } else {
      LOG("Decoding: %s\n", value);
      rv = decode(value, &request.data, (int32_t*)&request.len);
      if (rv != SECSuccess) {
          throwError(jenv, "decode");
          return rv;
      }

      rv = f_PK11SDR_Decrypt(&request, &reply, nullptr);
      if (rv != SECSuccess) {
        throwError(jenv, "PK11SDR_Decrypt");
        goto done;
      }

      *result = (char *)malloc(reply.len+1);
      strncpy(*result, (char *)reply.data, reply.len);
      (*result)[reply.len] = '\0';

      // This can print sensitive data. Uncomment if you need it.
      // LOG("Decoded %i letters: %s\n", reply.len, *result);
      free(request.data);
    }

done:
    f_SECITEM_ZfreeItem(&reply, false);
    return rv;
}
Example #12
0
v8::Local<v8::Value> handleMaxRecursionDepthExceeded()
{
    throwError(RangeError, "Maximum call stack size exceeded.");
    return v8::Local<v8::Value>();
}
Example #13
0
JSObject* RuntimeObject::throwInvalidAccessError(ExecState* exec)
{
    return throwError(exec, createReferenceError(exec, "Trying to access object from destroyed plug-in."));
}
Example #14
0
v8::Handle<v8::Value> DateExtension::OnSleepDetected(const v8::Arguments& args)
{
    return throwError(v8GeneralError, "Too much time spent in unload handler.", args.GetIsolate());
}
Example #15
0
/*
 *	t h r o w M e s s a g e
 */
returnValue MessageHandling::throwMessage(
	returnValue RETnumber,
	const char* additionaltext,
	const char* functionname,
	const char* filename,
	const unsigned long linenumber,
	VisibilityStatus localVisibilityStatus,
	const char* RETstring
 	)
{
	#ifndef __SUPPRESSANYOUTPUT__
	#ifndef __XPCTARGET__
	int keypos = 0;
	char myPrintfString[160];

	/* 1) Determine number of whitespace for output. */
	char whitespaces[41];
	int numberOfWhitespaces = (errorCount-1)*2;

	if ( numberOfWhitespaces < 0 )
		numberOfWhitespaces = 0;

	if ( numberOfWhitespaces > 40 )
		numberOfWhitespaces = 40;

	memset( whitespaces, ' ', (size_t) numberOfWhitespaces );
	whitespaces[numberOfWhitespaces] = '\0';

	/* 2) Find error/warning/info in list. */
	while ( returnValueList[keypos].key != TERMINAL_LIST_ELEMENT )
	{
		if ( returnValueList[keypos].key == RETnumber )
			break;
		else
			++keypos;
	}

	if ( returnValueList[keypos].key == TERMINAL_LIST_ELEMENT )
	{
		throwError( RET_EWI_UNDEFINED,0,__FUNCTION__,__FILE__,__LINE__,VS_VISIBLE );
		return RETnumber;
	}

	/* 3) Print error/warning/info. */
	if ( ( returnValueList[keypos].globalVisibilityStatus == VS_VISIBLE ) && ( localVisibilityStatus == VS_VISIBLE ) )
	{

		if ( errorCount > 0 )
		{
			snprintf( myPrintfString,160,"%s->", whitespaces );
			myPrintf( myPrintfString );
		}

		if ( additionaltext == 0 )
		{
			#ifdef __DEBUG__
			snprintf(	myPrintfString,160,"%s (%s, %s:%d): \t%s\n",
						RETstring,functionname,filename,(int)linenumber,returnValueList[keypos].data
						);
			#else
			snprintf(	myPrintfString,160,"%s:  %s\n",
									RETstring,returnValueList[keypos].data
						);
			#endif
			myPrintf( myPrintfString );
		}
		else
		{
			#ifdef __DEBUG__
			snprintf(	myPrintfString,160,"%s (%s, %s:%d): \t%s %s\n",
						RETstring,functionname,filename,(int)linenumber,returnValueList[keypos].data,additionaltext
						);
			#else
			snprintf(	myPrintfString,160,"%s:  %s %s\n",
						RETstring,returnValueList[keypos].data,additionaltext
						);
			#endif
			myPrintf( myPrintfString );
		}

		/* take care of proper indention for subsequent error messages */
		if ( RETstring[0] == 'E' )
		{
			++errorCount;
		}
		else
		{
			if ( errorCount > 0 )
				myPrintf( "\n" );
			errorCount = 0;
		}
	}
	#endif /* __XPCTARGET__ */
	#endif /* __SUPPRESSANYOUTPUT__ */

	return RETnumber;
}
Example #16
0
/**
	copy operator - performs a deep copy of the Vector passed in as a parameter.
*/
Vector& Vector::operator=(const Matrix &other){
	if (other.getColumnCount() != 1)
		throwError("Cannot copy a matrix into a vector.");
	Matrix::deepCopy(other);
	return *this;
}
Example #17
0
bool FileFormat::restore(IPropertyTree * props)
{
    StringBuffer formatText;
    props->getProp(FPformat, formatText);
    const char * format = formatText.str();

    if (stricmp(format, "blocked")==0)
        type = FFTblocked;
    else if (stricmp(format, "variable")==0)
        type = FFTvariable;
    else if (stricmp(format, "variablebigendian")==0)
        type = FFTvariablebigendian;
    else if (stricmp(format, "csv")==0)
    {
        type = FFTcsv;
        maxRecordSize = props->getPropInt(FPmaxRecordSize, DEFAULT_MAX_CSV_SIZE);
        separate.set(props->queryProp(FPcsvSeparate));
        quote.set(props->queryProp(FPcsvQuote));
        terminate.set(props->queryProp(FPcsvTerminate));
        if (props->hasProp(FPcsvEscape))
            escape.set(props->queryProp(FPcsvEscape));
        if (maxRecordSize == 0)
            throwError(DFTERR_MaxRecordSizeZero);
    }
    else if (memicmp(format, "utf", 3) == 0)
    {
        type = FFTutf;
        const char * tail = format + 3;
        if (*tail == '-')
            tail++;
        if (stricmp(tail, "8")==0)
            type = FFTutf8;
        else if (stricmp(tail, "8N")==0)
            type = FFTutf8n;
        else if (stricmp(tail, "16")==0)
            type = FFTutf16;
        else if (stricmp(tail, "16BE")==0)
            type = FFTutf16be;
        else if (stricmp(tail, "16LE")==0)
            type = FFTutf16le;
        else if (stricmp(tail, "32")==0)
            type = FFTutf32;
        else if (stricmp(tail, "32BE")==0)
            type = FFTutf32be;
        else if (stricmp(tail, "32LE")==0)
            type = FFTutf32le;
        else if (*tail)
            throwError1(DFTERR_UnknownUTFFormat, format);
        maxRecordSize = props->getPropInt(FPmaxRecordSize, DEFAULT_MAX_CSV_SIZE);
        separate.set(props->queryProp(FPcsvSeparate));
        quote.set(props->queryProp(FPcsvQuote));
        terminate.set(props->queryProp(FPcsvTerminate));
        if (props->hasProp(FPcsvEscape))
            escape.set(props->queryProp(FPcsvEscape));
        rowTag.set(props->queryProp(FProwTag));
        if (maxRecordSize == 0)
            throwError(DFTERR_MaxRecordSizeZero);
    }
    else if ((stricmp(format, "recfmvb")==0)||(stricmp(format, "recfm-vb")==0))
        type = FFTrecfmvb;
    else if ((stricmp(format, "recfmv")==0)||(stricmp(format, "recfm-v")==0))
        type = FFTrecfmv;
    else if (props->hasProp(FPrecordSize))
    {
        type = FFTfixed;
        recordSize = props->getPropInt(FPrecordSize);
    }
    else
        return false;
    return true;
}
Example #18
0
/**
	this method performs a deep copy of the vector that is passed in as a paramerer.
*/
void Vector::deepCopy(const Matrix& other){
	if (other.getColumnCount() != 1)
		throwError("Cannot copy a matrix into a vector.");
	Matrix::deepCopy(other);
}
JSValue JSJavaScriptCallFrame::setVariableValue(JSC::ExecState* exec)
{
    // FIXME: implement this. https://bugs.webkit.org/show_bug.cgi?id=107830
    throwError(exec, createTypeError(exec, "Variable value mutation is not supported"));
    return jsUndefined();
}
Example #20
0
// ECMA 8.6.2.2
void JSObject::put(ExecState* exec, const Identifier& propertyName, JSValuePtr value, PutPropertySlot& slot)
{
    ASSERT(value);
    ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));

    if (propertyName == exec->propertyNames().underscoreProto) {
        // Setting __proto__ to a non-object, non-null value is silently ignored to match Mozilla.
        if (!value->isObject() && !value->isNull())
            return;

        JSValuePtr nextPrototypeValue = value;
        while (nextPrototypeValue && nextPrototypeValue->isObject()) {
            JSObject* nextPrototype = asObject(nextPrototypeValue)->unwrappedObject();
            if (nextPrototype == this) {
                throwError(exec, GeneralError, "cyclic __proto__ value");
                return;
            }
            nextPrototypeValue = nextPrototype->prototype();
        }

        setPrototype(value);
        return;
    }

    // Check if there are any setters or getters in the prototype chain
    JSValuePtr prototype;
    for (JSObject* obj = this; !obj->structure()->hasGetterSetterProperties(); obj = asObject(prototype)) {
        prototype = obj->prototype();
        if (prototype->isNull()) {
            putDirect(propertyName, value, 0, true, slot);
            return;
        }
    }
    
    unsigned attributes;
    if ((m_structure->get(propertyName, attributes) != WTF::notFound) && attributes & ReadOnly)
        return;

    for (JSObject* obj = this; ; obj = asObject(prototype)) {
        if (JSValuePtr gs = obj->getDirect(propertyName)) {
            if (gs->isGetterSetter()) {
                JSObject* setterFunc = asGetterSetter(gs)->setter();        
                if (!setterFunc) {
                    throwSetterError(exec);
                    return;
                }
                
                CallData callData;
                CallType callType = setterFunc->getCallData(callData);
                ArgList args;
                args.append(value);
                call(exec, setterFunc, callType, callData, this, args);
                return;
            }

            // If there's an existing property on the object or one of its 
            // prototypes it should be replaced, so break here.
            break;
        }

        prototype = obj->prototype();
        if (prototype->isNull())
            break;
    }

    putDirect(propertyName, value, 0, true, slot);
    return;
}
Example #21
0
v8::Handle<v8::Value> V8AudioContext::constructorCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.AudioContext.Contructor");

    if (!args.IsConstructCall())
        return throwTypeError("AudioContext constructor cannot be called as a function.", args.GetIsolate());

    if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
        return args.Holder();

    Frame* frame = currentFrame(BindingState::instance());
    if (!frame)
        return throwError(ReferenceError, "AudioContext constructor associated frame is unavailable", args.GetIsolate());

    Document* document = frame->document();
    if (!document)
        return throwError(ReferenceError, "AudioContext constructor associated document is unavailable", args.GetIsolate());

    RefPtr<AudioContext> audioContext;
    
    if (!args.Length()) {
        // Constructor for default AudioContext which talks to audio hardware.
        ExceptionCode ec = 0;
        audioContext = AudioContext::create(document, ec);
        if (ec)
            return setDOMException(ec, args.GetIsolate());
        if (!audioContext.get())
            return throwError(SyntaxError, "audio resources unavailable for AudioContext construction", args.GetIsolate());
    } else {
        // Constructor for offline (render-target) AudioContext which renders into an AudioBuffer.
        // new AudioContext(in unsigned long numberOfChannels, in unsigned long numberOfFrames, in float sampleRate);
        if (args.Length() < 3)
            return throwNotEnoughArgumentsError(args.GetIsolate());

        bool ok = false;

        int32_t numberOfChannels = toInt32(args[0], ok);
        if (!ok || numberOfChannels <= 0 || numberOfChannels > 10)
            return throwError(SyntaxError, "Invalid number of channels", args.GetIsolate());

        int32_t numberOfFrames = toInt32(args[1], ok);
        if (!ok || numberOfFrames <= 0)
            return throwError(SyntaxError, "Invalid number of frames", args.GetIsolate());

        float sampleRate = toFloat(args[2]);
        if (sampleRate <= 0)
            return throwError(SyntaxError, "Invalid sample rate", args.GetIsolate());

        ExceptionCode ec = 0;
        audioContext = AudioContext::createOfflineContext(document, numberOfChannels, numberOfFrames, sampleRate, ec);
        if (ec)
            return setDOMException(ec, args.GetIsolate());
    }

    if (!audioContext.get())
        return throwError(SyntaxError, "Error creating AudioContext", args.GetIsolate());
    
    // Transform the holder into a wrapper object for the audio context.
    V8DOMWrapper::setDOMWrapper(args.Holder(), &info, audioContext.get());
    audioContext->ref();
    
    return args.Holder();
}
Example #22
0
static void throwSetterError(ExecState* exec)
{
    throwError(exec, TypeError, "setting a property that has only a getter");
}
Example #23
0
ITransformer * createTransformer(const FileFormat & srcFormat, const FileFormat & tgtFormat, size32_t buffersize)
{
    ITransformer * transformer = NULL;

#ifdef OPTIMIZE_COMMON_TRANSFORMS
    if (srcFormat.equals(tgtFormat))
        transformer = new CNullTransformer(buffersize);
    else
    {
        switch (srcFormat.type)
        {
        case FFTfixed:
            switch (tgtFormat.type)
            {
            case FFTvariable:
            case FFTvariablebigendian:
                transformer = new CFixedToVarTransformer(srcFormat.recordSize,buffersize,(tgtFormat.type==FFTvariablebigendian));
                break;
            }
            break;
        case FFTvariable:
        case FFTvariablebigendian:
            switch (tgtFormat.type)
            {
            case FFTfixed:
                transformer = new CVarToFixedTransformer(tgtFormat.recordSize,buffersize,(srcFormat.type==FFTvariablebigendian));
                break;
            case FFTblocked:
                transformer = new CVarToBlockTransformer((srcFormat.type==FFTvariablebigendian));
                break;
            }
            break;
        case FFTblocked:
            switch (tgtFormat.type)
            {
            case FFTvariable:
            case FFTvariablebigendian:
                transformer = new CBlockToVarTransformer((tgtFormat.type==FFTvariablebigendian));
                break;
            }
            break;
        case FFTutf8: case FFTutf8n:
            switch (tgtFormat.type)
            {
            case FFTutf8n: 
            case FFTutf8:
                transformer = new CNullTransformer(buffersize);
                break;
            case FFTutf16: case FFTutf16be: case FFTutf16le: case FFTutf32: case FFTutf32be: case FFTutf32le:
                break;
            default:
                throwError(DFTERR_BadSrcTgtCombination);
            }
            break;
        case FFTutf16: case FFTutf16be: case FFTutf16le: case FFTutf32: case FFTutf32be: case FFTutf32le:
            switch (tgtFormat.type)
            {
            case FFTutf8: case FFTutf8n: case FFTutf16: case FFTutf16be: case FFTutf16le: case FFTutf32: case FFTutf32be: case FFTutf32le:
                break;
            default:
                throwError(DFTERR_BadSrcTgtCombination);
            }
            break;
        }
    }
#endif

    if (!transformer)
        transformer = new CGeneralTransformer(srcFormat, tgtFormat);
//      throwError(DFTERR_BadSrcTgtCombination);
    
    return transformer;
}
Example #24
0
JSValue* JSHTMLTableElementPrototypeFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
{
    if (!thisObj->inherits(&JSHTMLTableElement::info))
      return throwError(exec, TypeError);

    JSHTMLTableElement* castedThisObj = static_cast<JSHTMLTableElement*>(thisObj);
    HTMLTableElement* imp = static_cast<HTMLTableElement*>(castedThisObj->impl());

    switch (id) {
    case JSHTMLTableElement::CreateTHeadFuncNum: {


        KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createTHead()));
        return result;
    }
    case JSHTMLTableElement::DeleteTHeadFuncNum: {

        imp->deleteTHead();
        return jsUndefined();
    }
    case JSHTMLTableElement::CreateTFootFuncNum: {


        KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createTFoot()));
        return result;
    }
    case JSHTMLTableElement::DeleteTFootFuncNum: {

        imp->deleteTFoot();
        return jsUndefined();
    }
    case JSHTMLTableElement::CreateCaptionFuncNum: {


        KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createCaption()));
        return result;
    }
    case JSHTMLTableElement::DeleteCaptionFuncNum: {

        imp->deleteCaption();
        return jsUndefined();
    }
    case JSHTMLTableElement::InsertRowFuncNum: {
        ExceptionCode ec = 0;
        bool indexOk;
        int index = args[0]->toInt32(exec, indexOk);
        if (!indexOk) {
            setDOMException(exec, TYPE_MISMATCH_ERR);
            return jsUndefined();
        }


        KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->insertRow(index, ec)));
        setDOMException(exec, ec);
        return result;
    }
    case JSHTMLTableElement::DeleteRowFuncNum: {
        ExceptionCode ec = 0;
        bool indexOk;
        int index = args[0]->toInt32(exec, indexOk);
        if (!indexOk) {
            setDOMException(exec, TYPE_MISMATCH_ERR);
            return jsUndefined();
        }

        imp->deleteRow(index, ec);
        setDOMException(exec, ec);
        return jsUndefined();
    }
    }
    return 0;
}
Example #25
0
int
CArchNetworkWinsock::pollSocket(CPollEntry pe[], int num, double timeout)
{
	int i;
	DWORD n;

	// prepare sockets and wait list
	bool canWrite = false;
	WSAEVENT* events = (WSAEVENT*)alloca((num + 1) * sizeof(WSAEVENT));
	for (i = 0, n = 0; i < num; ++i) {
		// reset return flags
		pe[i].m_revents = 0;

		// set invalid flag if socket is bogus then go to next socket
		if (pe[i].m_socket == NULL) {
			pe[i].m_revents |= kPOLLNVAL;
			continue;
		}

		// select desired events
		long socketEvents = 0;
		if ((pe[i].m_events & kPOLLIN) != 0) {
			socketEvents |= FD_READ | FD_ACCEPT | FD_CLOSE;
		}
		if ((pe[i].m_events & kPOLLOUT) != 0) {
			socketEvents |= FD_WRITE | FD_CONNECT | FD_CLOSE;

			// if m_pollWrite is false then we assume the socket is
			// writable.  winsock doesn't signal writability except
			// when the state changes from unwritable.
			if (!pe[i].m_socket->m_pollWrite) {
				canWrite         = true;
				pe[i].m_revents |= kPOLLOUT;
			}
		}

		// if no events then ignore socket
		if (socketEvents == 0) {
			continue;
		}

		// select socket for desired events
		WSAEventSelect_winsock(pe[i].m_socket->m_socket,
							pe[i].m_socket->m_event, socketEvents);

		// add socket event to wait list
		events[n++] = pe[i].m_socket->m_event;
	}

	// if no sockets then return immediately
	if (n == 0) {
		return 0;
	}

	// add the unblock event
	CArchMultithreadWindows* mt = CArchMultithreadWindows::getInstance();
	CArchThread thread     = mt->newCurrentThread();
	WSAEVENT* unblockEvent = (WSAEVENT*)mt->getNetworkDataForThread(thread);
	ARCH->closeThread(thread);
	if (unblockEvent == NULL) {
		unblockEvent  = new WSAEVENT;
		m_unblockEvents.push_back(unblockEvent);
		*unblockEvent = WSACreateEvent_winsock();
		mt->setNetworkDataForCurrentThread(unblockEvent);
	}
	events[n++] = *unblockEvent;

	// prepare timeout
	DWORD t = (timeout < 0.0) ? INFINITE : (DWORD)(1000.0 * timeout);
	if (canWrite) {
		// if we know we can write then don't block
		t = 0;
	}

	// wait
	DWORD result = WSAWaitForMultipleEvents_winsock(n, events, FALSE, t, FALSE);

	// reset the unblock event
	WSAResetEvent_winsock(*unblockEvent);

	// handle results
	if (result == WSA_WAIT_FAILED) {
		if (getsockerror_winsock() == WSAEINTR) {
			// interrupted system call
			ARCH->testCancelThread();
			return 0;
		}
		throwError(getsockerror_winsock());
	}
	if (result == WSA_WAIT_TIMEOUT && !canWrite) {
		return 0;
	}
	if (result == WSA_WAIT_EVENT_0 + n - 1) {
		// the unblock event was signalled
		return 0;
	}
	for (i = 0, n = 0; i < num; ++i) {
		// skip events we didn't check
		if (pe[i].m_socket == NULL ||
			(pe[i].m_events & (kPOLLIN | kPOLLOUT)) == 0) {
			continue;
		}

		// get events
		WSANETWORKEVENTS info;
		if (WSAEnumNetworkEvents_winsock(pe[i].m_socket->m_socket,
							pe[i].m_socket->m_event, &info) == SOCKET_ERROR) {
			continue;
		}
		if ((info.lNetworkEvents & FD_READ) != 0) {
			pe[i].m_revents |= kPOLLIN;
		}
		if ((info.lNetworkEvents & FD_ACCEPT) != 0) {
			pe[i].m_revents |= kPOLLIN;
		}
		if ((info.lNetworkEvents & FD_WRITE) != 0) {
			pe[i].m_revents |= kPOLLOUT;

			// socket is now writable so don't bothing polling for
			// writable until it becomes unwritable.
			pe[i].m_socket->m_pollWrite = false;
		}
		if ((info.lNetworkEvents & FD_CONNECT) != 0) {
			if (info.iErrorCode[FD_CONNECT_BIT] != 0) {
				pe[i].m_revents |= kPOLLERR;
			}
			else {
				pe[i].m_revents |= kPOLLOUT;
				pe[i].m_socket->m_pollWrite = false;
			}
		}
		if ((info.lNetworkEvents & FD_CLOSE) != 0) {
			if (info.iErrorCode[FD_CLOSE_BIT] != 0) {
				pe[i].m_revents |= kPOLLERR;
			}
			else {
				if ((pe[i].m_events & kPOLLIN) != 0) {
					pe[i].m_revents |= kPOLLIN;
				}
				if ((pe[i].m_events & kPOLLOUT) != 0) {
					pe[i].m_revents |= kPOLLOUT;
				}
			}
		}
		if (pe[i].m_revents != 0) {
			++n;
		}
	}

	return (int)n;
}
Example #26
0
JSObject* throwTypeError(ExecState* exec)
{
    return throwError(exec, createTypeError(exec, "Type error"));
}
Example #27
0
/**
	This method	computes the inverse of	the	matrix a and writes	it over	the	current	matrix.
*/
void Matrix::setToInverseOf(const Matrix &a, double t){
		if (a.matrix->size1 != a.matrix->size2)
			throwError("Cannot invert a matrix that is not square");
	
		int DIM = (int)a.matrix->size1;
		this->resizeTo(DIM, DIM);

//we'll write some messy code and try to get efficient inverses by means of determinants for 1x1, 2x2 and 3x3 matrices. We'll also safeguard 
//against very small determinants if desired...
		if (DIM == 1){
			double a00 = MATRIX_AT(a.matrix, 0, 0);
			if (fabs(a00)<t)
				a00 = t * fabs(a00)/a00;
			MATRIX_AT(this->matrix, 0, 0) = 1/a00;
			return;
		}

		if (DIM == 2){
			double a11 = MATRIX_AT(a.matrix, 0, 0);
			double a12 = MATRIX_AT(a.matrix, 0, 1);
			double a21 = MATRIX_AT(a.matrix, 1, 0);
			double a22 = MATRIX_AT(a.matrix, 1, 1);
			
			double det = a11*a22-a12*a21;
			if (fabs(det)<t)
				det = t * fabs(det)/det;

			MATRIX_AT(this->matrix, 0, 0) = a22 / det;
			MATRIX_AT(this->matrix, 0, 1) = -a12 / det;
			MATRIX_AT(this->matrix, 1, 0) = -a21 / det;
			MATRIX_AT(this->matrix, 1, 1) = a11 / det;
			return;
		}

		if (DIM == 3){
			double a11 = MATRIX_AT(a.matrix, 0, 0);
			double a12 = MATRIX_AT(a.matrix, 0, 1);
			double a13 = MATRIX_AT(a.matrix, 0, 2);

			double a21 = MATRIX_AT(a.matrix, 1, 0);
			double a22 = MATRIX_AT(a.matrix, 1, 1);
			double a23 = MATRIX_AT(a.matrix, 1, 2);

			double a31 = MATRIX_AT(a.matrix, 2, 0);
			double a32 = MATRIX_AT(a.matrix, 2, 1);
			double a33 = MATRIX_AT(a.matrix, 2, 2);
			
			double det = a11*(a33*a22-a32*a23)-a21*(a33*a12-a32*a13)+a31*(a23*a12-a22*a13);

			if (fabs(det)<t)
				det = t * fabs(det)/det;

			MATRIX_AT(this->matrix, 0, 0) = (a33*a22-a32*a23)/det;
			MATRIX_AT(this->matrix, 0, 1) = -(a33*a12-a32*a13)/det;
			MATRIX_AT(this->matrix, 0, 2) = (a23*a12-a22*a13)/det;

			MATRIX_AT(this->matrix, 1, 0) = -(a33*a21-a31*a23)/det;
			MATRIX_AT(this->matrix, 1, 1) = (a33*a11-a31*a13)/det;
			MATRIX_AT(this->matrix, 1, 2) = -(a23*a11-a21*a13)/det;


			MATRIX_AT(this->matrix, 2, 0) = (a32*a21-a31*a22)/det;
			MATRIX_AT(this->matrix, 2, 1) = -(a32*a11-a31*a12)/det;
			MATRIX_AT(this->matrix, 2, 2) = (a22*a11-a21*a12)/det;

			return;
		}

//ok, it's already messy, so if the dimmensions are even bigger than 3, we'll do it by row reduction


		double val, val2;
		int i, j, k, ind;
		
		//make a copy of the current matrix
		Matrix tmp = a;

		this->loadIdentity();
    
		for (i = 0; i != DIM; i++) {
			
			val = MATRIX_AT(tmp.matrix, i, i);			/* find pivot */
			ind = i;
			for (j = i + 1; j != DIM; j++) {
				if (fabs(MATRIX_AT(tmp.matrix, j, i)) > fabs(val)) {
					ind = j;
					val = MATRIX_AT(tmp.matrix, j, i);
				}
			}
            
			if (ind != i) {			
				for (j = 0; j != DIM; j++) {
					val2 = MATRIX_AT(this->matrix, i, j);
					MATRIX_AT(this->matrix,i,j) = MATRIX_AT(this->matrix, ind, j);
					MATRIX_AT(this->matrix,ind,j) = val2;           /* swap columns */
					val2 = MATRIX_AT(tmp.matrix, i, j);
					MATRIX_AT(tmp.matrix,i,j) = MATRIX_AT(tmp.matrix, ind, j);
					MATRIX_AT(tmp.matrix, ind,j) = val2;
				}
			}

			//safeguard against zero's if need be...
			if (fabs(val)<t)
				val = t * fabs(val)/val;

			if (IS_ZERO(val))
				throwError("Matrix is singular.");
            
			for (j = 0; j != DIM; j++) {
				MATRIX_AT(tmp.matrix, i, j) /= val;
				MATRIX_AT(this->matrix, i, j) /= val;
			}
        
			for (j = 0; j != DIM; j++) {		
				if (j == i)
					continue;                       /* eliminate column */
				val = MATRIX_AT(tmp.matrix, j, i);
				for (k = 0; k != DIM; k++) {
					MATRIX_AT(tmp.matrix, j,k) = MATRIX_AT(tmp.matrix, j, k) - MATRIX_AT(tmp.matrix, i, k)  * val;
					MATRIX_AT(this->matrix, j,k) = MATRIX_AT(this->matrix, j, k) - MATRIX_AT(this->matrix, i, k)  * val;
				}
			}
		}

		//and done
}
Example #28
0
JSObject* throwSyntaxError(ExecState* exec)
{
    return throwError(exec, createSyntaxError(exec, "Syntax error"));
}
// ES5 8.10.5 ToPropertyDescriptor
static bool toPropertyDescriptor(ExecState* exec, JSValue in, PropertyDescriptor& desc)
{
    if (!in.isObject()) {
        throwError(exec, TypeError, "Property description must be an object.");
        return false;
    }
    JSObject* description = asObject(in);

    PropertySlot enumerableSlot;
    if (description->getPropertySlot(exec, exec->propertyNames().enumerable, enumerableSlot)) {
        desc.setEnumerable(enumerableSlot.getValue(exec, exec->propertyNames().enumerable).toBoolean(exec));
        if (exec->hadException())
            return false;
    }

    PropertySlot configurableSlot;
    if (description->getPropertySlot(exec, exec->propertyNames().configurable, configurableSlot)) {
        desc.setConfigurable(configurableSlot.getValue(exec, exec->propertyNames().configurable).toBoolean(exec));
        if (exec->hadException())
            return false;
    }

    JSValue value;
    PropertySlot valueSlot;
    if (description->getPropertySlot(exec, exec->propertyNames().value, valueSlot)) {
        desc.setValue(valueSlot.getValue(exec, exec->propertyNames().value));
        if (exec->hadException())
            return false;
    }

    PropertySlot writableSlot;
    if (description->getPropertySlot(exec, exec->propertyNames().writable, writableSlot)) {
        desc.setWritable(writableSlot.getValue(exec, exec->propertyNames().writable).toBoolean(exec));
        if (exec->hadException())
            return false;
    }

    PropertySlot getSlot;
    if (description->getPropertySlot(exec, exec->propertyNames().get, getSlot)) {
        JSValue get = getSlot.getValue(exec, exec->propertyNames().get);
        if (exec->hadException())
            return false;
        if (!get.isUndefined()) {
            CallData callData;
            if (get.getCallData(callData) == CallTypeNone) {
                throwError(exec, TypeError, "Getter must be a function.");
                return false;
            }
        } else
            get = JSValue();
        desc.setGetter(get);
    }

    PropertySlot setSlot;
    if (description->getPropertySlot(exec, exec->propertyNames().set, setSlot)) {
        JSValue set = setSlot.getValue(exec, exec->propertyNames().set);
        if (exec->hadException())
            return false;
        if (!set.isUndefined()) {
            CallData callData;
            if (set.getCallData(callData) == CallTypeNone) {
                throwError(exec, TypeError, "Setter must be a function.");
                return false;
            }
        } else
            set = JSValue();

        desc.setSetter(set);
    }

    if (!desc.isAccessorDescriptor())
        return true;

    if (desc.value()) {
        throwError(exec, TypeError, "Invalid property.  'value' present on property with getter or setter.");
        return false;
    }

    if (desc.writablePresent()) {
        throwError(exec, TypeError, "Invalid property.  'writable' present on property with getter or setter.");
        return false;
    }
    return true;
}
Example #30
0
v8::Handle<v8::Value> V8Proxy::throwSyntaxError()
{
    return throwError(SyntaxError, "Syntax error");
}