コード例 #1
0
JSValue JSWebSocket::close(ExecState* exec)
{
    // FIXME: We should implement [Clamp] for IDL binding code generator, and
    // remove this custom method.
    WebSocket* webSocket = static_cast<WebSocket*>(impl());
    size_t argumentCount = exec->argumentCount();
    int code = WebSocketChannel::CloseEventCodeNotSpecified;
    String reason = "";
    if (argumentCount >= 1) {
        JSValue v = exec->argument(0);
        double x = v.toNumber(exec);
        double maxValue = static_cast<double>(std::numeric_limits<uint16_t>::max());
        double minValue = static_cast<double>(std::numeric_limits<uint16_t>::min());
        if (isnan(x))
            x = 0.0;
        else
            x = clampTo(x, minValue, maxValue);
        code = clampToInteger(x);
        if (argumentCount >= 2) {
            reason = ustringToString(exec->argument(1).toString(exec)->value(exec));
            if (exec->hadException()) {
                setDOMException(exec, SYNTAX_ERR);
                return jsUndefined();
            }
        }
    }
    ExceptionCode ec = 0;
    webSocket->close(code, reason, ec);
    setDOMException(exec, ec);
    return jsUndefined();
}
コード例 #2
0
ファイル: V8WebSocketCustom.cpp プロジェクト: 1833183060/wke
v8::Handle<v8::Value> V8WebSocket::closeCallback(const v8::Arguments& args)
{
    // FIXME: We should implement [Clamp] for IDL binding code generator, and
    // remove this custom method.
    WebSocket* webSocket = toNative(args.Holder());
    int argumentCount = args.Length();
    int code = WebSocketChannel::CloseEventCodeNotSpecified;
    String reason = "";
    if (argumentCount >= 1) {
        double x = args[0]->NumberValue();
        double maxValue = static_cast<double>(std::numeric_limits<uint16_t>::max());
        double minValue = static_cast<double>(std::numeric_limits<uint16_t>::min());
        if (isnan(x))
            x = 0.0;
        else
            x = clampTo(x, minValue, maxValue);
        code = clampToInteger(x);
        if (argumentCount >= 2) {
            v8::TryCatch tryCatch;
            v8::Handle<v8::String> reasonValue = args[1]->ToString();
            if (tryCatch.HasCaught())
                return throwError(tryCatch.Exception());
            reason = toWebCoreString(reasonValue);
        }
    }
    ExceptionCode ec = 0;
    webSocket->close(code, reason, ec);
    if (ec)
        return throwError(ec);
    return v8::Undefined();
}
コード例 #3
0
ファイル: JSWebSocket.cpp プロジェクト: Mr-Kumar-Abhishek/qt
JSValue JSC_HOST_CALL jsWebSocketPrototypeFunctionClose(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
{
    UNUSED_PARAM(args);
    if (!thisValue.inherits(&JSWebSocket::s_info))
        return throwError(exec, TypeError);
    JSWebSocket* castedThisObj = static_cast<JSWebSocket*>(asObject(thisValue));
    WebSocket* imp = static_cast<WebSocket*>(castedThisObj->impl());

    imp->close();
    return jsUndefined();
}
コード例 #4
0
ファイル: JSWebSocket.cpp プロジェクト: 13W/phantomjs
EncodedJSValue JSC_HOST_CALL jsWebSocketPrototypeFunctionClose(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    if (!thisValue.inherits(&JSWebSocket::s_info))
        return throwVMTypeError(exec);
    JSWebSocket* castedThis = static_cast<JSWebSocket*>(asObject(thisValue));
    WebSocket* imp = static_cast<WebSocket*>(castedThis->impl());

    imp->close();
    return JSValue::encode(jsUndefined());
}
コード例 #5
0
ファイル: jsb_websocket.cpp プロジェクト: Ben-Cortina/GameBox
JSBool js_cocos2dx_extension_WebSocket_close(JSContext *cx, uint32_t argc, jsval *vp){
	JSObject *obj = JS_THIS_OBJECT(cx, vp);
	js_proxy_t *proxy = jsb_get_js_proxy(obj);
	WebSocket* cobj = (WebSocket *)(proxy ? proxy->ptr : NULL);
	JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
    
	if(argc == 0){
		cobj->close();
		JS_SET_RVAL(cx, vp, JSVAL_VOID);
		return JS_TRUE;
	}
	JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
	return JS_FALSE;
}
コード例 #6
0
bool js_cocos2dx_extension_WebSocket_close(JSContext *cx, uint32_t argc, jsval *vp){
    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
    js_proxy_t *proxy = jsb_get_js_proxy(obj);
    WebSocket* cobj = (WebSocket *)(proxy ? proxy->ptr : NULL);
    JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");
    
    if(argc == 0){
        cobj->close();
        args.rval().setUndefined();
        return true;
    }
    JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
    return false;
}
コード例 #7
0
ファイル: SocketIO.cpp プロジェクト: Abioy/OpenBird
void SIOClientImpl::disconnect()
{
	if(_ws->getReadyState() == WebSocket::State::OPEN)
    {
		std::string s = "0::";

		_ws->send(s);

		log("Disconnect sent");

		_ws->close();
	}

	Director::getInstance()->getScheduler()->unscheduleAllForTarget(this);

	_connected = false;

	SocketIO::getInstance()->removeSocket(_uri);
}
コード例 #8
0
ファイル: WebSocket.cpp プロジェクト: RobloxLabs/OpenBlox
	/**
	 * @author John M. Harris, Jr.
	 * @internal
	 */
	int WebSocket::lua_close(lua_State* L){
		WebSocket* LuaWebSocket = checkWebSocket(L, 1);
		if(LuaWebSocket){
			if(LuaWebSocket->m_webSocket){
				if(LuaWebSocket->m_webSocket->getState() == QAbstractSocket::ConnectedState){
					ob_enum::LuaEnumItem* val = ob_enum::checkEnumItem(L, 2, ob_enum::LuaCloseCode);
					ob_enum::CloseCode cc = ob_enum::CloseCode::Normal;
					if(val){
						cc = (ob_enum::CloseCode)val->value;
					}
					QString reason;
					if(lua_isstring(L, 3)){
						reason = QString(lua_tostring(L, 3));
					}
					LuaWebSocket->close(cc, reason);
					return 0;
				}
			}
			luaL_error(L, "WebSocket is already closed.");
		}
		return 0;
	}