OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // This file has been auto-generated by code_generator_v8.py. DO NOT MODIFY! |
| 6 |
| 7 #include "config.h" |
| 8 #include "StringOrDouble.h" |
| 9 |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 StringOrDouble::StringOrDouble() |
| 14 : m_type(SpecificTypeNone) |
| 15 { |
| 16 } |
| 17 |
| 18 String StringOrDouble::getAsString() const |
| 19 { |
| 20 ASSERT(isString()); |
| 21 return m_string; |
| 22 } |
| 23 |
| 24 void StringOrDouble::setString(String value) |
| 25 { |
| 26 ASSERT(isNull()); |
| 27 m_string = value; |
| 28 m_type = SpecificTypeString; |
| 29 } |
| 30 |
| 31 StringOrDouble StringOrDouble::fromString(String value) |
| 32 { |
| 33 StringOrDouble container; |
| 34 container.setString(value); |
| 35 return container; |
| 36 } |
| 37 |
| 38 double StringOrDouble::getAsDouble() const |
| 39 { |
| 40 ASSERT(isDouble()); |
| 41 return m_double; |
| 42 } |
| 43 |
| 44 void StringOrDouble::setDouble(double value) |
| 45 { |
| 46 ASSERT(isNull()); |
| 47 m_double = value; |
| 48 m_type = SpecificTypeDouble; |
| 49 } |
| 50 |
| 51 StringOrDouble StringOrDouble::fromDouble(double value) |
| 52 { |
| 53 StringOrDouble container; |
| 54 container.setDouble(value); |
| 55 return container; |
| 56 } |
| 57 |
| 58 void V8StringOrDouble::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value
, StringOrDouble& impl, ExceptionState& exceptionState) |
| 59 { |
| 60 if (v8Value.IsEmpty()) |
| 61 return; |
| 62 |
| 63 if (v8Value->IsNumber()) { |
| 64 TONATIVE_VOID_EXCEPTIONSTATE(double, cppValue, toRestrictedDouble(v8Valu
e, exceptionState), exceptionState); |
| 65 impl.setDouble(cppValue); |
| 66 return; |
| 67 } |
| 68 |
| 69 { |
| 70 TOSTRING_VOID_EXCEPTIONSTATE(V8StringResource<>, cppValue, v8Value, exce
ptionState); |
| 71 impl.setString(cppValue); |
| 72 return; |
| 73 } |
| 74 |
| 75 } |
| 76 |
| 77 v8::Local<v8::Value> toV8(const StringOrDouble& impl, v8::Local<v8::Object> crea
tionContext, v8::Isolate* isolate) |
| 78 { |
| 79 switch (impl.m_type) { |
| 80 case StringOrDouble::SpecificTypeNone: |
| 81 return v8::Null(isolate); |
| 82 case StringOrDouble::SpecificTypeString: |
| 83 return v8String(isolate, impl.getAsString()); |
| 84 case StringOrDouble::SpecificTypeDouble: |
| 85 return v8::Number::New(isolate, impl.getAsDouble()); |
| 86 default: |
| 87 ASSERT_NOT_REACHED(); |
| 88 } |
| 89 return v8::Local<v8::Value>(); |
| 90 } |
| 91 |
| 92 StringOrDouble NativeValueTraits<StringOrDouble>::nativeValue(const v8::Local<v8
::Value>& value, v8::Isolate* isolate, ExceptionState& exceptionState) |
| 93 { |
| 94 StringOrDouble impl; |
| 95 V8StringOrDouble::toImpl(isolate, value, impl, exceptionState); |
| 96 return impl; |
| 97 } |
| 98 |
| 99 } // namespace blink |
OLD | NEW |