OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
13 * distribution. | 13 * distribution. |
14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
17 * | 17 * |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
| 30 |
30 #include "config.h" | 31 #include "config.h" |
31 #include "bindings/dart/DartScriptValue.h" | 32 #include "bindings/dart/DartScriptValue.h" |
32 | 33 |
33 #include "bindings/dart/DartDOMData.h" | |
34 #include "bindings/dart/DartUtilities.h" | 34 #include "bindings/dart/DartUtilities.h" |
| 35 #include "bindings/dart/V8Converter.h" |
| 36 #include "platform/JSONValues.h" |
35 | 37 |
36 namespace WebCore { | 38 namespace WebCore { |
37 | 39 |
38 DartScriptValue::DartScriptValue(Dart_Handle value) | 40 DartScriptValue::~DartScriptValue() |
39 { | 41 { |
40 m_value = Dart_NewPersistentHandle(value); | |
41 } | 42 } |
42 | 43 |
43 DartScriptValue::~DartScriptValue() | 44 // FIXMEDART: Renamed toString in M36. |
| 45 bool DartScriptValue::getString(String& result) const |
44 { | 46 { |
45 if (!isIsolateAlive()) | 47 if (hasNoValue()) |
46 return; | 48 return false; |
47 | 49 |
48 DartIsolateScope scope(isolate()); | 50 Dart_Handle exception = 0; |
49 Dart_DeletePersistentHandle(m_value); | 51 DartStringAdapter string = DartUtilities::dartToString(m_value, exception); |
| 52 if (exception) |
| 53 return false; |
| 54 result = string; |
| 55 return true; |
50 } | 56 } |
51 | 57 |
| 58 // FIXMEDART: Removed in M36. |
| 59 String DartScriptValue::toString() const |
| 60 { |
| 61 String result; |
| 62 if (!getString(result)) |
| 63 return String(); |
| 64 return result; |
52 } | 65 } |
| 66 |
| 67 // FIXMEDART: Implement without conversion to v8. |
| 68 PassRefPtr<JSONValue> DartScriptValue::toJSONValue(ScriptState* scriptState) con
st |
| 69 { |
| 70 Dart_Handle exception = 0; |
| 71 v8::Handle<v8::Value> v8Value = V8Converter::toV8(m_value, exception); |
| 72 if (exception) { |
| 73 ASSERT_NOT_REACHED(); |
| 74 return nullptr; |
| 75 } |
| 76 ScriptValue v8ScriptValue(v8Value, scriptState->isolate()); |
| 77 return v8ScriptValue.toJSONValue(scriptState); |
| 78 } |
| 79 |
| 80 } // namespace WebCore |
OLD | NEW |