yurys@chromium.org | 02ff0d6 | 2010-11-08 14:05:32 +0000 | [diff] [blame] | 1 | /* |
joepeck@webkit.org | 1f45df9 | 2014-02-06 23:45:53 +0000 | [diff] [blame] | 2 | * Copyright (C) 2014 Apple Inc. All rights reserved. |
yurys@chromium.org | 02ff0d6 | 2010-11-08 14:05:32 +0000 | [diff] [blame] | 3 | * Copyright (c) 2010 Google Inc. All rights reserved. |
joepeck@webkit.org | 1f45df9 | 2014-02-06 23:45:53 +0000 | [diff] [blame] | 4 | * |
yurys@chromium.org | 02ff0d6 | 2010-11-08 14:05:32 +0000 | [diff] [blame] | 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are |
| 7 | * met: |
joepeck@webkit.org | 1f45df9 | 2014-02-06 23:45:53 +0000 | [diff] [blame] | 8 | * |
yurys@chromium.org | 02ff0d6 | 2010-11-08 14:05:32 +0000 | [diff] [blame] | 9 | * * Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * * Redistributions in binary form must reproduce the above |
| 12 | * copyright notice, this list of conditions and the following disclaimer |
| 13 | * in the documentation and/or other materials provided with the |
| 14 | * distribution. |
| 15 | * * Neither the name of Google Inc. nor the names of its |
| 16 | * contributors may be used to endorse or promote products derived from |
| 17 | * this software without specific prior written permission. |
joepeck@webkit.org | 1f45df9 | 2014-02-06 23:45:53 +0000 | [diff] [blame] | 18 | * |
yurys@chromium.org | 02ff0d6 | 2010-11-08 14:05:32 +0000 | [diff] [blame] | 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | */ |
| 31 | |
| 32 | #include "config.h" |
| 33 | #include "ScriptArguments.h" |
| 34 | |
fpizlo@apple.com | fb7eff2 | 2014-02-11 01:45:50 +0000 | [diff] [blame] | 35 | #include "JSCInlines.h" |
joepeck@webkit.org | 1f45df9 | 2014-02-06 23:45:53 +0000 | [diff] [blame] | 36 | #include "ScriptValue.h" |
yurys@chromium.org | 02ff0d6 | 2010-11-08 14:05:32 +0000 | [diff] [blame] | 37 | |
joepeck@webkit.org | 1f45df9 | 2014-02-06 23:45:53 +0000 | [diff] [blame] | 38 | namespace Inspector { |
yurys@chromium.org | 02ff0d6 | 2010-11-08 14:05:32 +0000 | [diff] [blame] | 39 | |
gyuyoung.kim@webkit.org | 2068589 | 2015-06-09 02:17:48 +0000 | [diff] [blame] | 40 | Ref<ScriptArguments> ScriptArguments::create(JSC::ExecState* scriptState, Vector<Deprecated::ScriptValue>& arguments) |
yurys@chromium.org | ec8a30f | 2010-11-30 08:15:28 +0000 | [diff] [blame] | 41 | { |
gyuyoung.kim@webkit.org | 2068589 | 2015-06-09 02:17:48 +0000 | [diff] [blame] | 42 | return adoptRef(*new ScriptArguments(scriptState, arguments)); |
yurys@chromium.org | ec8a30f | 2010-11-30 08:15:28 +0000 | [diff] [blame] | 43 | } |
| 44 | |
joepeck@webkit.org | 1f45df9 | 2014-02-06 23:45:53 +0000 | [diff] [blame] | 45 | ScriptArguments::ScriptArguments(JSC::ExecState* execState, Vector<Deprecated::ScriptValue>& arguments) |
| 46 | : m_globalObject(execState->vm(), execState->lexicalGlobalObject()) |
yurys@chromium.org | 02ff0d6 | 2010-11-08 14:05:32 +0000 | [diff] [blame] | 47 | { |
| 48 | m_arguments.swap(arguments); |
| 49 | } |
| 50 | |
| 51 | ScriptArguments::~ScriptArguments() |
| 52 | { |
| 53 | } |
| 54 | |
joepeck@webkit.org | a319844 | 2013-12-11 22:40:23 +0000 | [diff] [blame] | 55 | const Deprecated::ScriptValue &ScriptArguments::argumentAt(size_t index) const |
yurys@chromium.org | 02ff0d6 | 2010-11-08 14:05:32 +0000 | [diff] [blame] | 56 | { |
| 57 | ASSERT(m_arguments.size() > index); |
| 58 | return m_arguments[index]; |
| 59 | } |
| 60 | |
weinig@apple.com | 4da3e8d | 2013-09-14 01:30:06 +0000 | [diff] [blame] | 61 | JSC::ExecState* ScriptArguments::globalState() const |
yurys@chromium.org | 02ff0d6 | 2010-11-08 14:05:32 +0000 | [diff] [blame] | 62 | { |
andersca@apple.com | 22504ad | 2013-04-16 20:05:38 +0000 | [diff] [blame] | 63 | if (m_globalObject) |
| 64 | return const_cast<JSC::JSGlobalObject*>(m_globalObject.get())->globalExec(); |
joepeck@webkit.org | 1f45df9 | 2014-02-06 23:45:53 +0000 | [diff] [blame] | 65 | |
joepeck@webkit.org | ed8058e | 2014-01-20 21:36:28 +0000 | [diff] [blame] | 66 | return nullptr; |
yurys@chromium.org | 02ff0d6 | 2010-11-08 14:05:32 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | bool ScriptArguments::getFirstArgumentAsString(String& result, bool checkForNullOrUndefined) |
| 70 | { |
| 71 | if (!argumentCount()) |
| 72 | return false; |
| 73 | |
joepeck@webkit.org | a319844 | 2013-12-11 22:40:23 +0000 | [diff] [blame] | 74 | const Deprecated::ScriptValue& value = argumentAt(0); |
yurys@chromium.org | 02ff0d6 | 2010-11-08 14:05:32 +0000 | [diff] [blame] | 75 | if (checkForNullOrUndefined && (value.isNull() || value.isUndefined())) |
| 76 | return false; |
| 77 | |
| 78 | if (!globalState()) { |
| 79 | ASSERT_NOT_REACHED(); |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | result = value.toString(globalState()); |
| 84 | return true; |
| 85 | } |
| 86 | |
| 87 | bool ScriptArguments::isEqual(ScriptArguments* other) const |
| 88 | { |
| 89 | if (!other) |
| 90 | return false; |
| 91 | |
| 92 | if (m_arguments.size() != other->m_arguments.size()) |
| 93 | return false; |
| 94 | if (!globalState() && m_arguments.size()) |
| 95 | return false; |
| 96 | |
| 97 | for (size_t i = 0; i < m_arguments.size(); ++i) { |
| 98 | if (!m_arguments[i].isEqual(other->globalState(), other->m_arguments[i])) |
| 99 | return false; |
| 100 | } |
joepeck@webkit.org | 1f45df9 | 2014-02-06 23:45:53 +0000 | [diff] [blame] | 101 | |
yurys@chromium.org | 02ff0d6 | 2010-11-08 14:05:32 +0000 | [diff] [blame] | 102 | return true; |
| 103 | } |
| 104 | |
joepeck@webkit.org | 1f45df9 | 2014-02-06 23:45:53 +0000 | [diff] [blame] | 105 | } // namespace Inspector |