/platform/external/webkit/WebCore/bindings/v8/WorkerContextExecutionProxy.h

https://github.com/aharish/totoro-gb-opensource-update2 · C Header · 110 lines · 48 code · 24 blank · 38 comment · 0 complexity · 5828f433069dd06bb757e2bdb6e76fb2 MD5 · raw file

  1. /*
  2. * Copyright (C) 2009 Google Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above
  11. * copyright notice, this list of conditions and the following disclaimer
  12. * in the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Google Inc. nor the names of its
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef WorkerContextExecutionProxy_h
  31. #define WorkerContextExecutionProxy_h
  32. #if ENABLE(WORKERS)
  33. #include "ScriptValue.h"
  34. #include "V8EventListenerList.h"
  35. #include "V8Index.h"
  36. #include <v8.h>
  37. #include <wtf/OwnPtr.h>
  38. #include <wtf/Vector.h>
  39. namespace WebCore {
  40. class Event;
  41. class EventTarget;
  42. class V8EventListener;
  43. class V8WorkerContextEventListener;
  44. class WorkerContext;
  45. struct WorkerContextExecutionState {
  46. WorkerContextExecutionState() : hadException(false), lineNumber(0) { }
  47. bool hadException;
  48. ScriptValue exception;
  49. String errorMessage;
  50. int lineNumber;
  51. String sourceURL;
  52. };
  53. class WorkerContextExecutionProxy {
  54. public:
  55. WorkerContextExecutionProxy(WorkerContext*);
  56. ~WorkerContextExecutionProxy();
  57. // Finds/creates event listener wrappers.
  58. PassRefPtr<V8EventListener> findOrCreateEventListener(v8::Local<v8::Value> listener, bool isInline, bool findOnly);
  59. // Track the event so that we can detach it from the JS wrapper when a worker
  60. // terminates. This is needed because we need to be able to dispose these
  61. // events and releases references to their event targets: WorkerContext.
  62. void trackEvent(Event*);
  63. // Evaluate a script file in the current execution environment.
  64. ScriptValue evaluate(const String& script, const String& fileName, int baseLine, WorkerContextExecutionState*);
  65. // Returns a local handle of the context.
  66. v8::Local<v8::Context> context() { return v8::Local<v8::Context>::New(m_context); }
  67. // Returns WorkerContext object.
  68. WorkerContext* workerContext() { return m_workerContext; }
  69. // Returns WorkerContextExecutionProxy object of the currently executing context. 0 will be returned if the current executing context is not the worker context.
  70. static WorkerContextExecutionProxy* retrieve();
  71. private:
  72. void initV8IfNeeded();
  73. void initContextIfNeeded();
  74. void dispose();
  75. // Run an already compiled script.
  76. v8::Local<v8::Value> runScript(v8::Handle<v8::Script>);
  77. static bool forgetV8EventObject(Event*);
  78. static const int kWorkerMaxStackSize = 500 * 1024;
  79. WorkerContext* m_workerContext;
  80. v8::Persistent<v8::Context> m_context;
  81. int m_recursion;
  82. Vector<Event*> m_events;
  83. };
  84. } // namespace WebCore
  85. #endif // ENABLE(WORKERS)
  86. #endif // WorkerContextExecutionProxy_h