Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Ericsson AB. All rights reserved. | 3 * Copyright (C) 2012 Ericsson AB. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 { | 202 { |
| 203 ASSERT(isolate); | 203 ASSERT(isolate); |
| 204 return v8::String::NewFromUtf8(isolate, str, v8::String::kInternalizedString , length); | 204 return v8::String::NewFromUtf8(isolate, str, v8::String::kInternalizedString , length); |
| 205 } | 205 } |
| 206 | 206 |
| 207 inline v8::Handle<v8::Value> v8Undefined() | 207 inline v8::Handle<v8::Value> v8Undefined() |
| 208 { | 208 { |
| 209 return v8::Handle<v8::Value>(); | 209 return v8::Handle<v8::Value>(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 // Converts a DOM object to a v8 value. | 212 // Converts a DOM object to a v8 value. This function is intended to be used |
| 213 // This is a no-inline version of toV8(). If you want to call toV8() | 213 // internally. If you want to convert a C++ value to a JS value without |
|
haraken
2014/09/02 01:20:40
JS value => V8 value
yhirano
2014/09/02 04:43:06
Done.
| |
| 214 // without creating #include cycles, you can use this function instead. | 214 // including V8X.h, consider using V8ValueTraits<T>::toV8Value. |
| 215 // Each specialized implementation will be generated. | 215 // Note: including bindings/{core, bindings}/v8/V8*.h from core and modules |
| 216 // is fine. In such a case, perhaps toV8 is what you want. | |
| 217 // Note: toV8NoInline is a non-inline toV8 and V8ValueTraits::toV8Value offers | |
| 218 // more: You can handle value conversion generally with it. | |
|
haraken
2014/09/02 01:20:40
Slightly more concise:
// toV8NoInline is intende
yhirano
2014/09/02 04:43:06
Done.
| |
| 216 template<typename T> | 219 template<typename T> |
| 217 v8::Handle<v8::Value> toV8NoInline(T* impl, v8::Handle<v8::Object> creationConte xt, v8::Isolate*); | 220 v8::Handle<v8::Value> toV8NoInline(T* impl, v8::Handle<v8::Object> creationConte xt, v8::Isolate*); |
| 218 | 221 |
| 219 template <typename T> | 222 template <typename T> |
| 220 struct V8ValueTraits { | 223 struct V8ValueTraits { |
| 221 static v8::Handle<v8::Value> toV8Value(const T& value, v8::Handle<v8::Object > creationContext, v8::Isolate* isolate) | 224 static v8::Handle<v8::Value> toV8Value(const T& value, v8::Handle<v8::Object > creationContext, v8::Isolate* isolate) |
| 222 { | 225 { |
| 223 if (!WTF::getPtr(value)) | 226 if (!WTF::getPtr(value)) |
| 224 return v8::Null(isolate); | 227 return v8::Null(isolate); |
| 225 return toV8NoInline(WTF::getPtr(value), creationContext, isolate); | 228 return toV8NoInline(WTF::getPtr(value), creationContext, isolate); |
| (...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 953 ~V8RethrowTryCatchScope() | 956 ~V8RethrowTryCatchScope() |
| 954 { | 957 { |
| 955 // ReThrow() is a no-op if no exception has been caught, so always call. | 958 // ReThrow() is a no-op if no exception has been caught, so always call. |
| 956 m_block.ReThrow(); | 959 m_block.ReThrow(); |
| 957 } | 960 } |
| 958 | 961 |
| 959 private: | 962 private: |
| 960 v8::TryCatch& m_block; | 963 v8::TryCatch& m_block; |
| 961 }; | 964 }; |
| 962 | 965 |
| 966 // Returns an object representing {done: true, value: undefined}. | |
| 967 v8::Local<v8::Value> v8DoneIteratorResult(v8::Isolate*); | |
| 968 | |
| 969 // Returns an object representing {done: false, value: |value|}. | |
| 970 v8::Local<v8::Value> v8IteratorResult(v8::Isolate*, v8::Handle<v8::Value>); | |
| 971 template <typename T> | |
| 972 v8::Local<v8::Value> v8IteratorResult(ScriptState* scriptState, const T& value) | |
| 973 { | |
| 974 return v8IteratorResult(scriptState->isolate(), V8ValueTraits<T>::toV8Value( value, scriptState->context()->Global(), scriptState->isolate())); | |
| 975 } | |
| 976 | |
| 963 } // namespace blink | 977 } // namespace blink |
| 964 | 978 |
| 965 #endif // V8Binding_h | 979 #endif // V8Binding_h |
| OLD | NEW |