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