OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 17 matching lines...) Expand all Loading... | |
28 | 28 |
29 #ifndef SQLError_h | 29 #ifndef SQLError_h |
30 #define SQLError_h | 30 #define SQLError_h |
31 | 31 |
32 #include "bindings/v8/ScriptWrappable.h" | 32 #include "bindings/v8/ScriptWrappable.h" |
33 #include "wtf/ThreadSafeRefCounted.h" | 33 #include "wtf/ThreadSafeRefCounted.h" |
34 #include "wtf/text/WTFString.h" | 34 #include "wtf/text/WTFString.h" |
35 | 35 |
36 namespace WebCore { | 36 namespace WebCore { |
37 | 37 |
38 class SQLError : public ThreadSafeRefCounted<SQLError>, public ScriptWrappable { | 38 class SQLErrorData { |
39 public: | 39 public: |
40 static PassRefPtr<SQLError> create(unsigned code, const String& message) { r eturn adoptRef(new SQLError(code, message)); } | 40 static PassOwnPtr<SQLErrorData> create(unsigned code, const String& message) |
41 static PassRefPtr<SQLError> create(unsigned code, const char* message, int s qliteCode, const char* sqliteMessage) | 41 { |
42 return adoptPtr(new SQLErrorData(code, message)); | |
43 } | |
44 | |
45 static PassOwnPtr<SQLErrorData> create(unsigned code, const char* message, i nt sqliteCode, const char* sqliteMessage) | |
42 { | 46 { |
43 return create(code, String::format("%s (%d %s)", message, sqliteCode, sq liteMessage)); | 47 return create(code, String::format("%s (%d %s)", message, sqliteCode, sq liteMessage)); |
44 } | 48 } |
45 | 49 |
50 static PassOwnPtr<SQLErrorData> create(const SQLErrorData& data) | |
51 { | |
52 return create(data.code(), data.message()); | |
53 } | |
54 | |
46 unsigned code() const { return m_code; } | 55 unsigned code() const { return m_code; } |
47 String message() const { return m_message.isolatedCopy(); } | 56 String message() const { return m_message.isolatedCopy(); } |
48 | 57 |
58 private: | |
59 SQLErrorData(unsigned code, const String& message) : m_code(code), m_message (message.isolatedCopy()) { } | |
60 | |
61 unsigned m_code; | |
62 String m_message; | |
63 }; | |
64 | |
65 class SQLError : public ThreadSafeRefCountedWillBeGarbageCollectedFinalized<SQLE rror>, public ScriptWrappable { | |
66 public: | |
67 static PassRefPtrWillBeRawPtr<SQLError> create(const SQLErrorData& data) { r eturn adoptRefWillBeNoop(new SQLError(data)); } | |
68 void trace(Visitor*) { } | |
69 | |
70 unsigned code() const { return m_code; } | |
71 String message() const { return m_message; } | |
72 | |
49 enum SQLErrorCode { | 73 enum SQLErrorCode { |
50 UNKNOWN_ERR = 0, | 74 UNKNOWN_ERR = 0, |
51 DATABASE_ERR = 1, | 75 DATABASE_ERR = 1, |
52 VERSION_ERR = 2, | 76 VERSION_ERR = 2, |
53 TOO_LARGE_ERR = 3, | 77 TOO_LARGE_ERR = 3, |
54 QUOTA_ERR = 4, | 78 QUOTA_ERR = 4, |
55 SYNTAX_ERR = 5, | 79 SYNTAX_ERR = 5, |
56 CONSTRAINT_ERR = 6, | 80 CONSTRAINT_ERR = 6, |
57 TIMEOUT_ERR = 7 | 81 TIMEOUT_ERR = 7 |
58 }; | 82 }; |
59 | 83 |
60 static const char quotaExceededErrorMessage[]; | 84 static const char quotaExceededErrorMessage[]; |
61 static const char unknownErrorMessage[]; | 85 static const char unknownErrorMessage[]; |
62 static const char versionErrorMessage[]; | 86 static const char versionErrorMessage[]; |
63 | 87 |
64 private: | 88 private: |
65 SQLError(unsigned code, const String& message) : m_code(code), m_message(mes sage.isolatedCopy()) | 89 SQLError(const SQLErrorData& data) : m_code(data.code()), m_message(data.mes sage()) |
haraken
2014/03/25 11:50:05
Add 'explicit'.
tkent
2014/03/25 22:07:13
Done.
| |
66 { | 90 { |
67 ScriptWrappable::init(this); | 91 ScriptWrappable::init(this); |
68 } | 92 } |
69 | 93 |
70 unsigned m_code; | 94 unsigned m_code; |
71 String m_message; | 95 String m_message; |
haraken
2014/03/25 11:50:05
How about making SQLError hold an OwnPtr<SQLErrorD
tkent
2014/03/25 22:07:13
Done.
| |
72 }; | 96 }; |
73 | 97 |
74 } | 98 } |
75 | 99 |
76 #endif // SQLError_h | 100 #endif // SQLError_h |
OLD | NEW |