blob: f80ce598a972acb7d5fc2f349968f4b9ea8f2bf6 [file] [log] [blame]
adamk@chromium.org136a5cf2011-10-11 16:57:07 +00001/*
2 * Copyright (C) 2011 Google 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 are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include "config.h"
32
33#if ENABLE(MUTATION_OBSERVERS)
34
adamk@chromium.org0e07f342012-07-09 21:34:09 +000035#include "V8MutationObserver.h"
adamk@chromium.org136a5cf2011-10-11 16:57:07 +000036
abarth@webkit.org61f87e12012-08-02 22:46:01 +000037#include "ExceptionCode.h"
adamk@chromium.org0e07f342012-07-09 21:34:09 +000038#include "MutationObserver.h"
adamk@chromium.org136a5cf2011-10-11 16:57:07 +000039#include "V8Binding.h"
adamk@chromium.org136a5cf2011-10-11 16:57:07 +000040#include "V8DOMWrapper.h"
41#include "V8MutationCallback.h"
adamk@chromium.org136a5cf2011-10-11 16:57:07 +000042#include "V8Utilities.h"
adamk@chromium.orgab4f33d2011-11-11 18:56:02 +000043
adamk@chromium.org136a5cf2011-10-11 16:57:07 +000044namespace WebCore {
45
adamk@chromium.org0e07f342012-07-09 21:34:09 +000046v8::Handle<v8::Value> V8MutationObserver::constructorCallback(const v8::Arguments& args)
adamk@chromium.org136a5cf2011-10-11 16:57:07 +000047{
adamk@chromium.org0e07f342012-07-09 21:34:09 +000048 INC_STATS("DOM.MutationObserver.Constructor");
adamk@chromium.org136a5cf2011-10-11 16:57:07 +000049
50 if (!args.IsConstructCall())
haraken@chromium.orgdc55eda2012-08-14 02:04:13 +000051 return throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate());
adamk@chromium.org136a5cf2011-10-11 16:57:07 +000052
haraken@chromium.org7816cc12011-10-20 03:53:02 +000053 if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
54 return args.Holder();
55
adamk@chromium.org136a5cf2011-10-11 16:57:07 +000056 if (args.Length() < 1)
haraken@chromium.orgdc55eda2012-08-14 02:04:13 +000057 return throwNotEnoughArgumentsError(args.GetIsolate());
adamk@chromium.org136a5cf2011-10-11 16:57:07 +000058
59 v8::Local<v8::Value> arg = args[0];
60 if (!arg->IsObject())
commit-queue@webkit.orga5d24142012-11-13 18:47:57 +000061 return setDOMException(TYPE_MISMATCH_ERR, args.GetIsolate());
adamk@chromium.org136a5cf2011-10-11 16:57:07 +000062
63 ScriptExecutionContext* context = getScriptExecutionContext();
adamk@chromium.org136a5cf2011-10-11 16:57:07 +000064
65 RefPtr<MutationCallback> callback = V8MutationCallback::create(arg, context);
commit-queue@webkit.orgd9f2a802012-11-19 20:06:00 +000066 RefPtr<MutationObserver> observer = MutationObserver::create(callback.release());
adamk@chromium.org136a5cf2011-10-11 16:57:07 +000067
haraken@chromium.orgf51f04d2012-08-08 02:09:04 +000068 v8::Handle<v8::Object> wrapper = args.Holder();
haraken@chromium.org1fae4fb2012-11-14 08:49:23 +000069 V8DOMWrapper::createDOMWrapper(observer.release(), &info, wrapper);
haraken@chromium.orgf51f04d2012-08-08 02:09:04 +000070 return wrapper;
adamk@chromium.org136a5cf2011-10-11 16:57:07 +000071}
72
adamk@chromium.org136a5cf2011-10-11 16:57:07 +000073} // namespace WebCore
74
75#endif // ENABLE(MUTATION_OBSERVERS)