Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Side by Side Diff: Source/bindings/core/v8/ScriptValue.cpp

Issue 1130763006: IDL: Add any support to IDL dictionary and use it in CustomEventInit (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 ASSERT(!m_scriptState->world().isWorkerWorld());
75 ASSERT(!targetScriptState->world().isWorkerWorld());
haraken 2015/05/20 00:43:42 Are these isWorkerWorld checks useful?
bashi 2015/05/20 00:52:22 I thought someone may misuse v8ValueFor() in worke
76 v8::Local<v8::Value> value = m_value->newLocal(isolate);
77 RefPtr<SerializedScriptValue> serialized = SerializedScriptValueFactory::ins tance().createAndSwallowExceptions(isolate, value);
78 return serialized->deserialize();
79 }
80
64 bool ScriptValue::toString(String& result) const 81 bool ScriptValue::toString(String& result) const
65 { 82 {
66 if (isEmpty()) 83 if (isEmpty())
67 return false; 84 return false;
68 85
69 ScriptState::Scope scope(m_scriptState.get()); 86 ScriptState::Scope scope(m_scriptState.get());
70 v8::Local<v8::Value> string = v8Value(); 87 v8::Local<v8::Value> string = v8Value();
71 if (string.IsEmpty() || !string->IsString()) 88 if (string.IsEmpty() || !string->IsString())
72 return false; 89 return false;
73 result = toCoreString(v8::Local<v8::String>::Cast(string)); 90 result = toCoreString(v8::Local<v8::String>::Cast(string));
74 return true; 91 return true;
75 } 92 }
76 93
77 ScriptValue ScriptValue::createNull(ScriptState* scriptState) 94 ScriptValue ScriptValue::createNull(ScriptState* scriptState)
78 { 95 {
79 return ScriptValue(scriptState, v8::Null(scriptState->isolate())); 96 return ScriptValue(scriptState, v8::Null(scriptState->isolate()));
80 } 97 }
81 98
82 } // namespace blink 99 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698