2 * Copyright (C) 2013 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "DFGLazyJSValue.h"
32 #include "Operations.h"
34 namespace JSC { namespace DFG {
36 JSValue LazyJSValue::getValue(VM& vm) const
41 case SingleCharacterString:
42 return jsSingleCharacterString(&vm, u.character);
44 return jsString(&vm, u.stringImpl);
46 RELEASE_ASSERT_NOT_REACHED();
50 static TriState equalToSingleCharacter(JSValue value, UChar character)
52 if (!value.isString())
55 JSString* jsString = asString(value);
56 if (jsString->length() != 1)
59 const StringImpl* string = jsString->tryGetValueImpl();
63 return triState(string->at(0) == character);
66 static TriState equalToStringImpl(JSValue value, StringImpl* stringImpl)
68 if (!value.isString())
71 JSString* jsString = asString(value);
72 const StringImpl* string = jsString->tryGetValueImpl();
76 return triState(WTF::equal(stringImpl, string));
79 TriState LazyJSValue::strictEqual(const LazyJSValue& other) const
83 switch (other.m_kind) {
85 return JSValue::pureStrictEqual(value(), other.value());
86 case SingleCharacterString:
87 return equalToSingleCharacter(value(), other.character());
89 return equalToStringImpl(value(), other.stringImpl());
92 case SingleCharacterString:
93 switch (other.m_kind) {
94 case SingleCharacterString:
95 return triState(character() == other.character());
97 if (other.stringImpl()->length() != 1)
99 return triState(other.stringImpl()->at(0) == character());
101 return other.strictEqual(*this);
104 case KnownStringImpl:
105 switch (other.m_kind) {
106 case KnownStringImpl:
107 return triState(WTF::equal(stringImpl(), other.stringImpl()));
109 return other.strictEqual(*this);
113 RELEASE_ASSERT_NOT_REACHED();
114 return FalseTriState;
117 void LazyJSValue::dumpInContext(PrintStream& out, DumpContext* context) const
121 value().dumpInContext(out, context);
123 case SingleCharacterString:
124 out.print("Lazy:SingleCharacterString(");
125 out.printf("%04X", static_cast<unsigned>(character()));
126 out.print(" / ", StringImpl::utf8ForCharacters(&u.character, 1), ")");
128 case KnownStringImpl:
129 out.print("Lazy:String(", stringImpl(), ")");
132 RELEASE_ASSERT_NOT_REACHED();
135 void LazyJSValue::dump(PrintStream& out) const
137 dumpInContext(out, 0);
140 } } // namespace JSC::DFG
142 #endif // ENABLE(DFG_JIT)