Permalink
Browse files

added v8

  • Loading branch information...
1 parent 8cafab4 commit 88d5425e6930b942e7cfc19942a473987b94783d @prsolucoes committed Sep 14, 2012
View
1 js/robot1.js
@@ -0,0 +1 @@
+var a = 1;
View
41 library/v8/.gitignore
@@ -0,0 +1,41 @@
+*.a
+*.exe
+*.idb
+*.lib
+*.log
+*.map
+*.mk
+*.ncb
+*.pdb
+*.pyc
+*.scons*
+*.sln
+*.so
+*.suo
+*.user
+*.vcproj
+*.xcodeproj
+#*#
+*~
+.cpplint-cache
+d8
+d8_g
+shell
+shell_g
+/build/Debug
+/build/gyp
+/build/Release
+/obj/
+/out/
+/test/es5conform/data
+/test/mozilla/data
+/test/sputnik/sputniktests
+/test/test262/data
+/third_party
+/tools/oom_dump/oom_dump
+/tools/oom_dump/oom_dump.o
+/tools/visual_studio/Debug
+/tools/visual_studio/Release
+/xcodebuild/
+TAGS
+*.Makefile
View
408 library/v8/mac/include/v8-debug.h
@@ -0,0 +1,408 @@
+// Copyright 2008 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef V8_V8_DEBUG_H_
+#define V8_V8_DEBUG_H_
+
+#include "v8.h"
+
+#ifdef _WIN32
+typedef int int32_t;
+typedef unsigned int uint32_t;
+typedef unsigned short uint16_t; // NOLINT
+typedef long long int64_t; // NOLINT
+
+// Setup for Windows DLL export/import. See v8.h in this directory for
+// information on how to build/use V8 as a DLL.
+#if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
+#error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
+ build configuration to ensure that at most one of these is set
+#endif
+
+#ifdef BUILDING_V8_SHARED
+#define EXPORT __declspec(dllexport)
+#elif USING_V8_SHARED
+#define EXPORT __declspec(dllimport)
+#else
+#define EXPORT
+#endif
+
+#else // _WIN32
+
+// Setup for Linux shared library export. See v8.h in this directory for
+// information on how to build/use V8 as shared library.
+#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(V8_SHARED)
+#define EXPORT __attribute__ ((visibility("default")))
+#else // defined(__GNUC__) && (__GNUC__ >= 4)
+#define EXPORT
+#endif // defined(__GNUC__) && (__GNUC__ >= 4)
+
+#endif // _WIN32
+
+
+/**
+ * Debugger support for the V8 JavaScript engine.
+ */
+namespace v8 {
+
+// Debug events which can occur in the V8 JavaScript engine.
+enum DebugEvent {
+ Break = 1,
+ Exception = 2,
+ NewFunction = 3,
+ BeforeCompile = 4,
+ AfterCompile = 5,
+ ScriptCollected = 6,
+ BreakForCommand = 7
+};
+
+
+class EXPORT Debug {
+ public:
+ /**
+ * A client object passed to the v8 debugger whose ownership will be taken by
+ * it. v8 is always responsible for deleting the object.
+ */
+ class ClientData {
+ public:
+ virtual ~ClientData() {}
+ };
+
+
+ /**
+ * A message object passed to the debug message handler.
+ */
+ class Message {
+ public:
+ /**
+ * Check type of message.
+ */
+ virtual bool IsEvent() const = 0;
+ virtual bool IsResponse() const = 0;
+ virtual DebugEvent GetEvent() const = 0;
+
+ /**
+ * Indicate whether this is a response to a continue command which will
+ * start the VM running after this is processed.
+ */
+ virtual bool WillStartRunning() const = 0;
+
+ /**
+ * Access to execution state and event data. Don't store these cross
+ * callbacks as their content becomes invalid. These objects are from the
+ * debugger event that started the debug message loop.
+ */
+ virtual Handle<Object> GetExecutionState() const = 0;
+ virtual Handle<Object> GetEventData() const = 0;
+
+ /**
+ * Get the debugger protocol JSON.
+ */
+ virtual Handle<String> GetJSON() const = 0;
+
+ /**
+ * Get the context active when the debug event happened. Note this is not
+ * the current active context as the JavaScript part of the debugger is
+ * running in its own context which is entered at this point.
+ */
+ virtual Handle<Context> GetEventContext() const = 0;
+
+ /**
+ * Client data passed with the corresponding request if any. This is the
+ * client_data data value passed into Debug::SendCommand along with the
+ * request that led to the message or NULL if the message is an event. The
+ * debugger takes ownership of the data and will delete it even if there is
+ * no message handler.
+ */
+ virtual ClientData* GetClientData() const = 0;
+
+ virtual ~Message() {}
+ };
+
+
+ /**
+ * An event details object passed to the debug event listener.
+ */
+ class EventDetails {
+ public:
+ /**
+ * Event type.
+ */
+ virtual DebugEvent GetEvent() const = 0;
+
+ /**
+ * Access to execution state and event data of the debug event. Don't store
+ * these cross callbacks as their content becomes invalid.
+ */
+ virtual Handle<Object> GetExecutionState() const = 0;
+ virtual Handle<Object> GetEventData() const = 0;
+
+ /**
+ * Get the context active when the debug event happened. Note this is not
+ * the current active context as the JavaScript part of the debugger is
+ * running in its own context which is entered at this point.
+ */
+ virtual Handle<Context> GetEventContext() const = 0;
+
+ /**
+ * Client data passed with the corresponding callback when it was
+ * registered.
+ */
+ virtual Handle<Value> GetCallbackData() const = 0;
+
+ /**
+ * Client data passed to DebugBreakForCommand function. The
+ * debugger takes ownership of the data and will delete it even if
+ * there is no message handler.
+ */
+ virtual ClientData* GetClientData() const = 0;
+
+ virtual ~EventDetails() {}
+ };
+
+
+ /**
+ * Debug event callback function.
+ *
+ * \param event the type of the debug event that triggered the callback
+ * (enum DebugEvent)
+ * \param exec_state execution state (JavaScript object)
+ * \param event_data event specific data (JavaScript object)
+ * \param data value passed by the user to SetDebugEventListener
+ */
+ typedef void (*EventCallback)(DebugEvent event,
+ Handle<Object> exec_state,
+ Handle<Object> event_data,
+ Handle<Value> data);
+
+ /**
+ * Debug event callback function.
+ *
+ * \param event_details object providing information about the debug event
+ *
+ * A EventCallback2 does not take possession of the event data,
+ * and must not rely on the data persisting after the handler returns.
+ */
+ typedef void (*EventCallback2)(const EventDetails& event_details);
+
+ /**
+ * Debug message callback function.
+ *
+ * \param message the debug message handler message object
+ * \param length length of the message
+ * \param client_data the data value passed when registering the message handler
+
+ * A MessageHandler does not take possession of the message string,
+ * and must not rely on the data persisting after the handler returns.
+ *
+ * This message handler is deprecated. Use MessageHandler2 instead.
+ */
+ typedef void (*MessageHandler)(const uint16_t* message, int length,
+ ClientData* client_data);
+
+ /**
+ * Debug message callback function.
+ *
+ * \param message the debug message handler message object
+ *
+ * A MessageHandler does not take possession of the message data,
+ * and must not rely on the data persisting after the handler returns.
+ */
+ typedef void (*MessageHandler2)(const Message& message);
+
+ /**
+ * Debug host dispatch callback function.
+ */
+ typedef void (*HostDispatchHandler)();
+
+ /**
+ * Callback function for the host to ensure debug messages are processed.
+ */
+ typedef void (*DebugMessageDispatchHandler)();
+
+ // Set a C debug event listener.
+ static bool SetDebugEventListener(EventCallback that,
+ Handle<Value> data = Handle<Value>());
+ static bool SetDebugEventListener2(EventCallback2 that,
+ Handle<Value> data = Handle<Value>());
+
+ // Set a JavaScript debug event listener.
+ static bool SetDebugEventListener(v8::Handle<v8::Object> that,
+ Handle<Value> data = Handle<Value>());
+
+ // Schedule a debugger break to happen when JavaScript code is run
+ // in the given isolate. If no isolate is provided the default
+ // isolate is used.
+ static void DebugBreak(Isolate* isolate = NULL);
+
+ // Remove scheduled debugger break in given isolate if it has not
+ // happened yet. If no isolate is provided the default isolate is
+ // used.
+ static void CancelDebugBreak(Isolate* isolate = NULL);
+
+ // Break execution of JavaScript in the given isolate (this method
+ // can be invoked from a non-VM thread) for further client command
+ // execution on a VM thread. Client data is then passed in
+ // EventDetails to EventCallback at the moment when the VM actually
+ // stops. If no isolate is provided the default isolate is used.
+ static void DebugBreakForCommand(ClientData* data = NULL,
+ Isolate* isolate = NULL);
+
+ // Message based interface. The message protocol is JSON. NOTE the message
+ // handler thread is not supported any more parameter must be false.
+ static void SetMessageHandler(MessageHandler handler,
+ bool message_handler_thread = false);
+ static void SetMessageHandler2(MessageHandler2 handler);
+
+ // If no isolate is provided the default isolate is
+ // used.
+ static void SendCommand(const uint16_t* command, int length,
+ ClientData* client_data = NULL,
+ Isolate* isolate = NULL);
+
+ // Dispatch interface.
+ static void SetHostDispatchHandler(HostDispatchHandler handler,
+ int period = 100);
+
+ /**
+ * Register a callback function to be called when a debug message has been
+ * received and is ready to be processed. For the debug messages to be
+ * processed V8 needs to be entered, and in certain embedding scenarios this
+ * callback can be used to make sure V8 is entered for the debug message to
+ * be processed. Note that debug messages will only be processed if there is
+ * a V8 break. This can happen automatically by using the option
+ * --debugger-auto-break.
+ * \param provide_locker requires that V8 acquires v8::Locker for you before
+ * calling handler
+ */
+ static void SetDebugMessageDispatchHandler(
+ DebugMessageDispatchHandler handler, bool provide_locker = false);
+
+ /**
+ * Run a JavaScript function in the debugger.
+ * \param fun the function to call
+ * \param data passed as second argument to the function
+ * With this call the debugger is entered and the function specified is called
+ * with the execution state as the first argument. This makes it possible to
+ * get access to information otherwise not available during normal JavaScript
+ * execution e.g. details on stack frames. Receiver of the function call will
+ * be the debugger context global object, however this is a subject to change.
+ * The following example shows a JavaScript function which when passed to
+ * v8::Debug::Call will return the current line of JavaScript execution.
+ *
+ * \code
+ * function frame_source_line(exec_state) {
+ * return exec_state.frame(0).sourceLine();
+ * }
+ * \endcode
+ */
+ static Local<Value> Call(v8::Handle<v8::Function> fun,
+ Handle<Value> data = Handle<Value>());
+
+ /**
+ * Returns a mirror object for the given object.
+ */
+ static Local<Value> GetMirror(v8::Handle<v8::Value> obj);
+
+ /**
+ * Enable the V8 builtin debug agent. The debugger agent will listen on the
+ * supplied TCP/IP port for remote debugger connection.
+ * \param name the name of the embedding application
+ * \param port the TCP/IP port to listen on
+ * \param wait_for_connection whether V8 should pause on a first statement
+ * allowing remote debugger to connect before anything interesting happened
+ */
+ static bool EnableAgent(const char* name, int port,
+ bool wait_for_connection = false);
+
+ /**
+ * Disable the V8 builtin debug agent. The TCP/IP connection will be closed.
+ */
+ static void DisableAgent();
+
+ /**
+ * Makes V8 process all pending debug messages.
+ *
+ * From V8 point of view all debug messages come asynchronously (e.g. from
+ * remote debugger) but they all must be handled synchronously: V8 cannot
+ * do 2 things at one time so normal script execution must be interrupted
+ * for a while.
+ *
+ * Generally when message arrives V8 may be in one of 3 states:
+ * 1. V8 is running script; V8 will automatically interrupt and process all
+ * pending messages (however auto_break flag should be enabled);
+ * 2. V8 is suspended on debug breakpoint; in this state V8 is dedicated
+ * to reading and processing debug messages;
+ * 3. V8 is not running at all or has called some long-working C++ function;
+ * by default it means that processing of all debug messages will be deferred
+ * until V8 gets control again; however, embedding application may improve
+ * this by manually calling this method.
+ *
+ * It makes sense to call this method whenever a new debug message arrived and
+ * V8 is not already running. Method v8::Debug::SetDebugMessageDispatchHandler
+ * should help with the former condition.
+ *
+ * Technically this method in many senses is equivalent to executing empty
+ * script:
+ * 1. It does nothing except for processing all pending debug messages.
+ * 2. It should be invoked with the same precautions and from the same context
+ * as V8 script would be invoked from, because:
+ * a. with "evaluate" command it can do whatever normal script can do,
+ * including all native calls;
+ * b. no other thread should call V8 while this method is running
+ * (v8::Locker may be used here).
+ *
+ * "Evaluate" debug command behavior currently is not specified in scope
+ * of this method.
+ */
+ static void ProcessDebugMessages();
+
+ /**
+ * Debugger is running in its own context which is entered while debugger
+ * messages are being dispatched. This is an explicit getter for this
+ * debugger context. Note that the content of the debugger context is subject
+ * to change.
+ */
+ static Local<Context> GetDebugContext();
+
+
+ /**
+ * Enable/disable LiveEdit functionality for the given Isolate
+ * (default Isolate if not provided). V8 will abort if LiveEdit is
+ * unexpectedly used. LiveEdit is enabled by default.
+ */
+ static void SetLiveEditEnabled(bool enable, Isolate* isolate = NULL);
+};
+
+
+} // namespace v8
+
+
+#undef EXPORT
+
+
+#endif // V8_V8_DEBUG_H_
View
118 library/v8/mac/include/v8-preparser.h
@@ -0,0 +1,118 @@
+// Copyright 2011 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef PREPARSER_H
+#define PREPARSER_H
+
+#include "v8stdint.h"
+
+#ifdef _WIN32
+
+// Setup for Windows DLL export/import. When building the V8 DLL the
+// BUILDING_V8_SHARED needs to be defined. When building a program which uses
+// the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
+// static library or building a program which uses the V8 static library neither
+// BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
+#if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
+#error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
+ build configuration to ensure that at most one of these is set
+#endif
+
+#ifdef BUILDING_V8_SHARED
+#define V8EXPORT __declspec(dllexport)
+#elif USING_V8_SHARED
+#define V8EXPORT __declspec(dllimport)
+#else
+#define V8EXPORT
+#endif // BUILDING_V8_SHARED
+
+#else // _WIN32
+
+// Setup for Linux shared library export. There is no need to distinguish
+// between building or using the V8 shared library, but we should not
+// export symbols when we are building a static library.
+#if defined(__GNUC__) && ((__GNUC__ >= 4) || \
+ (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(V8_SHARED)
+#define V8EXPORT __attribute__ ((visibility("default")))
+#else
+#define V8EXPORT
+#endif
+
+#endif // _WIN32
+
+
+namespace v8 {
+
+// The result of preparsing is either a stack overflow error, or an opaque
+// blob of data that can be passed back into the parser.
+class V8EXPORT PreParserData {
+ public:
+ PreParserData(size_t size, const uint8_t* data)
+ : data_(data), size_(size) { }
+
+ // Create a PreParserData value where stack_overflow reports true.
+ static PreParserData StackOverflow() { return PreParserData(0, NULL); }
+
+ // Whether the pre-parser stopped due to a stack overflow.
+ // If this is the case, size() and data() should not be used.
+ bool stack_overflow() { return size_ == 0u; }
+
+ // The size of the data in bytes.
+ size_t size() const { return size_; }
+
+ // Pointer to the data.
+ const uint8_t* data() const { return data_; }
+
+ private:
+ const uint8_t* const data_;
+ const size_t size_;
+};
+
+
+// Interface for a stream of Unicode characters.
+class V8EXPORT UnicodeInputStream { // NOLINT - Thinks V8EXPORT is class name.
+ public:
+ virtual ~UnicodeInputStream();
+
+ // Returns the next Unicode code-point in the input, or a negative value when
+ // there is no more input in the stream.
+ virtual int32_t Next() = 0;
+};
+
+
+// Preparse a JavaScript program. The source code is provided as a
+// UnicodeInputStream. The max_stack_size limits the amount of stack
+// space that the preparser is allowed to use. If the preparser uses
+// more stack space than the limit provided, the result's stack_overflow()
+// method will return true. Otherwise the result contains preparser
+// data that can be used by the V8 parser to speed up parsing.
+PreParserData V8EXPORT Preparse(UnicodeInputStream* input,
+ size_t max_stack_size);
+
+} // namespace v8.
+
+#endif // PREPARSER_H
View
565 library/v8/mac/include/v8-profiler.h
@@ -0,0 +1,565 @@
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef V8_V8_PROFILER_H_
+#define V8_V8_PROFILER_H_
+
+#include "v8.h"
+
+#ifdef _WIN32
+// Setup for Windows DLL export/import. See v8.h in this directory for
+// information on how to build/use V8 as a DLL.
+#if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
+#error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
+ build configuration to ensure that at most one of these is set
+#endif
+
+#ifdef BUILDING_V8_SHARED
+#define V8EXPORT __declspec(dllexport)
+#elif USING_V8_SHARED
+#define V8EXPORT __declspec(dllimport)
+#else
+#define V8EXPORT
+#endif
+
+#else // _WIN32
+
+// Setup for Linux shared library export. See v8.h in this directory for
+// information on how to build/use V8 as shared library.
+#if defined(__GNUC__) && ((__GNUC__ >= 4) || \
+ (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(V8_SHARED)
+#define V8EXPORT __attribute__ ((visibility("default")))
+#else
+#define V8EXPORT
+#endif
+
+#endif // _WIN32
+
+
+/**
+ * Profiler support for the V8 JavaScript engine.
+ */
+namespace v8 {
+
+typedef uint32_t SnapshotObjectId;
+
+/**
+ * CpuProfileNode represents a node in a call graph.
+ */
+class V8EXPORT CpuProfileNode {
+ public:
+ /** Returns function name (empty string for anonymous functions.) */
+ Handle<String> GetFunctionName() const;
+
+ /** Returns resource name for script from where the function originates. */
+ Handle<String> GetScriptResourceName() const;
+
+ /**
+ * Returns the number, 1-based, of the line where the function originates.
+ * kNoLineNumberInfo if no line number information is available.
+ */
+ int GetLineNumber() const;
+
+ /**
+ * Returns total (self + children) execution time of the function,
+ * in milliseconds, estimated by samples count.
+ */
+ double GetTotalTime() const;
+
+ /**
+ * Returns self execution time of the function, in milliseconds,
+ * estimated by samples count.
+ */
+ double GetSelfTime() const;
+
+ /** Returns the count of samples where function exists. */
+ double GetTotalSamplesCount() const;
+
+ /** Returns the count of samples where function was currently executing. */
+ double GetSelfSamplesCount() const;
+
+ /** Returns function entry UID. */
+ unsigned GetCallUid() const;
+
+ /** Returns child nodes count of the node. */
+ int GetChildrenCount() const;
+
+ /** Retrieves a child node by index. */
+ const CpuProfileNode* GetChild(int index) const;
+
+ static const int kNoLineNumberInfo = Message::kNoLineNumberInfo;
+};
+
+
+/**
+ * CpuProfile contains a CPU profile in a form of two call trees:
+ * - top-down (from main() down to functions that do all the work);
+ * - bottom-up call graph (in backward direction).
+ */
+class V8EXPORT CpuProfile {
+ public:
+ /** Returns CPU profile UID (assigned by the profiler.) */
+ unsigned GetUid() const;
+
+ /** Returns CPU profile title. */
+ Handle<String> GetTitle() const;
+
+ /** Returns the root node of the bottom up call tree. */
+ const CpuProfileNode* GetBottomUpRoot() const;
+
+ /** Returns the root node of the top down call tree. */
+ const CpuProfileNode* GetTopDownRoot() const;
+
+ /**
+ * Deletes the profile and removes it from CpuProfiler's list.
+ * All pointers to nodes previously returned become invalid.
+ * Profiles with the same uid but obtained using different
+ * security token are not deleted, but become inaccessible
+ * using FindProfile method. It is embedder's responsibility
+ * to call Delete on these profiles.
+ */
+ void Delete();
+};
+
+
+/**
+ * Interface for controlling CPU profiling.
+ */
+class V8EXPORT CpuProfiler {
+ public:
+ /**
+ * A note on security tokens usage. As scripts from different
+ * origins can run inside a single V8 instance, it is possible to
+ * have functions from different security contexts intermixed in a
+ * single CPU profile. To avoid exposing function names belonging to
+ * other contexts, filtering by security token is performed while
+ * obtaining profiling results.
+ */
+
+ /**
+ * Returns the number of profiles collected (doesn't include
+ * profiles that are being collected at the moment of call.)
+ */
+ static int GetProfilesCount();
+
+ /** Returns a profile by index. */
+ static const CpuProfile* GetProfile(
+ int index,
+ Handle<Value> security_token = Handle<Value>());
+
+ /** Returns a profile by uid. */
+ static const CpuProfile* FindProfile(
+ unsigned uid,
+ Handle<Value> security_token = Handle<Value>());
+
+ /**
+ * Starts collecting CPU profile. Title may be an empty string. It
+ * is allowed to have several profiles being collected at
+ * once. Attempts to start collecting several profiles with the same
+ * title are silently ignored. While collecting a profile, functions
+ * from all security contexts are included in it. The token-based
+ * filtering is only performed when querying for a profile.
+ */
+ static void StartProfiling(Handle<String> title);
+
+ /**
+ * Stops collecting CPU profile with a given title and returns it.
+ * If the title given is empty, finishes the last profile started.
+ */
+ static const CpuProfile* StopProfiling(
+ Handle<String> title,
+ Handle<Value> security_token = Handle<Value>());
+
+ /**
+ * Deletes all existing profiles, also cancelling all profiling
+ * activity. All previously returned pointers to profiles and their
+ * contents become invalid after this call.
+ */
+ static void DeleteAllProfiles();
+};
+
+
+class HeapGraphNode;
+
+
+/**
+ * HeapSnapshotEdge represents a directed connection between heap
+ * graph nodes: from retainers to retained nodes.
+ */
+class V8EXPORT HeapGraphEdge {
+ public:
+ enum Type {
+ kContextVariable = 0, // A variable from a function context.
+ kElement = 1, // An element of an array.
+ kProperty = 2, // A named object property.
+ kInternal = 3, // A link that can't be accessed from JS,
+ // thus, its name isn't a real property name
+ // (e.g. parts of a ConsString).
+ kHidden = 4, // A link that is needed for proper sizes
+ // calculation, but may be hidden from user.
+ kShortcut = 5, // A link that must not be followed during
+ // sizes calculation.
+ kWeak = 6 // A weak reference (ignored by the GC).
+ };
+
+ /** Returns edge type (see HeapGraphEdge::Type). */
+ Type GetType() const;
+
+ /**
+ * Returns edge name. This can be a variable name, an element index, or
+ * a property name.
+ */
+ Handle<Value> GetName() const;
+
+ /** Returns origin node. */
+ const HeapGraphNode* GetFromNode() const;
+
+ /** Returns destination node. */
+ const HeapGraphNode* GetToNode() const;
+};
+
+
+/**
+ * HeapGraphNode represents a node in a heap graph.
+ */
+class V8EXPORT HeapGraphNode {
+ public:
+ enum Type {
+ kHidden = 0, // Hidden node, may be filtered when shown to user.
+ kArray = 1, // An array of elements.
+ kString = 2, // A string.
+ kObject = 3, // A JS object (except for arrays and strings).
+ kCode = 4, // Compiled code.
+ kClosure = 5, // Function closure.
+ kRegExp = 6, // RegExp.
+ kHeapNumber = 7, // Number stored in the heap.
+ kNative = 8, // Native object (not from V8 heap).
+ kSynthetic = 9 // Synthetic object, usualy used for grouping
+ // snapshot items together.
+ };
+
+ /** Returns node type (see HeapGraphNode::Type). */
+ Type GetType() const;
+
+ /**
+ * Returns node name. Depending on node's type this can be the name
+ * of the constructor (for objects), the name of the function (for
+ * closures), string value, or an empty string (for compiled code).
+ */
+ Handle<String> GetName() const;
+
+ /**
+ * Returns node id. For the same heap object, the id remains the same
+ * across all snapshots.
+ */
+ SnapshotObjectId GetId() const;
+
+ /** Returns node's own size, in bytes. */
+ int GetSelfSize() const;
+
+ /** Returns child nodes count of the node. */
+ int GetChildrenCount() const;
+
+ /** Retrieves a child by index. */
+ const HeapGraphEdge* GetChild(int index) const;
+
+ /**
+ * Finds and returns a value from the heap corresponding to this node,
+ * if the value is still reachable.
+ */
+ Handle<Value> GetHeapValue() const;
+};
+
+
+/**
+ * HeapSnapshots record the state of the JS heap at some moment.
+ */
+class V8EXPORT HeapSnapshot {
+ public:
+ enum Type {
+ kFull = 0 // Heap snapshot with all instances and references.
+ };
+ enum SerializationFormat {
+ kJSON = 0 // See format description near 'Serialize' method.
+ };
+
+ /** Returns heap snapshot type. */
+ Type GetType() const;
+
+ /** Returns heap snapshot UID (assigned by the profiler.) */
+ unsigned GetUid() const;
+
+ /** Returns heap snapshot title. */
+ Handle<String> GetTitle() const;
+
+ /** Returns the root node of the heap graph. */
+ const HeapGraphNode* GetRoot() const;
+
+ /** Returns a node by its id. */
+ const HeapGraphNode* GetNodeById(SnapshotObjectId id) const;
+
+ /** Returns total nodes count in the snapshot. */
+ int GetNodesCount() const;
+
+ /** Returns a node by index. */
+ const HeapGraphNode* GetNode(int index) const;
+
+ /** Returns a max seen JS object Id. */
+ SnapshotObjectId GetMaxSnapshotJSObjectId() const;
+
+ /**
+ * Deletes the snapshot and removes it from HeapProfiler's list.
+ * All pointers to nodes, edges and paths previously returned become
+ * invalid.
+ */
+ void Delete();
+
+ /**
+ * Prepare a serialized representation of the snapshot. The result
+ * is written into the stream provided in chunks of specified size.
+ * The total length of the serialized snapshot is unknown in
+ * advance, it can be roughly equal to JS heap size (that means,
+ * it can be really big - tens of megabytes).
+ *
+ * For the JSON format, heap contents are represented as an object
+ * with the following structure:
+ *
+ * {
+ * snapshot: {
+ * title: "...",
+ * uid: nnn,
+ * meta: { meta-info },
+ * node_count: nnn,
+ * edge_count: nnn
+ * },
+ * nodes: [nodes array],
+ * edges: [edges array],
+ * strings: [strings array]
+ * }
+ *
+ * Nodes reference strings, other nodes, and edges by their indexes
+ * in corresponding arrays.
+ */
+ void Serialize(OutputStream* stream, SerializationFormat format) const;
+};
+
+
+class RetainedObjectInfo;
+
+/**
+ * Interface for controlling heap profiling.
+ */
+class V8EXPORT HeapProfiler {
+ public:
+ /**
+ * Callback function invoked for obtaining RetainedObjectInfo for
+ * the given JavaScript wrapper object. It is prohibited to enter V8
+ * while the callback is running: only getters on the handle and
+ * GetPointerFromInternalField on the objects are allowed.
+ */
+ typedef RetainedObjectInfo* (*WrapperInfoCallback)
+ (uint16_t class_id, Handle<Value> wrapper);
+
+ /** Returns the number of snapshots taken. */
+ static int GetSnapshotsCount();
+
+ /** Returns a snapshot by index. */
+ static const HeapSnapshot* GetSnapshot(int index);
+
+ /** Returns a profile by uid. */
+ static const HeapSnapshot* FindSnapshot(unsigned uid);
+
+ /**
+ * Returns SnapshotObjectId for a heap object referenced by |value| if
+ * it has been seen by the heap profiler, kUnknownObjectId otherwise.
+ */
+ static SnapshotObjectId GetSnapshotObjectId(Handle<Value> value);
+
+ /**
+ * A constant for invalid SnapshotObjectId. GetSnapshotObjectId will return
+ * it in case heap profiler cannot find id for the object passed as
+ * parameter. HeapSnapshot::GetNodeById will always return NULL for such id.
+ */
+ static const SnapshotObjectId kUnknownObjectId = 0;
+
+ /**
+ * Takes a heap snapshot and returns it. Title may be an empty string.
+ * See HeapSnapshot::Type for types description.
+ */
+ static const HeapSnapshot* TakeSnapshot(
+ Handle<String> title,
+ HeapSnapshot::Type type = HeapSnapshot::kFull,
+ ActivityControl* control = NULL);
+
+ /**
+ * Starts tracking of heap objects population statistics. After calling
+ * this method, all heap objects relocations done by the garbage collector
+ * are being registered.
+ */
+ static void StartHeapObjectsTracking();
+
+ /**
+ * Adds a new time interval entry to the aggregated statistics array. The
+ * time interval entry contains information on the current heap objects
+ * population size. The method also updates aggregated statistics and
+ * reports updates for all previous time intervals via the OutputStream
+ * object. Updates on each time interval are provided as a stream of the
+ * HeapStatsUpdate structure instances.
+ * The return value of the function is the last seen heap object Id.
+ *
+ * StartHeapObjectsTracking must be called before the first call to this
+ * method.
+ */
+ static SnapshotObjectId PushHeapObjectsStats(OutputStream* stream);
+
+ /**
+ * Stops tracking of heap objects population statistics, cleans up all
+ * collected data. StartHeapObjectsTracking must be called again prior to
+ * calling PushHeapObjectsStats next time.
+ */
+ static void StopHeapObjectsTracking();
+
+ /**
+ * Deletes all snapshots taken. All previously returned pointers to
+ * snapshots and their contents become invalid after this call.
+ */
+ static void DeleteAllSnapshots();
+
+ /** Binds a callback to embedder's class ID. */
+ static void DefineWrapperClass(
+ uint16_t class_id,
+ WrapperInfoCallback callback);
+
+ /**
+ * Default value of persistent handle class ID. Must not be used to
+ * define a class. Can be used to reset a class of a persistent
+ * handle.
+ */
+ static const uint16_t kPersistentHandleNoClassId = 0;
+
+ /** Returns the number of currently existing persistent handles. */
+ static int GetPersistentHandleCount();
+
+ /** Returns memory used for profiler internal data and snapshots. */
+ static size_t GetMemorySizeUsedByProfiler();
+};
+
+
+/**
+ * Interface for providing information about embedder's objects
+ * held by global handles. This information is reported in two ways:
+ *
+ * 1. When calling AddObjectGroup, an embedder may pass
+ * RetainedObjectInfo instance describing the group. To collect
+ * this information while taking a heap snapshot, V8 calls GC
+ * prologue and epilogue callbacks.
+ *
+ * 2. When a heap snapshot is collected, V8 additionally
+ * requests RetainedObjectInfos for persistent handles that
+ * were not previously reported via AddObjectGroup.
+ *
+ * Thus, if an embedder wants to provide information about native
+ * objects for heap snapshots, he can do it in a GC prologue
+ * handler, and / or by assigning wrapper class ids in the following way:
+ *
+ * 1. Bind a callback to class id by calling DefineWrapperClass.
+ * 2. Call SetWrapperClassId on certain persistent handles.
+ *
+ * V8 takes ownership of RetainedObjectInfo instances passed to it and
+ * keeps them alive only during snapshot collection. Afterwards, they
+ * are freed by calling the Dispose class function.
+ */
+class V8EXPORT RetainedObjectInfo { // NOLINT
+ public:
+ /** Called by V8 when it no longer needs an instance. */
+ virtual void Dispose() = 0;
+
+ /** Returns whether two instances are equivalent. */
+ virtual bool IsEquivalent(RetainedObjectInfo* other) = 0;
+
+ /**
+ * Returns hash value for the instance. Equivalent instances
+ * must have the same hash value.
+ */
+ virtual intptr_t GetHash() = 0;
+
+ /**
+ * Returns human-readable label. It must be a null-terminated UTF-8
+ * encoded string. V8 copies its contents during a call to GetLabel.
+ */
+ virtual const char* GetLabel() = 0;
+
+ /**
+ * Returns human-readable group label. It must be a null-terminated UTF-8
+ * encoded string. V8 copies its contents during a call to GetGroupLabel.
+ * Heap snapshot generator will collect all the group names, create
+ * top level entries with these names and attach the objects to the
+ * corresponding top level group objects. There is a default
+ * implementation which is required because embedders don't have their
+ * own implementation yet.
+ */
+ virtual const char* GetGroupLabel() { return GetLabel(); }
+
+ /**
+ * Returns element count in case if a global handle retains
+ * a subgraph by holding one of its nodes.
+ */
+ virtual intptr_t GetElementCount() { return -1; }
+
+ /** Returns embedder's object size in bytes. */
+ virtual intptr_t GetSizeInBytes() { return -1; }
+
+ protected:
+ RetainedObjectInfo() {}
+ virtual ~RetainedObjectInfo() {}
+
+ private:
+ RetainedObjectInfo(const RetainedObjectInfo&);
+ RetainedObjectInfo& operator=(const RetainedObjectInfo&);
+};
+
+
+/**
+ * A struct for exporting HeapStats data from V8, using "push" model.
+ * See HeapProfiler::PushHeapObjectsStats.
+ */
+struct HeapStatsUpdate {
+ HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size)
+ : index(index), count(count), size(size) { }
+ uint32_t index; // Index of the time interval that was changed.
+ uint32_t count; // New value of count field for the interval with this index.
+ uint32_t size; // New value of size field for the interval with this index.
+};
+
+
+} // namespace v8
+
+
+#undef V8EXPORT
+
+
+#endif // V8_V8_PROFILER_H_
View
105 library/v8/mac/include/v8-testing.h
@@ -0,0 +1,105 @@
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef V8_V8_TEST_H_
+#define V8_V8_TEST_H_
+
+#include "v8.h"
+
+#ifdef _WIN32
+// Setup for Windows DLL export/import. See v8.h in this directory for
+// information on how to build/use V8 as a DLL.
+#if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
+#error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
+ build configuration to ensure that at most one of these is set
+#endif
+
+#ifdef BUILDING_V8_SHARED
+#define V8EXPORT __declspec(dllexport)
+#elif USING_V8_SHARED
+#define V8EXPORT __declspec(dllimport)
+#else
+#define V8EXPORT
+#endif
+
+#else // _WIN32
+
+// Setup for Linux shared library export. See v8.h in this directory for
+// information on how to build/use V8 as shared library.
+#if defined(__GNUC__) && ((__GNUC__ >= 4) || \
+ (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(V8_SHARED)
+#define V8EXPORT __attribute__ ((visibility("default")))
+#else
+#define V8EXPORT
+#endif
+
+#endif // _WIN32
+
+
+/**
+ * Testing support for the V8 JavaScript engine.
+ */
+namespace v8 {
+
+class V8EXPORT Testing {
+ public:
+ enum StressType {
+ kStressTypeOpt,
+ kStressTypeDeopt
+ };
+
+ /**
+ * Set the type of stressing to do. The default if not set is kStressTypeOpt.
+ */
+ static void SetStressRunType(StressType type);
+
+ /**
+ * Get the number of runs of a given test that is required to get the full
+ * stress coverage.
+ */
+ static int GetStressRuns();
+
+ /**
+ * Indicate the number of the run which is about to start. The value of run
+ * should be between 0 and one less than the result from GetStressRuns()
+ */
+ static void PrepareStressRun(int run);
+
+ /**
+ * Force deoptimization of all functions.
+ */
+ static void DeoptimizeAll();
+};
+
+
+} // namespace v8
+
+
+#undef V8EXPORT
+
+
+#endif // V8_V8_TEST_H_
View
4,619 library/v8/mac/include/v8.h
4,619 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
54 library/v8/mac/include/v8stdint.h
@@ -0,0 +1,54 @@
+// Copyright 2012 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Load definitions of standard types.
+
+#ifndef V8STDINT_H_
+#define V8STDINT_H_
+
+#include <stddef.h>
+#include <stdio.h>
+
+#if defined(_WIN32) && !defined(__MINGW32__)
+
+typedef signed char int8_t;
+typedef unsigned char uint8_t;
+typedef short int16_t; // NOLINT
+typedef unsigned short uint16_t; // NOLINT
+typedef int int32_t;
+typedef unsigned int uint32_t;
+typedef __int64 int64_t;
+typedef unsigned __int64 uint64_t;
+// intptr_t and friends are defined in crtdefs.h through stdio.h.
+
+#else
+
+#include <stdint.h>
+
+#endif
+
+#endif // V8STDINT_H_
View
BIN resources/images/robot1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN resources/images/tank.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
21,489 sf_v8.cpp
21,489 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
2,587 sf_v8.h
2,587 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
258 v8wrap.cpp
@@ -0,0 +1,258 @@
+/***
+The zlib/libpng License
+Copyright (c) 2012 Steven Christy
+
+This software is provided 'as-is', without any express or implied warranty. In no event will
+the authors be held liable for any damages arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose, including commercial
+applications, and to alter it and redistribute it freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not claim that you wrote
+the original software. If you use this software in a product, an acknowledgment in the product
+documentation would be appreciated but is not required.
+
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as
+being the original software.
+
+3. This notice may not be removed or altered from any source distribution.
+***/
+
+#include "v8wrap.h"
+//---------------------------------------------------------------------------
+namespace v8wrap
+{
+//---------------------------------------------------------------------------
+const char *sUseNew = "Object must be constructed using the new keyword.";
+const char *sNotCreated = "Unable to construct object with the parameters given.";
+const char *sInvalidArgs = "The arguments to passed to this function are not valid.";
+const char *sAbstractClass = "Cannot create instance of abstract class.";
+//---------------------------------------------------------------------------
+void AutoCastToCPP(v8::Handle<v8::Value> Value, short *&p)
+{
+ if ( Value->IsExternal() )
+ {
+ p = static_cast<short *>(v8::External::Unwrap(Value));
+ }
+ else
+ {
+ p = NULL;
+ }
+}
+//---------------------------------------------------------------------------
+void AutoCastToCPP(v8::Handle<v8::Value> Value, unsigned int *&p)
+{
+ if ( Value->IsExternal() )
+ {
+ p = static_cast<unsigned int *>(v8::External::Unwrap(Value));
+ }
+ else
+ {
+ p = NULL;
+ }
+}
+//---------------------------------------------------------------------------
+void AutoCastToCPP(v8::Handle<v8::Value> Value, void *&p)
+{
+ if ( Value->IsExternal() )
+ {
+ p = static_cast<void *>(v8::External::Unwrap(Value));
+ }
+ else
+ {
+ p = NULL;
+ }
+}
+//---------------------------------------------------------------------------
+void AutoCastToCPP(v8::Handle<v8::Value> Value, long long int &p)
+{
+ p = static_cast<int64_t>(Value->NumberValue());
+}
+//---------------------------------------------------------------------------
+void AutoCastToCPP(v8::Handle<v8::Value> Value, short unsigned int &p )
+{
+ p = static_cast<short unsigned int>(Value->IntegerValue());
+}
+//---------------------------------------------------------------------------
+void AutoCastToCPP(v8::Handle<v8::Value> Value, wchar_t &p)
+{
+ p = static_cast<wchar_t>(Value->IntegerValue());
+}
+//---------------------------------------------------------------------------
+void AutoCastToCPP(v8::Handle<v8::Value> Value, char &p)
+{
+ p = static_cast<char>(Value->IntegerValue());
+}
+//---------------------------------------------------------------------------
+void AutoCastToCPP(v8::Handle<v8::Value> Value, unsigned char *&p)
+{
+ if ( Value->IsExternal() )
+ {
+ p = static_cast<unsigned char *>(v8::External::Unwrap(Value));
+ }
+ else
+ {
+ p = NULL;
+ }
+}
+//---------------------------------------------------------------------------
+void AutoCastToCPP(v8::Handle<v8::Value> Value, unsigned char &p)
+{
+ p = static_cast<unsigned char>(Value->IntegerValue());
+}
+//---------------------------------------------------------------------------
+void AutoCastToCPP(v8::Handle<v8::Value> Value, int &p)
+{
+ p = static_cast<int>(Value->NumberValue());
+}
+//---------------------------------------------------------------------------
+void AutoCastToCPP(v8::Handle<v8::Value> Value, unsigned int &p)
+{
+ p = static_cast<unsigned int>(Value->NumberValue());
+}
+//---------------------------------------------------------------------------
+void AutoCastToCPP(v8::Handle<v8::Value> Value, double &p)
+{
+ p = static_cast<double>(Value->NumberValue());
+}
+//---------------------------------------------------------------------------
+void AutoCastToCPP(v8::Handle<v8::Value> Value, float &p)
+{
+ p = static_cast<float>(Value->NumberValue());
+}
+//---------------------------------------------------------------------------
+void AutoCastToCPP(v8::Handle<v8::Value> Value, bool &p)
+{
+ p = Value->IsTrue();
+}
+//---------------------------------------------------------------------------
+void AutoCastToCPP(v8::Handle<v8::Value> Value, std::string &p)
+{
+ p = *v8::String::Utf8Value(Value);
+}
+//---------------------------------------------------------------------------
+void AutoCastToCPP(v8::Handle<v8::Value> Value, std::wstring &p)
+{
+ v8::Handle<v8::String> Str = Value->ToString();
+ p.resize(Str->Length());
+ Str->Write((uint16_t*)p.data(), 0, -1, v8::String::NO_NULL_TERMINATION);
+}
+//---------------------------------------------------------------------------
+void AutoCastToCPP(v8::Handle<v8::Value> Value, long unsigned int &p )
+{
+ p = static_cast<long unsigned int>(Value->NumberValue());
+}
+//---------------------------------------------------------------------------
+v8::Handle<v8::Value> CastToJS(int p)
+{
+ return v8::Number::New(p);
+}
+//---------------------------------------------------------------------------
+v8::Handle<v8::Value> CastToJS(unsigned int p)
+{
+ return v8::Number::New(p);
+}
+//---------------------------------------------------------------------------
+v8::Handle<v8::Value> CastToJS(long unsigned int p)
+{
+ return v8::Number::New(p);
+}
+//---------------------------------------------------------------------------
+v8::Handle<v8::Value> CastToJS(long long int p)
+{
+ return v8::Number::New((double)p);
+}
+//---------------------------------------------------------------------------
+v8::Handle<v8::Value> CastToJS(unsigned char p)
+{
+ return v8::Number::New(p);
+}
+//---------------------------------------------------------------------------
+v8::Handle<v8::Value> CastToJS(double p)
+{
+ return v8::Number::New(p);
+}
+//---------------------------------------------------------------------------
+v8::Handle<v8::Value> CastToJS(float p)
+{
+ return v8::Number::New(p);
+}
+//---------------------------------------------------------------------------
+v8::Handle<v8::Value> CastToJS(bool p)
+{
+ return v8::Boolean::New(p);
+}
+//---------------------------------------------------------------------------
+v8::Handle<v8::Value> CastToJS(char *p)
+{
+ if ( p == NULL )
+ return v8::Null();
+ else
+ return v8::String::New(p);
+}
+//---------------------------------------------------------------------------
+v8::Handle<v8::Value> CastToJS(wchar_t *p)
+{
+ if ( p == NULL )
+ return v8::Null();
+ else
+ return v8::String::New((uint16_t*)p);
+}
+//---------------------------------------------------------------------------
+v8::Handle<v8::Value> CastToJS(int16_t *p)
+{
+ return v8::External::New((void *)p);
+}
+//---------------------------------------------------------------------------
+v8::Handle<v8::Value> CastToJS(const std::string &p)
+{
+ return v8::String::New(p.c_str());
+}
+//---------------------------------------------------------------------------
+v8::Handle<v8::Value> CastToJS(const std::wstring &p)
+{
+ return v8::String::New((uint16_t*)p.c_str());
+}
+//---------------------------------------------------------------------------
+v8::Handle<v8::Value> CastToJS(void *p)
+{
+ return v8::External::New(p);
+}
+//---------------------------------------------------------------------------
+v8::Handle<v8::Value> CastToJS(unsigned int *p)
+{
+ return v8::External::New(p);
+}
+//---------------------------------------------------------------------------
+v8::Handle<v8::Value> CastToJS(unsigned char *p)
+{
+ return v8::External::New(p);
+}
+//---------------------------------------------------------------------------
+v8::Handle<v8::Value> CastToJS(float *p)
+{
+ return v8::External::New(p);
+}
+//---------------------------------------------------------------------------
+v8::Handle<v8::Value> CastToJS(const unsigned int *p)
+{
+ return v8::External::New(const_cast<unsigned int*>(p));
+}
+//---------------------------------------------------------------------------
+v8::Handle<v8::Value> CastToJS(const unsigned char *p)
+{
+ return v8::External::New(const_cast<unsigned char*>(p));
+}
+//---------------------------------------------------------------------------
+v8::Handle<v8::Value> CastToJS(const void *p)
+{
+ return v8::External::New(const_cast<void*>(p));
+}
+//---------------------------------------------------------------------------
+v8::Handle<v8::Value> CastToJS(const float *p)
+{
+ return v8::External::New(const_cast<float*>(p));
+}
+//---------------------------------------------------------------------------
+}
+//---------------------------------------------------------------------------
View
332 v8wrap.h
@@ -0,0 +1,332 @@
+/***
+The zlib/libpng License
+Copyright (c) 2012 Steven Christy and other contributors
+
+This software is provided 'as-is', without any express or implied warranty. In no event will
+the authors be held liable for any damages arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose, including commercial
+applications, and to alter it and redistribute it freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not claim that you wrote
+the original software. If you use this software in a product, an acknowledgment in the product
+documentation would be appreciated but is not required.
+
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as
+being the original software.
+
+3. This notice may not be removed or altered from any source distribution.
+***/
+
+#ifndef __v8wrap__H__
+#define __v8wrap__H__
+//---------------------------------------------------------------------------
+#ifdef _WIN32
+# include <windows.h>
+#endif
+#include <cstdlib>
+#include <cstring>
+#include <string>
+#include <v8.h>
+#include <vector>
+//---------------------------------------------------------------------------
+namespace v8wrap
+{
+//---------------------------------------------------------------------------
+#define PT_UNKNOWN 0
+#define PT_NUMBER 1
+#define PT_BOOLEAN 2
+#define PT_CLASS 4
+#define PT_POINTER 8
+#define PT_OBJECT 16
+#define PT_STRING 32
+#define PT_ARRAY 64
+#define PT_FUNCTION 128
+#define PT_DATE 256
+//---------------------------------------------------------------------------
+#define MAX_JSBINDING_PARAMS 32
+//---------------------------------------------------------------------------
+struct ParamEntry
+{
+ unsigned Type;
+ const char *Name;
+};
+//---------------------------------------------------------------------------
+struct FunctionEntry
+{
+ int Index;
+ unsigned ArgCnt;
+ ParamEntry Params[MAX_JSBINDING_PARAMS];
+};
+//---------------------------------------------------------------------------
+// Template class for matching JavaScript parameters to C++ method calls.
+//---------------------------------------------------------------------------
+template <int T> class Match
+{
+public:
+ v8::Handle<v8::Value> Params[T];
+ int Entry;
+
+ Match(const FunctionEntry *Funcs, int FuncCnt, const v8::Arguments &args)
+ {
+ unsigned Param[T];
+ unsigned Cnt = args.Length();
+
+ Entry = -1;
+
+ if ( Cnt > T )
+ {
+ return;
+ }
+
+ for ( unsigned P = 0; P < Cnt; P++ )
+ {
+ unsigned &curp = Param[P];
+ curp = 0;
+ if ( args[P]->IsBoolean() ) curp = PT_BOOLEAN;
+ else if ( args[P]->IsNumber() ) curp = PT_NUMBER;
+ else if ( args[P]->IsString() ) curp = PT_STRING;
+ else if ( args[P]->IsObject() )
+ {
+ if ( args[P]->ToObject()->InternalFieldCount() > 0 )
+ {
+ curp = PT_CLASS;
+ }
+ else
+ {
+ curp = PT_OBJECT;
+ }
+ }
+ else if ( args[P]->IsFunction() ) curp = PT_FUNCTION;
+ else if ( args[P]->IsExternal() ) curp = PT_POINTER;
+ else if ( args[P]->IsArray() ) curp = PT_ARRAY;
+ else if ( args[P]->IsDate() ) curp = PT_DATE;
+ }
+
+ if ( Cnt == 1 && (Param[0] & PT_OBJECT) )
+ {
+ // Match an object containing our parameters by name.
+ v8::Handle<v8::Object> Obj = args[0]->ToObject();
+ for ( unsigned x = 0; x < (unsigned)FuncCnt; x++ )
+ {
+ ParamEntry *PE = (ParamEntry *)&Funcs[x].Params[0];
+
+ if ( Funcs[x].ArgCnt == 0 ) continue; // An object (even if empty) cannot match an empty paramter list.
+
+ bool Match = true;
+ for ( unsigned y = 0; y < Funcs[x].ArgCnt; y++ )
+ {
+ unsigned &curp = Param[y];
+ v8::Handle<v8::String> s = v8::String::New(PE->Name);
+
+ if ( !Obj->Has(s) )
+ {
+ Match = false;
+ break;
+ }
+
+ v8::Local<v8::Value> arg = Obj->Get(s);
+
+ curp = 0;
+ if ( arg->IsBoolean() ) curp = PT_BOOLEAN;
+ else if ( arg->IsNumber() ) curp = PT_NUMBER;
+ else if ( arg->IsString() ) curp = PT_STRING;
+ else if ( arg->IsObject() )
+ {
+ if ( arg->ToObject()->InternalFieldCount() > 0 )
+ {
+ curp = PT_CLASS;
+ }
+ else
+ {
+ curp = PT_OBJECT;
+ }
+ }
+ else if ( arg->IsFunction() ) curp = PT_FUNCTION;
+ else if ( arg->IsExternal() ) curp = PT_POINTER;
+ else if ( arg->IsArray() ) curp = PT_ARRAY;
+ else if ( arg->IsDate() ) curp = PT_DATE;
+
+ if ( !(PE->Type & curp) )
+ {
+ Match = false;
+ break;
+ }
+
+ Params[y] = arg;
+ PE++;
+ }
+
+ if ( Match )
+ {
+ Entry = Funcs[x].Index;
+ return;
+ }
+ }
+ return;
+ }
+
+ for ( unsigned x = 0; x < (unsigned)FuncCnt; x++ )
+ {
+ // Traditional match based on parameter order and type.
+ if ( Funcs[x].ArgCnt != Cnt ) continue;
+
+ ParamEntry *PE = (ParamEntry *)&Funcs[x].Params[0];
+ bool Match = true;
+ for ( unsigned y = 0; y < Cnt; y++ )
+ {
+ if ( !(PE->Type & Param[y]) )
+ {
+ Match = false;
+ break;
+ }
+ PE++;
+ }
+ if ( Match )
+ {
+ Entry = Funcs[x].Index;
+ for ( unsigned y = 0; y < Cnt; y++ )
+ {
+ Params[y] = args[y];
+ }
+ return;
+ }
+ }
+
+ }
+};
+//---------------------------------------------------------------------------
+template <class DerivedT, typename T> class V8ClassTemplate
+{
+private:
+
+public:
+ static v8::Persistent<v8::FunctionTemplate> PFT;
+ static v8::Persistent<v8::ObjectTemplate> POT;
+ typedef T MyClass;
+
+ static void Dispose(v8::Persistent<v8::Value> object, void* parameter)
+ {
+ T *obj = (T*)v8::External::Unwrap(object->ToObject()->GetInternalField(0));
+
+ if ( obj && object->ToObject()->GetInternalField(1)->IsTrue() ) DerivedT::Delete(obj);
+
+ object.Dispose();
+ }
+
+ static inline void MakeReference( v8::Handle<v8::Object> Value, T *inst, bool MakeWeak = true )
+ {
+ Value->SetInternalField(0, v8::External::New(inst));
+ Value->SetInternalField(1, v8::Boolean::New(MakeWeak));
+ Value->SetInternalField(2, v8::External::New((void *)DerivedT::Bases));
+
+ if ( MakeWeak ) v8::Persistent<v8::Object>::New(Value).MakeWeak(NULL, Dispose);
+ }
+
+ static inline T *SafeUnwrap(v8::Handle<v8::Object> object)
+ {
+ T *Result = NULL;
+ int clen = strlen(DerivedT::ClassName);
+ const char *Bases = ((const char *)v8::External::Unwrap(object->GetInternalField(2)));
+ int l = 0;
+ bool safe = false;
+
+ while ( (l=strlen(Bases)) != 0 ) {
+ if ( l == clen && strcmp(Bases, DerivedT::ClassName) == 0 ) {
+ safe = true;
+ break;
+ }
+ Bases += (l+1);
+ }
+
+ if ( safe ) Result = ((T*)v8::External::Unwrap(object->GetInternalField(0)));
+ return Result;
+ }
+};
+//---------------------------------------------------------------------------
+template <class DerivedT, typename T> v8::Persistent<v8::FunctionTemplate> V8ClassTemplate<DerivedT, T>::PFT;
+template <class DerivedT, typename T> v8::Persistent<v8::ObjectTemplate> V8ClassTemplate<DerivedT, T>::POT;
+//---------------------------------------------------------------------------
+template <class T> class V8NamespaceTemplate
+{
+private:
+
+public:
+ static v8::Persistent<v8::ObjectTemplate> POT;
+
+};
+//---------------------------------------------------------------------------
+template <class T> v8::Persistent<v8::ObjectTemplate> V8NamespaceTemplate<T>::POT;
+//---------------------------------------------------------------------------
+#ifdef SFML_SYSTEM_WINDOWS
+template <class T> void AutoCastToCPP(v8::Handle<T> Value, ::sf::WindowHandle &p1) {
+ p1 = (::sf::WindowHandle) v8::External::Unwrap(Value);
+}
+#endif
+//---------------------------------------------------------------------------
+void AutoCastToCPP(v8::Handle<v8::Value> Value, short *&p);
+void AutoCastToCPP(v8::Handle<v8::Value> Value, unsigned int *&p);
+void AutoCastToCPP(v8::Handle<v8::Value> Value, void *&p);
+void AutoCastToCPP(v8::Handle<v8::Value> Value, long long int &p);
+void AutoCastToCPP(v8::Handle<v8::Value> Value, unsigned char &p);
+void AutoCastToCPP(v8::Handle<v8::Value> Value, short unsigned int &p );
+void AutoCastToCPP(v8::Handle<v8::Value> Value, char &p);
+void AutoCastToCPP(v8::Handle<v8::Value> Value, wchar_t &p);
+void AutoCastToCPP(v8::Handle<v8::Value> Value, unsigned char *&p);
+void AutoCastToCPP(v8::Handle<v8::Value> Value, unsigned int &p);
+void AutoCastToCPP(v8::Handle<v8::Value> Value, int &p);
+void AutoCastToCPP(v8::Handle<v8::Value> Value, double &p);
+void AutoCastToCPP(v8::Handle<v8::Value> Value, float &p);
+void AutoCastToCPP(v8::Handle<v8::Value> Value, bool &p);
+void AutoCastToCPP(v8::Handle<v8::Value> Value, std::string &p);
+void AutoCastToCPP(v8::Handle<v8::Value> Value, std::wstring &p);
+void AutoCastToCPP(v8::Handle<v8::Value> Value, long unsigned int &p );
+//---------------------------------------------------------------------------
+template <typename T> T CastToCPP(v8::Handle<v8::Value> Value)
+{
+ T Result;
+ AutoCastToCPP(Value, Result);
+ return Result;
+}
+//---------------------------------------------------------------------------
+v8::Handle<v8::Value> CastToJS(long unsigned int p);
+v8::Handle<v8::Value> CastToJS(int p);
+v8::Handle<v8::Value> CastToJS(unsigned int p);
+v8::Handle<v8::Value> CastToJS(long long int p);
+v8::Handle<v8::Value> CastToJS(unsigned char p);
+v8::Handle<v8::Value> CastToJS(double p);
+v8::Handle<v8::Value> CastToJS(float p);
+v8::Handle<v8::Value> CastToJS(bool p);
+v8::Handle<v8::Value> CastToJS(char *p);
+v8::Handle<v8::Value> CastToJS(wchar_t *p);
+v8::Handle<v8::Value> CastToJS(const std::string &p);
+v8::Handle<v8::Value> CastToJS(const std::wstring &p);
+v8::Handle<v8::Value> CastToJS(void *p);
+v8::Handle<v8::Value> CastToJS(long long int *p);
+v8::Handle<v8::Value> CastToJS(short *p);
+v8::Handle<v8::Value> CastToJS(unsigned int *p);
+v8::Handle<v8::Value> CastToJS(unsigned char *p);
+v8::Handle<v8::Value> CastToJS(float *p);
+v8::Handle<v8::Value> CastToJS(const unsigned int *p);
+v8::Handle<v8::Value> CastToJS(const unsigned char *p);
+v8::Handle<v8::Value> CastToJS(const void *p);
+v8::Handle<v8::Value> CastToJS(const float *p);
+//---------------------------------------------------------------------------
+template <typename T> v8::Handle<v8::Value> CastToJS( const std::vector<T> &vec )
+{
+ v8::Handle<v8::Array> Result = v8::Array::New(vec.size());
+ for ( unsigned x = 0; x < vec.size(); x++ ) {
+ v8::Handle<v8::Value> Ele = CastToJS( vec[x] );
+ Result->Set(v8::Integer::New(x), Ele);
+ }
+ return Result;
+}
+//---------------------------------------------------------------------------
+extern const char *sUseNew;
+extern const char *sNotCreated;
+extern const char *sInvalidArgs;
+extern const char *sAbstractClass;
+//---------------------------------------------------------------------------
+}
+#endif
+//---------------------------------------------------------------------------

0 comments on commit 88d5425

Please sign in to comment.