b069073f8082080beefcfa714050669f25f16559
[WebKit-https.git] / Source / JavaScriptCore / inspector / JSInjectedScriptHostPrototype.cpp
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 #include "Error.h"
30 #include "GetterSetter.h"
31 #include "Identifier.h"
32 #include "InjectedScriptHost.h"
33 #include "JSCInlines.h"
34 #include "JSFunction.h"
35 #include "JSInjectedScriptHost.h"
36
37 using namespace JSC;
38
39 namespace Inspector {
40
41 static EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionSubtype(ExecState*);
42 static EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionFunctionDetails(ExecState*);
43 static EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionGetInternalProperties(ExecState*);
44 static EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionInternalConstructorName(ExecState*);
45 static EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionIsHTMLAllCollection(ExecState*);
46 static EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionWeakMapEntries(ExecState*);
47
48 static EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeAttributeEvaluate(ExecState*);
49
50 const ClassInfo JSInjectedScriptHostPrototype::s_info = { "InjectedScriptHost", &Base::s_info, 0, CREATE_METHOD_TABLE(JSInjectedScriptHostPrototype) };
51
52 void JSInjectedScriptHostPrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
53 {
54     Base::finishCreation(vm);
55     ASSERT(inherits(info()));
56     vm.prototypeMap.addPrototype(this);
57
58     JSC_NATIVE_FUNCTION("subtype", jsInjectedScriptHostPrototypeFunctionSubtype, DontEnum, 1);
59     JSC_NATIVE_FUNCTION("functionDetails", jsInjectedScriptHostPrototypeFunctionFunctionDetails, DontEnum, 1);
60     JSC_NATIVE_FUNCTION("getInternalProperties", jsInjectedScriptHostPrototypeFunctionGetInternalProperties, DontEnum, 1);
61     JSC_NATIVE_FUNCTION("internalConstructorName", jsInjectedScriptHostPrototypeFunctionInternalConstructorName, DontEnum, 1);
62     JSC_NATIVE_FUNCTION("isHTMLAllCollection", jsInjectedScriptHostPrototypeFunctionIsHTMLAllCollection, DontEnum, 1);
63     JSC_NATIVE_FUNCTION("weakMapEntries", jsInjectedScriptHostPrototypeFunctionWeakMapEntries, DontEnum, 1);
64
65     Identifier evaluateIdentifier(&vm, "evaluate");
66     GetterSetter* accessor = GetterSetter::create(vm, globalObject);
67     JSFunction* function = JSFunction::create(vm, globalObject, 0, evaluateIdentifier.string(), jsInjectedScriptHostPrototypeAttributeEvaluate);
68     accessor->setGetter(vm, globalObject, function);
69     putDirectNonIndexAccessor(vm, evaluateIdentifier, accessor, DontEnum | Accessor);
70 }
71
72 EncodedJSValue 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
83 EncodedJSValue 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
94 EncodedJSValue 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
105 EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionWeakMapEntries(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->weakMapEntries(exec));
114 }
115
116 EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionSubtype(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->subtype(exec));
125 }
126
127 EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionFunctionDetails(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->functionDetails(exec));
136 }
137
138 EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionGetInternalProperties(ExecState* exec)
139 {
140     JSValue thisValue = exec->thisValue();
141     JSInjectedScriptHost* castedThis = jsDynamicCast<JSInjectedScriptHost*>(thisValue);
142     if (!castedThis)
143         return throwVMTypeError(exec);
144
145     ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
146     return JSValue::encode(castedThis->getInternalProperties(exec));
147 }
148
149 } // namespace Inspector
150