PageRenderTime 24ms CodeModel.GetById 13ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/platform/external/webkit/WebCore/bindings/v8/custom/V8TreeWalkerCustom.cpp

https://github.com/aharish/totoro-gb-opensource-update2
C++ | 128 lines | 76 code | 23 blank | 29 comment | 2 complexity | d1e4a0241d68bc3786e1aca67e7d2385 MD5 | raw file
  1/*
  2 * Copyright (C) 2007-2009 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#include "V8TreeWalker.h"
 33
 34#include "Node.h"
 35#include "ScriptState.h"
 36#include "TreeWalker.h"
 37
 38#include "V8Binding.h"
 39#include "V8Node.h"
 40#include "V8Proxy.h"
 41
 42#include <wtf/PassRefPtr.h>
 43#include <wtf/RefPtr.h>
 44
 45namespace WebCore {
 46
 47static inline v8::Handle<v8::Value> toV8Object(PassRefPtr<Node> object, ScriptState* state)
 48{
 49    if (state->hadException())
 50        return throwError(state->exception());
 51
 52    if (!object)
 53        return v8::Null();
 54
 55    return toV8(object);
 56}
 57
 58v8::Handle<v8::Value> V8TreeWalker::parentNodeCallback(const v8::Arguments& args)
 59{
 60    INC_STATS("DOM.TreeWalker.parentNode()");
 61    TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder());
 62
 63    EmptyScriptState state;
 64    RefPtr<Node> result = treeWalker->parentNode(&state);
 65    return toV8Object(result.release(), &state);
 66}
 67
 68v8::Handle<v8::Value> V8TreeWalker::firstChildCallback(const v8::Arguments& args)
 69{
 70    INC_STATS("DOM.TreeWalker.firstChild()");
 71    TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder());
 72
 73    EmptyScriptState state;
 74    RefPtr<Node> result = treeWalker->firstChild(&state);
 75    return toV8Object(result.release(), &state);
 76}
 77
 78v8::Handle<v8::Value> V8TreeWalker::lastChildCallback(const v8::Arguments& args)
 79{
 80    INC_STATS("DOM.TreeWalker.lastChild()");
 81    TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder());
 82
 83    EmptyScriptState state;
 84    RefPtr<Node> result = treeWalker->lastChild(&state);
 85    return toV8Object(result.release(), &state);
 86}
 87
 88v8::Handle<v8::Value> V8TreeWalker::nextNodeCallback(const v8::Arguments& args)
 89{
 90    INC_STATS("DOM.TreeWalker.nextNode()");
 91    TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder());
 92
 93    EmptyScriptState state;
 94    RefPtr<Node> result = treeWalker->nextNode(&state);
 95    return toV8Object(result.release(), &state);
 96}
 97
 98v8::Handle<v8::Value> V8TreeWalker::previousNodeCallback(const v8::Arguments& args)
 99{
100    INC_STATS("DOM.TreeWalker.previousNode()");
101    TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder());
102
103    EmptyScriptState state;
104    RefPtr<Node> result = treeWalker->previousNode(&state);
105    return toV8Object(result.release(), &state);
106}
107
108v8::Handle<v8::Value> V8TreeWalker::nextSiblingCallback(const v8::Arguments& args)
109{
110    INC_STATS("DOM.TreeWalker.nextSibling()");
111    TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder());
112
113    EmptyScriptState state;
114    RefPtr<Node> result = treeWalker->nextSibling(&state);
115    return toV8Object(result.release(), &state);
116}
117
118v8::Handle<v8::Value> V8TreeWalker::previousSiblingCallback(const v8::Arguments& args)
119{
120    INC_STATS("DOM.TreeWalker.previousSibling()");
121    TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder());
122
123    EmptyScriptState state;
124    RefPtr<Node> result = treeWalker->previousSibling(&state);
125    return toV8Object(result.release(), &state);
126}
127
128} // namespace WebCore