📄 v8.h.svn-base
字号:
private: // Make it impossible to create heap-allocated or illegal handle // scopes by disallowing certain operations. HandleScope(const HandleScope&); void operator=(const HandleScope&); void* operator new(size_t size); void operator delete(void*, size_t); class EXPORT Data { public: int extensions; void** next; void** limit; inline void Initialize() { extensions = -1; next = limit = NULL; } }; static Data current_; const Data previous_; /** * Re-establishes the previous scope state. Should be called only * once, and only for the current scope. */ void RestorePreviousState() { if (current_.extensions > 0) DeleteExtensions(); current_ = previous_;#ifdef DEBUG ZapRange(current_.next, current_.limit);#endif } // TODO(1245391): Consider creating a subclass for this. bool is_closed_; void** RawClose(void** value); /** Deallocates any extensions used by the current scope.*/ static void DeleteExtensions(); // Zaps the handles in the half-open interval [start, end). static void ZapRange(void** start, void** end); friend class ImplementationUtilities;};// --- S p e c i a l o b j e c t s ---/** * The superclass of values and API object templates. */class EXPORT Data { private: Data();};/** * Pre-compilation data that can be associated with a script. This * data can be calculated for a script in advance of actually * compiling it, and can be stored between compilations. When script * data is given to the compile method compilation will be faster. */class EXPORT ScriptData { // NOLINT public: virtual ~ScriptData() { } static ScriptData* PreCompile(const char* input, int length); static ScriptData* New(unsigned* data, int length); virtual int Length() = 0; virtual unsigned* Data() = 0;};/** * The origin, within a file, of a script. */class EXPORT ScriptOrigin { public: ScriptOrigin(Handle<Value> resource_name, Handle<Integer> resource_line_offset = Handle<Integer>(), Handle<Integer> resource_column_offset = Handle<Integer>()) : resource_name_(resource_name), resource_line_offset_(resource_line_offset), resource_column_offset_(resource_column_offset) { } inline Handle<Value> ResourceName(); inline Handle<Integer> ResourceLineOffset(); inline Handle<Integer> ResourceColumnOffset(); private: Handle<Value> resource_name_; Handle<Integer> resource_line_offset_; Handle<Integer> resource_column_offset_;};/** * A compiled JavaScript script. */class EXPORT Script { public: /** * Compiles the specified script. The ScriptOrigin* and ScriptData* * parameters are owned by the caller of Script::Compile. No * references to these objects are kept after compilation finishes. */ static Local<Script> Compile(Handle<String> source, ScriptOrigin* origin = NULL, ScriptData* pre_data = NULL); /** * Compiles the specified script using the specified file name * object (typically a string) as the script's origin. */ static Local<Script> Compile(Handle<String> source, Handle<Value> file_name); /** * Runs the script returning the resulting value. */ Local<Value> Run();};/** * An error message. */class EXPORT Message { public: Local<String> Get(); Local<String> GetSourceLine(); // TODO(1241256): Rewrite (or remove) this method. We don't want to // deal with ownership of the returned string and we want to use // JavaScript data structures exclusively. char* GetUnderline(char* source_line, char underline_char); Handle<String> GetScriptResourceName(); // TODO(1240903): Remove this when no longer used in WebKit V8 // bindings. Handle<Value> GetSourceData(); /** * Returns the number, 1-based, of the line where the error occurred. */ int GetLineNumber(); /** * Returns the index within the script of the first character where * the error occurred. */ int GetStartPosition(); /** * Returns the index within the script of the last character where * the error occurred. */ int GetEndPosition(); /** * Returns the index within the line of the first character where * the error occurred. */ int GetStartColumn(); /** * Returns the index within the line of the last character where * the error occurred. */ int GetEndColumn(); // TODO(1245381): Print to a string instead of on a FILE. static void PrintCurrentStackTrace(FILE* out);};// --- V a l u e ---/** * The superclass of all JavaScript values and objects. */class EXPORT Value : public Data { public: /** * Returns true if this value is the undefined value. See ECMA-262 * 4.3.10. */ bool IsUndefined(); /** * Returns true if this value is the null value. See ECMA-262 * 4.3.11. */ bool IsNull(); /** * Returns true if this value is true. */ bool IsTrue(); /** * Returns true if this value is false. */ bool IsFalse(); /** * Returns true if this value is an instance of the String type. * See ECMA-262 8.4. */ bool IsString(); /** * Returns true if this value is a function. */ bool IsFunction(); /** * Returns true if this value is an array. */ bool IsArray(); /** * Returns true if this value is an object. */ bool IsObject(); /** * Returns true if this value is boolean. */ bool IsBoolean(); /** * Returns true if this value is a number. */ bool IsNumber(); /** * Returns true if this value is external. */ bool IsExternal(); /** * Returns true if this value is a 32-bit signed integer. */ bool IsInt32(); Local<Boolean> ToBoolean(); Local<Number> ToNumber(); Local<String> ToString(); Local<String> ToDetailString(); Local<Object> ToObject(); Local<Integer> ToInteger(); Local<Uint32> ToUint32(); Local<Int32> ToInt32(); /** * Attempts to convert a string to an array index. * Returns an empty handle if the conversion fails. */ Local<Uint32> ToArrayIndex(); bool BooleanValue(); double NumberValue(); int64_t IntegerValue(); uint32_t Uint32Value(); int32_t Int32Value(); /** JS == */ bool Equals(Handle<Value> that); bool StrictEquals(Handle<Value> that);};/** * The superclass of primitive values. See ECMA-262 4.3.2. */class EXPORT Primitive : public Value { };/** * A primitive boolean value (ECMA-262, 4.3.14). Either the true * or false value. */class EXPORT Boolean : public Primitive { public: bool Value(); static inline Handle<Boolean> New(bool value);};/** * A JavaScript string value (ECMA-262, 4.3.17). */class EXPORT String : public Primitive { public: /** * Returns the number of characters in this string. */ int Length(); /** * Returns the number of bytes in the UTF-8 encoded * representation of this string. */ int Utf8Length(); /** * Write the contents of the string to an external buffer. * If no arguments are given, expects the buffer to be large * enough to hold the entire string and NULL terminator. Copies * the contents of the string and the NULL terminator into the * buffer. * * Copies up to length characters into the output buffer. * Only null-terminates if there is enough space in the buffer. * * \param buffer The buffer into which the string will be copied. * \param start The starting position within the string at which * copying begins. * \param length The number of bytes to copy from the string. * \return The number of characters copied to the buffer * excluding the NULL terminator. */ int Write(uint16_t* buffer, int start = 0, int length = -1); // UTF-16 int WriteAscii(char* buffer, int start = 0, int length = -1); // ASCII int WriteUtf8(char* buffer, int length = -1); // UTF-8 /** * Returns true if the string is external */ bool IsExternal(); /** * Returns true if the string is both external and ascii */ bool IsExternalAscii(); /** * An ExternalStringResource is a wrapper around a two-byte string * buffer that resides outside V8's heap. Implement an * ExternalStringResource to manage the life cycle of the underlying * buffer. Note that the string data must be immutable. */ class EXPORT ExternalStringResource { // NOLINT public: /** * Override the destructor to manage the life cycle of the underlying * buffer. */ virtual ~ExternalStringResource() {} /** The string data from the underlying buffer.*/ virtual const uint16_t* data() const = 0; /** The length of the string. That is, the number of two-byte characters.*/ virtual size_t length() const = 0; protected: ExternalStringResource() {} private: ExternalStringResource(const ExternalStringResource&); void operator=(const ExternalStringResource&); }; /** * An ExternalAsciiStringResource is a wrapper around an ascii * string buffer that resides outside V8's heap. Implement an * ExternalAsciiStringResource to manage the life cycle of the * underlying buffer. Note that the string data must be immutable * and that the data must be strict 7-bit ASCII, not Latin1 or * UTF-8, which would require special treatment internally in the * engine and, in the case of UTF-8, do not allow efficient indexing. * Use String::New or convert to 16 bit data for non-ASCII. */ class EXPORT ExternalAsciiStringResource { // NOLINT public: /** * Override the destructor to manage the life cycle of the underlying * buffer. */ virtual ~ExternalAsciiStringResource() {} /** The string data from the underlying buffer.*/ virtual const char* data() const = 0; /** The number of ascii characters in the string.*/ virtual size_t length() const = 0; protected: ExternalAsciiStringResource() {} private: ExternalAsciiStringResource(const ExternalAsciiStringResource&); void operator=(const ExternalAsciiStringResource&); }; /** * Get the ExternalStringResource for an external string. Only * valid if IsExternal() returns true. */ ExternalStringResource* GetExternalStringResource(); /** * Get the ExternalAsciiStringResource for an external ascii string. * Only valid if IsExternalAscii() returns true. */ ExternalAsciiStringResource* GetExternalAsciiStringResource(); static String* Cast(v8::Value* obj); /** * Allocates a new string from either utf-8 encoded or ascii data. * The second parameter 'length' gives the buffer length. * If the data is utf-8 encoded, the caller must * be careful to supply the length parameter. * If it is not given, the function calls * 'strlen' to determine the buffer length, it might be * wrong if 'data' contains a null character. */ static Local<String> New(const char* data, int length = -1); /** Allocates a new string from utf16 data.*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -