OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 "use strict"; | |
6 | |
7 function PrivateScriptController() | |
8 { | |
9 this._installedClasses = {}; | |
10 this._DOMException = {}; | |
11 this._JSError = {}; | |
12 // This list must be in sync with the enum in ExceptionCode.h. The order mat
ters. | |
13 var domExceptions = [ | |
14 "IndexSizeError", | |
15 "HierarchyRequestError", | |
16 "WrongDocumentError", | |
17 "InvalidCharacterError", | |
18 "NoModificationAllowedError", | |
19 "NotFoundError", | |
20 "NotSupportedError", | |
21 "InUseAttributeError", // Historical. Only used in setAttributeNode etc
which have been removed from the DOM specs. | |
22 | |
23 // Introduced in DOM Level 2: | |
24 "InvalidStateError", | |
25 "SyntaxError", | |
26 "InvalidModificationError", | |
27 "NamespaceError", | |
28 "InvalidAccessError", | |
29 | |
30 // Introduced in DOM Level 3: | |
31 "TypeMismatchError", // Historical; use TypeError instead | |
32 | |
33 // XMLHttpRequest extension: | |
34 "SecurityError", | |
35 | |
36 // Others introduced in HTML5: | |
37 "NetworkError", | |
38 "AbortError", | |
39 "URLMismatchError", | |
40 "QuotaExceededError", | |
41 "TimeoutError", | |
42 "InvalidNodeTypeError", | |
43 "DataCloneError", | |
44 | |
45 // These are IDB-specific. | |
46 "UnknownError", | |
47 "ConstraintError", | |
48 "DataError", | |
49 "TransactionInactiveError", | |
50 "ReadOnlyError", | |
51 "VersionError", | |
52 | |
53 // File system | |
54 "NotReadableError", | |
55 "EncodingError", | |
56 "PathExistsError", | |
57 | |
58 // SQL | |
59 "SQLDatabaseError", // Naming conflict with DatabaseError class. | |
60 | |
61 // Web Crypto | |
62 "OperationError", | |
63 | |
64 // Push API | |
65 "PermissionDeniedError", | |
66 | |
67 // Pointer Events | |
68 "InvalidPointerId", | |
69 ]; | |
70 | |
71 // This list must be in sync with the enum in ExceptionCode.h. The order mat
ters. | |
72 var jsErrors = [ | |
73 "Error", | |
74 "TypeError", | |
75 "RangeError", | |
76 "SyntaxError", | |
77 "ReferenceError", | |
78 ]; | |
79 | |
80 var code = 1; | |
81 domExceptions.forEach(function (exception) { | |
82 this._DOMException[exception] = code; | |
83 ++code; | |
84 }.bind(this)); | |
85 | |
86 var code = 1000; | |
87 jsErrors.forEach(function (exception) { | |
88 this._JSError[exception] = code; | |
89 ++code; | |
90 }.bind(this)); | |
91 } | |
92 | |
93 PrivateScriptController.prototype = { | |
94 get installedClasses() | |
95 { | |
96 return this._installedClasses; | |
97 }, | |
98 | |
99 get DOMException() | |
100 { | |
101 return this._DOMException; | |
102 }, | |
103 | |
104 get JSError() | |
105 { | |
106 return this._JSError; | |
107 }, | |
108 | |
109 installClass: function(className, implementation) | |
110 { | |
111 function PrivateScriptClass() | |
112 { | |
113 } | |
114 | |
115 if (!(className in this._installedClasses)) | |
116 this._installedClasses[className] = new PrivateScriptClass(); | |
117 implementation(this._installedClasses[className]); | |
118 }, | |
119 | |
120 // Private scripts can throw JS errors and DOM exceptions as follows: | |
121 // throwException(privateScriptController.DOMException.IndexSizeError, "
..."); | |
122 // throwException(privateScriptController.JSError.TypeError, "..."); | |
123 // | |
124 // Note that normal JS errors thrown by private scripts are treated | |
125 // as real JS errors caused by programming mistake and the execution crashes
. | |
126 // If you want to intentially throw JS errors from private scripts, | |
127 // you need to use throwException(privateScriptController.JSError.TypeError,
"..."). | |
128 throwException: function(code, message) | |
129 { | |
130 function PrivateScriptException() | |
131 { | |
132 } | |
133 | |
134 var exception = new PrivateScriptException(); | |
135 exception.code = code; | |
136 exception.message = message; | |
137 exception.name = "PrivateScriptException"; | |
138 throw exception; | |
139 }, | |
140 } | |
141 | |
142 if (!window.hasOwnProperty("privateScriptController")) | |
143 window.privateScriptController = new PrivateScriptController(); | |
144 | |
145 // This line must be the last statement of this JS file. | |
146 // A parenthesis is needed, because the caller of this script (PrivateScriptRunn
er.cpp) | |
147 // is depending on the completion value of this script. | |
148 (privateScriptController.installedClasses); | |
OLD | NEW |