summaryrefslogtreecommitdiff
path: root/Source/WebCore/bindings/js/JSDocumentCustom.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/bindings/js/JSDocumentCustom.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/bindings/js/JSDocumentCustom.cpp')
-rw-r--r--Source/WebCore/bindings/js/JSDocumentCustom.cpp160
1 files changed, 95 insertions, 65 deletions
diff --git a/Source/WebCore/bindings/js/JSDocumentCustom.cpp b/Source/WebCore/bindings/js/JSDocumentCustom.cpp
index 34088ca48..a78b01844 100644
--- a/Source/WebCore/bindings/js/JSDocumentCustom.cpp
+++ b/Source/WebCore/bindings/js/JSDocumentCustom.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007, 2008, 2009, 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2009, 2011, 2016 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -25,108 +25,138 @@
#include "FrameLoader.h"
#include "HTMLDocument.h"
#include "JSCanvasRenderingContext2D.h"
-#if ENABLE(WEBGL)
-#include "JSWebGLRenderingContext.h"
-#endif
+#include "JSDOMConvert.h"
#include "JSDOMWindowCustom.h"
#include "JSHTMLDocument.h"
#include "JSLocation.h"
-#include "JSTouch.h"
-#include "JSTouchList.h"
+#include "JSXMLDocument.h"
#include "Location.h"
#include "NodeTraversal.h"
+#include "SVGDocument.h"
#include "ScriptController.h"
#include "TouchList.h"
+#include "XMLDocument.h"
+#include <wtf/GetPtr.h>
-#if ENABLE(SVG)
-#include "JSSVGDocument.h"
-#include "SVGDocument.h"
+#if ENABLE(WEBGL)
+#include "JSWebGLRenderingContextBase.h"
#endif
-#include <wtf/GetPtr.h>
+#if ENABLE(TOUCH_EVENTS)
+#include "JSTouch.h"
+#include "JSTouchList.h"
+#endif
using namespace JSC;
namespace WebCore {
-JSValue JSDocument::location(ExecState* exec) const
+static inline JSValue createNewDocumentWrapper(ExecState& state, JSDOMGlobalObject& globalObject, Ref<Document>&& passedDocument)
{
- RefPtr<Frame> frame = impl().frame();
- if (!frame)
- return jsNull();
+ auto& document = passedDocument.get();
+ JSObject* wrapper;
+ if (document.isHTMLDocument())
+ wrapper = createWrapper<HTMLDocument>(&globalObject, WTFMove(passedDocument));
+ else if (document.isXMLDocument())
+ wrapper = createWrapper<XMLDocument>(&globalObject, WTFMove(passedDocument));
+ else
+ wrapper = createWrapper<Document>(&globalObject, WTFMove(passedDocument));
+
+ reportMemoryForDocumentIfFrameless(state, document);
- RefPtr<Location> location = frame->document()->domWindow()->location();
- if (JSObject* wrapper = getCachedWrapper(currentWorld(exec), location.get()))
+ return wrapper;
+}
+
+JSObject* cachedDocumentWrapper(ExecState& state, JSDOMGlobalObject& globalObject, Document& document)
+{
+ if (auto* wrapper = getCachedWrapper(globalObject.world(), document))
return wrapper;
- JSLocation* jsLocation = JSLocation::create(getDOMStructure<JSLocation>(exec->vm(), globalObject()), globalObject(), location.get());
- cacheWrapper(currentWorld(exec), location.get(), jsLocation);
- return jsLocation;
+ auto* window = document.domWindow();
+ if (!window)
+ return nullptr;
+
+ // Creating a wrapper for domWindow might have created a wrapper for document as well.
+ return getCachedWrapper(toJSDOMWindow(state.vm(), toJS(&state, *window))->world(), document);
}
-void JSDocument::setLocation(ExecState* exec, JSValue value)
+void reportMemoryForDocumentIfFrameless(ExecState& state, Document& document)
{
- String locationString = value.toString(exec)->value(exec);
- if (exec->hadException())
+ // Make sure the document is kept around by the window object, and works right with the back/forward cache.
+ if (document.frame())
return;
- RefPtr<Frame> frame = impl().frame();
- if (!frame)
- return;
+ size_t memoryCost = 0;
+ for (Node* node = &document; node; node = NodeTraversal::next(*node))
+ memoryCost += node->approximateMemoryCost();
- if (RefPtr<Location> location = frame->document()->domWindow()->location())
- location->setHref(locationString, activeDOMWindow(exec), firstDOMWindow(exec));
+ // FIXME: Adopt reportExtraMemoryVisited, and switch to reportExtraMemoryAllocated.
+ // https://bugs.webkit.org/show_bug.cgi?id=142595
+ state.heap()->deprecatedReportExtraMemory(memoryCost);
}
-JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, Document* document)
+JSValue toJSNewlyCreated(ExecState* state, JSDOMGlobalObject* globalObject, Ref<Document>&& document)
{
- if (!document)
- return jsNull();
+ return createNewDocumentWrapper(*state, *globalObject, WTFMove(document));
+}
- JSObject* wrapper = getCachedWrapper(currentWorld(exec), document);
- if (wrapper)
+JSValue toJS(ExecState* state, JSDOMGlobalObject* globalObject, Document& document)
+{
+ if (auto* wrapper = cachedDocumentWrapper(*state, *globalObject, document))
return wrapper;
+ return toJSNewlyCreated(state, globalObject, Ref<Document>(document));
+}
- if (DOMWindow* domWindow = document->domWindow()) {
- globalObject = toJSDOMWindow(toJS(exec, domWindow));
- // Creating a wrapper for domWindow might have created a wrapper for document as well.
- wrapper = getCachedWrapper(currentWorld(exec), document);
- if (wrapper)
- return wrapper;
- }
+#if ENABLE(TOUCH_EVENTS)
+JSValue JSDocument::createTouchList(ExecState& state)
+{
+ VM& vm = state.vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
- if (document->isHTMLDocument())
- wrapper = CREATE_DOM_WRAPPER(exec, globalObject, HTMLDocument, document);
-#if ENABLE(SVG)
- else if (document->isSVGDocument())
- wrapper = CREATE_DOM_WRAPPER(exec, globalObject, SVGDocument, document);
-#endif
- else
- wrapper = CREATE_DOM_WRAPPER(exec, globalObject, Document, document);
-
- // Make sure the document is kept around by the window object, and works right with the
- // back/forward cache.
- if (!document->frame()) {
- size_t nodeCount = 0;
- for (Node* n = document; n; n = NodeTraversal::next(n))
- nodeCount++;
-
- exec->heap()->reportExtraMemoryCost(nodeCount * sizeof(Node));
- }
+ auto touchList = TouchList::create();
- return wrapper;
+ for (size_t i = 0; i < state.argumentCount(); ++i) {
+ auto* item = JSTouch::toWrapped(vm, state.uncheckedArgument(i));
+ if (!item)
+ return JSValue::decode(throwArgumentTypeError(state, scope, i, "touches", "Document", "createTouchList", "Touch"));
+
+ touchList->append(*item);
+ }
+ return toJSNewlyCreated(&state, globalObject(), WTFMove(touchList));
}
+#endif
-#if ENABLE(TOUCH_EVENTS)
-JSValue JSDocument::createTouchList(ExecState* exec)
+JSValue JSDocument::getCSSCanvasContext(JSC::ExecState& state)
{
- RefPtr<TouchList> touchList = TouchList::create();
+ VM& vm = state.vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
+ if (UNLIKELY(state.argumentCount() < 4))
+ return throwException(&state, scope, createNotEnoughArgumentsError(&state));
+ auto contextId = state.uncheckedArgument(0).toWTFString(&state);
+ RETURN_IF_EXCEPTION(scope, JSValue());
+ auto name = state.uncheckedArgument(1).toWTFString(&state);
+ RETURN_IF_EXCEPTION(scope, JSValue());
+ auto width = convert<IDLLong>(state, state.uncheckedArgument(2), IntegerConversionConfiguration::Normal);
+ RETURN_IF_EXCEPTION(scope, JSValue());
+ auto height = convert<IDLLong>(state, state.uncheckedArgument(3), IntegerConversionConfiguration::Normal);
+ RETURN_IF_EXCEPTION(scope, JSValue());
+
+ auto* context = wrapped().getCSSCanvasContext(WTFMove(contextId), WTFMove(name), WTFMove(width), WTFMove(height));
+ if (!context)
+ return jsNull();
- for (size_t i = 0; i < exec->argumentCount(); i++)
- touchList->append(toTouch(exec->argument(i)));
+#if ENABLE(WEBGL)
+ if (is<WebGLRenderingContextBase>(*context))
+ return toJS(&state, globalObject(), downcast<WebGLRenderingContextBase>(*context));
+#endif
- return toJS(exec, globalObject(), touchList.release());
+ return toJS(&state, globalObject(), downcast<CanvasRenderingContext2D>(*context));
+}
+
+void JSDocument::visitAdditionalChildren(SlotVisitor& visitor)
+{
+ visitor.addOpaqueRoot(static_cast<ScriptExecutionContext*>(&wrapped()));
}
-#endif
} // namespace WebCore