@@ -345,6 +345,57 @@ void SetConstructorFunction(v8::Isolate* isolate,
345345 SetConstructorFunctionFlag::SET_CLASS_NAME);
346346
347347
348+ template <int N>
349+ inline v8::Local<v8::String> FIXED_ONE_BYTE_STRING (
350+ v8::Isolate* isolate,
351+ const char (&data)[N]) {
352+ return OneByteString (isolate, data, N - 1 );
353+ }
354+
355+ template <std::size_t N>
356+ inline v8::Local<v8::String> FIXED_ONE_BYTE_STRING (
357+ v8::Isolate* isolate,
358+ const std::array<char , N>& arr) {
359+ return OneByteString (isolate, arr.data (), N - 1 );
360+ }
361+
362+ class PersistentToLocal {
363+ public:
364+ // If persistent.IsWeak() == false, then do not call persistent.Reset()
365+ // while the returned Local<T> is still in scope, it will destroy the
366+ // reference to the object.
367+ template <class TypeName >
368+ static inline v8::Local<TypeName> Default (
369+ v8::Isolate* isolate,
370+ const v8::PersistentBase<TypeName>& persistent) {
371+ if (persistent.IsWeak ()) {
372+ return PersistentToLocal::Weak (isolate, persistent);
373+ } else {
374+ return PersistentToLocal::Strong (persistent);
375+ }
376+ }
377+
378+ // Unchecked conversion from a non-weak Persistent<T> to Local<T>,
379+ // use with care!
380+ //
381+ // Do not call persistent.Reset() while the returned Local<T> is still in
382+ // scope, it will destroy the reference to the object.
383+ template <class TypeName >
384+ static inline v8::Local<TypeName> Strong (
385+ const v8::PersistentBase<TypeName>& persistent) {
386+ // DCHECK(!persistent.IsWeak());
387+ return *reinterpret_cast <v8::Local<TypeName>*>(
388+ const_cast <v8::PersistentBase<TypeName>*>(&persistent));
389+ }
390+
391+ template <class TypeName >
392+ static inline v8::Local<TypeName> Weak (
393+ v8::Isolate* isolate,
394+ const v8::PersistentBase<TypeName>& persistent) {
395+ return v8::Local<TypeName>::New (isolate, persistent);
396+ }
397+ };
398+
348399}
349400
350401#endif /* Helpers_h */
0 commit comments