Web Inspector: Array/Collection Sizes should be visible and distinct
[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 jsInjectedScriptHostPrototypeFunctionWeakMapSize(ExecState*);
47 static EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionWeakMapEntries(ExecState*);
48
49 static EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeAttributeEvaluate(ExecState*);
50
51 const ClassInfo JSInjectedScriptHostPrototype::s_info = { "InjectedScriptHost", &Base::s_info, 0, CREATE_METHOD_TABLE(JSInjectedScriptHostPrototype) };
52
53 void 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("subtype", jsInjectedScriptHostPrototypeFunctionSubtype, 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     JSC_NATIVE_FUNCTION("weakMapSize", jsInjectedScriptHostPrototypeFunctionWeakMapSize, DontEnum, 1);
65     JSC_NATIVE_FUNCTION("weakMapEntries", jsInjectedScriptHostPrototypeFunctionWeakMapEntries, DontEnum, 1);
66
67     Identifier evaluateIdentifier(&vm, "evaluate");
68     GetterSetter* accessor = GetterSetter::create(vm, globalObject);
69     JSFunction* function = JSFunction::create(vm, globalObject, 0, evaluateIdentifier.string(), jsInjectedScriptHostPrototypeAttributeEvaluate);
70     accessor->setGetter(vm, globalObject, function);
71     putDirectNonIndexAccessor(vm, evaluateIdentifier, accessor, DontEnum | Accessor);
72 }
73
74 EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeAttributeEvaluate(ExecState* exec)
75 {
76     JSValue thisValue = exec->thisValue();
77     JSInjectedScriptHost* castedThis = jsDynamicCast<JSInjectedScriptHost*>(thisValue);
78     if (!castedThis)
79         return throwVMTypeError(exec);
80
81     ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
82     return JSValue::encode(castedThis->evaluate(exec));
83 }
84
85 EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionInternalConstructorName(ExecState* exec)
86 {
87     JSValue thisValue = exec->thisValue();
88     JSInjectedScriptHost* castedThis = jsDynamicCast<JSInjectedScriptHost*>(thisValue);
89     if (!castedThis)
90         return throwVMTypeError(exec);
91
92     ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
93     return JSValue::encode(castedThis->internalConstructorName(exec));
94 }
95
96 EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionIsHTMLAllCollection(ExecState* exec)
97 {
98     JSValue thisValue = exec->thisValue();
99     JSInjectedScriptHost* castedThis = jsDynamicCast<JSInjectedScriptHost*>(thisValue);
100     if (!castedThis)
101         return throwVMTypeError(exec);
102
103     ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
104     return JSValue::encode(castedThis->isHTMLAllCollection(exec));
105 }
106
107 EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionWeakMapSize(ExecState* exec)
108 {
109     JSValue thisValue = exec->thisValue();
110     JSInjectedScriptHost* castedThis = jsDynamicCast<JSInjectedScriptHost*>(thisValue);
111     if (!castedThis)
112         return throwVMTypeError(exec);
113
114     ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
115     return JSValue::encode(castedThis->weakMapSize(exec));
116 }
117
118 EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionWeakMapEntries(ExecState* exec)
119 {
120     JSValue thisValue = exec->thisValue();
121     JSInjectedScriptHost* castedThis = jsDynamicCast<JSInjectedScriptHost*>(thisValue);
122     if (!castedThis)
123         return throwVMTypeError(exec);
124
125     ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
126     return JSValue::encode(castedThis->weakMapEntries(exec));
127 }
128
129 EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionSubtype(ExecState* exec)
130 {
131     JSValue thisValue = exec->thisValue();
132     JSInjectedScriptHost* castedThis = jsDynamicCast<JSInjectedScriptHost*>(thisValue);
133     if (!castedThis)
134         return throwVMTypeError(exec);
135
136     ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
137     return JSValue::encode(castedThis->subtype(exec));
138 }
139
140 EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionFunctionDetails(ExecState* exec)
141 {
142     JSValue thisValue = exec->thisValue();
143     JSInjectedScriptHost* castedThis = jsDynamicCast<JSInjectedScriptHost*>(thisValue);
144     if (!castedThis)
145         return throwVMTypeError(exec);
146
147     ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
148     return JSValue::encode(castedThis->functionDetails(exec));
149 }
150
151 EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionGetInternalProperties(ExecState* exec)
152 {
153     JSValue thisValue = exec->thisValue();
154     JSInjectedScriptHost* castedThis = jsDynamicCast<JSInjectedScriptHost*>(thisValue);
155     if (!castedThis)
156         return throwVMTypeError(exec);
157
158     ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
159     return JSValue::encode(castedThis->getInternalProperties(exec));
160 }
161
162 } // namespace Inspector
163