2 Copyright (C) 2012 Intel Corporation
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
23 #include "Dictionary.h"
24 #include "ExceptionCode.h"
25 #include "JSCJSValue.h"
26 #include "JSDOMBinding.h"
28 #include "JSMessagePortCustom.h"
29 #include <runtime/Error.h>
30 #include <wtf/ArrayBuffer.h>
36 EncodedJSValue JSC_HOST_CALL JSIntentConstructor::constructJSIntent(ExecState* exec)
38 JSIntentConstructor* castedThis = jsCast<JSIntentConstructor*>(exec->callee());
40 if (exec->argumentCount() < 1)
41 return throwVMError(exec, createNotEnoughArgumentsError(exec));
43 if (exec->argumentCount() == 1) {
44 // Use the dictionary constructor. This block will return if the
45 // argument isn't a valid Dictionary.
46 JSValue optionsValue = exec->argument(0);
47 if (!optionsValue.isObject()) {
48 setDOMException(exec, SYNTAX_ERR);
49 return JSValue::encode(jsUndefined());
51 Dictionary options(exec, optionsValue);
52 if (exec->hadException())
53 return JSValue::encode(jsUndefined());
56 RefPtr<Intent> impl = Intent::create(exec, options, ec);
58 setDOMException(exec, ec);
59 return JSValue::encode(jsUndefined());
61 return JSValue::encode(asObject(toJS(exec, castedThis->globalObject(), impl.get())));
64 const String action(MAYBE_MISSING_PARAMETER(exec, 0, DefaultIsUndefined).isEmpty() ? String() : MAYBE_MISSING_PARAMETER(exec, 0, DefaultIsUndefined).toWTFString(exec));
65 if (exec->hadException())
66 return JSValue::encode(jsUndefined());
68 const String type(MAYBE_MISSING_PARAMETER(exec, 1, DefaultIsUndefined).isEmpty() ? String() : MAYBE_MISSING_PARAMETER(exec, 1, DefaultIsUndefined).toWTFString(exec));
69 if (exec->hadException())
70 return JSValue::encode(jsUndefined());
72 MessagePortArray messagePortArrayTransferList;
73 ArrayBufferArray arrayBufferArrayTransferList;
74 if (exec->argumentCount() > 3) {
75 fillMessagePortArray(exec, exec->argument(3), messagePortArrayTransferList, arrayBufferArrayTransferList);
76 if (exec->hadException())
77 return JSValue::encode(jsUndefined());
79 RefPtr<SerializedScriptValue> data = SerializedScriptValue::create(exec, exec->argument(2), &messagePortArrayTransferList, &arrayBufferArrayTransferList);
80 if (exec->hadException())
81 return JSValue::encode(jsUndefined());
84 RefPtr<Intent> impl = Intent::create(action, type, data, messagePortArrayTransferList, ec);
86 setDOMException(exec, ec);
87 return JSValue::encode(jsUndefined());
89 return JSValue::encode(asObject(toJS(exec, castedThis->globalObject(), impl.get())));
92 } // namespace WebCore