adamk@chromium.org | 136a5cf | 2011-10-11 16:57:07 +0000 | [diff] [blame] | 1 | /* |
| 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.org | 0e07f34 | 2012-07-09 21:34:09 +0000 | [diff] [blame] | 35 | #include "V8MutationObserver.h" |
adamk@chromium.org | 136a5cf | 2011-10-11 16:57:07 +0000 | [diff] [blame] | 36 | |
abarth@webkit.org | 61f87e1 | 2012-08-02 22:46:01 +0000 | [diff] [blame] | 37 | #include "ExceptionCode.h" |
adamk@chromium.org | 0e07f34 | 2012-07-09 21:34:09 +0000 | [diff] [blame] | 38 | #include "MutationObserver.h" |
adamk@chromium.org | 136a5cf | 2011-10-11 16:57:07 +0000 | [diff] [blame] | 39 | #include "V8Binding.h" |
adamk@chromium.org | 136a5cf | 2011-10-11 16:57:07 +0000 | [diff] [blame] | 40 | #include "V8DOMWrapper.h" |
| 41 | #include "V8MutationCallback.h" |
adamk@chromium.org | 136a5cf | 2011-10-11 16:57:07 +0000 | [diff] [blame] | 42 | #include "V8Utilities.h" |
adamk@chromium.org | ab4f33d | 2011-11-11 18:56:02 +0000 | [diff] [blame] | 43 | |
adamk@chromium.org | 136a5cf | 2011-10-11 16:57:07 +0000 | [diff] [blame] | 44 | namespace WebCore { |
| 45 | |
adamk@chromium.org | 0e07f34 | 2012-07-09 21:34:09 +0000 | [diff] [blame] | 46 | v8::Handle<v8::Value> V8MutationObserver::constructorCallback(const v8::Arguments& args) |
adamk@chromium.org | 136a5cf | 2011-10-11 16:57:07 +0000 | [diff] [blame] | 47 | { |
adamk@chromium.org | 0e07f34 | 2012-07-09 21:34:09 +0000 | [diff] [blame] | 48 | INC_STATS("DOM.MutationObserver.Constructor"); |
adamk@chromium.org | 136a5cf | 2011-10-11 16:57:07 +0000 | [diff] [blame] | 49 | |
| 50 | if (!args.IsConstructCall()) |
haraken@chromium.org | dc55eda | 2012-08-14 02:04:13 +0000 | [diff] [blame] | 51 | return throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate()); |
adamk@chromium.org | 136a5cf | 2011-10-11 16:57:07 +0000 | [diff] [blame] | 52 | |
haraken@chromium.org | 7816cc1 | 2011-10-20 03:53:02 +0000 | [diff] [blame] | 53 | if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) |
| 54 | return args.Holder(); |
| 55 | |
adamk@chromium.org | 136a5cf | 2011-10-11 16:57:07 +0000 | [diff] [blame] | 56 | if (args.Length() < 1) |
haraken@chromium.org | dc55eda | 2012-08-14 02:04:13 +0000 | [diff] [blame] | 57 | return throwNotEnoughArgumentsError(args.GetIsolate()); |
adamk@chromium.org | 136a5cf | 2011-10-11 16:57:07 +0000 | [diff] [blame] | 58 | |
| 59 | v8::Local<v8::Value> arg = args[0]; |
| 60 | if (!arg->IsObject()) |
commit-queue@webkit.org | a5d2414 | 2012-11-13 18:47:57 +0000 | [diff] [blame] | 61 | return setDOMException(TYPE_MISMATCH_ERR, args.GetIsolate()); |
adamk@chromium.org | 136a5cf | 2011-10-11 16:57:07 +0000 | [diff] [blame] | 62 | |
| 63 | ScriptExecutionContext* context = getScriptExecutionContext(); |
adamk@chromium.org | 136a5cf | 2011-10-11 16:57:07 +0000 | [diff] [blame] | 64 | |
| 65 | RefPtr<MutationCallback> callback = V8MutationCallback::create(arg, context); |
commit-queue@webkit.org | d9f2a80 | 2012-11-19 20:06:00 +0000 | [diff] [blame^] | 66 | RefPtr<MutationObserver> observer = MutationObserver::create(callback.release()); |
adamk@chromium.org | 136a5cf | 2011-10-11 16:57:07 +0000 | [diff] [blame] | 67 | |
haraken@chromium.org | f51f04d | 2012-08-08 02:09:04 +0000 | [diff] [blame] | 68 | v8::Handle<v8::Object> wrapper = args.Holder(); |
haraken@chromium.org | 1fae4fb | 2012-11-14 08:49:23 +0000 | [diff] [blame] | 69 | V8DOMWrapper::createDOMWrapper(observer.release(), &info, wrapper); |
haraken@chromium.org | f51f04d | 2012-08-08 02:09:04 +0000 | [diff] [blame] | 70 | return wrapper; |
adamk@chromium.org | 136a5cf | 2011-10-11 16:57:07 +0000 | [diff] [blame] | 71 | } |
| 72 | |
adamk@chromium.org | 136a5cf | 2011-10-11 16:57:07 +0000 | [diff] [blame] | 73 | } // namespace WebCore |
| 74 | |
| 75 | #endif // ENABLE(MUTATION_OBSERVERS) |