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

Unified Diff: Source/bindings/core/v8/PrivateScriptRunner.js

Issue 756053002: [Blink-in-JS] Migrate the PrivateScript specific methods/attributes to ScriptController (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: ScriptController => PrivateScriptController Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/core/html/HTMLMarqueeElement.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/core/v8/PrivateScriptRunner.js
diff --git a/Source/bindings/core/v8/PrivateScriptRunner.js b/Source/bindings/core/v8/PrivateScriptRunner.js
index aaea26d0e4aae2897e655dc89f56d82ed2a84cb3..cd8f78d4f29f16f7fea7d200324595dd19f3c295 100644
--- a/Source/bindings/core/v8/PrivateScriptRunner.js
+++ b/Source/bindings/core/v8/PrivateScriptRunner.js
@@ -4,43 +4,11 @@
"use strict";
-var installedClasses = {};
-var PrivateScriptDOMException = {};
-var PrivateScriptJSError = {};
-
-// Private scripts can throw JS errors and DOM exceptions as follows:
-// throwException(PrivateScriptDOMException.IndexSizeError, "...");
-// throwException(PrivateScriptJSError.TypeError, "...");
-//
-// Note that normal JS errors thrown by private scripts are treated
-// as real JS errors caused by programming mistake and the execution crashes.
-// If you want to intentially throw JS errors from private scripts,
-// you need to use throwException(PrivateScriptJSError.TypeError, "...").
-function throwException(code, message)
+function PrivateScriptController()
{
- function PrivateScriptException()
- {
- }
-
- var exception = new PrivateScriptException();
- exception.code = code;
- exception.message = message;
- exception.name = "PrivateScriptException";
- throw exception;
-}
-
-function installClass(className, implementation)
-{
- function PrivateScriptClass()
- {
- }
-
- if (!(className in installedClasses))
- installedClasses[className] = new PrivateScriptClass();
- implementation(installedClasses[className]);
-}
-
-(function (global) {
+ this._installedClasses = {};
+ this._DOMException = {};
+ this._JSError = {};
// This list must be in sync with the enum in ExceptionCode.h. The order matters.
var domExceptions = [
"IndexSizeError",
@@ -105,19 +73,70 @@ function installClass(className, implementation)
var code = 1;
domExceptions.forEach(function (exception) {
- global.PrivateScriptDOMException[exception] = code;
+ this._DOMException[exception] = code;
++code;
- });
+ }.bind(this));
var code = 1000;
jsErrors.forEach(function (exception) {
- global.PrivateScriptJSError[exception] = code;
+ this._JSError[exception] = code;
++code;
- });
+ }.bind(this));
+}
+
+PrivateScriptController.prototype = {
+ get installedClasses()
+ {
+ return this._installedClasses;
+ },
+
+ get DOMException()
+ {
+ return this._DOMException;
+ },
+
+ get JSError()
+ {
+ return this._JSError;
+ },
+
+ installClass: function(className, implementation)
+ {
+ function PrivateScriptClass()
+ {
+ }
+
+ if (!(className in this._installedClasses))
+ this._installedClasses[className] = new PrivateScriptClass();
+ implementation(this._installedClasses[className]);
+ },
+
+ // Private scripts can throw JS errors and DOM exceptions as follows:
+ // throwException(privateScriptController.DOMException.IndexSizeError, "...");
+ // throwException(privateScriptController.JSError.TypeError, "...");
+ //
+ // Note that normal JS errors thrown by private scripts are treated
+ // as real JS errors caused by programming mistake and the execution crashes.
+ // If you want to intentially throw JS errors from private scripts,
+ // you need to use throwException(privateScriptController.JSError.TypeError, "...").
+ throwException: function(code, message)
+ {
+ function PrivateScriptException()
+ {
+ }
+
+ var exception = new PrivateScriptException();
+ exception.code = code;
+ exception.message = message;
+ exception.name = "PrivateScriptException";
+ throw exception;
+ },
+}
-})(window);
+if (typeof window.privateScriptController === 'undefined')
+ window.privateScriptController = new PrivateScriptController();
// This line must be the last statement of this JS file.
// A parenthesis is needed, because the caller of this script (PrivateScriptRunner.cpp)
// is depending on the completion value of this script.
-(installedClasses);
+(privateScriptController.installedClasses);
« no previous file with comments | « no previous file | Source/core/html/HTMLMarqueeElement.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698