summaryrefslogtreecommitdiff
path: root/Source/WebCore/bindings/js/JSMutationObserverCustom.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/bindings/js/JSMutationObserverCustom.cpp')
-rw-r--r--Source/WebCore/bindings/js/JSMutationObserverCustom.cpp32
1 files changed, 17 insertions, 15 deletions
diff --git a/Source/WebCore/bindings/js/JSMutationObserverCustom.cpp b/Source/WebCore/bindings/js/JSMutationObserverCustom.cpp
index 09760945e..33c5509ae 100644
--- a/Source/WebCore/bindings/js/JSMutationObserverCustom.cpp
+++ b/Source/WebCore/bindings/js/JSMutationObserverCustom.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -29,10 +30,10 @@
*/
#include "config.h"
-
#include "JSMutationObserver.h"
#include "ExceptionCode.h"
+#include "JSDOMConstructorBase.h"
#include "JSMutationCallback.h"
#include "JSNodeCustom.h"
#include "MutationObserver.h"
@@ -43,30 +44,31 @@ using namespace JSC;
namespace WebCore {
-EncodedJSValue JSC_HOST_CALL JSMutationObserverConstructor::constructJSMutationObserver(ExecState* exec)
+EncodedJSValue JSC_HOST_CALL constructJSMutationObserver(ExecState& exec)
{
- if (exec->argumentCount() < 1)
- return throwVMError(exec, createNotEnoughArgumentsError(exec));
+ VM& vm = exec.vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
+ if (exec.argumentCount() < 1)
+ return throwVMError(&exec, scope, createNotEnoughArgumentsError(&exec));
- JSObject* object = exec->argument(0).getObject();
+ JSObject* object = exec.uncheckedArgument(0).getObject();
CallData callData;
- if (!object || object->methodTable()->getCallData(object, callData) == CallTypeNone)
- return throwVMError(exec, createTypeError(exec, "Callback argument must be a function"));
+ if (!object || object->methodTable()->getCallData(object, callData) == CallType::None)
+ return throwArgumentTypeError(exec, scope, 0, "callback", "MutationObserver", nullptr, "MutationCallback");
- JSMutationObserverConstructor* jsConstructor = jsCast<JSMutationObserverConstructor*>(exec->callee());
- RefPtr<JSMutationCallback> callback = JSMutationCallback::create(object, jsConstructor->globalObject());
- JSObject* jsObserver = asObject(toJS(exec, jsConstructor->globalObject(), MutationObserver::create(callback.release())));
+ auto* jsConstructor = jsCast<JSDOMConstructorBase*>(exec.jsCallee());
+ auto callback = JSMutationCallback::create(object, jsConstructor->globalObject());
+ JSObject* jsObserver = asObject(toJSNewlyCreated(&exec, jsConstructor->globalObject(), MutationObserver::create(WTFMove(callback))));
PrivateName propertyName;
- jsObserver->putDirect(jsConstructor->globalObject()->vm(), propertyName, object);
+ jsObserver->putDirect(vm, propertyName, object);
return JSValue::encode(jsObserver);
}
bool JSMutationObserverOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
{
- MutationObserver& observer = jsCast<JSMutationObserver*>(handle.get().asCell())->impl();
- auto observedNodes = observer.getObservedNodes();
- for (auto it = observedNodes.begin(), end = observedNodes.end(); it != end; ++it) {
- if (visitor.containsOpaqueRoot(root(*it)))
+ for (auto* node : jsCast<JSMutationObserver*>(handle.slot()->asCell())->wrapped().observedNodes()) {
+ if (visitor.containsOpaqueRoot(root(node)))
return true;
}
return false;