v8  5.5.372(node7.10.1)
V8 is Google's open source JavaScript engine
v8.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 /** \mainpage V8 API Reference Guide
6  *
7  * V8 is Google's open source JavaScript engine.
8  *
9  * This set of documents provides reference material generated from the
10  * V8 header file, include/v8.h.
11  *
12  * For other documentation see http://code.google.com/apis/v8/
13  */
14 
15 #ifndef INCLUDE_V8_H_
16 #define INCLUDE_V8_H_
17 
18 #include <stddef.h>
19 #include <stdint.h>
20 #include <stdio.h>
21 #include <memory>
22 #include <utility>
23 #include <vector>
24 
25 #include "v8-version.h" // NOLINT(build/include)
26 #include "v8config.h" // NOLINT(build/include)
27 
28 // We reserve the V8_* prefix for macros defined in V8 public API and
29 // assume there are no name conflicts with the embedder's code.
30 
31 #ifdef V8_OS_WIN
32 
33 // Setup for Windows DLL export/import. When building the V8 DLL the
34 // BUILDING_V8_SHARED needs to be defined. When building a program which uses
35 // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
36 // static library or building a program which uses the V8 static library neither
37 // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
38 #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
39 #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the
40  build configuration to ensure that at most one of these is set
41 #endif
42 
43 #ifdef BUILDING_V8_SHARED
44 # define V8_EXPORT __declspec(dllexport)
45 #elif USING_V8_SHARED
46 # define V8_EXPORT __declspec(dllimport)
47 #else
48 # define V8_EXPORT
49 #endif // BUILDING_V8_SHARED
50 
51 #else // V8_OS_WIN
52 
53 // Setup for Linux shared library export.
54 #if V8_HAS_ATTRIBUTE_VISIBILITY
55 # ifdef BUILDING_V8_SHARED
56 # define V8_EXPORT __attribute__ ((visibility("default")))
57 # else
58 # define V8_EXPORT
59 # endif
60 #else
61 # define V8_EXPORT
62 #endif
63 
64 #endif // V8_OS_WIN
65 
66 /**
67  * The v8 JavaScript engine.
68  */
69 namespace v8 {
70 
71 class AccessorSignature;
72 class Array;
73 class ArrayBuffer;
74 class Boolean;
75 class BooleanObject;
76 class Context;
77 class CpuProfiler;
78 class Data;
79 class Date;
80 class External;
81 class Function;
82 class FunctionTemplate;
83 class HeapProfiler;
84 class ImplementationUtilities;
85 class Int32;
86 class Integer;
87 class Isolate;
88 template <class T>
89 class Maybe;
90 class Name;
91 class Number;
92 class NumberObject;
93 class Object;
94 class ObjectOperationDescriptor;
95 class ObjectTemplate;
96 class Platform;
97 class Primitive;
98 class Promise;
99 class PropertyDescriptor;
100 class Proxy;
101 class RawOperationDescriptor;
102 class Script;
103 class SharedArrayBuffer;
104 class Signature;
105 class StartupData;
106 class StackFrame;
107 class StackTrace;
108 class String;
109 class StringObject;
110 class Symbol;
111 class SymbolObject;
112 class Private;
113 class Uint32;
114 class Utils;
115 class Value;
116 template <class T> class Local;
117 template <class T>
118 class MaybeLocal;
119 template <class T> class Eternal;
120 template<class T> class NonCopyablePersistentTraits;
121 template<class T> class PersistentBase;
122 template <class T, class M = NonCopyablePersistentTraits<T> >
123 class Persistent;
124 template <class T>
125 class Global;
126 template<class K, class V, class T> class PersistentValueMap;
127 template <class K, class V, class T>
129 template <class K, class V, class T>
130 class GlobalValueMap;
131 template<class V, class T> class PersistentValueVector;
132 template<class T, class P> class WeakCallbackObject;
133 class FunctionTemplate;
134 class ObjectTemplate;
135 class Data;
136 template<typename T> class FunctionCallbackInfo;
137 template<typename T> class PropertyCallbackInfo;
138 class StackTrace;
139 class StackFrame;
140 class Isolate;
141 class CallHandlerHelper;
143 template<typename T> class ReturnValue;
144 
145 namespace experimental {
146 class FastAccessorBuilder;
147 } // namespace experimental
148 
149 namespace internal {
150 class Arguments;
151 class Heap;
152 class HeapObject;
153 class Isolate;
154 class Object;
155 struct StreamedSource;
156 template<typename T> class CustomArguments;
157 class PropertyCallbackArguments;
158 class FunctionCallbackArguments;
159 class GlobalHandles;
160 } // namespace internal
161 
162 
163 /**
164  * General purpose unique identifier.
165  */
166 class UniqueId {
167  public:
168  explicit UniqueId(intptr_t data)
169  : data_(data) {}
170 
171  bool operator==(const UniqueId& other) const {
172  return data_ == other.data_;
173  }
174 
175  bool operator!=(const UniqueId& other) const {
176  return data_ != other.data_;
177  }
178 
179  bool operator<(const UniqueId& other) const {
180  return data_ < other.data_;
181  }
182 
183  private:
184  intptr_t data_;
185 };
186 
187 // --- Handles ---
188 
189 #define TYPE_CHECK(T, S)
190  while (false) {
191  *(static_cast<T* volatile*>(0)) = static_cast<S*>(0);
192  }
193 
194 
195 /**
196  * An object reference managed by the v8 garbage collector.
197  *
198  * All objects returned from v8 have to be tracked by the garbage
199  * collector so that it knows that the objects are still alive. Also,
200  * because the garbage collector may move objects, it is unsafe to
201  * point directly to an object. Instead, all objects are stored in
202  * handles which are known by the garbage collector and updated
203  * whenever an object moves. Handles should always be passed by value
204  * (except in cases like out-parameters) and they should never be
205  * allocated on the heap.
206  *
207  * There are two types of handles: local and persistent handles.
208  * Local handles are light-weight and transient and typically used in
209  * local operations. They are managed by HandleScopes. Persistent
210  * handles can be used when storing objects across several independent
211  * operations and have to be explicitly deallocated when they're no
212  * longer used.
213  *
214  * It is safe to extract the object stored in the handle by
215  * dereferencing the handle (for instance, to extract the Object* from
216  * a Local<Object>); the value will still be governed by a handle
217  * behind the scenes and the same rules apply to these values as to
218  * their handles.
219  */
220 template <class T>
221 class Local {
222  public:
223  V8_INLINE Local() : val_(0) {}
224  template <class S>
225  V8_INLINE Local(Local<S> that)
226  : val_(reinterpret_cast<T*>(*that)) {
227  /**
228  * This check fails when trying to convert between incompatible
229  * handles. For example, converting from a Local<String> to a
230  * Local<Number>.
231  */
232  TYPE_CHECK(T, S);
233  }
234 
235  /**
236  * Returns true if the handle is empty.
237  */
238  V8_INLINE bool IsEmpty() const { return val_ == 0; }
239 
240  /**
241  * Sets the handle to be empty. IsEmpty() will then return true.
242  */
243  V8_INLINE void Clear() { val_ = 0; }
244 
245  V8_INLINE T* operator->() const { return val_; }
246 
247  V8_INLINE T* operator*() const { return val_; }
248 
249  /**
250  * Checks whether two handles are the same.
251  * Returns true if both are empty, or if the objects
252  * to which they refer are identical.
253  * The handles' references are not checked.
254  */
255  template <class S>
256  V8_INLINE bool operator==(const Local<S>& that) const {
257  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
258  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
259  if (a == 0) return b == 0;
260  if (b == 0) return false;
261  return *a == *b;
262  }
263 
264  template <class S> V8_INLINE bool operator==(
265  const PersistentBase<S>& that) const {
266  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
267  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
268  if (a == 0) return b == 0;
269  if (b == 0) return false;
270  return *a == *b;
271  }
272 
273  /**
274  * Checks whether two handles are different.
275  * Returns true if only one of the handles is empty, or if
276  * the objects to which they refer are different.
277  * The handles' references are not checked.
278  */
279  template <class S>
280  V8_INLINE bool operator!=(const Local<S>& that) const {
281  return !operator==(that);
282  }
283 
284  template <class S> V8_INLINE bool operator!=(
285  const Persistent<S>& that) const {
286  return !operator==(that);
287  }
288 
289  template <class S> V8_INLINE static Local<T> Cast(Local<S> that) {
290 #ifdef V8_ENABLE_CHECKS
291  // If we're going to perform the type check then we have to check
292  // that the handle isn't empty before doing the checked cast.
293  if (that.IsEmpty()) return Local<T>();
294 #endif
295  return Local<T>(T::Cast(*that));
296  }
297 
298  template <class S>
299  V8_INLINE Local<S> As() const {
300  return Local<S>::Cast(*this);
301  }
302 
303  /**
304  * Create a local handle for the content of another handle.
305  * The referee is kept alive by the local handle even when
306  * the original handle is destroyed/disposed.
307  */
308  V8_INLINE static Local<T> New(Isolate* isolate, Local<T> that);
309  V8_INLINE static Local<T> New(Isolate* isolate,
310  const PersistentBase<T>& that);
311 
312  private:
313  friend class Utils;
314  template<class F> friend class Eternal;
315  template<class F> friend class PersistentBase;
316  template<class F, class M> friend class Persistent;
317  template<class F> friend class Local;
318  template <class F>
319  friend class MaybeLocal;
320  template<class F> friend class FunctionCallbackInfo;
321  template<class F> friend class PropertyCallbackInfo;
322  friend class String;
323  friend class Object;
324  friend class Context;
325  friend class Private;
326  template<class F> friend class internal::CustomArguments;
328  friend Local<Primitive> Null(Isolate* isolate);
329  friend Local<Boolean> True(Isolate* isolate);
330  friend Local<Boolean> False(Isolate* isolate);
331  friend class HandleScope;
332  friend class EscapableHandleScope;
333  template <class F1, class F2, class F3>
335  template<class F1, class F2> friend class PersistentValueVector;
336  template <class F>
337  friend class ReturnValue;
338 
339  explicit V8_INLINE Local(T* that) : val_(that) {}
340  V8_INLINE static Local<T> New(Isolate* isolate, T* that);
341  T* val_;
342 };
343 
344 
345 #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
346 // Handle is an alias for Local for historical reasons.
347 template <class T>
348 using Handle = Local<T>;
349 #endif
350 
351 
352 /**
353  * A MaybeLocal<> is a wrapper around Local<> that enforces a check whether
354  * the Local<> is empty before it can be used.
355  *
356  * If an API method returns a MaybeLocal<>, the API method can potentially fail
357  * either because an exception is thrown, or because an exception is pending,
358  * e.g. because a previous API call threw an exception that hasn't been caught
359  * yet, or because a TerminateExecution exception was thrown. In that case, an
360  * empty MaybeLocal is returned.
361  */
362 template <class T>
363 class MaybeLocal {
364  public:
366  template <class S>
367  V8_INLINE MaybeLocal(Local<S> that)
368  : val_(reinterpret_cast<T*>(*that)) {
369  TYPE_CHECK(T, S);
370  }
371 
372  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
373 
374  template <class S>
375  V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local<S>* out) const {
376  out->val_ = IsEmpty() ? nullptr : this->val_;
377  return !IsEmpty();
378  }
379 
380  // Will crash if the MaybeLocal<> is empty.
381  V8_INLINE Local<T> ToLocalChecked();
382 
383  template <class S>
384  V8_INLINE Local<S> FromMaybe(Local<S> default_value) const {
385  return IsEmpty() ? default_value : Local<S>(val_);
386  }
387 
388  private:
389  T* val_;
390 };
391 
392 
393 // Eternal handles are set-once handles that live for the life of the isolate.
394 template <class T> class Eternal {
395  public:
396  V8_INLINE Eternal() : index_(kInitialValue) { }
397  template<class S>
398  V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : index_(kInitialValue) {
399  Set(isolate, handle);
400  }
401  // Can only be safely called if already set.
402  V8_INLINE Local<T> Get(Isolate* isolate);
403  V8_INLINE bool IsEmpty() { return index_ == kInitialValue; }
404  template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle);
405 
406  private:
407  static const int kInitialValue = -1;
408  int index_;
409 };
410 
411 
412 static const int kInternalFieldsInWeakCallback = 2;
413 
414 
415 template <typename T>
417  public:
418  typedef void (*Callback)(const WeakCallbackInfo<T>& data);
419 
420  WeakCallbackInfo(Isolate* isolate, T* parameter,
421  void* internal_fields[kInternalFieldsInWeakCallback],
422  Callback* callback)
423  : isolate_(isolate), parameter_(parameter), callback_(callback) {
424  for (int i = 0; i < kInternalFieldsInWeakCallback; ++i) {
425  internal_fields_[i] = internal_fields[i];
426  }
427  }
428 
429  V8_INLINE Isolate* GetIsolate() const { return isolate_; }
430  V8_INLINE T* GetParameter() const { return parameter_; }
431  V8_INLINE void* GetInternalField(int index) const;
432 
433  V8_INLINE V8_DEPRECATED("use indexed version",
434  void* GetInternalField1() const) {
435  return internal_fields_[0];
436  }
437  V8_INLINE V8_DEPRECATED("use indexed version",
438  void* GetInternalField2() const) {
439  return internal_fields_[1];
440  }
441 
442  V8_DEPRECATED("Not realiable once SetSecondPassCallback() was used.",
443  bool IsFirstPass() const) {
444  return callback_ != nullptr;
445  }
446 
447  // When first called, the embedder MUST Reset() the Global which triggered the
448  // callback. The Global itself is unusable for anything else. No v8 other api
449  // calls may be called in the first callback. Should additional work be
450  // required, the embedder must set a second pass callback, which will be
451  // called after all the initial callbacks are processed.
452  // Calling SetSecondPassCallback on the second pass will immediately crash.
453  void SetSecondPassCallback(Callback callback) const { *callback_ = callback; }
454 
455  private:
456  Isolate* isolate_;
457  T* parameter_;
458  Callback* callback_;
459  void* internal_fields_[kInternalFieldsInWeakCallback];
460 };
461 
462 
463 // kParameter will pass a void* parameter back to the callback, kInternalFields
464 // will pass the first two internal fields back to the callback, kFinalizer
465 // will pass a void* parameter back, but is invoked before the object is
466 // actually collected, so it can be resurrected. In the last case, it is not
467 // possible to request a second pass callback.
469 
470 /**
471  * A reporter class that embedder will use to report reachable references found
472  * by EmbedderHeapTracer.
473  */
475  public:
476  virtual void ReportExternalReference(Value* object) = 0;
477  virtual ~EmbedderReachableReferenceReporter() = default;
478 };
479 
480 /**
481  * An object reference that is independent of any handle scope. Where
482  * a Local handle only lives as long as the HandleScope in which it was
483  * allocated, a PersistentBase handle remains valid until it is explicitly
484  * disposed.
485  *
486  * A persistent handle contains a reference to a storage cell within
487  * the v8 engine which holds an object value and which is updated by
488  * the garbage collector whenever the object is moved. A new storage
489  * cell can be created using the constructor or PersistentBase::Reset and
490  * existing handles can be disposed using PersistentBase::Reset.
491  *
492  */
493 template <class T> class PersistentBase {
494  public:
495  /**
496  * If non-empty, destroy the underlying storage cell
497  * IsEmpty() will return true after this call.
498  */
499  V8_INLINE void Reset();
500  /**
501  * If non-empty, destroy the underlying storage cell
502  * and create a new one with the contents of other if other is non empty
503  */
504  template <class S>
505  V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
506 
507  /**
508  * If non-empty, destroy the underlying storage cell
509  * and create a new one with the contents of other if other is non empty
510  */
511  template <class S>
512  V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other);
513 
514  V8_INLINE bool IsEmpty() const { return val_ == NULL; }
515  V8_INLINE void Empty() { val_ = 0; }
516 
517  V8_INLINE Local<T> Get(Isolate* isolate) const {
518  return Local<T>::New(isolate, *this);
519  }
520 
521  template <class S>
522  V8_INLINE bool operator==(const PersistentBase<S>& that) const {
523  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
524  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
525  if (a == NULL) return b == NULL;
526  if (b == NULL) return false;
527  return *a == *b;
528  }
529 
530  template <class S>
531  V8_INLINE bool operator==(const Local<S>& that) const {
532  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
533  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
534  if (a == NULL) return b == NULL;
535  if (b == NULL) return false;
536  return *a == *b;
537  }
538 
539  template <class S>
540  V8_INLINE bool operator!=(const PersistentBase<S>& that) const {
541  return !operator==(that);
542  }
543 
544  template <class S>
545  V8_INLINE bool operator!=(const Local<S>& that) const {
546  return !operator==(that);
547  }
548 
549  /**
550  * Install a finalization callback on this object.
551  * NOTE: There is no guarantee as to *when* or even *if* the callback is
552  * invoked. The invocation is performed solely on a best effort basis.
553  * As always, GC-based finalization should *not* be relied upon for any
554  * critical form of resource management!
555  */
556  template <typename P>
557  V8_INLINE void SetWeak(P* parameter,
558  typename WeakCallbackInfo<P>::Callback callback,
559  WeakCallbackType type);
560 
561  /**
562  * Turns this handle into a weak phantom handle without finalization callback.
563  * The handle will be reset automatically when the garbage collector detects
564  * that the object is no longer reachable.
565  * A related function Isolate::NumberOfPhantomHandleResetsSinceLastCall
566  * returns how many phantom handles were reset by the garbage collector.
567  */
568  V8_INLINE void SetWeak();
569 
570  template<typename P>
571  V8_INLINE P* ClearWeak();
572 
573  // TODO(dcarney): remove this.
574  V8_INLINE void ClearWeak() { ClearWeak<void>(); }
575 
576  /**
577  * Deprecated.
578  * TODO(hlopko): remove once migration to reporter is finished.
579  */
581 
582  /**
583  * Allows the embedder to tell the v8 garbage collector that a certain object
584  * is alive. Only allowed when the embedder is asked to trace its heap by
585  * EmbedderHeapTracer.
586  */
588  EmbedderReachableReferenceReporter* reporter) const;
589 
590  /**
591  * Marks the reference to this object independent. Garbage collector is free
592  * to ignore any object groups containing this object. Weak callback for an
593  * independent handle should not assume that it will be preceded by a global
594  * GC prologue callback or followed by a global GC epilogue callback.
595  */
596  V8_INLINE void MarkIndependent();
597 
598  /**
599  * Marks the reference to this object partially dependent. Partially dependent
600  * handles only depend on other partially dependent handles and these
601  * dependencies are provided through object groups. It provides a way to build
602  * smaller object groups for young objects that represent only a subset of all
603  * external dependencies. This mark is automatically cleared after each
604  * garbage collection.
605  */
607  "deprecated optimization, do not use partially dependent groups",
608  void MarkPartiallyDependent());
609 
610  /**
611  * Marks the reference to this object as active. The scavenge garbage
612  * collection should not reclaim the objects marked as active.
613  * This bit is cleared after the each garbage collection pass.
614  */
615  V8_INLINE void MarkActive();
616 
617  V8_INLINE bool IsIndependent() const;
618 
619  /** Checks if the handle holds the only reference to an object. */
620  V8_INLINE bool IsNearDeath() const;
621 
622  /** Returns true if the handle's reference is weak. */
623  V8_INLINE bool IsWeak() const;
624 
625  /**
626  * Assigns a wrapper class ID to the handle. See RetainedObjectInfo interface
627  * description in v8-profiler.h for details.
628  */
629  V8_INLINE void SetWrapperClassId(uint16_t class_id);
630 
631  /**
632  * Returns the class ID previously assigned to this handle or 0 if no class ID
633  * was previously assigned.
634  */
635  V8_INLINE uint16_t WrapperClassId() const;
636 
637  PersistentBase(const PersistentBase& other) = delete; // NOLINT
638  void operator=(const PersistentBase&) = delete;
639 
640  private:
641  friend class Isolate;
642  friend class Utils;
643  template<class F> friend class Local;
644  template<class F1, class F2> friend class Persistent;
645  template <class F>
646  friend class Global;
647  template<class F> friend class PersistentBase;
648  template<class F> friend class ReturnValue;
649  template <class F1, class F2, class F3>
651  template<class F1, class F2> friend class PersistentValueVector;
652  friend class Object;
653 
654  explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
655  V8_INLINE static T* New(Isolate* isolate, T* that);
656 
657  T* val_;
658 };
659 
660 
661 /**
662  * Default traits for Persistent. This class does not allow
663  * use of the copy constructor or assignment operator.
664  * At present kResetInDestructor is not set, but that will change in a future
665  * version.
666  */
667 template<class T>
668 class NonCopyablePersistentTraits {
669  public:
670  typedef Persistent<T, NonCopyablePersistentTraits<T> > NonCopyablePersistent;
671  static const bool kResetInDestructor = false;
672  template<class S, class M>
673  V8_INLINE static void Copy(const Persistent<S, M>& source,
674  NonCopyablePersistent* dest) {
675  Uncompilable<Object>();
676  }
677  // TODO(dcarney): come up with a good compile error here.
678  template<class O> V8_INLINE static void Uncompilable() {
679  TYPE_CHECK(O, Primitive);
680  }
681 };
682 
683 
684 /**
685  * Helper class traits to allow copying and assignment of Persistent.
686  * This will clone the contents of storage cell, but not any of the flags, etc.
687  */
688 template<class T>
690  typedef Persistent<T, CopyablePersistentTraits<T> > CopyablePersistent;
691  static const bool kResetInDestructor = true;
692  template<class S, class M>
693  static V8_INLINE void Copy(const Persistent<S, M>& source,
694  CopyablePersistent* dest) {
695  // do nothing, just allow copy
696  }
697 };
698 
699 
700 /**
701  * A PersistentBase which allows copy and assignment.
702  *
703  * Copy, assignment and destructor bevavior is controlled by the traits
704  * class M.
705  *
706  * Note: Persistent class hierarchy is subject to future changes.
707  */
708 template <class T, class M> class Persistent : public PersistentBase<T> {
709  public:
710  /**
711  * A Persistent with no storage cell.
712  */
713  V8_INLINE Persistent() : PersistentBase<T>(0) { }
714  /**
715  * Construct a Persistent from a Local.
716  * When the Local is non-empty, a new storage cell is created
717  * pointing to the same object, and no flags are set.
718  */
719  template <class S>
720  V8_INLINE Persistent(Isolate* isolate, Local<S> that)
721  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
722  TYPE_CHECK(T, S);
723  }
724  /**
725  * Construct a Persistent from a Persistent.
726  * When the Persistent is non-empty, a new storage cell is created
727  * pointing to the same object, and no flags are set.
728  */
729  template <class S, class M2>
730  V8_INLINE Persistent(Isolate* isolate, const Persistent<S, M2>& that)
731  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
732  TYPE_CHECK(T, S);
733  }
734  /**
735  * The copy constructors and assignment operator create a Persistent
736  * exactly as the Persistent constructor, but the Copy function from the
737  * traits class is called, allowing the setting of flags based on the
738  * copied Persistent.
739  */
740  V8_INLINE Persistent(const Persistent& that) : PersistentBase<T>(0) {
741  Copy(that);
742  }
743  template <class S, class M2>
744  V8_INLINE Persistent(const Persistent<S, M2>& that) : PersistentBase<T>(0) {
745  Copy(that);
746  }
747  V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT
748  Copy(that);
749  return *this;
750  }
751  template <class S, class M2>
752  V8_INLINE Persistent& operator=(const Persistent<S, M2>& that) { // NOLINT
753  Copy(that);
754  return *this;
755  }
756  /**
757  * The destructor will dispose the Persistent based on the
758  * kResetInDestructor flags in the traits class. Since not calling dispose
759  * can result in a memory leak, it is recommended to always set this flag.
760  */
762  if (M::kResetInDestructor) this->Reset();
763  }
764 
765  // TODO(dcarney): this is pretty useless, fix or remove
766  template <class S>
767  V8_INLINE static Persistent<T>& Cast(const Persistent<S>& that) { // NOLINT
768 #ifdef V8_ENABLE_CHECKS
769  // If we're going to perform the type check then we have to check
770  // that the handle isn't empty before doing the checked cast.
771  if (!that.IsEmpty()) T::Cast(*that);
772 #endif
773  return reinterpret_cast<Persistent<T>&>(const_cast<Persistent<S>&>(that));
774  }
775 
776  // TODO(dcarney): this is pretty useless, fix or remove
777  template <class S>
778  V8_INLINE Persistent<S>& As() const { // NOLINT
779  return Persistent<S>::Cast(*this);
780  }
781 
782  private:
783  friend class Isolate;
784  friend class Utils;
785  template<class F> friend class Local;
786  template<class F1, class F2> friend class Persistent;
787  template<class F> friend class ReturnValue;
788 
789  explicit V8_INLINE Persistent(T* that) : PersistentBase<T>(that) {}
790  V8_INLINE T* operator*() const { return this->val_; }
791  template<class S, class M2>
792  V8_INLINE void Copy(const Persistent<S, M2>& that);
793 };
794 
795 
796 /**
797  * A PersistentBase which has move semantics.
798  *
799  * Note: Persistent class hierarchy is subject to future changes.
800  */
801 template <class T>
802 class Global : public PersistentBase<T> {
803  public:
804  /**
805  * A Global with no storage cell.
806  */
808  /**
809  * Construct a Global from a Local.
810  * When the Local is non-empty, a new storage cell is created
811  * pointing to the same object, and no flags are set.
812  */
813  template <class S>
814  V8_INLINE Global(Isolate* isolate, Local<S> that)
815  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
816  TYPE_CHECK(T, S);
817  }
818  /**
819  * Construct a Global from a PersistentBase.
820  * When the Persistent is non-empty, a new storage cell is created
821  * pointing to the same object, and no flags are set.
822  */
823  template <class S>
824  V8_INLINE Global(Isolate* isolate, const PersistentBase<S>& that)
825  : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) {
826  TYPE_CHECK(T, S);
827  }
828  /**
829  * Move constructor.
830  */
831  V8_INLINE Global(Global&& other) : PersistentBase<T>(other.val_) { // NOLINT
832  other.val_ = nullptr;
833  }
834  V8_INLINE ~Global() { this->Reset(); }
835  /**
836  * Move via assignment.
837  */
838  template <class S>
839  V8_INLINE Global& operator=(Global<S>&& rhs) { // NOLINT
840  TYPE_CHECK(T, S);
841  if (this != &rhs) {
842  this->Reset();
843  this->val_ = rhs.val_;
844  rhs.val_ = nullptr;
845  }
846  return *this;
847  }
848  /**
849  * Pass allows returning uniques from functions, etc.
850  */
851  Global Pass() { return static_cast<Global&&>(*this); } // NOLINT
852 
853  /*
854  * For compatibility with Chromium's base::Bind (base::Passed).
855  */
856  typedef void MoveOnlyTypeForCPP03;
857 
858  Global(const Global&) = delete;
859  void operator=(const Global&) = delete;
860 
861  private:
862  template <class F>
863  friend class ReturnValue;
864  V8_INLINE T* operator*() const { return this->val_; }
865 };
866 
867 
868 // UniquePersistent is an alias for Global for historical reason.
869 template <class T>
870 using UniquePersistent = Global<T>;
871 
872 
873  /**
874  * A stack-allocated class that governs a number of local handles.
875  * After a handle scope has been created, all local handles will be
876  * allocated within that handle scope until either the handle scope is
877  * deleted or another handle scope is created. If there is already a
878  * handle scope and a new one is created, all allocations will take
879  * place in the new handle scope until it is deleted. After that,
880  * new handles will again be allocated in the original handle scope.
881  *
882  * After the handle scope of a local handle has been deleted the
883  * garbage collector will no longer track the object stored in the
884  * handle and may deallocate it. The behavior of accessing a handle
885  * for which the handle scope has been deleted is undefined.
886  */
888  public:
889  explicit HandleScope(Isolate* isolate);
890 
891  ~HandleScope();
892 
893  /**
894  * Counts the number of allocated handles.
895  */
896  static int NumberOfHandles(Isolate* isolate);
897 
899  return reinterpret_cast<Isolate*>(isolate_);
900  }
901 
902  HandleScope(const HandleScope&) = delete;
903  void operator=(const HandleScope&) = delete;
904  void* operator new(size_t size) = delete;
905  void operator delete(void*, size_t) = delete;
906 
907  protected:
909 
910  void Initialize(Isolate* isolate);
911 
912  static internal::Object** CreateHandle(internal::Isolate* isolate,
913  internal::Object* value);
914 
915  private:
916  // Uses heap_object to obtain the current Isolate.
917  static internal::Object** CreateHandle(internal::HeapObject* heap_object,
918  internal::Object* value);
919 
920  internal::Isolate* isolate_;
921  internal::Object** prev_next_;
922  internal::Object** prev_limit_;
923 
924  // Local::New uses CreateHandle with an Isolate* parameter.
925  template<class F> friend class Local;
926 
927  // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with
928  // a HeapObject* in their shortcuts.
929  friend class Object;
930  friend class Context;
931 };
932 
933 
934 /**
935  * A HandleScope which first allocates a handle in the current scope
936  * which will be later filled with the escape value.
937  */
939  public:
940  explicit EscapableHandleScope(Isolate* isolate);
942 
943  /**
944  * Pushes the value into the previous scope and returns a handle to it.
945  * Cannot be called twice.
946  */
947  template <class T>
948  V8_INLINE Local<T> Escape(Local<T> value) {
949  internal::Object** slot =
950  Escape(reinterpret_cast<internal::Object**>(*value));
951  return Local<T>(reinterpret_cast<T*>(slot));
952  }
953 
955  void operator=(const EscapableHandleScope&) = delete;
956  void* operator new(size_t size) = delete;
957  void operator delete(void*, size_t) = delete;
958 
959  private:
960  internal::Object** Escape(internal::Object** escape_value);
961  internal::Object** escape_slot_;
962 };
963 
965  public:
966  SealHandleScope(Isolate* isolate);
967  ~SealHandleScope();
968 
969  SealHandleScope(const SealHandleScope&) = delete;
970  void operator=(const SealHandleScope&) = delete;
971  void* operator new(size_t size) = delete;
972  void operator delete(void*, size_t) = delete;
973 
974  private:
975  internal::Isolate* const isolate_;
976  internal::Object** prev_limit_;
977  int prev_sealed_level_;
978 };
979 
980 
981 // --- Special objects ---
982 
983 
984 /**
985  * The superclass of values and API object templates.
986  */
988  private:
989  Data();
990 };
991 
992 
993 /**
994  * The optional attributes of ScriptOrigin.
995  */
997  public:
998  V8_INLINE ScriptOriginOptions(bool is_embedder_debug_script = false,
999  bool is_shared_cross_origin = false,
1000  bool is_opaque = false)
1001  : flags_((is_embedder_debug_script ? kIsEmbedderDebugScript : 0) |
1002  (is_shared_cross_origin ? kIsSharedCrossOrigin : 0) |
1003  (is_opaque ? kIsOpaque : 0)) {}
1005  : flags_(flags &
1006  (kIsEmbedderDebugScript | kIsSharedCrossOrigin | kIsOpaque)) {}
1007  bool IsEmbedderDebugScript() const {
1008  return (flags_ & kIsEmbedderDebugScript) != 0;
1009  }
1010  bool IsSharedCrossOrigin() const {
1011  return (flags_ & kIsSharedCrossOrigin) != 0;
1012  }
1013  bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; }
1014  int Flags() const { return flags_; }
1015 
1016  private:
1017  enum {
1018  kIsEmbedderDebugScript = 1,
1019  kIsSharedCrossOrigin = 1 << 1,
1020  kIsOpaque = 1 << 2
1021  };
1022  const int flags_;
1023 };
1024 
1025 /**
1026  * The origin, within a file, of a script.
1027  */
1029  public:
1031  Local<Value> resource_name,
1032  Local<Integer> resource_line_offset = Local<Integer>(),
1033  Local<Integer> resource_column_offset = Local<Integer>(),
1034  Local<Boolean> resource_is_shared_cross_origin = Local<Boolean>(),
1035  Local<Integer> script_id = Local<Integer>(),
1036  Local<Boolean> resource_is_embedder_debug_script = Local<Boolean>(),
1037  Local<Value> source_map_url = Local<Value>(),
1038  Local<Boolean> resource_is_opaque = Local<Boolean>());
1039  V8_INLINE Local<Value> ResourceName() const;
1040  V8_INLINE Local<Integer> ResourceLineOffset() const;
1041  V8_INLINE Local<Integer> ResourceColumnOffset() const;
1042  /**
1043  * Returns true for embedder's debugger scripts
1044  */
1045  V8_INLINE Local<Integer> ScriptID() const;
1046  V8_INLINE Local<Value> SourceMapUrl() const;
1047  V8_INLINE ScriptOriginOptions Options() const { return options_; }
1048 
1049  private:
1050  Local<Value> resource_name_;
1051  Local<Integer> resource_line_offset_;
1052  Local<Integer> resource_column_offset_;
1053  ScriptOriginOptions options_;
1054  Local<Integer> script_id_;
1055  Local<Value> source_map_url_;
1056 };
1057 
1058 
1059 /**
1060  * A compiled JavaScript script, not yet tied to a Context.
1061  */
1063  public:
1064  /**
1065  * Binds the script to the currently entered context.
1066  */
1067  Local<Script> BindToCurrentContext();
1068 
1069  int GetId();
1070  Local<Value> GetScriptName();
1071 
1072  /**
1073  * Data read from magic sourceURL comments.
1074  */
1075  Local<Value> GetSourceURL();
1076  /**
1077  * Data read from magic sourceMappingURL comments.
1078  */
1079  Local<Value> GetSourceMappingURL();
1080 
1081  /**
1082  * Returns zero based line number of the code_pos location in the script.
1083  * -1 will be returned if no information available.
1084  */
1085  int GetLineNumber(int code_pos);
1086 
1087  static const int kNoScriptId = 0;
1088 };
1089 
1090 /**
1091  * This is an unfinished experimental feature, and is only exposed
1092  * here for internal testing purposes. DO NOT USE.
1093  *
1094  * A compiled JavaScript module.
1095  */
1097  public:
1098  /**
1099  * Returns the number of modules requested by this module.
1100  */
1101  int GetModuleRequestsLength() const;
1102 
1103  /**
1104  * Returns the ith module specifier in this module.
1105  * i must be < GetModuleRequestsLength() and >= 0.
1106  */
1107  Local<String> GetModuleRequest(int i) const;
1108 
1109  void SetEmbedderData(Local<Value> data);
1110  Local<Value> GetEmbedderData() const;
1111 
1112  typedef MaybeLocal<Module> (*ResolveCallback)(Local<Context> context,
1113  Local<String> specifier,
1114  Local<Module> referrer,
1115  Local<Value> data);
1116 
1117  /**
1118  * ModuleDeclarationInstantiation
1119  *
1120  * Returns false if an exception occurred during instantiation.
1121  */
1123  Local<Context> context, ResolveCallback callback,
1124  Local<Value> callback_data = Local<Value>());
1125 
1126  /**
1127  * ModuleEvaluation
1128  */
1129  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Evaluate(Local<Context> context);
1130 };
1131 
1132 /**
1133  * A compiled JavaScript script, tied to a Context which was active when the
1134  * script was compiled.
1135  */
1137  public:
1138  /**
1139  * A shorthand for ScriptCompiler::Compile().
1140  */
1141  static V8_DEPRECATE_SOON(
1142  "Use maybe version",
1143  Local<Script> Compile(Local<String> source,
1144  ScriptOrigin* origin = nullptr));
1145  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1146  Local<Context> context, Local<String> source,
1147  ScriptOrigin* origin = nullptr);
1148 
1149  static Local<Script> V8_DEPRECATE_SOON("Use maybe version",
1150  Compile(Local<String> source,
1151  Local<String> file_name));
1152 
1153  /**
1154  * Runs the script returning the resulting value. It will be run in the
1155  * context in which it was created (ScriptCompiler::CompileBound or
1156  * UnboundScript::BindToCurrentContext()).
1157  */
1158  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Run());
1159  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Run(Local<Context> context);
1160 
1161  /**
1162  * Returns the corresponding context-unbound script.
1163  */
1165 };
1166 
1167 
1168 /**
1169  * For compiling scripts.
1170  */
1172  public:
1173  /**
1174  * Compilation data that the embedder can cache and pass back to speed up
1175  * future compilations. The data is produced if the CompilerOptions passed to
1176  * the compilation functions in ScriptCompiler contains produce_data_to_cache
1177  * = true. The data to cache can then can be retrieved from
1178  * UnboundScript.
1179  */
1184  };
1185 
1187  : data(NULL),
1188  length(0),
1189  rejected(false),
1191 
1192  // If buffer_policy is BufferNotOwned, the caller keeps the ownership of
1193  // data and guarantees that it stays alive until the CachedData object is
1194  // destroyed. If the policy is BufferOwned, the given data will be deleted
1195  // (with delete[]) when the CachedData object is destroyed.
1196  CachedData(const uint8_t* data, int length,
1197  BufferPolicy buffer_policy = BufferNotOwned);
1198  ~CachedData();
1199  // TODO(marja): Async compilation; add constructors which take a callback
1200  // which will be called when V8 no longer needs the data.
1201  const uint8_t* data;
1202  int length;
1203  bool rejected;
1205 
1206  // Prevent copying.
1207  CachedData(const CachedData&) = delete;
1208  CachedData& operator=(const CachedData&) = delete;
1209  };
1210 
1211  /**
1212  * Source code which can be then compiled to a UnboundScript or Script.
1213  */
1214  class Source {
1215  public:
1216  // Source takes ownership of CachedData.
1217  V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
1218  CachedData* cached_data = NULL);
1219  V8_INLINE Source(Local<String> source_string,
1220  CachedData* cached_data = NULL);
1221  V8_INLINE ~Source();
1222 
1223  // Ownership of the CachedData or its buffers is *not* transferred to the
1224  // caller. The CachedData object is alive as long as the Source object is
1225  // alive.
1226  V8_INLINE const CachedData* GetCachedData() const;
1227 
1228  // Prevent copying.
1229  Source(const Source&) = delete;
1230  Source& operator=(const Source&) = delete;
1231 
1232  private:
1233  friend class ScriptCompiler;
1234 
1235  Local<String> source_string;
1236 
1237  // Origin information
1238  Local<Value> resource_name;
1239  Local<Integer> resource_line_offset;
1240  Local<Integer> resource_column_offset;
1241  ScriptOriginOptions resource_options;
1242  Local<Value> source_map_url;
1243 
1244  // Cached data from previous compilation (if a kConsume*Cache flag is
1245  // set), or hold newly generated cache data (kProduce*Cache flags) are
1246  // set when calling a compile method.
1247  CachedData* cached_data;
1248  };
1249 
1250  /**
1251  * For streaming incomplete script data to V8. The embedder should implement a
1252  * subclass of this class.
1253  */
1255  public:
1256  virtual ~ExternalSourceStream() {}
1257 
1258  /**
1259  * V8 calls this to request the next chunk of data from the embedder. This
1260  * function will be called on a background thread, so it's OK to block and
1261  * wait for the data, if the embedder doesn't have data yet. Returns the
1262  * length of the data returned. When the data ends, GetMoreData should
1263  * return 0. Caller takes ownership of the data.
1264  *
1265  * When streaming UTF-8 data, V8 handles multi-byte characters split between
1266  * two data chunks, but doesn't handle multi-byte characters split between
1267  * more than two data chunks. The embedder can avoid this problem by always
1268  * returning at least 2 bytes of data.
1269  *
1270  * If the embedder wants to cancel the streaming, they should make the next
1271  * GetMoreData call return 0. V8 will interpret it as end of data (and most
1272  * probably, parsing will fail). The streaming task will return as soon as
1273  * V8 has parsed the data it received so far.
1274  */
1275  virtual size_t GetMoreData(const uint8_t** src) = 0;
1276 
1277  /**
1278  * V8 calls this method to set a 'bookmark' at the current position in
1279  * the source stream, for the purpose of (maybe) later calling
1280  * ResetToBookmark. If ResetToBookmark is called later, then subsequent
1281  * calls to GetMoreData should return the same data as they did when
1282  * SetBookmark was called earlier.
1283  *
1284  * The embedder may return 'false' to indicate it cannot provide this
1285  * functionality.
1286  */
1287  virtual bool SetBookmark();
1288 
1289  /**
1290  * V8 calls this to return to a previously set bookmark.
1291  */
1292  virtual void ResetToBookmark();
1293  };
1294 
1295 
1296  /**
1297  * Source code which can be streamed into V8 in pieces. It will be parsed
1298  * while streaming. It can be compiled after the streaming is complete.
1299  * StreamedSource must be kept alive while the streaming task is ran (see
1300  * ScriptStreamingTask below).
1301  */
1303  public:
1305 
1306  StreamedSource(ExternalSourceStream* source_stream, Encoding encoding);
1307  ~StreamedSource();
1308 
1309  // Ownership of the CachedData or its buffers is *not* transferred to the
1310  // caller. The CachedData object is alive as long as the StreamedSource
1311  // object is alive.
1312  const CachedData* GetCachedData() const;
1313 
1314  internal::StreamedSource* impl() const { return impl_; }
1315 
1316  // Prevent copying.
1317  StreamedSource(const StreamedSource&) = delete;
1318  StreamedSource& operator=(const StreamedSource&) = delete;
1319 
1320  private:
1321  internal::StreamedSource* impl_;
1322  };
1323 
1324  /**
1325  * A streaming task which the embedder must run on a background thread to
1326  * stream scripts into V8. Returned by ScriptCompiler::StartStreamingScript.
1327  */
1329  public:
1330  virtual ~ScriptStreamingTask() {}
1331  virtual void Run() = 0;
1332  };
1333 
1340  };
1341 
1342  /**
1343  * Compiles the specified script (context-independent).
1344  * Cached data as part of the source object can be optionally produced to be
1345  * consumed later to speed up compilation of identical source scripts.
1346  *
1347  * Note that when producing cached data, the source must point to NULL for
1348  * cached data. When consuming cached data, the cached data must have been
1349  * produced by the same version of V8.
1350  *
1351  * \param source Script source code.
1352  * \return Compiled script object (context independent; for running it must be
1353  * bound to a context).
1354  */
1355  static V8_DEPRECATED("Use maybe version",
1356  Local<UnboundScript> CompileUnbound(
1357  Isolate* isolate, Source* source,
1358  CompileOptions options = kNoCompileOptions));
1360  Isolate* isolate, Source* source,
1361  CompileOptions options = kNoCompileOptions);
1362 
1363  /**
1364  * Compiles the specified script (bound to current context).
1365  *
1366  * \param source Script source code.
1367  * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
1368  * using pre_data speeds compilation if it's done multiple times.
1369  * Owned by caller, no references are kept when this function returns.
1370  * \return Compiled script object, bound to the context that was active
1371  * when this function was called. When run it will always use this
1372  * context.
1373  */
1374  static V8_DEPRECATED(
1375  "Use maybe version",
1376  Local<Script> Compile(Isolate* isolate, Source* source,
1377  CompileOptions options = kNoCompileOptions));
1378  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1379  Local<Context> context, Source* source,
1380  CompileOptions options = kNoCompileOptions);
1381 
1382  /**
1383  * Returns a task which streams script data into V8, or NULL if the script
1384  * cannot be streamed. The user is responsible for running the task on a
1385  * background thread and deleting it. When ran, the task starts parsing the
1386  * script, and it will request data from the StreamedSource as needed. When
1387  * ScriptStreamingTask::Run exits, all data has been streamed and the script
1388  * can be compiled (see Compile below).
1389  *
1390  * This API allows to start the streaming with as little data as possible, and
1391  * the remaining data (for example, the ScriptOrigin) is passed to Compile.
1392  */
1394  Isolate* isolate, StreamedSource* source,
1395  CompileOptions options = kNoCompileOptions);
1396 
1397  /**
1398  * Compiles a streamed script (bound to current context).
1399  *
1400  * This can only be called after the streaming has finished
1401  * (ScriptStreamingTask has been run). V8 doesn't construct the source string
1402  * during streaming, so the embedder needs to pass the full source here.
1403  */
1404  static V8_DEPRECATED("Use maybe version",
1405  Local<Script> Compile(Isolate* isolate,
1406  StreamedSource* source,
1407  Local<String> full_source_string,
1408  const ScriptOrigin& origin));
1409  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1410  Local<Context> context, StreamedSource* source,
1411  Local<String> full_source_string, const ScriptOrigin& origin);
1412 
1413  /**
1414  * Return a version tag for CachedData for the current V8 version & flags.
1415  *
1416  * This value is meant only for determining whether a previously generated
1417  * CachedData instance is still valid; the tag has no other meaing.
1418  *
1419  * Background: The data carried by CachedData may depend on the exact
1420  * V8 version number or currently compiler flags. This means when
1421  * persisting CachedData, the embedder must take care to not pass in
1422  * data from another V8 version, or the same version with different
1423  * features enabled.
1424  *
1425  * The easiest way to do so is to clear the embedder's cache on any
1426  * such change.
1427  *
1428  * Alternatively, this tag can be stored alongside the cached data and
1429  * compared when it is being used.
1430  */
1431  static uint32_t CachedDataVersionTag();
1432 
1433  /**
1434  * This is an unfinished experimental feature, and is only exposed
1435  * here for internal testing purposes. DO NOT USE.
1436  *
1437  * Compile an ES module, returning a Module that encapsulates
1438  * the compiled code.
1439  *
1440  * Corresponds to the ParseModule abstract operation in the
1441  * ECMAScript specification.
1442  */
1443  static V8_WARN_UNUSED_RESULT MaybeLocal<Module> CompileModule(
1444  Isolate* isolate, Source* source);
1445 
1446  /**
1447  * Compile a function for a given context. This is equivalent to running
1448  *
1449  * with (obj) {
1450  * return function(args) { ... }
1451  * }
1452  *
1453  * It is possible to specify multiple context extensions (obj in the above
1454  * example).
1455  */
1456  static V8_DEPRECATE_SOON("Use maybe version",
1457  Local<Function> CompileFunctionInContext(
1458  Isolate* isolate, Source* source,
1459  Local<Context> context, size_t arguments_count,
1460  Local<String> arguments[],
1461  size_t context_extension_count,
1462  Local<Object> context_extensions[]));
1464  Local<Context> context, Source* source, size_t arguments_count,
1465  Local<String> arguments[], size_t context_extension_count,
1466  Local<Object> context_extensions[]);
1467 
1468  private:
1469  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundInternal(
1470  Isolate* isolate, Source* source, CompileOptions options, bool is_module);
1471 };
1472 
1473 
1474 /**
1475  * An error message.
1476  */
1478  public:
1479  Local<String> Get() const;
1480 
1481  V8_DEPRECATE_SOON("Use maybe version", Local<String> GetSourceLine() const);
1483  Local<Context> context) const;
1484 
1485  /**
1486  * Returns the origin for the script from where the function causing the
1487  * error originates.
1488  */
1489  ScriptOrigin GetScriptOrigin() const;
1490 
1491  /**
1492  * Returns the resource name for the script from where the function causing
1493  * the error originates.
1494  */
1495  Local<Value> GetScriptResourceName() const;
1496 
1497  /**
1498  * Exception stack trace. By default stack traces are not captured for
1499  * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows
1500  * to change this option.
1501  */
1502  Local<StackTrace> GetStackTrace() const;
1503 
1504  /**
1505  * Returns the number, 1-based, of the line where the error occurred.
1506  */
1507  V8_DEPRECATE_SOON("Use maybe version", int GetLineNumber() const);
1508  V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const;
1509 
1510  /**
1511  * Returns the index within the script of the first character where
1512  * the error occurred.
1513  */
1514  int GetStartPosition() const;
1515 
1516  /**
1517  * Returns the index within the script of the last character where
1518  * the error occurred.
1519  */
1520  int GetEndPosition() const;
1521 
1522  /**
1523  * Returns the index within the line of the first character where
1524  * the error occurred.
1525  */
1526  V8_DEPRECATE_SOON("Use maybe version", int GetStartColumn() const);
1527  V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const;
1528 
1529  /**
1530  * Returns the index within the line of the last character where
1531  * the error occurred.
1532  */
1533  V8_DEPRECATED("Use maybe version", int GetEndColumn() const);
1534  V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const;
1535 
1536  /**
1537  * Passes on the value set by the embedder when it fed the script from which
1538  * this Message was generated to V8.
1539  */
1540  bool IsSharedCrossOrigin() const;
1541  bool IsOpaque() const;
1542 
1543  // TODO(1245381): Print to a string instead of on a FILE.
1544  static void PrintCurrentStackTrace(Isolate* isolate, FILE* out);
1545 
1546  static const int kNoLineNumberInfo = 0;
1547  static const int kNoColumnInfo = 0;
1548  static const int kNoScriptIdInfo = 0;
1549 };
1550 
1551 
1552 /**
1553  * Representation of a JavaScript stack trace. The information collected is a
1554  * snapshot of the execution stack and the information remains valid after
1555  * execution continues.
1556  */
1558  public:
1559  /**
1560  * Flags that determine what information is placed captured for each
1561  * StackFrame when grabbing the current stack trace.
1562  */
1566  kScriptName = 1 << 2,
1567  kFunctionName = 1 << 3,
1568  kIsEval = 1 << 4,
1569  kIsConstructor = 1 << 5,
1571  kScriptId = 1 << 7,
1575  };
1576 
1577  /**
1578  * Returns a StackFrame at a particular index.
1579  */
1580  Local<StackFrame> GetFrame(uint32_t index) const;
1581 
1582  /**
1583  * Returns the number of StackFrames.
1584  */
1585  int GetFrameCount() const;
1586 
1587  /**
1588  * Returns StackTrace as a v8::Array that contains StackFrame objects.
1589  */
1590  Local<Array> AsArray();
1591 
1592  /**
1593  * Grab a snapshot of the current JavaScript execution stack.
1594  *
1595  * \param frame_limit The maximum number of stack frames we want to capture.
1596  * \param options Enumerates the set of things we will capture for each
1597  * StackFrame.
1598  */
1599  static Local<StackTrace> CurrentStackTrace(
1600  Isolate* isolate,
1601  int frame_limit,
1602  StackTraceOptions options = kOverview);
1603 };
1604 
1605 
1606 /**
1607  * A single JavaScript stack frame.
1608  */
1610  public:
1611  /**
1612  * Returns the number, 1-based, of the line for the associate function call.
1613  * This method will return Message::kNoLineNumberInfo if it is unable to
1614  * retrieve the line number, or if kLineNumber was not passed as an option
1615  * when capturing the StackTrace.
1616  */
1617  int GetLineNumber() const;
1618 
1619  /**
1620  * Returns the 1-based column offset on the line for the associated function
1621  * call.
1622  * This method will return Message::kNoColumnInfo if it is unable to retrieve
1623  * the column number, or if kColumnOffset was not passed as an option when
1624  * capturing the StackTrace.
1625  */
1626  int GetColumn() const;
1627 
1628  /**
1629  * Returns the id of the script for the function for this StackFrame.
1630  * This method will return Message::kNoScriptIdInfo if it is unable to
1631  * retrieve the script id, or if kScriptId was not passed as an option when
1632  * capturing the StackTrace.
1633  */
1634  int GetScriptId() const;
1635 
1636  /**
1637  * Returns the name of the resource that contains the script for the
1638  * function for this StackFrame.
1639  */
1640  Local<String> GetScriptName() const;
1641 
1642  /**
1643  * Returns the name of the resource that contains the script for the
1644  * function for this StackFrame or sourceURL value if the script name
1645  * is undefined and its source ends with //# sourceURL=... string or
1646  * deprecated //@ sourceURL=... string.
1647  */
1648  Local<String> GetScriptNameOrSourceURL() const;
1649 
1650  /**
1651  * Returns the name of the function associated with this stack frame.
1652  */
1653  Local<String> GetFunctionName() const;
1654 
1655  /**
1656  * Returns whether or not the associated function is compiled via a call to
1657  * eval().
1658  */
1659  bool IsEval() const;
1660 
1661  /**
1662  * Returns whether or not the associated function is called as a
1663  * constructor via "new".
1664  */
1665  bool IsConstructor() const;
1666 };
1667 
1668 
1669 // A StateTag represents a possible state of the VM.
1671 
1672 // A RegisterState represents the current state of registers used
1673 // by the sampling profiler API.
1676  void* pc; // Instruction pointer.
1677  void* sp; // Stack pointer.
1678  void* fp; // Frame pointer.
1679 };
1680 
1681 // The output structure filled up by GetStackSample API function.
1682 struct SampleInfo {
1683  size_t frames_count; // Number of frames collected.
1684  StateTag vm_state; // Current VM state.
1685  void* external_callback_entry; // External callback address if VM is
1686  // executing an external callback.
1687 };
1688 
1689 /**
1690  * A JSON Parser and Stringifier.
1691  */
1693  public:
1694  /**
1695  * Tries to parse the string |json_string| and returns it as value if
1696  * successful.
1697  *
1698  * \param json_string The string to parse.
1699  * \return The corresponding value if successfully parsed.
1700  */
1701  static V8_DEPRECATED("Use the maybe version taking context",
1702  Local<Value> Parse(Local<String> json_string));
1703  static V8_DEPRECATE_SOON("Use the maybe version taking context",
1704  MaybeLocal<Value> Parse(Isolate* isolate,
1705  Local<String> json_string));
1706  static V8_WARN_UNUSED_RESULT MaybeLocal<Value> Parse(
1707  Local<Context> context, Local<String> json_string);
1708 
1709  /**
1710  * Tries to stringify the JSON-serializable object |json_object| and returns
1711  * it as string if successful.
1712  *
1713  * \param json_object The JSON-serializable object to stringify.
1714  * \return The corresponding string if successfully stringified.
1715  */
1716  static V8_WARN_UNUSED_RESULT MaybeLocal<String> Stringify(
1717  Local<Context> context, Local<Object> json_object,
1718  Local<String> gap = Local<String>());
1719 };
1720 
1721 /**
1722  * Value serialization compatible with the HTML structured clone algorithm.
1723  * The format is backward-compatible (i.e. safe to store to disk).
1724  *
1725  * WARNING: This API is under development, and changes (including incompatible
1726  * changes to the API or wire format) may occur without notice until this
1727  * warning is removed.
1728  */
1730  public:
1732  public:
1733  virtual ~Delegate() {}
1734 
1735  /*
1736  * Handles the case where a DataCloneError would be thrown in the structured
1737  * clone spec. Other V8 embedders may throw some other appropriate exception
1738  * type.
1739  */
1740  virtual void ThrowDataCloneError(Local<String> message) = 0;
1741 
1742  /*
1743  * The embedder overrides this method to write some kind of host object, if
1744  * possible. If not, a suitable exception should be thrown and
1745  * Nothing<bool>() returned.
1746  */
1747  virtual Maybe<bool> WriteHostObject(Isolate* isolate, Local<Object> object);
1748  };
1749 
1750  explicit ValueSerializer(Isolate* isolate);
1751  ValueSerializer(Isolate* isolate, Delegate* delegate);
1752  ~ValueSerializer();
1753 
1754  /*
1755  * Writes out a header, which includes the format version.
1756  */
1757  void WriteHeader();
1758 
1759  /*
1760  * Serializes a JavaScript value into the buffer.
1761  */
1762  V8_WARN_UNUSED_RESULT Maybe<bool> WriteValue(Local<Context> context,
1763  Local<Value> value);
1764 
1765  /*
1766  * Returns the stored data. This serializer should not be used once the buffer
1767  * is released. The contents are undefined if a previous write has failed.
1768  */
1769  std::vector<uint8_t> ReleaseBuffer();
1770 
1771  /*
1772  * Marks an ArrayBuffer as havings its contents transferred out of band.
1773  * Pass the corresponding JSArrayBuffer in the deserializing context to
1774  * ValueDeserializer::TransferArrayBuffer.
1775  */
1776  void TransferArrayBuffer(uint32_t transfer_id,
1777  Local<ArrayBuffer> array_buffer);
1778 
1779  /*
1780  * Similar to TransferArrayBuffer, but for SharedArrayBuffer.
1781  */
1782  void TransferSharedArrayBuffer(uint32_t transfer_id,
1783  Local<SharedArrayBuffer> shared_array_buffer);
1784 
1785  /*
1786  * Write raw data in various common formats to the buffer.
1787  * Note that integer types are written in base-128 varint format, not with a
1788  * binary copy. For use during an override of Delegate::WriteHostObject.
1789  */
1790  void WriteUint32(uint32_t value);
1791  void WriteUint64(uint64_t value);
1792  void WriteDouble(double value);
1793  void WriteRawBytes(const void* source, size_t length);
1794 
1795  private:
1796  ValueSerializer(const ValueSerializer&) = delete;
1797  void operator=(const ValueSerializer&) = delete;
1798 
1799  struct PrivateData;
1800  PrivateData* private_;
1801 };
1802 
1803 /**
1804  * Deserializes values from data written with ValueSerializer, or a compatible
1805  * implementation.
1806  *
1807  * WARNING: This API is under development, and changes (including incompatible
1808  * changes to the API or wire format) may occur without notice until this
1809  * warning is removed.
1810  */
1812  public:
1814  public:
1815  virtual ~Delegate() {}
1816 
1817  /*
1818  * The embedder overrides this method to read some kind of host object, if
1819  * possible. If not, a suitable exception should be thrown and
1820  * MaybeLocal<Object>() returned.
1821  */
1822  virtual MaybeLocal<Object> ReadHostObject(Isolate* isolate);
1823  };
1824 
1825  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size);
1826  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size,
1827  Delegate* delegate);
1828  ~ValueDeserializer();
1829 
1830  /*
1831  * Reads and validates a header (including the format version).
1832  * May, for example, reject an invalid or unsupported wire format.
1833  */
1834  V8_WARN_UNUSED_RESULT Maybe<bool> ReadHeader(Local<Context> context);
1835  V8_DEPRECATE_SOON("Use Local<Context> version", Maybe<bool> ReadHeader());
1836 
1837  /*
1838  * Deserializes a JavaScript value from the buffer.
1839  */
1840  V8_WARN_UNUSED_RESULT MaybeLocal<Value> ReadValue(Local<Context> context);
1841 
1842  /*
1843  * Accepts the array buffer corresponding to the one passed previously to
1844  * ValueSerializer::TransferArrayBuffer.
1845  */
1846  void TransferArrayBuffer(uint32_t transfer_id,
1847  Local<ArrayBuffer> array_buffer);
1848 
1849  /*
1850  * Similar to TransferArrayBuffer, but for SharedArrayBuffer.
1851  * transfer_id exists in the same namespace as unshared ArrayBuffer objects.
1852  */
1853  void TransferSharedArrayBuffer(uint32_t transfer_id,
1854  Local<SharedArrayBuffer> shared_array_buffer);
1855 
1856  /*
1857  * Must be called before ReadHeader to enable support for reading the legacy
1858  * wire format (i.e., which predates this being shipped).
1859  *
1860  * Don't use this unless you need to read data written by previous versions of
1861  * blink::ScriptValueSerializer.
1862  */
1863  void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format);
1864 
1865  /*
1866  * Reads the underlying wire format version. Likely mostly to be useful to
1867  * legacy code reading old wire format versions. Must be called after
1868  * ReadHeader.
1869  */
1870  uint32_t GetWireFormatVersion() const;
1871 
1872  /*
1873  * Reads raw data in various common formats to the buffer.
1874  * Note that integer types are read in base-128 varint format, not with a
1875  * binary copy. For use during an override of Delegate::ReadHostObject.
1876  */
1877  V8_WARN_UNUSED_RESULT bool ReadUint32(uint32_t* value);
1878  V8_WARN_UNUSED_RESULT bool ReadUint64(uint64_t* value);
1879  V8_WARN_UNUSED_RESULT bool ReadDouble(double* value);
1880  V8_WARN_UNUSED_RESULT bool ReadRawBytes(size_t length, const void** data);
1881 
1882  private:
1883  ValueDeserializer(const ValueDeserializer&) = delete;
1884  void operator=(const ValueDeserializer&) = delete;
1885 
1886  struct PrivateData;
1887  PrivateData* private_;
1888 };
1889 
1890 /**
1891  * A map whose keys are referenced weakly. It is similar to JavaScript WeakMap
1892  * but can be created without entering a v8::Context and hence shouldn't
1893  * escape to JavaScript.
1894  */
1895 class V8_EXPORT NativeWeakMap : public Data {
1896  public:
1897  static Local<NativeWeakMap> New(Isolate* isolate);
1898  void Set(Local<Value> key, Local<Value> value);
1899  Local<Value> Get(Local<Value> key);
1900  bool Has(Local<Value> key);
1901  bool Delete(Local<Value> key);
1902 };
1903 
1904 
1905 // --- Value ---
1906 
1907 
1908 /**
1909  * The superclass of all JavaScript values and objects.
1910  */
1911 class V8_EXPORT Value : public Data {
1912  public:
1913  /**
1914  * Returns true if this value is the undefined value. See ECMA-262
1915  * 4.3.10.
1916  */
1917  V8_INLINE bool IsUndefined() const;
1918 
1919  /**
1920  * Returns true if this value is the null value. See ECMA-262
1921  * 4.3.11.
1922  */
1923  V8_INLINE bool IsNull() const;
1924 
1925  /**
1926  * Returns true if this value is true.
1927  */
1928  bool IsTrue() const;
1929 
1930  /**
1931  * Returns true if this value is false.
1932  */
1933  bool IsFalse() const;
1934 
1935  /**
1936  * Returns true if this value is a symbol or a string.
1937  * This is an experimental feature.
1938  */
1939  bool IsName() const;
1940 
1941  /**
1942  * Returns true if this value is an instance of the String type.
1943  * See ECMA-262 8.4.
1944  */
1945  V8_INLINE bool IsString() const;
1946 
1947  /**
1948  * Returns true if this value is a symbol.
1949  * This is an experimental feature.
1950  */
1951  bool IsSymbol() const;
1952 
1953  /**
1954  * Returns true if this value is a function.
1955  */
1956  bool IsFunction() const;
1957 
1958  /**
1959  * Returns true if this value is an array. Note that it will return false for
1960  * an Proxy for an array.
1961  */
1962  bool IsArray() const;
1963 
1964  /**
1965  * Returns true if this value is an object.
1966  */
1967  bool IsObject() const;
1968 
1969  /**
1970  * Returns true if this value is boolean.
1971  */
1972  bool IsBoolean() const;
1973 
1974  /**
1975  * Returns true if this value is a number.
1976  */
1977  bool IsNumber() const;
1978 
1979  /**
1980  * Returns true if this value is external.
1981  */
1982  bool IsExternal() const;
1983 
1984  /**
1985  * Returns true if this value is a 32-bit signed integer.
1986  */
1987  bool IsInt32() const;
1988 
1989  /**
1990  * Returns true if this value is a 32-bit unsigned integer.
1991  */
1992  bool IsUint32() const;
1993 
1994  /**
1995  * Returns true if this value is a Date.
1996  */
1997  bool IsDate() const;
1998 
1999  /**
2000  * Returns true if this value is an Arguments object.
2001  */
2002  bool IsArgumentsObject() const;
2003 
2004  /**
2005  * Returns true if this value is a Boolean object.
2006  */
2007  bool IsBooleanObject() const;
2008 
2009  /**
2010  * Returns true if this value is a Number object.
2011  */
2012  bool IsNumberObject() const;
2013 
2014  /**
2015  * Returns true if this value is a String object.
2016  */
2017  bool IsStringObject() const;
2018 
2019  /**
2020  * Returns true if this value is a Symbol object.
2021  * This is an experimental feature.
2022  */
2023  bool IsSymbolObject() const;
2024 
2025  /**
2026  * Returns true if this value is a NativeError.
2027  */
2028  bool IsNativeError() const;
2029 
2030  /**
2031  * Returns true if this value is a RegExp.
2032  */
2033  bool IsRegExp() const;
2034 
2035  /**
2036  * Returns true if this value is an async function.
2037  */
2038  bool IsAsyncFunction() const;
2039 
2040  /**
2041  * Returns true if this value is a Generator function.
2042  * This is an experimental feature.
2043  */
2044  bool IsGeneratorFunction() const;
2045 
2046  /**
2047  * Returns true if this value is a Generator object (iterator).
2048  * This is an experimental feature.
2049  */
2050  bool IsGeneratorObject() const;
2051 
2052  /**
2053  * Returns true if this value is a Promise.
2054  * This is an experimental feature.
2055  */
2056  bool IsPromise() const;
2057 
2058  /**
2059  * Returns true if this value is a Map.
2060  */
2061  bool IsMap() const;
2062 
2063  /**
2064  * Returns true if this value is a Set.
2065  */
2066  bool IsSet() const;
2067 
2068  /**
2069  * Returns true if this value is a Map Iterator.
2070  */
2071  bool IsMapIterator() const;
2072 
2073  /**
2074  * Returns true if this value is a Set Iterator.
2075  */
2076  bool IsSetIterator() const;
2077 
2078  /**
2079  * Returns true if this value is a WeakMap.
2080  */
2081  bool IsWeakMap() const;
2082 
2083  /**
2084  * Returns true if this value is a WeakSet.
2085  */
2086  bool IsWeakSet() const;
2087 
2088  /**
2089  * Returns true if this value is an ArrayBuffer.
2090  * This is an experimental feature.
2091  */
2092  bool IsArrayBuffer() const;
2093 
2094  /**
2095  * Returns true if this value is an ArrayBufferView.
2096  * This is an experimental feature.
2097  */
2098  bool IsArrayBufferView() const;
2099 
2100  /**
2101  * Returns true if this value is one of TypedArrays.
2102  * This is an experimental feature.
2103  */
2104  bool IsTypedArray() const;
2105 
2106  /**
2107  * Returns true if this value is an Uint8Array.
2108  * This is an experimental feature.
2109  */
2110  bool IsUint8Array() const;
2111 
2112  /**
2113  * Returns true if this value is an Uint8ClampedArray.
2114  * This is an experimental feature.
2115  */
2116  bool IsUint8ClampedArray() const;
2117 
2118  /**
2119  * Returns true if this value is an Int8Array.
2120  * This is an experimental feature.
2121  */
2122  bool IsInt8Array() const;
2123 
2124  /**
2125  * Returns true if this value is an Uint16Array.
2126  * This is an experimental feature.
2127  */
2128  bool IsUint16Array() const;
2129 
2130  /**
2131  * Returns true if this value is an Int16Array.
2132  * This is an experimental feature.
2133  */
2134  bool IsInt16Array() const;
2135 
2136  /**
2137  * Returns true if this value is an Uint32Array.
2138  * This is an experimental feature.
2139  */
2140  bool IsUint32Array() const;
2141 
2142  /**
2143  * Returns true if this value is an Int32Array.
2144  * This is an experimental feature.
2145  */
2146  bool IsInt32Array() const;
2147 
2148  /**
2149  * Returns true if this value is a Float32Array.
2150  * This is an experimental feature.
2151  */
2152  bool IsFloat32Array() const;
2153 
2154  /**
2155  * Returns true if this value is a Float64Array.
2156  * This is an experimental feature.
2157  */
2158  bool IsFloat64Array() const;
2159 
2160  /**
2161  * Returns true if this value is a SIMD Float32x4.
2162  * This is an experimental feature.
2163  */
2164  bool IsFloat32x4() const;
2165 
2166  /**
2167  * Returns true if this value is a DataView.
2168  * This is an experimental feature.
2169  */
2170  bool IsDataView() const;
2171 
2172  /**
2173  * Returns true if this value is a SharedArrayBuffer.
2174  * This is an experimental feature.
2175  */
2176  bool IsSharedArrayBuffer() const;
2177 
2178  /**
2179  * Returns true if this value is a JavaScript Proxy.
2180  */
2181  bool IsProxy() const;
2182 
2183  bool IsWebAssemblyCompiledModule() const;
2184 
2186  Local<Context> context) const;
2188  Local<Context> context) const;
2190  Local<Context> context) const;
2192  Local<Context> context) const;
2194  Local<Context> context) const;
2196  Local<Context> context) const;
2198  Local<Context> context) const;
2199  V8_WARN_UNUSED_RESULT MaybeLocal<Int32> ToInt32(Local<Context> context) const;
2200 
2201  V8_DEPRECATE_SOON("Use maybe version",
2202  Local<Boolean> ToBoolean(Isolate* isolate) const);
2203  V8_DEPRECATE_SOON("Use maybe version",
2204  Local<Number> ToNumber(Isolate* isolate) const);
2205  V8_DEPRECATE_SOON("Use maybe version",
2206  Local<String> ToString(Isolate* isolate) const);
2207  V8_DEPRECATED("Use maybe version",
2208  Local<String> ToDetailString(Isolate* isolate) const);
2209  V8_DEPRECATE_SOON("Use maybe version",
2210  Local<Object> ToObject(Isolate* isolate) const);
2211  V8_DEPRECATE_SOON("Use maybe version",
2212  Local<Integer> ToInteger(Isolate* isolate) const);
2213  V8_DEPRECATED("Use maybe version",
2214  Local<Uint32> ToUint32(Isolate* isolate) const);
2215  V8_DEPRECATE_SOON("Use maybe version",
2216  Local<Int32> ToInt32(Isolate* isolate) const);
2217 
2218  inline V8_DEPRECATE_SOON("Use maybe version",
2219  Local<Boolean> ToBoolean() const);
2220  inline V8_DEPRECATED("Use maybe version", Local<Number> ToNumber() const);
2221  inline V8_DEPRECATE_SOON("Use maybe version", Local<String> ToString() const);
2222  inline V8_DEPRECATED("Use maybe version",
2223  Local<String> ToDetailString() const);
2224  inline V8_DEPRECATE_SOON("Use maybe version", Local<Object> ToObject() const);
2225  inline V8_DEPRECATE_SOON("Use maybe version",
2226  Local<Integer> ToInteger() const);
2227  inline V8_DEPRECATED("Use maybe version", Local<Uint32> ToUint32() const);
2228  inline V8_DEPRECATED("Use maybe version", Local<Int32> ToInt32() const);
2229 
2230  /**
2231  * Attempts to convert a string to an array index.
2232  * Returns an empty handle if the conversion fails.
2233  */
2234  V8_DEPRECATED("Use maybe version", Local<Uint32> ToArrayIndex() const);
2236  Local<Context> context) const;
2237 
2238  V8_WARN_UNUSED_RESULT Maybe<bool> BooleanValue(Local<Context> context) const;
2239  V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const;
2240  V8_WARN_UNUSED_RESULT Maybe<int64_t> IntegerValue(
2241  Local<Context> context) const;
2242  V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
2243  Local<Context> context) const;
2244  V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
2245 
2246  V8_DEPRECATE_SOON("Use maybe version", bool BooleanValue() const);
2247  V8_DEPRECATE_SOON("Use maybe version", double NumberValue() const);
2248  V8_DEPRECATE_SOON("Use maybe version", int64_t IntegerValue() const);
2249  V8_DEPRECATE_SOON("Use maybe version", uint32_t Uint32Value() const);
2250  V8_DEPRECATE_SOON("Use maybe version", int32_t Int32Value() const);
2251 
2252  /** JS == */
2253  V8_DEPRECATE_SOON("Use maybe version", bool Equals(Local<Value> that) const);
2254  V8_WARN_UNUSED_RESULT Maybe<bool> Equals(Local<Context> context,
2255  Local<Value> that) const;
2256  bool StrictEquals(Local<Value> that) const;
2257  bool SameValue(Local<Value> that) const;
2258 
2259  template <class T> V8_INLINE static Value* Cast(T* value);
2260 
2261  Local<String> TypeOf(v8::Isolate*);
2262 
2263  private:
2264  V8_INLINE bool QuickIsUndefined() const;
2265  V8_INLINE bool QuickIsNull() const;
2266  V8_INLINE bool QuickIsString() const;
2267  bool FullIsUndefined() const;
2268  bool FullIsNull() const;
2269  bool FullIsString() const;
2270 };
2271 
2272 
2273 /**
2274  * The superclass of primitive values. See ECMA-262 4.3.2.
2275  */
2276 class V8_EXPORT Primitive : public Value { };
2277 
2278 
2279 /**
2280  * A primitive boolean value (ECMA-262, 4.3.14). Either the true
2281  * or false value.
2282  */
2283 class V8_EXPORT Boolean : public Primitive {
2284  public:
2285  bool Value() const;
2286  V8_INLINE static Boolean* Cast(v8::Value* obj);
2287  V8_INLINE static Local<Boolean> New(Isolate* isolate, bool value);
2288 
2289  private:
2290  static void CheckCast(v8::Value* obj);
2291 };
2292 
2293 
2294 /**
2295  * A superclass for symbols and strings.
2296  */
2297 class V8_EXPORT Name : public Primitive {
2298  public:
2299  /**
2300  * Returns the identity hash for this object. The current implementation
2301  * uses an inline property on the object to store the identity hash.
2302  *
2303  * The return value will never be 0. Also, it is not guaranteed to be
2304  * unique.
2305  */
2306  int GetIdentityHash();
2307 
2308  V8_INLINE static Name* Cast(v8::Value* obj);
2309  private:
2310  static void CheckCast(v8::Value* obj);
2311 };
2312 
2313 
2315 
2316 
2317 /**
2318  * A JavaScript string value (ECMA-262, 4.3.17).
2319  */
2320 class V8_EXPORT String : public Name {
2321  public:
2322  static const int kMaxLength = (1 << 28) - 16;
2323 
2324  enum Encoding {
2328  };
2329  /**
2330  * Returns the number of characters in this string.
2331  */
2332  int Length() const;
2333 
2334  /**
2335  * Returns the number of bytes in the UTF-8 encoded
2336  * representation of this string.
2337  */
2338  int Utf8Length() const;
2339 
2340  /**
2341  * Returns whether this string is known to contain only one byte data.
2342  * Does not read the string.
2343  * False negatives are possible.
2344  */
2345  bool IsOneByte() const;
2346 
2347  /**
2348  * Returns whether this string contain only one byte data.
2349  * Will read the entire string in some cases.
2350  */
2351  bool ContainsOnlyOneByte() const;
2352 
2353  /**
2354  * Write the contents of the string to an external buffer.
2355  * If no arguments are given, expects the buffer to be large
2356  * enough to hold the entire string and NULL terminator. Copies
2357  * the contents of the string and the NULL terminator into the
2358  * buffer.
2359  *
2360  * WriteUtf8 will not write partial UTF-8 sequences, preferring to stop
2361  * before the end of the buffer.
2362  *
2363  * Copies up to length characters into the output buffer.
2364  * Only null-terminates if there is enough space in the buffer.
2365  *
2366  * \param buffer The buffer into which the string will be copied.
2367  * \param start The starting position within the string at which
2368  * copying begins.
2369  * \param length The number of characters to copy from the string. For
2370  * WriteUtf8 the number of bytes in the buffer.
2371  * \param nchars_ref The number of characters written, can be NULL.
2372  * \param options Various options that might affect performance of this or
2373  * subsequent operations.
2374  * \return The number of characters copied to the buffer excluding the null
2375  * terminator. For WriteUtf8: The number of bytes copied to the buffer
2376  * including the null terminator (if written).
2377  */
2383  // Used by WriteUtf8 to replace orphan surrogate code units with the
2384  // unicode replacement character. Needs to be set to guarantee valid UTF-8
2385  // output.
2387  };
2388 
2389  // 16-bit character codes.
2390  int Write(uint16_t* buffer,
2391  int start = 0,
2392  int length = -1,
2393  int options = NO_OPTIONS) const;
2394  // One byte characters.
2395  int WriteOneByte(uint8_t* buffer,
2396  int start = 0,
2397  int length = -1,
2398  int options = NO_OPTIONS) const;
2399  // UTF-8 encoded characters.
2400  int WriteUtf8(char* buffer,
2401  int length = -1,
2402  int* nchars_ref = NULL,
2403  int options = NO_OPTIONS) const;
2404 
2405  /**
2406  * A zero length string.
2407  */
2408  V8_INLINE static v8::Local<v8::String> Empty(Isolate* isolate);
2409 
2410  /**
2411  * Returns true if the string is external
2412  */
2413  bool IsExternal() const;
2414 
2415  /**
2416  * Returns true if the string is both external and one-byte.
2417  */
2418  bool IsExternalOneByte() const;
2419 
2421  public:
2423 
2424  virtual bool IsCompressible() const { return false; }
2425 
2426  protected:
2428 
2429  /**
2430  * Internally V8 will call this Dispose method when the external string
2431  * resource is no longer needed. The default implementation will use the
2432  * delete operator. This method can be overridden in subclasses to
2433  * control how allocated external string resources are disposed.
2434  */
2435  virtual void Dispose() { delete this; }
2436 
2437  // Disallow copying and assigning.
2439  void operator=(const ExternalStringResourceBase&) = delete;
2440 
2441  private:
2442  friend class v8::internal::Heap;
2443  };
2444 
2445  /**
2446  * An ExternalStringResource is a wrapper around a two-byte string
2447  * buffer that resides outside V8's heap. Implement an
2448  * ExternalStringResource to manage the life cycle of the underlying
2449  * buffer. Note that the string data must be immutable.
2450  */
2452  : public ExternalStringResourceBase {
2453  public:
2454  /**
2455  * Override the destructor to manage the life cycle of the underlying
2456  * buffer.
2457  */
2459 
2460  /**
2461  * The string data from the underlying buffer.
2462  */
2463  virtual const uint16_t* data() const = 0;
2464 
2465  /**
2466  * The length of the string. That is, the number of two-byte characters.
2467  */
2468  virtual size_t length() const = 0;
2469 
2470  protected:
2472  };
2473 
2474  /**
2475  * An ExternalOneByteStringResource is a wrapper around an one-byte
2476  * string buffer that resides outside V8's heap. Implement an
2477  * ExternalOneByteStringResource to manage the life cycle of the
2478  * underlying buffer. Note that the string data must be immutable
2479  * and that the data must be Latin-1 and not UTF-8, which would require
2480  * special treatment internally in the engine and do not allow efficient
2481  * indexing. Use String::New or convert to 16 bit data for non-Latin1.
2482  */
2483 
2485  : public ExternalStringResourceBase {
2486  public:
2487  /**
2488  * Override the destructor to manage the life cycle of the underlying
2489  * buffer.
2490  */
2492  /** The string data from the underlying buffer.*/
2493  virtual const char* data() const = 0;
2494  /** The number of Latin-1 characters in the string.*/
2495  virtual size_t length() const = 0;
2496  protected:
2498  };
2499 
2500  /**
2501  * If the string is an external string, return the ExternalStringResourceBase
2502  * regardless of the encoding, otherwise return NULL. The encoding of the
2503  * string is returned in encoding_out.
2504  */
2506  Encoding* encoding_out) const;
2507 
2508  /**
2509  * Get the ExternalStringResource for an external string. Returns
2510  * NULL if IsExternal() doesn't return true.
2511  */
2513 
2514  /**
2515  * Get the ExternalOneByteStringResource for an external one-byte string.
2516  * Returns NULL if IsExternalOneByte() doesn't return true.
2517  */
2519 
2520  V8_INLINE static String* Cast(v8::Value* obj);
2521 
2522  // TODO(dcarney): remove with deprecation of New functions.
2524  kNormalString = static_cast<int>(v8::NewStringType::kNormal),
2526  };
2527 
2528  /** Allocates a new string from UTF-8 data.*/
2529  static V8_DEPRECATE_SOON(
2530  "Use maybe version",
2531  Local<String> NewFromUtf8(Isolate* isolate, const char* data,
2533  int length = -1));
2534 
2535  /** Allocates a new string from UTF-8 data. Only returns an empty value when
2536  * length > kMaxLength. **/
2537  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromUtf8(
2538  Isolate* isolate, const char* data, v8::NewStringType type,
2539  int length = -1);
2540 
2541  /** Allocates a new string from Latin-1 data.*/
2542  static V8_DEPRECATED(
2543  "Use maybe version",
2544  Local<String> NewFromOneByte(Isolate* isolate, const uint8_t* data,
2546  int length = -1));
2547 
2548  /** Allocates a new string from Latin-1 data. Only returns an empty value
2549  * when length > kMaxLength. **/
2550  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromOneByte(
2551  Isolate* isolate, const uint8_t* data, v8::NewStringType type,
2552  int length = -1);
2553 
2554  /** Allocates a new string from UTF-16 data.*/
2555  static V8_DEPRECATE_SOON(
2556  "Use maybe version",
2557  Local<String> NewFromTwoByte(Isolate* isolate, const uint16_t* data,
2559  int length = -1));
2560 
2561  /** Allocates a new string from UTF-16 data. Only returns an empty value when
2562  * length > kMaxLength. **/
2563  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromTwoByte(
2564  Isolate* isolate, const uint16_t* data, v8::NewStringType type,
2565  int length = -1);
2566 
2567  /**
2568  * Creates a new string by concatenating the left and the right strings
2569  * passed in as parameters.
2570  */
2571  static Local<String> Concat(Local<String> left, Local<String> right);
2572 
2573  /**
2574  * Creates a new external string using the data defined in the given
2575  * resource. When the external string is no longer live on V8's heap the
2576  * resource will be disposed by calling its Dispose method. The caller of
2577  * this function should not otherwise delete or modify the resource. Neither
2578  * should the underlying buffer be deallocated or modified except through the
2579  * destructor of the external string resource.
2580  */
2581  static V8_DEPRECATED("Use maybe version",
2582  Local<String> NewExternal(
2583  Isolate* isolate, ExternalStringResource* resource));
2584  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalTwoByte(
2585  Isolate* isolate, ExternalStringResource* resource);
2586 
2587  /**
2588  * Associate an external string resource with this string by transforming it
2589  * in place so that existing references to this string in the JavaScript heap
2590  * will use the external string resource. The external string resource's
2591  * character contents need to be equivalent to this string.
2592  * Returns true if the string has been changed to be an external string.
2593  * The string is not modified if the operation fails. See NewExternal for
2594  * information on the lifetime of the resource.
2595  */
2596  bool MakeExternal(ExternalStringResource* resource);
2597 
2598  /**
2599  * Creates a new external string using the one-byte data defined in the given
2600  * resource. When the external string is no longer live on V8's heap the
2601  * resource will be disposed by calling its Dispose method. The caller of
2602  * this function should not otherwise delete or modify the resource. Neither
2603  * should the underlying buffer be deallocated or modified except through the
2604  * destructor of the external string resource.
2605  */
2606  static V8_DEPRECATE_SOON(
2607  "Use maybe version",
2608  Local<String> NewExternal(Isolate* isolate,
2609  ExternalOneByteStringResource* resource));
2610  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalOneByte(
2611  Isolate* isolate, ExternalOneByteStringResource* resource);
2612 
2613  /**
2614  * Associate an external string resource with this string by transforming it
2615  * in place so that existing references to this string in the JavaScript heap
2616  * will use the external string resource. The external string resource's
2617  * character contents need to be equivalent to this string.
2618  * Returns true if the string has been changed to be an external string.
2619  * The string is not modified if the operation fails. See NewExternal for
2620  * information on the lifetime of the resource.
2621  */
2623 
2624  /**
2625  * Returns true if this string can be made external.
2626  */
2627  bool CanMakeExternal();
2628 
2629  /**
2630  * Converts an object to a UTF-8-encoded character array. Useful if
2631  * you want to print the object. If conversion to a string fails
2632  * (e.g. due to an exception in the toString() method of the object)
2633  * then the length() method returns 0 and the * operator returns
2634  * NULL.
2635  */
2637  public:
2638  explicit Utf8Value(Local<v8::Value> obj);
2639  ~Utf8Value();
2640  char* operator*() { return str_; }
2641  const char* operator*() const { return str_; }
2642  int length() const { return length_; }
2643 
2644  // Disallow copying and assigning.
2645  Utf8Value(const Utf8Value&) = delete;
2646  void operator=(const Utf8Value&) = delete;
2647 
2648  private:
2649  char* str_;
2650  int length_;
2651  };
2652 
2653  /**
2654  * Converts an object to a two-byte string.
2655  * If conversion to a string fails (eg. due to an exception in the toString()
2656  * method of the object) then the length() method returns 0 and the * operator
2657  * returns NULL.
2658  */
2660  public:
2661  explicit Value(Local<v8::Value> obj);
2662  ~Value();
2663  uint16_t* operator*() { return str_; }
2664  const uint16_t* operator*() const { return str_; }
2665  int length() const { return length_; }
2666 
2667  // Disallow copying and assigning.
2668  Value(const Value&) = delete;
2669  void operator=(const Value&) = delete;
2670 
2671  private:
2672  uint16_t* str_;
2673  int length_;
2674  };
2675 
2676  private:
2677  void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
2678  Encoding encoding) const;
2679  void VerifyExternalStringResource(ExternalStringResource* val) const;
2680  static void CheckCast(v8::Value* obj);
2681 };
2682 
2683 
2684 /**
2685  * A JavaScript symbol (ECMA-262 edition 6)
2686  *
2687  * This is an experimental feature. Use at your own risk.
2688  */
2689 class V8_EXPORT Symbol : public Name {
2690  public:
2691  // Returns the print name string of the symbol, or undefined if none.
2692  Local<Value> Name() const;
2693 
2694  // Create a symbol. If name is not empty, it will be used as the description.
2695  static Local<Symbol> New(Isolate* isolate,
2696  Local<String> name = Local<String>());
2697 
2698  // Access global symbol registry.
2699  // Note that symbols created this way are never collected, so
2700  // they should only be used for statically fixed properties.
2701  // Also, there is only one global name space for the names used as keys.
2702  // To minimize the potential for clashes, use qualified names as keys.
2703  static Local<Symbol> For(Isolate *isolate, Local<String> name);
2704 
2705  // Retrieve a global symbol. Similar to |For|, but using a separate
2706  // registry that is not accessible by (and cannot clash with) JavaScript code.
2707  static Local<Symbol> ForApi(Isolate *isolate, Local<String> name);
2708 
2709  // Well-known symbols
2710  static Local<Symbol> GetIterator(Isolate* isolate);
2711  static Local<Symbol> GetUnscopables(Isolate* isolate);
2712  static Local<Symbol> GetToStringTag(Isolate* isolate);
2713  static Local<Symbol> GetIsConcatSpreadable(Isolate* isolate);
2714 
2715  V8_INLINE static Symbol* Cast(v8::Value* obj);
2716 
2717  private:
2718  Symbol();
2719  static void CheckCast(v8::Value* obj);
2720 };
2721 
2722 
2723 /**
2724  * A private symbol
2725  *
2726  * This is an experimental feature. Use at your own risk.
2727  */
2728 class V8_EXPORT Private : public Data {
2729  public:
2730  // Returns the print name string of the private symbol, or undefined if none.
2731  Local<Value> Name() const;
2732 
2733  // Create a private symbol. If name is not empty, it will be the description.
2734  static Local<Private> New(Isolate* isolate,
2735  Local<String> name = Local<String>());
2736 
2737  // Retrieve a global private symbol. If a symbol with this name has not
2738  // been retrieved in the same isolate before, it is created.
2739  // Note that private symbols created this way are never collected, so
2740  // they should only be used for statically fixed properties.
2741  // Also, there is only one global name space for the names used as keys.
2742  // To minimize the potential for clashes, use qualified names as keys,
2743  // e.g., "Class#property".
2744  static Local<Private> ForApi(Isolate* isolate, Local<String> name);
2745 
2746  private:
2747  Private();
2748 };
2749 
2750 
2751 /**
2752  * A JavaScript number value (ECMA-262, 4.3.20)
2753  */
2754 class V8_EXPORT Number : public Primitive {
2755  public:
2756  double Value() const;
2757  static Local<Number> New(Isolate* isolate, double value);
2758  V8_INLINE static Number* Cast(v8::Value* obj);
2759  private:
2760  Number();
2761  static void CheckCast(v8::Value* obj);
2762 };
2763 
2764 
2765 /**
2766  * A JavaScript value representing a signed integer.
2767  */
2768 class V8_EXPORT Integer : public Number {
2769  public:
2770  static Local<Integer> New(Isolate* isolate, int32_t value);
2771  static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value);
2772  int64_t Value() const;
2773  V8_INLINE static Integer* Cast(v8::Value* obj);
2774  private:
2775  Integer();
2776  static void CheckCast(v8::Value* obj);
2777 };
2778 
2779 
2780 /**
2781  * A JavaScript value representing a 32-bit signed integer.
2782  */
2783 class V8_EXPORT Int32 : public Integer {
2784  public:
2785  int32_t Value() const;
2786  V8_INLINE static Int32* Cast(v8::Value* obj);
2787 
2788  private:
2789  Int32();
2790  static void CheckCast(v8::Value* obj);
2791 };
2792 
2793 
2794 /**
2795  * A JavaScript value representing a 32-bit unsigned integer.
2796  */
2797 class V8_EXPORT Uint32 : public Integer {
2798  public:
2799  uint32_t Value() const;
2800  V8_INLINE static Uint32* Cast(v8::Value* obj);
2801 
2802  private:
2803  Uint32();
2804  static void CheckCast(v8::Value* obj);
2805 };
2806 
2807 /**
2808  * PropertyAttribute.
2809  */
2811  /** None. **/
2812  None = 0,
2813  /** ReadOnly, i.e., not writable. **/
2814  ReadOnly = 1 << 0,
2815  /** DontEnum, i.e., not enumerable. **/
2816  DontEnum = 1 << 1,
2817  /** DontDelete, i.e., not configurable. **/
2818  DontDelete = 1 << 2
2819 };
2820 
2821 /**
2822  * Accessor[Getter|Setter] are used as callback functions when
2823  * setting|getting a particular property. See Object and ObjectTemplate's
2824  * method SetAccessor.
2825  */
2826 typedef void (*AccessorGetterCallback)(
2827  Local<String> property,
2828  const PropertyCallbackInfo<Value>& info);
2830  Local<Name> property,
2831  const PropertyCallbackInfo<Value>& info);
2832 
2833 
2834 typedef void (*AccessorSetterCallback)(
2835  Local<String> property,
2836  Local<Value> value,
2837  const PropertyCallbackInfo<void>& info);
2839  Local<Name> property,
2840  Local<Value> value,
2841  const PropertyCallbackInfo<void>& info);
2842 
2843 
2844 /**
2845  * Access control specifications.
2846  *
2847  * Some accessors should be accessible across contexts. These
2848  * accessors have an explicit access control parameter which specifies
2849  * the kind of cross-context access that should be allowed.
2850  *
2851  * TODO(dcarney): Remove PROHIBITS_OVERWRITING as it is now unused.
2852  */
2854  DEFAULT = 0,
2856  ALL_CAN_WRITE = 1 << 1,
2858 };
2859 
2860 /**
2861  * Property filter bits. They can be or'ed to build a composite filter.
2862  */
2870 };
2871 
2872 /**
2873  * Keys/Properties filter enums:
2874  *
2875  * KeyCollectionMode limits the range of collected properties. kOwnOnly limits
2876  * the collected properties to the given Object only. kIncludesPrototypes will
2877  * include all keys of the objects's prototype chain as well.
2878  */
2880 
2881 /**
2882  * kIncludesIndices allows for integer indices to be collected, while
2883  * kSkipIndices will exclude integer indicies from being collected.
2884  */
2886 
2887 /**
2888  * Integrity level for objects.
2889  */
2891 
2892 /**
2893  * A JavaScript object (ECMA-262, 4.3.3)
2894  */
2895 class V8_EXPORT Object : public Value {
2896  public:
2897  V8_DEPRECATE_SOON("Use maybe version",
2898  bool Set(Local<Value> key, Local<Value> value));
2899  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
2900  Local<Value> key, Local<Value> value);
2901 
2902  V8_DEPRECATE_SOON("Use maybe version",
2903  bool Set(uint32_t index, Local<Value> value));
2904  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
2905  Local<Value> value);
2906 
2907  // Implements CreateDataProperty (ECMA-262, 7.3.4).
2908  //
2909  // Defines a configurable, writable, enumerable property with the given value
2910  // on the object unless the property already exists and is not configurable
2911  // or the object is not extensible.
2912  //
2913  // Returns true on success.
2914  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
2915  Local<Name> key,
2916  Local<Value> value);
2917  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
2918  uint32_t index,
2919  Local<Value> value);
2920 
2921  // Implements DefineOwnProperty.
2922  //
2923  // In general, CreateDataProperty will be faster, however, does not allow
2924  // for specifying attributes.
2925  //
2926  // Returns true on success.
2928  Local<Context> context, Local<Name> key, Local<Value> value,
2929  PropertyAttribute attributes = None);
2930 
2931  // Implements Object.DefineProperty(O, P, Attributes), see Ecma-262 19.1.2.4.
2932  //
2933  // The defineProperty function is used to add an own property or
2934  // update the attributes of an existing own property of an object.
2935  //
2936  // Both data and accessor descriptors can be used.
2937  //
2938  // In general, CreateDataProperty is faster, however, does not allow
2939  // for specifying attributes or an accessor descriptor.
2940  //
2941  // The PropertyDescriptor can change when redefining a property.
2942  //
2943  // Returns true on success.
2945  Local<Context> context, Local<Name> key, PropertyDescriptor& descriptor);
2946 
2947  // Sets an own property on this object bypassing interceptors and
2948  // overriding accessors or read-only properties.
2949  //
2950  // Note that if the object has an interceptor the property will be set
2951  // locally, but since the interceptor takes precedence the local property
2952  // will only be returned if the interceptor doesn't return a value.
2953  //
2954  // Note also that this only works for named properties.
2955  V8_DEPRECATED("Use CreateDataProperty / DefineOwnProperty",
2956  bool ForceSet(Local<Value> key, Local<Value> value,
2957  PropertyAttribute attribs = None));
2958  V8_DEPRECATE_SOON("Use CreateDataProperty / DefineOwnProperty",
2959  Maybe<bool> ForceSet(Local<Context> context,
2960  Local<Value> key, Local<Value> value,
2961  PropertyAttribute attribs = None));
2962 
2963  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
2964  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
2965  Local<Value> key);
2966 
2967  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(uint32_t index));
2968  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
2969  uint32_t index);
2970 
2971  /**
2972  * Gets the property attributes of a property which can be None or
2973  * any combination of ReadOnly, DontEnum and DontDelete. Returns
2974  * None when the property doesn't exist.
2975  */
2976  V8_DEPRECATED("Use maybe version",
2977  PropertyAttribute GetPropertyAttributes(Local<Value> key));
2979  Local<Context> context, Local<Value> key);
2980 
2981  /**
2982  * Returns Object.getOwnPropertyDescriptor as per ES5 section 15.2.3.3.
2983  */
2984  V8_DEPRECATED("Use maybe version",
2985  Local<Value> GetOwnPropertyDescriptor(Local<String> key));
2987  Local<Context> context, Local<String> key);
2988 
2989  V8_DEPRECATE_SOON("Use maybe version", bool Has(Local<Value> key));
2990  /**
2991  * Object::Has() calls the abstract operation HasProperty(O, P) described
2992  * in ECMA-262, 7.3.10. Has() returns
2993  * true, if the object has the property, either own or on the prototype chain.
2994  * Interceptors, i.e., PropertyQueryCallbacks, are called if present.
2995  *
2996  * Has() has the same side effects as JavaScript's `variable in object`.
2997  * For example, calling Has() on a revoked proxy will throw an exception.
2998  *
2999  * \note Has() converts the key to a name, which possibly calls back into
3000  * JavaScript.
3001  *
3002  * See also v8::Object::HasOwnProperty() and
3003  * v8::Object::HasRealNamedProperty().
3004  */
3005  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
3006  Local<Value> key);
3007 
3008  V8_DEPRECATE_SOON("Use maybe version", bool Delete(Local<Value> key));
3009  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
3010  Maybe<bool> Delete(Local<Context> context, Local<Value> key);
3011 
3012  V8_DEPRECATED("Use maybe version", bool Has(uint32_t index));
3013  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, uint32_t index);
3014 
3015  V8_DEPRECATED("Use maybe version", bool Delete(uint32_t index));
3016  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
3017  Maybe<bool> Delete(Local<Context> context, uint32_t index);
3018 
3019  V8_DEPRECATED("Use maybe version",
3020  bool SetAccessor(Local<String> name,
3021  AccessorGetterCallback getter,
3022  AccessorSetterCallback setter = 0,
3023  Local<Value> data = Local<Value>(),
3024  AccessControl settings = DEFAULT,
3025  PropertyAttribute attribute = None));
3026  V8_DEPRECATED("Use maybe version",
3027  bool SetAccessor(Local<Name> name,
3029  AccessorNameSetterCallback setter = 0,
3030  Local<Value> data = Local<Value>(),
3031  AccessControl settings = DEFAULT,
3032  PropertyAttribute attribute = None));
3033  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
3034  Maybe<bool> SetAccessor(Local<Context> context, Local<Name> name,
3036  AccessorNameSetterCallback setter = 0,
3037  MaybeLocal<Value> data = MaybeLocal<Value>(),
3038  AccessControl settings = DEFAULT,
3039  PropertyAttribute attribute = None);
3040 
3041  void SetAccessorProperty(Local<Name> name, Local<Function> getter,
3042  Local<Function> setter = Local<Function>(),
3043  PropertyAttribute attribute = None,
3044  AccessControl settings = DEFAULT);
3045 
3046  /**
3047  * Functionality for private properties.
3048  * This is an experimental feature, use at your own risk.
3049  * Note: Private properties are not inherited. Do not rely on this, since it
3050  * may change.
3051  */
3052  Maybe<bool> HasPrivate(Local<Context> context, Local<Private> key);
3053  Maybe<bool> SetPrivate(Local<Context> context, Local<Private> key,
3054  Local<Value> value);
3055  Maybe<bool> DeletePrivate(Local<Context> context, Local<Private> key);
3056  MaybeLocal<Value> GetPrivate(Local<Context> context, Local<Private> key);
3057 
3058  /**
3059  * Returns an array containing the names of the enumerable properties
3060  * of this object, including properties from prototype objects. The
3061  * array returned by this method contains the same values as would
3062  * be enumerated by a for-in statement over this object.
3063  */
3064  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetPropertyNames());
3066  Local<Context> context);
3068  Local<Context> context, KeyCollectionMode mode,
3069  PropertyFilter property_filter, IndexFilter index_filter);
3070 
3071  /**
3072  * This function has the same functionality as GetPropertyNames but
3073  * the returned array doesn't contain the names of properties from
3074  * prototype objects.
3075  */
3076  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetOwnPropertyNames());
3078  Local<Context> context);
3079 
3080  /**
3081  * Returns an array containing the names of the filtered properties
3082  * of this object, including properties from prototype objects. The
3083  * array returned by this method contains the same values as would
3084  * be enumerated by a for-in statement over this object.
3085  */
3087  Local<Context> context, PropertyFilter filter);
3088 
3089  /**
3090  * Get the prototype object. This does not skip objects marked to
3091  * be skipped by __proto__ and it does not consult the security
3092  * handler.
3093  */
3094  Local<Value> GetPrototype();
3095 
3096  /**
3097  * Set the prototype object. This does not skip objects marked to
3098  * be skipped by __proto__ and it does not consult the security
3099  * handler.
3100  */
3101  V8_DEPRECATED("Use maybe version", bool SetPrototype(Local<Value> prototype));
3102  V8_WARN_UNUSED_RESULT Maybe<bool> SetPrototype(Local<Context> context,
3103  Local<Value> prototype);
3104 
3105  /**
3106  * Finds an instance of the given function template in the prototype
3107  * chain.
3108  */
3110 
3111  /**
3112  * Call builtin Object.prototype.toString on this object.
3113  * This is different from Value::ToString() that may call
3114  * user-defined toString function. This one does not.
3115  */
3116  V8_DEPRECATED("Use maybe version", Local<String> ObjectProtoToString());
3118  Local<Context> context);
3119 
3120  /**
3121  * Returns the name of the function invoked as a constructor for this object.
3122  */
3123  Local<String> GetConstructorName();
3124 
3125  /**
3126  * Sets the integrity level of the object.
3127  */
3128  Maybe<bool> SetIntegrityLevel(Local<Context> context, IntegrityLevel level);
3129 
3130  /** Gets the number of internal fields for this Object. */
3131  int InternalFieldCount();
3132 
3133  /** Same as above, but works for Persistents */
3135  const PersistentBase<Object>& object) {
3136  return object.val_->InternalFieldCount();
3137  }
3138 
3139  /** Gets the value from an internal field. */
3140  V8_INLINE Local<Value> GetInternalField(int index);
3141 
3142  /** Sets the value in an internal field. */
3143  void SetInternalField(int index, Local<Value> value);
3144 
3145  /**
3146  * Gets a 2-byte-aligned native pointer from an internal field. This field
3147  * must have been set by SetAlignedPointerInInternalField, everything else
3148  * leads to undefined behavior.
3149  */
3151 
3152  /** Same as above, but works for Persistents */
3154  const PersistentBase<Object>& object, int index) {
3155  return object.val_->GetAlignedPointerFromInternalField(index);
3156  }
3157 
3158  /**
3159  * Sets a 2-byte-aligned native pointer in an internal field. To retrieve such
3160  * a field, GetAlignedPointerFromInternalField must be used, everything else
3161  * leads to undefined behavior.
3162  */
3163  void SetAlignedPointerInInternalField(int index, void* value);
3164  void SetAlignedPointerInInternalFields(int argc, int indices[],
3165  void* values[]);
3166 
3167  // Testers for local properties.
3168  V8_DEPRECATED("Use maybe version", bool HasOwnProperty(Local<String> key));
3169 
3170  /**
3171  * HasOwnProperty() is like JavaScript's Object.prototype.hasOwnProperty().
3172  *
3173  * See also v8::Object::Has() and v8::Object::HasRealNamedProperty().
3174  */
3175  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
3176  Local<Name> key);
3177  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
3178  uint32_t index);
3179  V8_DEPRECATE_SOON("Use maybe version",
3180  bool HasRealNamedProperty(Local<String> key));
3181  /**
3182  * Use HasRealNamedProperty() if you want to check if an object has an own
3183  * property without causing side effects, i.e., without calling interceptors.
3184  *
3185  * This function is similar to v8::Object::HasOwnProperty(), but it does not
3186  * call interceptors.
3187  *
3188  * \note Consider using non-masking interceptors, i.e., the interceptors are
3189  * not called if the receiver has the real named property. See
3190  * `v8::PropertyHandlerFlags::kNonMasking`.
3191  *
3192  * See also v8::Object::Has().
3193  */
3194  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedProperty(Local<Context> context,
3195  Local<Name> key);
3196  V8_DEPRECATE_SOON("Use maybe version",
3197  bool HasRealIndexedProperty(uint32_t index));
3199  Local<Context> context, uint32_t index);
3200  V8_DEPRECATE_SOON("Use maybe version",
3201  bool HasRealNamedCallbackProperty(Local<String> key));
3203  Local<Context> context, Local<Name> key);
3204 
3205  /**
3206  * If result.IsEmpty() no real property was located in the prototype chain.
3207  * This means interceptors in the prototype chain are not called.
3208  */
3209  V8_DEPRECATED(
3210  "Use maybe version",
3211  Local<Value> GetRealNamedPropertyInPrototypeChain(Local<String> key));
3213  Local<Context> context, Local<Name> key);
3214 
3215  /**
3216  * Gets the property attributes of a real property in the prototype chain,
3217  * which can be None or any combination of ReadOnly, DontEnum and DontDelete.
3218  * Interceptors in the prototype chain are not called.
3219  */
3220  V8_DEPRECATED(
3221  "Use maybe version",
3222  Maybe<PropertyAttribute> GetRealNamedPropertyAttributesInPrototypeChain(
3223  Local<String> key));
3226  Local<Name> key);
3227 
3228  /**
3229  * If result.IsEmpty() no real property was located on the object or
3230  * in the prototype chain.
3231  * This means interceptors in the prototype chain are not called.
3232  */
3233  V8_DEPRECATED("Use maybe version",
3234  Local<Value> GetRealNamedProperty(Local<String> key));
3236  Local<Context> context, Local<Name> key);
3237 
3238  /**
3239  * Gets the property attributes of a real property which can be
3240  * None or any combination of ReadOnly, DontEnum and DontDelete.
3241  * Interceptors in the prototype chain are not called.
3242  */
3243  V8_DEPRECATED("Use maybe version",
3244  Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
3245  Local<String> key));
3247  Local<Context> context, Local<Name> key);
3248 
3249  /** Tests for a named lookup interceptor.*/
3251 
3252  /** Tests for an index lookup interceptor.*/
3254 
3255  /**
3256  * Returns the identity hash for this object. The current implementation
3257  * uses a hidden property on the object to store the identity hash.
3258  *
3259  * The return value will never be 0. Also, it is not guaranteed to be
3260  * unique.
3261  */
3262  int GetIdentityHash();
3263 
3264  /**
3265  * Clone this object with a fast but shallow copy. Values will point
3266  * to the same values as the original object.
3267  */
3268  // TODO(dcarney): take an isolate and optionally bail out?
3269  Local<Object> Clone();
3270 
3271  /**
3272  * Returns the context in which the object was created.
3273  */
3274  Local<Context> CreationContext();
3275 
3276  /** Same as above, but works for Persistents */
3278  const PersistentBase<Object>& object) {
3279  return object.val_->CreationContext();
3280  }
3281 
3282  /**
3283  * Checks whether a callback is set by the
3284  * ObjectTemplate::SetCallAsFunctionHandler method.
3285  * When an Object is callable this method returns true.
3286  */
3287  bool IsCallable();
3288 
3289  /**
3290  * True if this object is a constructor.
3291  */
3292  bool IsConstructor();
3293 
3294  /**
3295  * Call an Object as a function if a callback is set by the
3296  * ObjectTemplate::SetCallAsFunctionHandler method.
3297  */
3298  V8_DEPRECATED("Use maybe version",
3299  Local<Value> CallAsFunction(Local<Value> recv, int argc,
3300  Local<Value> argv[]));
3301  V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsFunction(Local<Context> context,
3302  Local<Value> recv,
3303  int argc,
3304  Local<Value> argv[]);
3305 
3306  /**
3307  * Call an Object as a constructor if a callback is set by the
3308  * ObjectTemplate::SetCallAsFunctionHandler method.
3309  * Note: This method behaves like the Function::NewInstance method.
3310  */
3311  V8_DEPRECATED("Use maybe version",
3312  Local<Value> CallAsConstructor(int argc, Local<Value> argv[]));
3314  Local<Context> context, int argc, Local<Value> argv[]);
3315 
3316  /**
3317  * Return the isolate to which the Object belongs to.
3318  */
3319  V8_DEPRECATE_SOON("Keep track of isolate correctly", Isolate* GetIsolate());
3320 
3321  static Local<Object> New(Isolate* isolate);
3322 
3323  V8_INLINE static Object* Cast(Value* obj);
3324 
3325  private:
3326  Object();
3327  static void CheckCast(Value* obj);
3328  Local<Value> SlowGetInternalField(int index);
3329  void* SlowGetAlignedPointerFromInternalField(int index);
3330 };
3331 
3332 
3333 /**
3334  * An instance of the built-in array constructor (ECMA-262, 15.4.2).
3335  */
3336 class V8_EXPORT Array : public Object {
3337  public:
3338  uint32_t Length() const;
3339 
3340  /**
3341  * Clones an element at index |index|. Returns an empty
3342  * handle if cloning fails (for any reason).
3343  */
3344  V8_DEPRECATED("Cloning is not supported.",
3345  Local<Object> CloneElementAt(uint32_t index));
3346  V8_DEPRECATED("Cloning is not supported.",
3347  MaybeLocal<Object> CloneElementAt(Local<Context> context,
3348  uint32_t index));
3349 
3350  /**
3351  * Creates a JavaScript array with the given length. If the length
3352  * is negative the returned array will have length 0.
3353  */
3354  static Local<Array> New(Isolate* isolate, int length = 0);
3355 
3356  V8_INLINE static Array* Cast(Value* obj);
3357  private:
3358  Array();
3359  static void CheckCast(Value* obj);
3360 };
3361 
3362 
3363 /**
3364  * An instance of the built-in Map constructor (ECMA-262, 6th Edition, 23.1.1).
3365  */
3366 class V8_EXPORT Map : public Object {
3367  public:
3368  size_t Size() const;
3369  void Clear();
3370  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
3371  Local<Value> key);
3372  V8_WARN_UNUSED_RESULT MaybeLocal<Map> Set(Local<Context> context,
3373  Local<Value> key,
3374  Local<Value> value);
3375  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
3376  Local<Value> key);
3377  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
3378  Local<Value> key);
3379 
3380  /**
3381  * Returns an array of length Size() * 2, where index N is the Nth key and
3382  * index N + 1 is the Nth value.
3383  */
3384  Local<Array> AsArray() const;
3385 
3386  /**
3387  * Creates a new empty Map.
3388  */
3389  static Local<Map> New(Isolate* isolate);
3390 
3391  V8_INLINE static Map* Cast(Value* obj);
3392 
3393  private:
3394  Map();
3395  static void CheckCast(Value* obj);
3396 };
3397 
3398 
3399 /**
3400  * An instance of the built-in Set constructor (ECMA-262, 6th Edition, 23.2.1).
3401  */
3402 class V8_EXPORT Set : public Object {
3403  public:
3404  size_t Size() const;
3405  void Clear();
3406  V8_WARN_UNUSED_RESULT MaybeLocal<Set> Add(Local<Context> context,
3407  Local<Value> key);
3408  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
3409  Local<Value> key);
3410  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
3411  Local<Value> key);
3412 
3413  /**
3414  * Returns an array of the keys in this Set.
3415  */
3416  Local<Array> AsArray() const;
3417 
3418  /**
3419  * Creates a new empty Set.
3420  */
3421  static Local<Set> New(Isolate* isolate);
3422 
3423  V8_INLINE static Set* Cast(Value* obj);
3424 
3425  private:
3426  Set();
3427  static void CheckCast(Value* obj);
3428 };
3429 
3430 
3431 template<typename T>
3432 class ReturnValue {
3433  public:
3434  template <class S> V8_INLINE ReturnValue(const ReturnValue<S>& that)
3435  : value_(that.value_) {
3436  TYPE_CHECK(T, S);
3437  }
3438  // Local setters
3439  template <typename S>
3440  V8_INLINE V8_DEPRECATE_SOON("Use Global<> instead",
3441  void Set(const Persistent<S>& handle));
3442  template <typename S>
3443  V8_INLINE void Set(const Global<S>& handle);
3444  template <typename S>
3445  V8_INLINE void Set(const Local<S> handle);
3446  // Fast primitive setters
3447  V8_INLINE void Set(bool value);
3448  V8_INLINE void Set(double i);
3449  V8_INLINE void Set(int32_t i);
3450  V8_INLINE void Set(uint32_t i);
3451  // Fast JS primitive setters
3452  V8_INLINE void SetNull();
3453  V8_INLINE void SetUndefined();
3454  V8_INLINE void SetEmptyString();
3455  // Convenience getter for Isolate
3456  V8_INLINE Isolate* GetIsolate() const;
3457 
3458  // Pointer setter: Uncompilable to prevent inadvertent misuse.
3459  template <typename S>
3460  V8_INLINE void Set(S* whatever);
3461 
3462  // Getter. Creates a new Local<> so it comes with a certain performance
3463  // hit. If the ReturnValue was not yet set, this will return the undefined
3464  // value.
3465  V8_INLINE Local<Value> Get() const;
3466 
3467  private:
3468  template<class F> friend class ReturnValue;
3469  template<class F> friend class FunctionCallbackInfo;
3470  template<class F> friend class PropertyCallbackInfo;
3471  template <class F, class G, class H>
3473  V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; }
3474  V8_INLINE internal::Object* GetDefaultValue();
3475  V8_INLINE explicit ReturnValue(internal::Object** slot);
3476  internal::Object** value_;
3477 };
3478 
3479 
3480 /**
3481  * The argument information given to function call callbacks. This
3482  * class provides access to information about the context of the call,
3483  * including the receiver, the number and values of arguments, and
3484  * the holder of the function.
3485  */
3486 template<typename T>
3487 class FunctionCallbackInfo {
3488  public:
3489  V8_INLINE int Length() const;
3490  V8_INLINE Local<Value> operator[](int i) const;
3491  V8_INLINE V8_DEPRECATED("Use Data() to explicitly pass Callee instead",
3492  Local<Function> Callee() const);
3493  V8_INLINE Local<Object> This() const;
3494  V8_INLINE Local<Object> Holder() const;
3495  V8_INLINE Local<Value> NewTarget() const;
3496  V8_INLINE bool IsConstructCall() const;
3497  V8_INLINE Local<Value> Data() const;
3498  V8_INLINE Isolate* GetIsolate() const;
3499  V8_INLINE ReturnValue<T> GetReturnValue() const;
3500  // This shouldn't be public, but the arm compiler needs it.
3501  static const int kArgsLength = 8;
3502 
3503  protected:
3506  static const int kHolderIndex = 0;
3507  static const int kIsolateIndex = 1;
3508  static const int kReturnValueDefaultValueIndex = 2;
3509  static const int kReturnValueIndex = 3;
3510  static const int kDataIndex = 4;
3511  static const int kCalleeIndex = 5;
3512  static const int kContextSaveIndex = 6;
3513  static const int kNewTargetIndex = 7;
3514 
3515  V8_INLINE FunctionCallbackInfo(internal::Object** implicit_args,
3516  internal::Object** values, int length);
3518  internal::Object** values_;
3519  int length_;
3520 };
3521 
3522 
3523 /**
3524  * The information passed to a property callback about the context
3525  * of the property access.
3526  */
3527 template<typename T>
3528 class PropertyCallbackInfo {
3529  public:
3530  /**
3531  * \return The isolate of the property access.
3532  */
3533  V8_INLINE Isolate* GetIsolate() const;
3534 
3535  /**
3536  * \return The data set in the configuration, i.e., in
3537  * `NamedPropertyHandlerConfiguration` or
3538  * `IndexedPropertyHandlerConfiguration.`
3539  */
3540  V8_INLINE Local<Value> Data() const;
3541 
3542  /**
3543  * \return The receiver. In many cases, this is the object on which the
3544  * property access was intercepted. When using
3545  * `Reflect.Get`, `Function.prototype.call`, or similar functions, it is the
3546  * object passed in as receiver or thisArg.
3547  *
3548  * \code
3549  * void GetterCallback(Local<Name> name,
3550  * const v8::PropertyCallbackInfo<v8::Value>& info) {
3551  * auto context = info.GetIsolate()->GetCurrentContext();
3552  *
3553  * v8::Local<v8::Value> a_this =
3554  * info.This()
3555  * ->GetRealNamedProperty(context, v8_str("a"))
3556  * .ToLocalChecked();
3557  * v8::Local<v8::Value> a_holder =
3558  * info.Holder()
3559  * ->GetRealNamedProperty(context, v8_str("a"))
3560  * .ToLocalChecked();
3561  *
3562  * CHECK(v8_str("r")->Equals(context, a_this).FromJust());
3563  * CHECK(v8_str("obj")->Equals(context, a_holder).FromJust());
3564  *
3565  * info.GetReturnValue().Set(name);
3566  * }
3567  *
3568  * v8::Local<v8::FunctionTemplate> templ =
3569  * v8::FunctionTemplate::New(isolate);
3570  * templ->InstanceTemplate()->SetHandler(
3571  * v8::NamedPropertyHandlerConfiguration(GetterCallback));
3572  * LocalContext env;
3573  * env->Global()
3574  * ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local())
3575  * .ToLocalChecked()
3576  * ->NewInstance(env.local())
3577  * .ToLocalChecked())
3578  * .FromJust();
3579  *
3580  * CompileRun("obj.a = 'obj'; var r = {a: 'r'}; Reflect.get(obj, 'x', r)");
3581  * \endcode
3582  */
3583  V8_INLINE Local<Object> This() const;
3584 
3585  /**
3586  * \return The object in the prototype chain of the receiver that has the
3587  * interceptor. Suppose you have `x` and its prototype is `y`, and `y`
3588  * has an interceptor. Then `info.This()` is `x` and `info.Holder()` is `y`.
3589  * The Holder() could be a hidden object (the global object, rather
3590  * than the global proxy).
3591  *
3592  * \note For security reasons, do not pass the object back into the runtime.
3593  */
3594  V8_INLINE Local<Object> Holder() const;
3595 
3596  /**
3597  * \return The return value of the callback.
3598  * Can be changed by calling Set().
3599  * \code
3600  * info.GetReturnValue().Set(...)
3601  * \endcode
3602  *
3603  */
3604  V8_INLINE ReturnValue<T> GetReturnValue() const;
3605 
3606  /**
3607  * \return True if the intercepted function should throw if an error occurs.
3608  * Usually, `true` corresponds to `'use strict'`.
3609  *
3610  * \note Always `false` when intercepting `Reflect.Set()`
3611  * independent of the language mode.
3612  */
3613  V8_INLINE bool ShouldThrowOnError() const;
3614 
3615  // This shouldn't be public, but the arm compiler needs it.
3616  static const int kArgsLength = 7;
3617 
3618  protected:
3619  friend class MacroAssembler;
3622  static const int kShouldThrowOnErrorIndex = 0;
3623  static const int kHolderIndex = 1;
3624  static const int kIsolateIndex = 2;
3625  static const int kReturnValueDefaultValueIndex = 3;
3626  static const int kReturnValueIndex = 4;
3627  static const int kDataIndex = 5;
3628  static const int kThisIndex = 6;
3629 
3630  V8_INLINE PropertyCallbackInfo(internal::Object** args) : args_(args) {}
3631  internal::Object** args_;
3632 };
3633 
3634 
3635 typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info);
3636 
3638 
3639 /**
3640  * A JavaScript function object (ECMA-262, 15.3).
3641  */
3642 class V8_EXPORT Function : public Object {
3643  public:
3644  /**
3645  * Create a function in the current execution context
3646  * for a given FunctionCallback.
3647  */
3648  static MaybeLocal<Function> New(
3649  Local<Context> context, FunctionCallback callback,
3650  Local<Value> data = Local<Value>(), int length = 0,
3652  static V8_DEPRECATE_SOON(
3653  "Use maybe version",
3654  Local<Function> New(Isolate* isolate, FunctionCallback callback,
3655  Local<Value> data = Local<Value>(), int length = 0));
3656 
3657  V8_DEPRECATED("Use maybe version",
3658  Local<Object> NewInstance(int argc, Local<Value> argv[]) const);
3660  Local<Context> context, int argc, Local<Value> argv[]) const;
3661 
3662  V8_DEPRECATED("Use maybe version", Local<Object> NewInstance() const);
3664  Local<Context> context) const {
3665  return NewInstance(context, 0, nullptr);
3666  }
3667 
3668  V8_DEPRECATE_SOON("Use maybe version",
3669  Local<Value> Call(Local<Value> recv, int argc,
3670  Local<Value> argv[]));
3671  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Call(Local<Context> context,
3672  Local<Value> recv, int argc,
3673  Local<Value> argv[]);
3674 
3675  void SetName(Local<String> name);
3676  Local<Value> GetName() const;
3677 
3678  /**
3679  * Name inferred from variable or property assignment of this function.
3680  * Used to facilitate debugging and profiling of JavaScript code written
3681  * in an OO style, where many functions are anonymous but are assigned
3682  * to object properties.
3683  */
3684  Local<Value> GetInferredName() const;
3685 
3686  /**
3687  * displayName if it is set, otherwise name if it is configured, otherwise
3688  * function name, otherwise inferred name.
3689  */
3690  Local<Value> GetDebugName() const;
3691 
3692  /**
3693  * User-defined name assigned to the "displayName" property of this function.
3694  * Used to facilitate debugging and profiling of JavaScript code.
3695  */
3696  Local<Value> GetDisplayName() const;
3697 
3698  /**
3699  * Returns zero based line number of function body and
3700  * kLineOffsetNotFound if no information available.
3701  */
3702  int GetScriptLineNumber() const;
3703  /**
3704  * Returns zero based column number of function body and
3705  * kLineOffsetNotFound if no information available.
3706  */
3707  int GetScriptColumnNumber() const;
3708 
3709  /**
3710  * Tells whether this function is builtin.
3711  */
3712  bool IsBuiltin() const;
3713 
3714  /**
3715  * Returns scriptId.
3716  */
3717  int ScriptId() const;
3718 
3719  /**
3720  * Returns the original function if this function is bound, else returns
3721  * v8::Undefined.
3722  */
3723  Local<Value> GetBoundFunction() const;
3724 
3725  ScriptOrigin GetScriptOrigin() const;
3726  V8_INLINE static Function* Cast(Value* obj);
3727  static const int kLineOffsetNotFound;
3728 
3729  private:
3730  Function();
3731  static void CheckCast(Value* obj);
3732 };
3733 
3734 
3735 /**
3736  * An instance of the built-in Promise constructor (ES6 draft).
3737  * This API is experimental. Only works with --harmony flag.
3738  */
3739 class V8_EXPORT Promise : public Object {
3740  public:
3741  class V8_EXPORT Resolver : public Object {
3742  public:
3743  /**
3744  * Create a new resolver, along with an associated promise in pending state.
3745  */
3746  static V8_DEPRECATE_SOON("Use maybe version",
3747  Local<Resolver> New(Isolate* isolate));
3748  static V8_WARN_UNUSED_RESULT MaybeLocal<Resolver> New(
3749  Local<Context> context);
3750 
3751  /**
3752  * Extract the associated promise.
3753  */
3754  Local<Promise> GetPromise();
3755 
3756  /**
3757  * Resolve/reject the associated promise with a given value.
3758  * Ignored if the promise is no longer pending.
3759  */
3760  V8_DEPRECATE_SOON("Use maybe version", void Resolve(Local<Value> value));
3761  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
3762  Maybe<bool> Resolve(Local<Context> context, Local<Value> value);
3763 
3764  V8_DEPRECATE_SOON("Use maybe version", void Reject(Local<Value> value));
3765  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
3766  Maybe<bool> Reject(Local<Context> context, Local<Value> value);
3767 
3768  V8_INLINE static Resolver* Cast(Value* obj);
3769 
3770  private:
3771  Resolver();
3772  static void CheckCast(Value* obj);
3773  };
3774 
3775  /**
3776  * Register a resolution/rejection handler with a promise.
3777  * The handler is given the respective resolution/rejection value as
3778  * an argument. If the promise is already resolved/rejected, the handler is
3779  * invoked at the end of turn.
3780  */
3781  V8_DEPRECATED("Use maybe version",
3782  Local<Promise> Catch(Local<Function> handler));
3783  V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Catch(Local<Context> context,
3784  Local<Function> handler);
3785 
3786  V8_DEPRECATED("Use maybe version",
3787  Local<Promise> Then(Local<Function> handler));
3788  V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Then(Local<Context> context,
3789  Local<Function> handler);
3790 
3791  /**
3792  * Returns true if the promise has at least one derived promise, and
3793  * therefore resolve/reject handlers (including default handler).
3794  */
3795  bool HasHandler();
3796 
3797  V8_INLINE static Promise* Cast(Value* obj);
3798 
3799  private:
3800  Promise();
3801  static void CheckCast(Value* obj);
3802 };
3803 
3804 /**
3805  * An instance of a Property Descriptor, see Ecma-262 6.2.4.
3806  *
3807  * Properties in a descriptor are present or absent. If you do not set
3808  * `enumerable`, `configurable`, and `writable`, they are absent. If `value`,
3809  * `get`, or `set` are absent, but you must specify them in the constructor, use
3810  * empty handles.
3811  *
3812  * Accessors `get` and `set` must be callable or undefined if they are present.
3813  *
3814  * \note Only query properties if they are present, i.e., call `x()` only if
3815  * `has_x()` returns true.
3816  *
3817  * \code
3818  * // var desc = {writable: false}
3819  * v8::PropertyDescriptor d(Local<Value>()), false);
3820  * d.value(); // error, value not set
3821  * if (d.has_writable()) {
3822  * d.writable(); // false
3823  * }
3824  *
3825  * // var desc = {value: undefined}
3826  * v8::PropertyDescriptor d(v8::Undefined(isolate));
3827  *
3828  * // var desc = {get: undefined}
3829  * v8::PropertyDescriptor d(v8::Undefined(isolate), Local<Value>()));
3830  * \endcode
3831  */
3833  public:
3834  // GenericDescriptor
3836 
3837  // DataDescriptor
3838  PropertyDescriptor(Local<Value> value);
3839 
3840  // DataDescriptor with writable property
3841  PropertyDescriptor(Local<Value> value, bool writable);
3842 
3843  // AccessorDescriptor
3844  PropertyDescriptor(Local<Value> get, Local<Value> set);
3845 
3846  ~PropertyDescriptor();
3847 
3848  Local<Value> value() const;
3849  bool has_value() const;
3850 
3851  Local<Value> get() const;
3852  bool has_get() const;
3853  Local<Value> set() const;
3854  bool has_set() const;
3855 
3856  void set_enumerable(bool enumerable);
3857  bool enumerable() const;
3858  bool has_enumerable() const;
3859 
3860  void set_configurable(bool configurable);
3861  bool configurable() const;
3862  bool has_configurable() const;
3863 
3864  bool writable() const;
3865  bool has_writable() const;
3866 
3867  struct PrivateData;
3868  PrivateData* get_private() const { return private_; }
3869 
3870  PropertyDescriptor(const PropertyDescriptor&) = delete;
3871  void operator=(const PropertyDescriptor&) = delete;
3872 
3873  private:
3874  PrivateData* private_;
3875 };
3876 
3877 /**
3878  * An instance of the built-in Proxy constructor (ECMA-262, 6th Edition,
3879  * 26.2.1).
3880  */
3881 class V8_EXPORT Proxy : public Object {
3882  public:
3883  Local<Object> GetTarget();
3884  Local<Value> GetHandler();
3885  bool IsRevoked();
3886  void Revoke();
3887 
3888  /**
3889  * Creates a new Proxy for the target object.
3890  */
3891  static MaybeLocal<Proxy> New(Local<Context> context,
3892  Local<Object> local_target,
3893  Local<Object> local_handler);
3894 
3895  V8_INLINE static Proxy* Cast(Value* obj);
3896 
3897  private:
3898  Proxy();
3899  static void CheckCast(Value* obj);
3900 };
3901 
3903  public:
3905 
3907  static MaybeLocal<WasmCompiledModule> Deserialize(
3908  Isolate* isolate, const SerializedModule& serialized_data);
3909  V8_INLINE static WasmCompiledModule* Cast(Value* obj);
3910 
3911  private:
3912  WasmCompiledModule();
3913  static void CheckCast(Value* obj);
3914 };
3915 
3916 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
3917 // The number of required internal fields can be defined by embedder.
3918 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
3919 #endif
3920 
3921 
3923 
3924 
3925 /**
3926  * An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5).
3927  * This API is experimental and may change significantly.
3928  */
3929 class V8_EXPORT ArrayBuffer : public Object {
3930  public:
3931  /**
3932  * A thread-safe allocator that V8 uses to allocate |ArrayBuffer|'s memory.
3933  * The allocator is a global V8 setting. It has to be set via
3934  * Isolate::CreateParams.
3935  *
3936  * Memory allocated through this allocator by V8 is accounted for as external
3937  * memory by V8. Note that V8 keeps track of the memory for all internalized
3938  * |ArrayBuffer|s. Responsibility for tracking external memory (using
3939  * Isolate::AdjustAmountOfExternalAllocatedMemory) is handed over to the
3940  * embedder upon externalization and taken over upon internalization (creating
3941  * an internalized buffer from an existing buffer).
3942  *
3943  * Note that it is unsafe to call back into V8 from any of the allocator
3944  * functions.
3945  */
3946  class V8_EXPORT Allocator { // NOLINT
3947  public:
3948  virtual ~Allocator() {}
3949 
3950  /**
3951  * Allocate |length| bytes. Return NULL if allocation is not successful.
3952  * Memory should be initialized to zeroes.
3953  */
3954  virtual void* Allocate(size_t length) = 0;
3955 
3956  /**
3957  * Allocate |length| bytes. Return NULL if allocation is not successful.
3958  * Memory does not have to be initialized.
3959  */
3960  virtual void* AllocateUninitialized(size_t length) = 0;
3961 
3962  /**
3963  * Free the memory block of size |length|, pointed to by |data|.
3964  * That memory is guaranteed to be previously allocated by |Allocate|.
3965  */
3966  virtual void Free(void* data, size_t length) = 0;
3967 
3968  /**
3969  * malloc/free based convenience allocator.
3970  *
3971  * Caller takes ownership.
3972  */
3973  static Allocator* NewDefaultAllocator();
3974  };
3975 
3976  /**
3977  * The contents of an |ArrayBuffer|. Externalization of |ArrayBuffer|
3978  * returns an instance of this class, populated, with a pointer to data
3979  * and byte length.
3980  *
3981  * The Data pointer of ArrayBuffer::Contents is always allocated with
3982  * Allocator::Allocate that is set via Isolate::CreateParams.
3983  *
3984  * This API is experimental and may change significantly.
3985  */
3986  class V8_EXPORT Contents { // NOLINT
3987  public:
3988  Contents() : data_(NULL), byte_length_(0) {}
3989 
3990  void* Data() const { return data_; }
3991  size_t ByteLength() const { return byte_length_; }
3992 
3993  private:
3994  void* data_;
3995  size_t byte_length_;
3996 
3997  friend class ArrayBuffer;
3998  };
3999 
4000 
4001  /**
4002  * Data length in bytes.
4003  */
4004  size_t ByteLength() const;
4005 
4006  /**
4007  * Create a new ArrayBuffer. Allocate |byte_length| bytes.
4008  * Allocated memory will be owned by a created ArrayBuffer and
4009  * will be deallocated when it is garbage-collected,
4010  * unless the object is externalized.
4011  */
4012  static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
4013 
4014  /**
4015  * Create a new ArrayBuffer over an existing memory block.
4016  * The created array buffer is by default immediately in externalized state.
4017  * The memory block will not be reclaimed when a created ArrayBuffer
4018  * is garbage-collected.
4019  */
4020  static Local<ArrayBuffer> New(
4021  Isolate* isolate, void* data, size_t byte_length,
4023 
4024  /**
4025  * Returns true if ArrayBuffer is externalized, that is, does not
4026  * own its memory block.
4027  */
4028  bool IsExternal() const;
4029 
4030  /**
4031  * Returns true if this ArrayBuffer may be neutered.
4032  */
4033  bool IsNeuterable() const;
4034 
4035  /**
4036  * Neuters this ArrayBuffer and all its views (typed arrays).
4037  * Neutering sets the byte length of the buffer and all typed arrays to zero,
4038  * preventing JavaScript from ever accessing underlying backing store.
4039  * ArrayBuffer should have been externalized and must be neuterable.
4040  */
4041  void Neuter();
4042 
4043  /**
4044  * Make this ArrayBuffer external. The pointer to underlying memory block
4045  * and byte length are returned as |Contents| structure. After ArrayBuffer
4046  * had been externalized, it does no longer own the memory block. The caller
4047  * should take steps to free memory when it is no longer needed.
4048  *
4049  * The memory block is guaranteed to be allocated with |Allocator::Allocate|
4050  * that has been set via Isolate::CreateParams.
4051  */
4053 
4054  /**
4055  * Get a pointer to the ArrayBuffer's underlying memory block without
4056  * externalizing it. If the ArrayBuffer is not externalized, this pointer
4057  * will become invalid as soon as the ArrayBuffer gets garbage collected.
4058  *
4059  * The embedder should make sure to hold a strong reference to the
4060  * ArrayBuffer while accessing this pointer.
4061  *
4062  * The memory block is guaranteed to be allocated with |Allocator::Allocate|.
4063  */
4065 
4066  V8_INLINE static ArrayBuffer* Cast(Value* obj);
4067 
4069 
4070  private:
4071  ArrayBuffer();
4072  static void CheckCast(Value* obj);
4073 };
4074 
4075 
4076 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
4077 // The number of required internal fields can be defined by embedder.
4078 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
4079 #endif
4080 
4081 
4082 /**
4083  * A base class for an instance of one of "views" over ArrayBuffer,
4084  * including TypedArrays and DataView (ES6 draft 15.13).
4085  *
4086  * This API is experimental and may change significantly.
4087  */
4089  public:
4090  /**
4091  * Returns underlying ArrayBuffer.
4092  */
4093  Local<ArrayBuffer> Buffer();
4094  /**
4095  * Byte offset in |Buffer|.
4096  */
4097  size_t ByteOffset();
4098  /**
4099  * Size of a view in bytes.
4100  */
4101  size_t ByteLength();
4102 
4103  /**
4104  * Copy the contents of the ArrayBufferView's buffer to an embedder defined
4105  * memory without additional overhead that calling ArrayBufferView::Buffer
4106  * might incur.
4107  *
4108  * Will write at most min(|byte_length|, ByteLength) bytes starting at
4109  * ByteOffset of the underlying buffer to the memory starting at |dest|.
4110  * Returns the number of bytes actually written.
4111  */
4113 
4114  /**
4115  * Returns true if ArrayBufferView's backing ArrayBuffer has already been
4116  * allocated.
4117  */
4118  bool HasBuffer() const;
4119 
4120  V8_INLINE static ArrayBufferView* Cast(Value* obj);
4121 
4122  static const int kInternalFieldCount =
4124 
4125  private:
4126  ArrayBufferView();
4127  static void CheckCast(Value* obj);
4128 };
4129 
4130 
4131 /**
4132  * A base class for an instance of TypedArray series of constructors
4133  * (ES6 draft 15.13.6).
4134  * This API is experimental and may change significantly.
4135  */
4137  public:
4138  /**
4139  * Number of elements in this typed array
4140  * (e.g. for Int16Array, |ByteLength|/2).
4141  */
4142  size_t Length();
4143 
4144  V8_INLINE static TypedArray* Cast(Value* obj);
4145 
4146  private:
4147  TypedArray();
4148  static void CheckCast(Value* obj);
4149 };
4150 
4151 
4152 /**
4153  * An instance of Uint8Array constructor (ES6 draft 15.13.6).
4154  * This API is experimental and may change significantly.
4155  */
4157  public:
4158  static Local<Uint8Array> New(Local<ArrayBuffer> array_buffer,
4159  size_t byte_offset, size_t length);
4160  static Local<Uint8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4161  size_t byte_offset, size_t length);
4162  V8_INLINE static Uint8Array* Cast(Value* obj);
4163 
4164  private:
4165  Uint8Array();
4166  static void CheckCast(Value* obj);
4167 };
4168 
4169 
4170 /**
4171  * An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6).
4172  * This API is experimental and may change significantly.
4173  */
4175  public:
4176  static Local<Uint8ClampedArray> New(Local<ArrayBuffer> array_buffer,
4177  size_t byte_offset, size_t length);
4178  static Local<Uint8ClampedArray> New(
4179  Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,
4180  size_t length);
4181  V8_INLINE static Uint8ClampedArray* Cast(Value* obj);
4182 
4183  private:
4184  Uint8ClampedArray();
4185  static void CheckCast(Value* obj);
4186 };
4187 
4188 /**
4189  * An instance of Int8Array constructor (ES6 draft 15.13.6).
4190  * This API is experimental and may change significantly.
4191  */
4193  public:
4194  static Local<Int8Array> New(Local<ArrayBuffer> array_buffer,
4195  size_t byte_offset, size_t length);
4196  static Local<Int8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4197  size_t byte_offset, size_t length);
4198  V8_INLINE static Int8Array* Cast(Value* obj);
4199 
4200  private:
4201  Int8Array();
4202  static void CheckCast(Value* obj);
4203 };
4204 
4205 
4206 /**
4207  * An instance of Uint16Array constructor (ES6 draft 15.13.6).
4208  * This API is experimental and may change significantly.
4209  */
4211  public:
4212  static Local<Uint16Array> New(Local<ArrayBuffer> array_buffer,
4213  size_t byte_offset, size_t length);
4214  static Local<Uint16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4215  size_t byte_offset, size_t length);
4216  V8_INLINE static Uint16Array* Cast(Value* obj);
4217 
4218  private:
4219  Uint16Array();
4220  static void CheckCast(Value* obj);
4221 };
4222 
4223 
4224 /**
4225  * An instance of Int16Array constructor (ES6 draft 15.13.6).
4226  * This API is experimental and may change significantly.
4227  */
4229  public:
4230  static Local<Int16Array> New(Local<ArrayBuffer> array_buffer,
4231  size_t byte_offset, size_t length);
4232  static Local<Int16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4233  size_t byte_offset, size_t length);
4234  V8_INLINE static Int16Array* Cast(Value* obj);
4235 
4236  private:
4237  Int16Array();
4238  static void CheckCast(Value* obj);
4239 };
4240 
4241 
4242 /**
4243  * An instance of Uint32Array constructor (ES6 draft 15.13.6).
4244  * This API is experimental and may change significantly.
4245  */
4247  public:
4248  static Local<Uint32Array> New(Local<ArrayBuffer> array_buffer,
4249  size_t byte_offset, size_t length);
4250  static Local<Uint32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4251  size_t byte_offset, size_t length);
4252  V8_INLINE static Uint32Array* Cast(Value* obj);
4253 
4254  private:
4255  Uint32Array();
4256  static void CheckCast(Value* obj);
4257 };
4258 
4259 
4260 /**
4261  * An instance of Int32Array constructor (ES6 draft 15.13.6).
4262  * This API is experimental and may change significantly.
4263  */
4265  public:
4266  static Local<Int32Array> New(Local<ArrayBuffer> array_buffer,
4267  size_t byte_offset, size_t length);
4268  static Local<Int32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4269  size_t byte_offset, size_t length);
4270  V8_INLINE static Int32Array* Cast(Value* obj);
4271 
4272  private:
4273  Int32Array();
4274  static void CheckCast(Value* obj);
4275 };
4276 
4277 
4278 /**
4279  * An instance of Float32Array constructor (ES6 draft 15.13.6).
4280  * This API is experimental and may change significantly.
4281  */
4283  public:
4284  static Local<Float32Array> New(Local<ArrayBuffer> array_buffer,
4285  size_t byte_offset, size_t length);
4286  static Local<Float32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4287  size_t byte_offset, size_t length);
4288  V8_INLINE static Float32Array* Cast(Value* obj);
4289 
4290  private:
4291  Float32Array();
4292  static void CheckCast(Value* obj);
4293 };
4294 
4295 
4296 /**
4297  * An instance of Float64Array constructor (ES6 draft 15.13.6).
4298  * This API is experimental and may change significantly.
4299  */
4301  public:
4302  static Local<Float64Array> New(Local<ArrayBuffer> array_buffer,
4303  size_t byte_offset, size_t length);
4304  static Local<Float64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4305  size_t byte_offset, size_t length);
4306  V8_INLINE static Float64Array* Cast(Value* obj);
4307 
4308  private:
4309  Float64Array();
4310  static void CheckCast(Value* obj);
4311 };
4312 
4313 
4314 /**
4315  * An instance of DataView constructor (ES6 draft 15.13.7).
4316  * This API is experimental and may change significantly.
4317  */
4319  public:
4320  static Local<DataView> New(Local<ArrayBuffer> array_buffer,
4321  size_t byte_offset, size_t length);
4322  static Local<DataView> New(Local<SharedArrayBuffer> shared_array_buffer,
4323  size_t byte_offset, size_t length);
4324  V8_INLINE static DataView* Cast(Value* obj);
4325 
4326  private:
4327  DataView();
4328  static void CheckCast(Value* obj);
4329 };
4330 
4331 
4332 /**
4333  * An instance of the built-in SharedArrayBuffer constructor.
4334  * This API is experimental and may change significantly.
4335  */
4337  public:
4338  /**
4339  * The contents of an |SharedArrayBuffer|. Externalization of
4340  * |SharedArrayBuffer| returns an instance of this class, populated, with a
4341  * pointer to data and byte length.
4342  *
4343  * The Data pointer of SharedArrayBuffer::Contents is always allocated with
4344  * |ArrayBuffer::Allocator::Allocate| by the allocator specified in
4345  * v8::Isolate::CreateParams::array_buffer_allocator.
4346  *
4347  * This API is experimental and may change significantly.
4348  */
4349  class V8_EXPORT Contents { // NOLINT
4350  public:
4351  Contents() : data_(NULL), byte_length_(0) {}
4352 
4353  void* Data() const { return data_; }
4354  size_t ByteLength() const { return byte_length_; }
4355 
4356  private:
4357  void* data_;
4358  size_t byte_length_;
4359 
4360  friend class SharedArrayBuffer;
4361  };
4362 
4363 
4364  /**
4365  * Data length in bytes.
4366  */
4367  size_t ByteLength() const;
4368 
4369  /**
4370  * Create a new SharedArrayBuffer. Allocate |byte_length| bytes.
4371  * Allocated memory will be owned by a created SharedArrayBuffer and
4372  * will be deallocated when it is garbage-collected,
4373  * unless the object is externalized.
4374  */
4375  static Local<SharedArrayBuffer> New(Isolate* isolate, size_t byte_length);
4376 
4377  /**
4378  * Create a new SharedArrayBuffer over an existing memory block. The created
4379  * array buffer is immediately in externalized state unless otherwise
4380  * specified. The memory block will not be reclaimed when a created
4381  * SharedArrayBuffer is garbage-collected.
4382  */
4383  static Local<SharedArrayBuffer> New(
4384  Isolate* isolate, void* data, size_t byte_length,
4386 
4387  /**
4388  * Returns true if SharedArrayBuffer is externalized, that is, does not
4389  * own its memory block.
4390  */
4391  bool IsExternal() const;
4392 
4393  /**
4394  * Make this SharedArrayBuffer external. The pointer to underlying memory
4395  * block and byte length are returned as |Contents| structure. After
4396  * SharedArrayBuffer had been externalized, it does no longer own the memory
4397  * block. The caller should take steps to free memory when it is no longer
4398  * needed.
4399  *
4400  * The memory block is guaranteed to be allocated with |Allocator::Allocate|
4401  * by the allocator specified in
4402  * v8::Isolate::CreateParams::array_buffer_allocator.
4403  *
4404  */
4406 
4407  /**
4408  * Get a pointer to the ArrayBuffer's underlying memory block without
4409  * externalizing it. If the ArrayBuffer is not externalized, this pointer
4410  * will become invalid as soon as the ArrayBuffer became garbage collected.
4411  *
4412  * The embedder should make sure to hold a strong reference to the
4413  * ArrayBuffer while accessing this pointer.
4414  *
4415  * The memory block is guaranteed to be allocated with |Allocator::Allocate|
4416  * by the allocator specified in
4417  * v8::Isolate::CreateParams::array_buffer_allocator.
4418  */
4420 
4421  V8_INLINE static SharedArrayBuffer* Cast(Value* obj);
4422 
4424 
4425  private:
4426  SharedArrayBuffer();
4427  static void CheckCast(Value* obj);
4428 };
4429 
4430 
4431 /**
4432  * An instance of the built-in Date constructor (ECMA-262, 15.9).
4433  */
4434 class V8_EXPORT Date : public Object {
4435  public:
4436  static V8_DEPRECATE_SOON("Use maybe version.",
4437  Local<Value> New(Isolate* isolate, double time));
4438  static V8_WARN_UNUSED_RESULT MaybeLocal<Value> New(Local<Context> context,
4439  double time);
4440 
4441  /**
4442  * A specialization of Value::NumberValue that is more efficient
4443  * because we know the structure of this object.
4444  */
4445  double ValueOf() const;
4446 
4447  V8_INLINE static Date* Cast(v8::Value* obj);
4448 
4449  /**
4450  * Notification that the embedder has changed the time zone,
4451  * daylight savings time, or other date / time configuration
4452  * parameters. V8 keeps a cache of various values used for
4453  * date / time computation. This notification will reset
4454  * those cached values for the current context so that date /
4455  * time configuration changes would be reflected in the Date
4456  * object.
4457  *
4458  * This API should not be called more than needed as it will
4459  * negatively impact the performance of date operations.
4460  */
4461  static void DateTimeConfigurationChangeNotification(Isolate* isolate);
4462 
4463  private:
4464  static void CheckCast(v8::Value* obj);
4465 };
4466 
4467 
4468 /**
4469  * A Number object (ECMA-262, 4.3.21).
4470  */
4472  public:
4473  static Local<Value> New(Isolate* isolate, double value);
4474 
4475  double ValueOf() const;
4476 
4477  V8_INLINE static NumberObject* Cast(v8::Value* obj);
4478 
4479  private:
4480  static void CheckCast(v8::Value* obj);
4481 };
4482 
4483 
4484 /**
4485  * A Boolean object (ECMA-262, 4.3.15).
4486  */
4488  public:
4489  static Local<Value> New(Isolate* isolate, bool value);
4490  V8_DEPRECATED("Pass an isolate", static Local<Value> New(bool value));
4491 
4492  bool ValueOf() const;
4493 
4494  V8_INLINE static BooleanObject* Cast(v8::Value* obj);
4495 
4496  private:
4497  static void CheckCast(v8::Value* obj);
4498 };
4499 
4500 
4501 /**
4502  * A String object (ECMA-262, 4.3.18).
4503  */
4505  public:
4506  static Local<Value> New(Local<String> value);
4507 
4508  Local<String> ValueOf() const;
4509 
4510  V8_INLINE static StringObject* Cast(v8::Value* obj);
4511 
4512  private:
4513  static void CheckCast(v8::Value* obj);
4514 };
4515 
4516 
4517 /**
4518  * A Symbol object (ECMA-262 edition 6).
4519  *
4520  * This is an experimental feature. Use at your own risk.
4521  */
4523  public:
4524  static Local<Value> New(Isolate* isolate, Local<Symbol> value);
4525 
4526  Local<Symbol> ValueOf() const;
4527 
4528  V8_INLINE static SymbolObject* Cast(v8::Value* obj);
4529 
4530  private:
4531  static void CheckCast(v8::Value* obj);
4532 };
4533 
4534 
4535 /**
4536  * An instance of the built-in RegExp constructor (ECMA-262, 15.10).
4537  */
4538 class V8_EXPORT RegExp : public Object {
4539  public:
4540  /**
4541  * Regular expression flag bits. They can be or'ed to enable a set
4542  * of flags.
4543  */
4544  enum Flags {
4545  kNone = 0,
4546  kGlobal = 1,
4549  kSticky = 8,
4551  };
4552 
4553  /**
4554  * Creates a regular expression from the given pattern string and
4555  * the flags bit field. May throw a JavaScript exception as
4556  * described in ECMA-262, 15.10.4.1.
4557  *
4558  * For example,
4559  * RegExp::New(v8::String::New("foo"),
4560  * static_cast<RegExp::Flags>(kGlobal | kMultiline))
4561  * is equivalent to evaluating "/foo/gm".
4562  */
4563  static V8_DEPRECATE_SOON("Use maybe version",
4564  Local<RegExp> New(Local<String> pattern,
4565  Flags flags));
4566  static V8_WARN_UNUSED_RESULT MaybeLocal<RegExp> New(Local<Context> context,
4567  Local<String> pattern,
4568  Flags flags);
4569 
4570  /**
4571  * Returns the value of the source property: a string representing
4572  * the regular expression.
4573  */
4574  Local<String> GetSource() const;
4575 
4576  /**
4577  * Returns the flags bit field.
4578  */
4579  Flags GetFlags() const;
4580 
4581  V8_INLINE static RegExp* Cast(v8::Value* obj);
4582 
4583  private:
4584  static void CheckCast(v8::Value* obj);
4585 };
4586 
4587 
4588 /**
4589  * A JavaScript value that wraps a C++ void*. This type of value is mainly used
4590  * to associate C++ data structures with JavaScript objects.
4591  */
4592 class V8_EXPORT External : public Value {
4593  public:
4594  static Local<External> New(Isolate* isolate, void* value);
4595  V8_INLINE static External* Cast(Value* obj);
4596  void* Value() const;
4597  private:
4598  static void CheckCast(v8::Value* obj);
4599 };
4600 
4601 
4602 #define V8_INTRINSICS_LIST(F) F(ArrayProto_values, array_values_iterator)
4603 
4605 #define V8_DECL_INTRINSIC(name, iname) k##name,
4607 #undef V8_DECL_INTRINSIC
4608 };
4609 
4610 
4611 // --- Templates ---
4612 
4613 
4614 /**
4615  * The superclass of object and function templates.
4616  */
4617 class V8_EXPORT Template : public Data {
4618  public:
4619  /**
4620  * Adds a property to each instance created by this template.
4621  *
4622  * The property must be defined either as a primitive value, or a template.
4623  */
4624  void Set(Local<Name> name, Local<Data> value,
4625  PropertyAttribute attributes = None);
4626  V8_INLINE void Set(Isolate* isolate, const char* name, Local<Data> value);
4627 
4628  void SetAccessorProperty(
4629  Local<Name> name,
4630  Local<FunctionTemplate> getter = Local<FunctionTemplate>(),
4631  Local<FunctionTemplate> setter = Local<FunctionTemplate>(),
4632  PropertyAttribute attribute = None,
4633  AccessControl settings = DEFAULT);
4634 
4635  /**
4636  * Whenever the property with the given name is accessed on objects
4637  * created from this Template the getter and setter callbacks
4638  * are called instead of getting and setting the property directly
4639  * on the JavaScript object.
4640  *
4641  * \param name The name of the property for which an accessor is added.
4642  * \param getter The callback to invoke when getting the property.
4643  * \param setter The callback to invoke when setting the property.
4644  * \param data A piece of data that will be passed to the getter and setter
4645  * callbacks whenever they are invoked.
4646  * \param settings Access control settings for the accessor. This is a bit
4647  * field consisting of one of more of
4648  * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2.
4649  * The default is to not allow cross-context access.
4650  * ALL_CAN_READ means that all cross-context reads are allowed.
4651  * ALL_CAN_WRITE means that all cross-context writes are allowed.
4652  * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all
4653  * cross-context access.
4654  * \param attribute The attributes of the property for which an accessor
4655  * is added.
4656  * \param signature The signature describes valid receivers for the accessor
4657  * and is used to perform implicit instance checks against them. If the
4658  * receiver is incompatible (i.e. is not an instance of the constructor as
4659  * defined by FunctionTemplate::HasInstance()), an implicit TypeError is
4660  * thrown and no callback is invoked.
4661  */
4662  void SetNativeDataProperty(
4663  Local<String> name, AccessorGetterCallback getter,
4664  AccessorSetterCallback setter = 0,
4665  // TODO(dcarney): gcc can't handle Local below
4666  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
4667  Local<AccessorSignature> signature = Local<AccessorSignature>(),
4668  AccessControl settings = DEFAULT);
4669  void SetNativeDataProperty(
4670  Local<Name> name, AccessorNameGetterCallback getter,
4671  AccessorNameSetterCallback setter = 0,
4672  // TODO(dcarney): gcc can't handle Local below
4673  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
4674  Local<AccessorSignature> signature = Local<AccessorSignature>(),
4675  AccessControl settings = DEFAULT);
4676 
4677  /**
4678  * During template instantiation, sets the value with the intrinsic property
4679  * from the correct context.
4680  */
4681  void SetIntrinsicDataProperty(Local<Name> name, Intrinsic intrinsic,
4682  PropertyAttribute attribute = None);
4683 
4684  private:
4685  Template();
4686 
4687  friend class ObjectTemplate;
4688  friend class FunctionTemplate;
4689 };
4690 
4691 
4692 /**
4693  * NamedProperty[Getter|Setter] are used as interceptors on object.
4694  * See ObjectTemplate::SetNamedPropertyHandler.
4695  */
4697  Local<String> property,
4698  const PropertyCallbackInfo<Value>& info);
4699 
4700 
4701 /**
4702  * Returns the value if the setter intercepts the request.
4703  * Otherwise, returns an empty handle.
4704  */
4706  Local<String> property,
4707  Local<Value> value,
4708  const PropertyCallbackInfo<Value>& info);
4709 
4710 
4711 /**
4712  * Returns a non-empty handle if the interceptor intercepts the request.
4713  * The result is an integer encoding property attributes (like v8::None,
4714  * v8::DontEnum, etc.)
4715  */
4717  Local<String> property,
4718  const PropertyCallbackInfo<Integer>& info);
4719 
4720 
4721 /**
4722  * Returns a non-empty handle if the deleter intercepts the request.
4723  * The return value is true if the property could be deleted and false
4724  * otherwise.
4725  */
4727  Local<String> property,
4728  const PropertyCallbackInfo<Boolean>& info);
4729 
4730 
4731 /**
4732  * Returns an array containing the names of the properties the named
4733  * property getter intercepts.
4734  */
4736  const PropertyCallbackInfo<Array>& info);
4737 
4738 
4739 // TODO(dcarney): Deprecate and remove previous typedefs, and replace
4740 // GenericNamedPropertyFooCallback with just NamedPropertyFooCallback.
4741 
4742 /**
4743  * Interceptor for get requests on an object.
4744  *
4745  * Use `info.GetReturnValue().Set()` to set the return value of the
4746  * intercepted get request.
4747  *
4748  * \param property The name of the property for which the request was
4749  * intercepted.
4750  * \param info Information about the intercepted request, such as
4751  * isolate, receiver, return value, or whether running in `'use strict`' mode.
4752  * See `PropertyCallbackInfo`.
4753  *
4754  * \code
4755  * void GetterCallback(
4756  * Local<Name> name,
4757  * const v8::PropertyCallbackInfo<v8::Value>& info) {
4758  * info.GetReturnValue().Set(v8_num(42));
4759  * }
4760  *
4761  * v8::Local<v8::FunctionTemplate> templ =
4762  * v8::FunctionTemplate::New(isolate);
4763  * templ->InstanceTemplate()->SetHandler(
4764  * v8::NamedPropertyHandlerConfiguration(GetterCallback));
4765  * LocalContext env;
4766  * env->Global()
4767  * ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local())
4768  * .ToLocalChecked()
4769  * ->NewInstance(env.local())
4770  * .ToLocalChecked())
4771  * .FromJust();
4772  * v8::Local<v8::Value> result = CompileRun("obj.a = 17; obj.a");
4773  * CHECK(v8_num(42)->Equals(env.local(), result).FromJust());
4774  * \endcode
4775  *
4776  * See also `ObjectTemplate::SetHandler`.
4777  */
4779  Local<Name> property, const PropertyCallbackInfo<Value>& info);
4780 
4781 /**
4782  * Interceptor for set requests on an object.
4783  *
4784  * Use `info.GetReturnValue()` to indicate whether the request was intercepted
4785  * or not. If the setter successfully intercepts the request, i.e., if the
4786  * request should not be further executed, call
4787  * `info.GetReturnValue().Set(value)`. If the setter
4788  * did not intercept the request, i.e., if the request should be handled as
4789  * if no interceptor is present, do not not call `Set()`.
4790  *
4791  * \param property The name of the property for which the request was
4792  * intercepted.
4793  * \param value The value which the property will have if the request
4794  * is not intercepted.
4795  * \param info Information about the intercepted request, such as
4796  * isolate, receiver, return value, or whether running in `'use strict'` mode.
4797  * See `PropertyCallbackInfo`.
4798  *
4799  * See also
4800  * `ObjectTemplate::SetHandler.`
4801  */
4803  Local<Name> property, Local<Value> value,
4804  const PropertyCallbackInfo<Value>& info);
4805 
4806 /**
4807  * Intercepts all requests that query the attributes of the
4808  * property, e.g., getOwnPropertyDescriptor(), propertyIsEnumerable(), and
4809  * defineProperty().
4810  *
4811  * Use `info.GetReturnValue().Set(value)` to set the property attributes. The
4812  * value is an interger encoding a `v8::PropertyAttribute`.
4813  *
4814  * \param property The name of the property for which the request was
4815  * intercepted.
4816  * \param info Information about the intercepted request, such as
4817  * isolate, receiver, return value, or whether running in `'use strict'` mode.
4818  * See `PropertyCallbackInfo`.
4819  *
4820  * \note Some functions query the property attributes internally, even though
4821  * they do not return the attributes. For example, `hasOwnProperty()` can
4822  * trigger this interceptor depending on the state of the object.
4823  *
4824  * See also
4825  * `ObjectTemplate::SetHandler.`
4826  */
4828  Local<Name> property, const PropertyCallbackInfo<Integer>& info);
4829 
4830 /**
4831  * Interceptor for delete requests on an object.
4832  *
4833  * Use `info.GetReturnValue()` to indicate whether the request was intercepted
4834  * or not. If the deleter successfully intercepts the request, i.e., if the
4835  * request should not be further executed, call
4836  * `info.GetReturnValue().Set(value)` with a boolean `value`. The `value` is
4837  * used as the return value of `delete`.
4838  *
4839  * \param property The name of the property for which the request was
4840  * intercepted.
4841  * \param info Information about the intercepted request, such as
4842  * isolate, receiver, return value, or whether running in `'use strict'` mode.
4843  * See `PropertyCallbackInfo`.
4844  *
4845  * \note If you need to mimic the behavior of `delete`, i.e., throw in strict
4846  * mode instead of returning false, use `info.ShouldThrowOnError()` to determine
4847  * if you are in strict mode.
4848  *
4849  * See also `ObjectTemplate::SetHandler.`
4850  */
4852  Local<Name> property, const PropertyCallbackInfo<Boolean>& info);
4853 
4854 
4855 /**
4856  * Returns an array containing the names of the properties the named
4857  * property getter intercepts.
4858  */
4860  const PropertyCallbackInfo<Array>& info);
4861 
4862 /**
4863  * Interceptor for defineProperty requests on an object.
4864  *
4865  * Use `info.GetReturnValue()` to indicate whether the request was intercepted
4866  * or not. If the definer successfully intercepts the request, i.e., if the
4867  * request should not be further executed, call
4868  * `info.GetReturnValue().Set(value)`. If the definer
4869  * did not intercept the request, i.e., if the request should be handled as
4870  * if no interceptor is present, do not not call `Set()`.
4871  *
4872  * \param property The name of the property for which the request was
4873  * intercepted.
4874  * \param desc The property descriptor which is used to define the
4875  * property if the request is not intercepted.
4876  * \param info Information about the intercepted request, such as
4877  * isolate, receiver, return value, or whether running in `'use strict'` mode.
4878  * See `PropertyCallbackInfo`.
4879  *
4880  * See also `ObjectTemplate::SetHandler`.
4881  */
4883  Local<Name> property, const PropertyDescriptor& desc,
4884  const PropertyCallbackInfo<Value>& info);
4885 
4886 /**
4887  * Interceptor for getOwnPropertyDescriptor requests on an object.
4888  *
4889  * Use `info.GetReturnValue().Set()` to set the return value of the
4890  * intercepted request. The return value must be an object that
4891  * can be converted to a PropertyDescriptor, e.g., a `v8::value` returned from
4892  * `v8::Object::getOwnPropertyDescriptor`.
4893  *
4894  * \param property The name of the property for which the request was
4895  * intercepted.
4896  * \info Information about the intercepted request, such as
4897  * isolate, receiver, return value, or whether running in `'use strict'` mode.
4898  * See `PropertyCallbackInfo`.
4899  *
4900  * \note If GetOwnPropertyDescriptor is intercepted, it will
4901  * always return true, i.e., indicate that the property was found.
4902  *
4903  * See also `ObjectTemplate::SetHandler`.
4904  */
4906  Local<Name> property, const PropertyCallbackInfo<Value>& info);
4907 
4908 /**
4909  * See `v8::GenericNamedPropertyGetterCallback`.
4910  */
4912  uint32_t index,
4913  const PropertyCallbackInfo<Value>& info);
4914 
4915 /**
4916  * See `v8::GenericNamedPropertySetterCallback`.
4917  */
4919  uint32_t index,
4920  Local<Value> value,
4921  const PropertyCallbackInfo<Value>& info);
4922 
4923 /**
4924  * See `v8::GenericNamedPropertyQueryCallback`.
4925  */
4927  uint32_t index,
4928  const PropertyCallbackInfo<Integer>& info);
4929 
4930 /**
4931  * See `v8::GenericNamedPropertyDeleterCallback`.
4932  */
4934  uint32_t index,
4935  const PropertyCallbackInfo<Boolean>& info);
4936 
4937 /**
4938  * See `v8::GenericNamedPropertyEnumeratorCallback`.
4939  */
4941  const PropertyCallbackInfo<Array>& info);
4942 
4943 /**
4944  * See `v8::GenericNamedPropertyDefinerCallback`.
4945  */
4947  uint32_t index, const PropertyDescriptor& desc,
4948  const PropertyCallbackInfo<Value>& info);
4949 
4950 /**
4951  * See `v8::GenericNamedPropertyDescriptorCallback`.
4952  */
4954  uint32_t index, const PropertyCallbackInfo<Value>& info);
4955 
4956 /**
4957  * Access type specification.
4958  */
4965 };
4966 
4967 
4968 /**
4969  * Returns true if the given context should be allowed to access the given
4970  * object.
4971  */
4972 typedef bool (*AccessCheckCallback)(Local<Context> accessing_context,
4973  Local<Object> accessed_object,
4974  Local<Value> data);
4975 
4976 /**
4977  * A FunctionTemplate is used to create functions at runtime. There
4978  * can only be one function created from a FunctionTemplate in a
4979  * context. The lifetime of the created function is equal to the
4980  * lifetime of the context. So in case the embedder needs to create
4981  * temporary functions that can be collected using Scripts is
4982  * preferred.
4983  *
4984  * Any modification of a FunctionTemplate after first instantiation will trigger
4985  * a crash.
4986  *
4987  * A FunctionTemplate can have properties, these properties are added to the
4988  * function object when it is created.
4989  *
4990  * A FunctionTemplate has a corresponding instance template which is
4991  * used to create object instances when the function is used as a
4992  * constructor. Properties added to the instance template are added to
4993  * each object instance.
4994  *
4995  * A FunctionTemplate can have a prototype template. The prototype template
4996  * is used to create the prototype object of the function.
4997  *
4998  * The following example shows how to use a FunctionTemplate:
4999  *
5000  * \code
5001  * v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
5002  * t->Set(isolate, "func_property", v8::Number::New(isolate, 1));
5003  *
5004  * v8::Local<v8::Template> proto_t = t->PrototypeTemplate();
5005  * proto_t->Set(isolate,
5006  * "proto_method",
5007  * v8::FunctionTemplate::New(isolate, InvokeCallback));
5008  * proto_t->Set(isolate, "proto_const", v8::Number::New(isolate, 2));
5009  *
5010  * v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate();
5011  * instance_t->SetAccessor(String::NewFromUtf8(isolate, "instance_accessor"),
5012  * InstanceAccessorCallback);
5013  * instance_t->SetNamedPropertyHandler(PropertyHandlerCallback);
5014  * instance_t->Set(String::NewFromUtf8(isolate, "instance_property"),
5015  * Number::New(isolate, 3));
5016  *
5017  * v8::Local<v8::Function> function = t->GetFunction();
5018  * v8::Local<v8::Object> instance = function->NewInstance();
5019  * \endcode
5020  *
5021  * Let's use "function" as the JS variable name of the function object
5022  * and "instance" for the instance object created above. The function
5023  * and the instance will have the following properties:
5024  *
5025  * \code
5026  * func_property in function == true;
5027  * function.func_property == 1;
5028  *
5029  * function.prototype.proto_method() invokes 'InvokeCallback'
5030  * function.prototype.proto_const == 2;
5031  *
5032  * instance instanceof function == true;
5033  * instance.instance_accessor calls 'InstanceAccessorCallback'
5034  * instance.instance_property == 3;
5035  * \endcode
5036  *
5037  * A FunctionTemplate can inherit from another one by calling the
5038  * FunctionTemplate::Inherit method. The following graph illustrates
5039  * the semantics of inheritance:
5040  *
5041  * \code
5042  * FunctionTemplate Parent -> Parent() . prototype -> { }
5043  * ^ ^
5044  * | Inherit(Parent) | .__proto__
5045  * | |
5046  * FunctionTemplate Child -> Child() . prototype -> { }
5047  * \endcode
5048  *
5049  * A FunctionTemplate 'Child' inherits from 'Parent', the prototype
5050  * object of the Child() function has __proto__ pointing to the
5051  * Parent() function's prototype object. An instance of the Child
5052  * function has all properties on Parent's instance templates.
5053  *
5054  * Let Parent be the FunctionTemplate initialized in the previous
5055  * section and create a Child FunctionTemplate by:
5056  *
5057  * \code
5058  * Local<FunctionTemplate> parent = t;
5059  * Local<FunctionTemplate> child = FunctionTemplate::New();
5060  * child->Inherit(parent);
5061  *
5062  * Local<Function> child_function = child->GetFunction();
5063  * Local<Object> child_instance = child_function->NewInstance();
5064  * \endcode
5065  *
5066  * The Child function and Child instance will have the following
5067  * properties:
5068  *
5069  * \code
5070  * child_func.prototype.__proto__ == function.prototype;
5071  * child_instance.instance_accessor calls 'InstanceAccessorCallback'
5072  * child_instance.instance_property == 3;
5073  * \endcode
5074  */
5076  public:
5077  /** Creates a function template.*/
5078  static Local<FunctionTemplate> New(
5079  Isolate* isolate, FunctionCallback callback = 0,
5080  Local<Value> data = Local<Value>(),
5081  Local<Signature> signature = Local<Signature>(), int length = 0,
5083 
5084  /** Get a template included in the snapshot by index. */
5085  static MaybeLocal<FunctionTemplate> FromSnapshot(Isolate* isolate,
5086  size_t index);
5087 
5088  /**
5089  * Creates a function template with a fast handler. If a fast handler is set,
5090  * the callback cannot be null.
5091  */
5092  static Local<FunctionTemplate> NewWithFastHandler(
5093  Isolate* isolate, FunctionCallback callback,
5094  experimental::FastAccessorBuilder* fast_handler = nullptr,
5095  Local<Value> data = Local<Value>(),
5096  Local<Signature> signature = Local<Signature>(), int length = 0);
5097 
5098  /** Returns the unique function instance in the current execution context.*/
5099  V8_DEPRECATE_SOON("Use maybe version", Local<Function> GetFunction());
5101  Local<Context> context);
5102 
5103  /**
5104  * Similar to Context::NewRemoteContext, this creates an instance that
5105  * isn't backed by an actual object.
5106  *
5107  * The InstanceTemplate of this FunctionTemplate must have access checks with
5108  * handlers installed.
5109  */
5111 
5112  /**
5113  * Set the call-handler callback for a FunctionTemplate. This
5114  * callback is called whenever the function created from this
5115  * FunctionTemplate is called.
5116  */
5117  void SetCallHandler(
5118  FunctionCallback callback, Local<Value> data = Local<Value>(),
5119  experimental::FastAccessorBuilder* fast_handler = nullptr);
5120 
5121  /** Set the predefined length property for the FunctionTemplate. */
5122  void SetLength(int length);
5123 
5124  /** Get the InstanceTemplate. */
5126 
5127  /** Causes the function template to inherit from a parent function template.*/
5128  void Inherit(Local<FunctionTemplate> parent);
5129 
5130  /**
5131  * A PrototypeTemplate is the template used to create the prototype object
5132  * of the function created by this template.
5133  */
5135 
5136  /**
5137  * Set the class name of the FunctionTemplate. This is used for
5138  * printing objects created with the function created from the
5139  * FunctionTemplate as its constructor.
5140  */
5141  void SetClassName(Local<String> name);
5142 
5143 
5144  /**
5145  * When set to true, no access check will be performed on the receiver of a
5146  * function call. Currently defaults to true, but this is subject to change.
5147  */
5148  void SetAcceptAnyReceiver(bool value);
5149 
5150  /**
5151  * Determines whether the __proto__ accessor ignores instances of
5152  * the function template. If instances of the function template are
5153  * ignored, __proto__ skips all instances and instead returns the
5154  * next object in the prototype chain.
5155  *
5156  * Call with a value of true to make the __proto__ accessor ignore
5157  * instances of the function template. Call with a value of false
5158  * to make the __proto__ accessor not ignore instances of the
5159  * function template. By default, instances of a function template
5160  * are not ignored.
5161  */
5162  void SetHiddenPrototype(bool value);
5163 
5164  /**
5165  * Sets the ReadOnly flag in the attributes of the 'prototype' property
5166  * of functions created from this FunctionTemplate to true.
5167  */
5168  void ReadOnlyPrototype();
5169 
5170  /**
5171  * Removes the prototype property from functions created from this
5172  * FunctionTemplate.
5173  */
5174  void RemovePrototype();
5175 
5176  /**
5177  * Returns true if the given object is an instance of this function
5178  * template.
5179  */
5180  bool HasInstance(Local<Value> object);
5181 
5182  private:
5183  FunctionTemplate();
5184  friend class Context;
5185  friend class ObjectTemplate;
5186 };
5187 
5188 /**
5189  * Configuration flags for v8::NamedPropertyHandlerConfiguration or
5190  * v8::IndexedPropertyHandlerConfiguration.
5191  */
5193  /**
5194  * None.
5195  */
5196  kNone = 0,
5197 
5198  /**
5199  * See ALL_CAN_READ above.
5200  */
5201  kAllCanRead = 1,
5202 
5203  /** Will not call into interceptor for properties on the receiver or prototype
5204  * chain, i.e., only call into interceptor for properties that do not exist.
5205  * Currently only valid for named interceptors.
5206  */
5207  kNonMasking = 1 << 1,
5208 
5209  /**
5210  * Will not call into interceptor for symbol lookup. Only meaningful for
5211  * named interceptors.
5212  */
5213  kOnlyInterceptStrings = 1 << 2,
5214 };
5215 
5218  /** Note: getter is required */
5224  Local<Value> data = Local<Value>(),
5226  : getter(getter),
5227  setter(setter),
5228  query(query),
5229  deleter(deleter),
5230  enumerator(enumerator),
5231  definer(0),
5232  descriptor(0),
5233  data(data),
5234  flags(flags) {}
5235 
5243  Local<Value> data = Local<Value>(),
5245  : getter(getter),