| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2009, 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009, 2011 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 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 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 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "bindings/core/v8/ScriptValue.h" | 32 #include "bindings/core/v8/ScriptValue.h" |
| 33 | 33 |
| 34 #include "bindings/core/v8/ScriptState.h" | 34 #include "bindings/core/v8/ScriptState.h" |
| 35 #include "bindings/core/v8/SerializedScriptValueFactory.h" |
| 35 #include "bindings/core/v8/V8Binding.h" | 36 #include "bindings/core/v8/V8Binding.h" |
| 36 #include "platform/JSONValues.h" | 37 #include "platform/JSONValues.h" |
| 37 | 38 |
| 38 namespace blink { | 39 namespace blink { |
| 39 | 40 |
| 40 v8::Local<v8::Value> ScriptValue::v8Value() const | 41 v8::Local<v8::Value> ScriptValue::v8Value() const |
| 41 { | 42 { |
| 42 if (isEmpty()) | 43 if (isEmpty()) |
| 43 return v8::Local<v8::Value>(); | 44 return v8::Local<v8::Value>(); |
| 44 | 45 |
| 45 ASSERT(isolate()->InContext()); | 46 ASSERT(isolate()->InContext()); |
| 46 | 47 |
| 47 // This is a check to validate that you don't return a ScriptValue to a worl
d different | 48 // This is a check to validate that you don't return a ScriptValue to a worl
d different |
| 48 // from the world that created the ScriptValue. | 49 // from the world that created the ScriptValue. |
| 49 // Probably this could be: | 50 // Probably this could be: |
| 50 // if (&m_scriptState->world() == &DOMWrapperWorld::current(isolate())) | 51 // if (&m_scriptState->world() == &DOMWrapperWorld::current(isolate())) |
| 51 // return v8::Local<v8::Value>(); | 52 // return v8::Local<v8::Value>(); |
| 52 // instead of triggering RELEASE_ASSERT. | 53 // instead of triggering RELEASE_ASSERT. |
| 53 RELEASE_ASSERT(&m_scriptState->world() == &DOMWrapperWorld::current(isolate(
))); | 54 RELEASE_ASSERT(&m_scriptState->world() == &DOMWrapperWorld::current(isolate(
))); |
| 54 return m_value->newLocal(isolate()); | 55 return m_value->newLocal(isolate()); |
| 55 } | 56 } |
| 56 | 57 |
| 57 v8::Local<v8::Value> ScriptValue::v8ValueUnsafe() const | 58 v8::Local<v8::Value> ScriptValue::v8ValueUnsafe() const |
| 58 { | 59 { |
| 59 if (isEmpty()) | 60 if (isEmpty()) |
| 60 return v8::Local<v8::Value>(); | 61 return v8::Local<v8::Value>(); |
| 61 return m_value->newLocal(isolate()); | 62 return m_value->newLocal(isolate()); |
| 62 } | 63 } |
| 63 | 64 |
| 65 v8::Local<v8::Value> ScriptValue::v8ValueFor(ScriptState* targetScriptState) |
| 66 { |
| 67 if (isEmpty()) |
| 68 return v8::Local<v8::Value>(); |
| 69 v8::Isolate* isolate = targetScriptState->isolate(); |
| 70 if (&m_scriptState->world() == &targetScriptState->world()) |
| 71 return m_value->newLocal(isolate); |
| 72 |
| 73 ASSERT(isolate->InContext()); |
| 74 v8::Local<v8::Value> value = m_value->newLocal(isolate); |
| 75 RefPtr<SerializedScriptValue> serialized = SerializedScriptValueFactory::ins
tance().createAndSwallowExceptions(isolate, value); |
| 76 return serialized->deserialize(); |
| 77 } |
| 78 |
| 64 bool ScriptValue::toString(String& result) const | 79 bool ScriptValue::toString(String& result) const |
| 65 { | 80 { |
| 66 if (isEmpty()) | 81 if (isEmpty()) |
| 67 return false; | 82 return false; |
| 68 | 83 |
| 69 ScriptState::Scope scope(m_scriptState.get()); | 84 ScriptState::Scope scope(m_scriptState.get()); |
| 70 v8::Local<v8::Value> string = v8Value(); | 85 v8::Local<v8::Value> string = v8Value(); |
| 71 if (string.IsEmpty() || !string->IsString()) | 86 if (string.IsEmpty() || !string->IsString()) |
| 72 return false; | 87 return false; |
| 73 result = toCoreString(v8::Local<v8::String>::Cast(string)); | 88 result = toCoreString(v8::Local<v8::String>::Cast(string)); |
| 74 return true; | 89 return true; |
| 75 } | 90 } |
| 76 | 91 |
| 77 ScriptValue ScriptValue::createNull(ScriptState* scriptState) | 92 ScriptValue ScriptValue::createNull(ScriptState* scriptState) |
| 78 { | 93 { |
| 79 return ScriptValue(scriptState, v8::Null(scriptState->isolate())); | 94 return ScriptValue(scriptState, v8::Null(scriptState->isolate())); |
| 80 } | 95 } |
| 81 | 96 |
| 82 } // namespace blink | 97 } // namespace blink |
| OLD | NEW |