1 | /* |
2 | * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) |
3 | * Copyright (C) 2003-2006, 2008-2009, 2013, 2016 Apple Inc. All rights reserved. |
4 | * Copyright (C) 2007 Samuel Weinig <sam@webkit.org> |
5 | * Copyright (C) 2009 Google, Inc. All rights reserved. |
6 | * Copyright (C) 2012 Ericsson AB. All rights reserved. |
7 | * Copyright (C) 2013 Michael Pruett <michael@68k.org> |
8 | * |
9 | * This library is free software; you can redistribute it and/or |
10 | * modify it under the terms of the GNU Lesser General Public |
11 | * License as published by the Free Software Foundation; either |
12 | * version 2 of the License, or (at your option) any later version. |
13 | * |
14 | * This library is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 | * Lesser General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU Lesser General Public |
20 | * License along with this library; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | */ |
23 | |
24 | #pragma once |
25 | |
26 | #include "JSDOMCastedThisErrorBehavior.h" |
27 | #include "JSDOMExceptionHandling.h" |
28 | |
29 | namespace WebCore { |
30 | |
31 | template<typename JSClass> |
32 | class IDLOperation { |
33 | public: |
34 | using ClassParameter = JSClass*; |
35 | using Operation = JSC::EncodedJSValue(JSC::ExecState*, ClassParameter, JSC::ThrowScope&); |
36 | using StaticOperation = JSC::EncodedJSValue(JSC::ExecState*, JSC::ThrowScope&); |
37 | |
38 | static JSClass* cast(JSC::ExecState&); |
39 | |
40 | template<Operation operation, CastedThisErrorBehavior shouldThrow = CastedThisErrorBehavior::Throw> |
41 | static JSC::EncodedJSValue call(JSC::ExecState& state, const char* operationName) |
42 | { |
43 | auto throwScope = DECLARE_THROW_SCOPE(state.vm()); |
44 | |
45 | auto* thisObject = cast(state); |
46 | if (shouldThrow != CastedThisErrorBehavior::Assert && UNLIKELY(!thisObject)) |
47 | return throwThisTypeError(state, throwScope, JSClass::info()->className, operationName); |
48 | |
49 | ASSERT(thisObject); |
50 | ASSERT_GC_OBJECT_INHERITS(thisObject, JSClass::info()); |
51 | |
52 | // FIXME: We should refactor the binding generated code to use references for state and thisObject. |
53 | return operation(&state, thisObject, throwScope); |
54 | } |
55 | |
56 | template<StaticOperation operation, CastedThisErrorBehavior shouldThrow = CastedThisErrorBehavior::Throw> |
57 | static JSC::EncodedJSValue callStatic(JSC::ExecState& state, const char*) |
58 | { |
59 | auto throwScope = DECLARE_THROW_SCOPE(state.vm()); |
60 | |
61 | // FIXME: We should refactor the binding generated code to use references for state. |
62 | return operation(&state, throwScope); |
63 | } |
64 | }; |
65 | |
66 | } // namespace WebCore |
67 | |