Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 #include "wtf/text/WTFString.h" | 37 #include "wtf/text/WTFString.h" |
| 38 #include <v8.h> | 38 #include <v8.h> |
| 39 | 39 |
| 40 namespace WebCore { | 40 namespace WebCore { |
| 41 | 41 |
| 42 typedef int ExceptionCode; | 42 typedef int ExceptionCode; |
| 43 | 43 |
| 44 class ExceptionState { | 44 class ExceptionState { |
| 45 WTF_MAKE_NONCOPYABLE(ExceptionState); | 45 WTF_MAKE_NONCOPYABLE(ExceptionState); |
| 46 public: | 46 public: |
| 47 enum Context { | |
| 48 ConstructionContext, | |
| 49 ExecutionContext, | |
| 50 DeletionContext, | |
| 51 GetterContext, | |
| 52 SetterContext, | |
| 53 UnknownContext, // FIXME: Remove this once we've flipped over to the new API. | |
| 54 }; | |
| 55 | |
| 47 explicit ExceptionState(const v8::Handle<v8::Object>& creationContext, v8::I solate* isolate) | 56 explicit ExceptionState(const v8::Handle<v8::Object>& creationContext, v8::I solate* isolate) |
| 48 : m_code(0) | 57 : m_code(0) |
| 58 , m_context(UnknownContext) | |
| 59 , m_property(0) | |
| 60 , m_interface(0) | |
| 49 , m_creationContext(creationContext) | 61 , m_creationContext(creationContext) |
| 50 , m_isolate(isolate) { } | 62 , m_isolate(isolate) { } |
| 51 | 63 |
| 64 ExceptionState(Context context, const char* property, const char* interface, const v8::Handle<v8::Object>& creationContext, v8::Isolate* isolate) | |
| 65 : m_code(0) | |
| 66 , m_context(context) | |
| 67 , m_property(property) | |
| 68 , m_interface(interface) | |
| 69 , m_creationContext(creationContext) | |
| 70 , m_isolate(isolate) { } | |
| 71 | |
| 72 ExceptionState(Context context, const char* interface, const v8::Handle<v8:: Object>& creationContext, v8::Isolate* isolate) | |
| 73 : m_code(0) | |
| 74 , m_context(context) | |
| 75 , m_property(0) | |
| 76 , m_interface(interface) | |
| 77 , m_creationContext(creationContext) | |
| 78 , m_isolate(isolate) { ASSERT(m_executionContext == ExceptionStateForCon struction); } | |
| 79 | |
| 52 virtual void throwDOMException(const ExceptionCode&, const String& message); | 80 virtual void throwDOMException(const ExceptionCode&, const String& message); |
| 53 virtual void throwTypeError(const String& message); | 81 virtual void throwTypeError(const String& message); |
| 54 virtual void throwSecurityError(const String& sanitizedMessage, const String & unsanitizedMessage = String()); | 82 virtual void throwSecurityError(const String& sanitizedMessage, const String & unsanitizedMessage = String()); |
| 55 | 83 |
| 56 // Please don't use these methods. Use ::throwDOMException and ::throwTypeEr ror, and pass in a useful exception message. | 84 // Please don't use these methods. Use ::throwDOMException and ::throwTypeEr ror, and pass in a useful exception message. |
| 57 virtual void throwUninformativeAndGenericDOMException(const ExceptionCode& e c) { throwDOMException(ec, String()); } | 85 virtual void throwUninformativeAndGenericDOMException(const ExceptionCode& e c) { throwDOMException(ec, String()); } |
| 58 virtual void throwUninformativeAndGenericTypeError() { throwTypeError(String ()); } | 86 virtual void throwUninformativeAndGenericTypeError() { throwTypeError(String ()); } |
| 59 | 87 |
| 60 bool hadException() const { return !m_exception.isEmpty() || m_code; } | 88 bool hadException() const { return !m_exception.isEmpty() || m_code; } |
| 61 void clearException(); | 89 void clearException(); |
| 62 | 90 |
| 63 ExceptionCode code() { return m_code; } | 91 ExceptionCode code() { return m_code; } |
| 64 | 92 |
| 65 bool throwIfNeeded() | 93 bool throwIfNeeded() |
| 66 { | 94 { |
| 67 if (m_exception.isEmpty()) { | 95 if (m_exception.isEmpty()) { |
| 68 if (!m_code) | 96 if (!m_code) |
| 69 return false; | 97 return false; |
| 70 throwUninformativeAndGenericDOMException(m_code); | 98 throwUninformativeAndGenericDOMException(m_code); |
| 71 } | 99 } |
| 72 | 100 |
| 73 V8ThrowException::throwError(m_exception.newLocal(m_isolate), m_isolate) ; | 101 V8ThrowException::throwError(m_exception.newLocal(m_isolate), m_isolate) ; |
| 74 return true; | 102 return true; |
| 75 } | 103 } |
| 76 | 104 |
| 105 Context context() { return m_context; } | |
| 106 const char* property() { return m_property; } | |
| 107 const char* interface() { return m_interface; } | |
| 108 | |
| 77 protected: | 109 protected: |
| 78 ExceptionCode m_code; | 110 ExceptionCode m_code; |
| 111 Context m_context; | |
| 112 const char* m_property; | |
| 113 const char* m_interface; | |
|
haraken
2013/11/26 10:49:36
Don't you want to use String instead of char*?
Mike West
2013/11/26 10:53:26
I don't want the performance hit of converting to
| |
| 79 | 114 |
| 80 private: | 115 private: |
| 81 void setException(v8::Handle<v8::Value>); | 116 void setException(v8::Handle<v8::Value>); |
| 82 | 117 |
| 83 ScopedPersistent<v8::Value> m_exception; | 118 ScopedPersistent<v8::Value> m_exception; |
| 84 v8::Handle<v8::Object> m_creationContext; | 119 v8::Handle<v8::Object> m_creationContext; |
| 85 v8::Isolate* m_isolate; | 120 v8::Isolate* m_isolate; |
| 86 }; | 121 }; |
| 87 | 122 |
| 88 class TrackExceptionState : public ExceptionState { | 123 class TrackExceptionState : public ExceptionState { |
| 89 public: | 124 public: |
| 90 TrackExceptionState(): ExceptionState(v8::Handle<v8::Object>(), 0) { } | 125 TrackExceptionState(): ExceptionState(v8::Handle<v8::Object>(), 0) { } |
| 91 virtual void throwDOMException(const ExceptionCode&, const String& message) OVERRIDE FINAL; | 126 virtual void throwDOMException(const ExceptionCode&, const String& message) OVERRIDE FINAL; |
| 92 virtual void throwTypeError(const String& message = String()) OVERRIDE FINAL ; | 127 virtual void throwTypeError(const String& message = String()) OVERRIDE FINAL ; |
| 93 virtual void throwSecurityError(const String& sanitizedMessage, const String & unsanitizedMessage = String()) OVERRIDE FINAL; | 128 virtual void throwSecurityError(const String& sanitizedMessage, const String & unsanitizedMessage = String()) OVERRIDE FINAL; |
| 94 }; | 129 }; |
| 95 | 130 |
| 96 } // namespace WebCore | 131 } // namespace WebCore |
| 97 | 132 |
| 98 #endif // ExceptionState_h | 133 #endif // ExceptionState_h |
| OLD | NEW |