1/*
2 * Copyright (C) 2013 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "JSInjectedScriptHostPrototype.h"
28
29#if ENABLE(INSPECTOR)
30
31#include "Error.h"
32#include "GetterSetter.h"
33#include "Identifier.h"
34#include "InjectedScriptHost.h"
35#include "JSCInlines.h"
36#include "JSFunction.h"
37#include "JSInjectedScriptHost.h"
38
39using namespace JSC;
40
41namespace Inspector {
42
43static EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionType(ExecState*);
44static EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionFunctionDetails(ExecState*);
45static EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionGetInternalProperties(ExecState*);
46static EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionInternalConstructorName(ExecState*);
47static EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionIsHTMLAllCollection(ExecState*);
48
49static EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeAttributeEvaluate(ExecState*);
50
51const ClassInfo JSInjectedScriptHostPrototype::s_info = { "InjectedScriptHost", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(JSInjectedScriptHostPrototype) };
52
53void JSInjectedScriptHostPrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
54{
55    Base::finishCreation(vm);
56    ASSERT(inherits(info()));
57    vm.prototypeMap.addPrototype(this);
58
59    JSC_NATIVE_FUNCTION("type", jsInjectedScriptHostPrototypeFunctionType, DontEnum, 1);
60    JSC_NATIVE_FUNCTION("functionDetails", jsInjectedScriptHostPrototypeFunctionFunctionDetails, DontEnum, 1);
61    JSC_NATIVE_FUNCTION("getInternalProperties", jsInjectedScriptHostPrototypeFunctionGetInternalProperties, DontEnum, 1);
62    JSC_NATIVE_FUNCTION("internalConstructorName", jsInjectedScriptHostPrototypeFunctionInternalConstructorName, DontEnum, 1);
63    JSC_NATIVE_FUNCTION("isHTMLAllCollection", jsInjectedScriptHostPrototypeFunctionIsHTMLAllCollection, DontEnum, 1);
64
65    Identifier evaluateIdentifier(&vm, "evaluate");
66    GetterSetter* accessor = GetterSetter::create(vm);
67    JSFunction* function = JSFunction::create(vm, globalObject, 0, evaluateIdentifier.string(), jsInjectedScriptHostPrototypeAttributeEvaluate);
68    accessor->setGetter(vm, function);
69    putDirectNonIndexAccessor(vm, evaluateIdentifier, accessor, DontEnum | Accessor);
70}
71
72EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeAttributeEvaluate(ExecState* exec)
73{
74    JSValue thisValue = exec->thisValue();
75    JSInjectedScriptHost* castedThis = jsDynamicCast<JSInjectedScriptHost*>(thisValue);
76    if (!castedThis)
77        return throwVMTypeError(exec);
78
79    ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
80    return JSValue::encode(castedThis->evaluate(exec));
81}
82
83EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionInternalConstructorName(ExecState* exec)
84{
85    JSValue thisValue = exec->thisValue();
86    JSInjectedScriptHost* castedThis = jsDynamicCast<JSInjectedScriptHost*>(thisValue);
87    if (!castedThis)
88        return throwVMTypeError(exec);
89
90    ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
91    return JSValue::encode(castedThis->internalConstructorName(exec));
92}
93
94EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionIsHTMLAllCollection(ExecState* exec)
95{
96    JSValue thisValue = exec->thisValue();
97    JSInjectedScriptHost* castedThis = jsDynamicCast<JSInjectedScriptHost*>(thisValue);
98    if (!castedThis)
99        return throwVMTypeError(exec);
100
101    ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
102    return JSValue::encode(castedThis->isHTMLAllCollection(exec));
103}
104
105EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionType(ExecState* exec)
106{
107    JSValue thisValue = exec->thisValue();
108    JSInjectedScriptHost* castedThis = jsDynamicCast<JSInjectedScriptHost*>(thisValue);
109    if (!castedThis)
110        return throwVMTypeError(exec);
111
112    ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
113    return JSValue::encode(castedThis->type(exec));
114}
115
116EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionFunctionDetails(ExecState* exec)
117{
118    JSValue thisValue = exec->thisValue();
119    JSInjectedScriptHost* castedThis = jsDynamicCast<JSInjectedScriptHost*>(thisValue);
120    if (!castedThis)
121        return throwVMTypeError(exec);
122
123    ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
124    return JSValue::encode(castedThis->functionDetails(exec));
125}
126
127EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionGetInternalProperties(ExecState* exec)
128{
129    JSValue thisValue = exec->thisValue();
130    JSInjectedScriptHost* castedThis = jsDynamicCast<JSInjectedScriptHost*>(thisValue);
131    if (!castedThis)
132        return throwVMTypeError(exec);
133
134    ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
135    return JSValue::encode(castedThis->getInternalProperties(exec));
136}
137
138} // namespace Inspector
139
140#endif // ENABLE(INSPECTOR)
141