Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: Source/bindings/v8/ExceptionState.h

Issue 87963002: Improve Crypto::getRandomValues exception messages. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: DEBUG. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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_propertyName(0)
60 , m_interfaceName(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* propertyName, const char* interf aceName, const v8::Handle<v8::Object>& creationContext, v8::Isolate* isolate)
65 : m_code(0)
66 , m_context(context)
67 , m_propertyName(propertyName)
68 , m_interfaceName(interfaceName)
69 , m_creationContext(creationContext)
70 , m_isolate(isolate) { }
71
72 ExceptionState(Context context, const char* interfaceName, const v8::Handle< v8::Object>& creationContext, v8::Isolate* isolate)
73 : m_code(0)
74 , m_context(context)
75 , m_propertyName(0)
76 , m_interfaceName(interfaceName)
77 , m_creationContext(creationContext)
78 , m_isolate(isolate) { ASSERT(m_context == ConstructionContext); }
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* propertyName() { return m_propertyName; }
107 const char* interfaceName() { return m_interfaceName; }
108
77 protected: 109 protected:
78 ExceptionCode m_code; 110 ExceptionCode m_code;
111 Context m_context;
112 const char* m_propertyName;
113 const char* m_interfaceName;
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
OLDNEW
« no previous file with comments | « LayoutTests/crypto/worker-random-values-types-expected.txt ('k') | Source/bindings/v8/ExceptionState.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698