forked from oven-sh/bun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JSDOMGlobalObject.cpp
87 lines (74 loc) · 3.73 KB
/
JSDOMGlobalObject.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "JSDOMGlobalObject.h"
#include <JavaScriptCore/JSCast.h>
#include "ZigGlobalObject.h"
namespace WebCore {
Zig::GlobalObject* toJSDOMGlobalObject(ScriptExecutionContext& ctx, DOMWrapperWorld& world)
{
return JSC::jsCast<Zig::GlobalObject*>(ctx.jsGlobalObject());
}
// static JSDOMGlobalObject& callerGlobalObject(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame* callFrame, bool skipFirstFrame, bool lookUpFromVMEntryScope)
// {
// VM& vm = lexicalGlobalObject.vm();
// if (callFrame) {
// class GetCallerGlobalObjectFunctor {
// public:
// GetCallerGlobalObjectFunctor(bool skipFirstFrame)
// : m_skipFirstFrame(skipFirstFrame)
// {
// }
// StackVisitor::Status operator()(StackVisitor& visitor) const
// {
// if (m_skipFirstFrame) {
// if (!m_hasSkippedFirstFrame) {
// m_hasSkippedFirstFrame = true;
// return StackVisitor::Continue;
// }
// }
// if (auto* codeBlock = visitor->codeBlock())
// m_globalObject = codeBlock->globalObject();
// else {
// ASSERT(visitor->callee().rawPtr());
// // FIXME: Callee is not an object if the caller is Web Assembly.
// // Figure out what to do here. We can probably get the global object
// // from the top-most Wasm Instance. https://bugs.webkit.org/show_bug.cgi?id=165721
// if (visitor->callee().isCell() && visitor->callee().asCell()->isObject())
// m_globalObject = jsCast<JSObject*>(visitor->callee().asCell())->globalObject();
// }
// return StackVisitor::Done;
// }
// JSC::JSGlobalObject* globalObject() const { return m_globalObject; }
// private:
// bool m_skipFirstFrame { false };
// mutable bool m_hasSkippedFirstFrame { false };
// mutable JSC::JSGlobalObject* m_globalObject { nullptr };
// };
// GetCallerGlobalObjectFunctor iter(skipFirstFrame);
// callFrame->iterate(vm, iter);
// if (iter.globalObject())
// return *jsCast<JSDOMGlobalObject*>(iter.globalObject());
// }
// // In the case of legacyActiveGlobalObjectForAccessor, it is possible that vm.topCallFrame is nullptr when the script is evaluated as JSONP.
// // Since we put JSGlobalObject to VMEntryScope, we can retrieve the right globalObject from that.
// // For callerGlobalObject, we do not check vm.entryScope to keep it the old behavior.
// if (lookUpFromVMEntryScope) {
// if (vm.entryScope) {
// if (auto* result = vm.entryScope->globalObject())
// return *jsCast<JSDOMGlobalObject*>(result);
// }
// }
// // If we cannot find JSGlobalObject in caller frames, we just return the current lexicalGlobalObject.
// return *jsCast<JSDOMGlobalObject*>(&lexicalGlobalObject);
// }
// JSDOMGlobalObject& callerGlobalObject(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame* callFrame)
// {
// constexpr bool skipFirstFrame = true;
// constexpr bool lookUpFromVMEntryScope = false;
// return callerGlobalObject(lexicalGlobalObject, callFrame, skipFirstFrame, lookUpFromVMEntryScope);
// }
// JSDOMGlobalObject& legacyActiveGlobalObjectForAccessor(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame* callFrame)
// {
// constexpr bool skipFirstFrame = false;
// constexpr bool lookUpFromVMEntryScope = true;
// return callerGlobalObject(lexicalGlobalObject, callFrame, skipFirstFrame, lookUpFromVMEntryScope);
// }
}