summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/api/jsapi.7.txt20
-rw-r--r--doc/api/jsapi.txt44
-rw-r--r--doc/dwb-js.735
-rw-r--r--extensions/perdomainsettings2
-rw-r--r--scripts/lib/dwb.js59
5 files changed, 124 insertions, 36 deletions
diff --git a/doc/api/jsapi.7.txt b/doc/api/jsapi.7.txt
index d81f7894..8b156756 100644
--- a/doc/api/jsapi.7.txt
+++ b/doc/api/jsapi.7.txt
@@ -65,6 +65,17 @@ _name_;; A name that identifies the function on command line, optional
_returns_;; true if the function was bound successfully
****
+==== String checksum(String data, [ChecksumType type])
+
+****
+
+Computes a checksum for given data.
+
+_shortcut_;; The to compute the checksum for.
+_type_;; The type of the checksum, optional, defaults to ChecksumType.sha256
+_returns_;; The checksum
+****
+
==== Boolean execute(String command)
****
@@ -1769,6 +1780,7 @@ function, it has the following properties and methods:
_script.path (Object, read)_;; The path of the script.
+_script._arguments (Object, read)_;; *arguments* object of the encapsulating function
==== void script.debug(Object params)
****
@@ -1790,8 +1802,12 @@ _returns_;; The private value
==== void script.setPrivate(Object object, String key, String value)
****
-Sets a private property on an object, this is mostly useful for objects derived
-from GObject since GObjects are shared between all scripts.
+Convenience method to set a private property on an object that doesn't conflict
+with properties set in other scripts, it uses a random unique id to set
+the property, so the property can most likely be only retrieved with
+*script.getPrivate*.
+This is mostly useful for objects derived from GObject since GObjects are shared
+between all scripts.
_object_;; The object on which the value should be set.
_key_;; The property name
diff --git a/doc/api/jsapi.txt b/doc/api/jsapi.txt
index a7ac47fe..6244b87a 100644
--- a/doc/api/jsapi.txt
+++ b/doc/api/jsapi.txt
@@ -89,6 +89,25 @@ _name_;; A name that identifies the function on command line, optional
_returns_;; +true+ if the function was bound successfully
****
+****
+[[checksum]]
+[float]
+==== *checksum()* ====
+
+[source,javascript]
+----
+String checksum(String data, [ChecksumType type])
+----
+
+Computes a checksum for given data.
+
+ ::
+
+_shortcut_;; The to compute the checksum for.
+_type_;; The type of the checksum, optional, defaults to ChecksumType.sha256
+_returns_;; The checksum
+****
+
****
[[execute]]
@@ -3126,6 +3145,18 @@ The path of the script.
****
****
+[float]
+==== *_arguments* ====
+
+[source,javascript]
+----
+script._arguments string read
+----
+
+*arguments* object of the encapsulating function
+****
+
+****
[[thisdebug]]
[float]
==== *debug()* ====
@@ -3140,7 +3171,7 @@ an Error, this method will also print the corresponding source of the error.
****
****
-[[thissetprivate]]
+[[getPrivate]]
[float]
==== *getPrivate()* ====
@@ -3149,7 +3180,8 @@ an Error, this method will also print the corresponding source of the error.
Object script.getPrivate(Object object, String key, Object value)
----
-Gets a private property of an object previously set with <<setPrivate>>.
+Gets a private property of an object previously set with
+<<setPrivate,script.setPrivate>>.
::
@@ -3169,8 +3201,12 @@ _returns_;; The private value
void script.setPrivate(Object object, String key, Object value)
----
-Sets a private property on an object, this is mostly useful for objects derived
-from GObject since GObjects are shared between all scripts.
+Convenience method to set a private property on an object that doesn't conflict
+with properties set in other scripts, it uses a random unique id to set
+the property, so the property can most likely only be retrieved with
+<<getPrivate,script.getPrivate>>.
+This is mostly useful for objects derived from GObject since GObjects are shared
+between all scripts.
::
diff --git a/doc/dwb-js.7 b/doc/dwb-js.7
index f61b36be..f59013f9 100644
--- a/doc/dwb-js.7
+++ b/doc/dwb-js.7
@@ -133,6 +133,32 @@ true if the function was bound successfully
.nr an-break-flag 1
.br
.ps +1
+\fBString checksum(String data, [ChecksumType type])\fR
+.RS 4
+.sp
+Computes a checksum for given data\&.
+.PP
+\fIshortcut\fR
+.RS 4
+The to compute the checksum for\&.
+.RE
+.PP
+\fItype\fR
+.RS 4
+The type of the checksum, optional, defaults to ChecksumType\&.sha256
+.RE
+.PP
+\fIreturns\fR
+.RS 4
+The checksum
+.RE
+.RE
+.sp
+.it 1 an-trap
+.nr an-no-space-flag 1
+.nr an-break-flag 1
+.br
+.ps +1
\fBBoolean execute(String command)\fR
.RS 4
.sp
@@ -3489,6 +3515,13 @@ In every script the variable \fBscript\fR refers to \fBthis\fR, the encapsulatin
.RS 4
The path of the script\&.
.RE
+.PP
+\fIscript\&._arguments (Object, read)\fR
+.RS 4
+
+\fBarguments\fR
+object of the encapsulating function
+.RE
.sp
.it 1 an-trap
.nr an-no-space-flag 1
@@ -3535,7 +3568,7 @@ The private value
\fBvoid script.setPrivate(Object object, String key, String value)\fR
.RS 4
.sp
-Sets a private property on an object, this is mostly useful for objects derived from GObject since GObjects are shared between all scripts\&.
+Convenience method to set a private property on an object that doesn\(cqt conflict with properties set in other scripts, it uses a random unique id to set the property, so the property can most likely be only retrieved with \fBscript\&.getPrivate\fR\&. This is mostly useful for objects derived from GObject since GObjects are shared between all scripts\&.
.PP
\fIobject\fR
.RS 4
diff --git a/extensions/perdomainsettings b/extensions/perdomainsettings
index e50fca37..5f0b5ab8 100644
--- a/extensions/perdomainsettings
+++ b/extensions/perdomainsettings
@@ -169,7 +169,7 @@ function onNavigation(wv, frame, request, action)
if (! o)
{
o = { webview : wv, defaults : false, settings : wv.settings };
- script.setPrivate(wv, "pds");
+ script.setPrivate(wv, "pds", o);
}
o.set = {};
var uri = request.uri;
diff --git a/scripts/lib/dwb.js b/scripts/lib/dwb.js
index 40743560..26605c62 100644
--- a/scripts/lib/dwb.js
+++ b/scripts/lib/dwb.js
@@ -28,25 +28,6 @@
}
};
var _contexts = {};
- var _setPrivate = function(id, object, key, value)
- {
- var realKey = key + id;
- if (object)
- {
- if (object[realKey])
- {
- object[realKey] = value;
- }
- else
- {
- Object.defineProperty(object, realKey, { value : value, writable : true });
- }
- }
- };
- var _getPrivate = function(id, object, key)
- {
- return object[key+id];
- };
Object.defineProperties(this, {
"provide" :
{
@@ -103,21 +84,43 @@
"_initNewContext" :
{
value : (function() {
- var lastId = Math.ceil(Math.random() * 314159) + 271828;
- var nextId = function() {
- lastId++;
- return String(Math.floor(Math.random() * 89999) + 10000) + lastId +
- String(Math.floor(Math.random() * 89999) + 10000);
- };
+ var lastId = Math.ceil(Math.random() * 35897932) + 28459025;
+ // get a random unique id, avoids conflicts with real properties
+ function nextId()
+ {
+ lastId += Math.round(Math.random() * 37);
+ return String(Math.floor(Math.random() * 8999999) + 1000000) + lastId +
+ String(Math.floor(Math.random() * 8999999) + 1000000);
+ }
return function(self, arguments, path) {
- var id = nextId();
+ var id = "_" + nextId();
_contexts[id] = self;
Object.defineProperties(self, {
"path" : { value : path },
"debug" : { value : io.debug.bind(this) },
"_arguments" : { value : arguments },
- "setPrivate" : { value : _setPrivate.bind(this, String(id)) },
- "getPrivate" : { value : _getPrivate.bind(this, String(id)) }
+ "setPrivate" :
+ {
+ value : function(id, object, key, value)
+ {
+ var realKey = key + id;
+ if (object[realKey])
+ object[realKey] = value;
+ else
+ {
+ Object.defineProperty(object, realKey, {
+ value : value, writable : true
+ });
+ }
+ }.bind(self, id)
+ },
+ "getPrivate" :
+ {
+ value : function(id, object, key)
+ {
+ return object[key + id];
+ }.bind(self, id)
+ }
});
Object.freeze(self);