GWicke has uploaded a new change for review.
https://gerrit.wikimedia.org/r/68114
Change subject: Add thoroughClone method and remove tracer object
......................................................................
Add thoroughClone method and remove tracer object
* Adds native and deep clone variant that also handles non-plain objects
(those with custom constructors). This is in theory a fix for bug 48048, but
in practice this is not yet usable as cyclic structures are not handled
well.
* Remove tracer object, which is not used much any more.
Change-Id: Iffaf8c6617f8df894ddb45327992a28d59b40fec
---
M js/lib/ext.core.ListHandler.js
M js/lib/ext.core.TemplateHandler.js
M js/lib/mediawiki.TokenTransformManager.js
M js/lib/mediawiki.Util.js
M js/lib/mediawiki.parser.environment.js
M js/lib/mediawiki.tokenizer.peg.js
M js/lib/pegTokenizer.pegjs.txt
7 files changed, 63 insertions(+), 28 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid
refs/changes/14/68114/1
diff --git a/js/lib/ext.core.ListHandler.js b/js/lib/ext.core.ListHandler.js
index c6c3a27..69bb73a 100644
--- a/js/lib/ext.core.ListHandler.js
+++ b/js/lib/ext.core.ListHandler.js
@@ -393,10 +393,6 @@
res = tokens;
}
- if (this.manager.env.conf.parsoid.trace) {
- this.manager.env.tracer.output("Returning: " +
Util.toStringTokens(res).join(","));
- }
-
// clear out sol-tokens
res = this.currListFrame.solTokens.concat(res);
res.rank = this.anyRank + 0.01;
diff --git a/js/lib/ext.core.TemplateHandler.js
b/js/lib/ext.core.TemplateHandler.js
index ba46b3c..f7bc161 100644
--- a/js/lib/ext.core.TemplateHandler.js
+++ b/js/lib/ext.core.TemplateHandler.js
@@ -648,9 +648,6 @@
*/
TemplateHandler.prototype._onChunk = function( state, cb, chunk ) {
var env = this.manager.env;
- if (env.conf.parsoid.trace) {
- env.tracer.startPass("TemplateHandler:onChunk (" +
state.token.toString(true) + ")");
- }
chunk = Util.stripEOFTkfromTokens( chunk );
var i, n;
@@ -699,9 +696,6 @@
env.dp( 'TemplateHandler._onChunk', chunk );
cb( { tokens: chunk, async: true } );
- if (env.conf.parsoid.trace) {
- env.tracer.endPass("TemplateHandler:onChunk (" +
state.token.toString(true) + ")");
- }
};
/**
diff --git a/js/lib/mediawiki.TokenTransformManager.js
b/js/lib/mediawiki.TokenTransformManager.js
index 9f0f0cc..d93f9a6 100644
--- a/js/lib/mediawiki.TokenTransformManager.js
+++ b/js/lib/mediawiki.TokenTransformManager.js
@@ -143,9 +143,7 @@
// Trace info
var mgr = this;
t.transform = function() {
- mgr.env.tracer.startPass(debug_name + ":" + rank);
var r = transformation.apply(null, arguments);
- mgr.env.tracer.endPass(debug_name + ":" + rank);
return r;
};
}
@@ -379,7 +377,6 @@
* @param {Array} tokens
*/
AsyncTokenTransformManager.prototype.onChunk = function ( tokens ) {
- this.env.tracer.startPass("onChunk (Async:" + this.attributeType + ")");
// Set top-level callback to next transform phase
var res = this.transformTokens ( tokens, this.tokenCB );
@@ -401,7 +398,6 @@
this.tokenCB =
res.asyncAccum.receiveToksFromSibling.bind(res.asyncAccum);
}
- this.env.tracer.endPass("onChunk (Async:" + this.attributeType + ")");
};
/**
@@ -574,7 +570,6 @@
} else {
// SSS FIXME: with individual stage tracing, this
overall generic tracing
// is becoming less and less useful now. Do a cleanup
one of these days.
- this.env.tracer.traceToken(token);
}
var ts = this._getTransforms( token, minRank );
@@ -864,7 +859,6 @@
return;
}
- this.env.tracer.startPass("onChunk (Sync:" + this.attributeType + ")");
this.env.dp( 'SyncTokenTransformManager.onChunk, input: ', tokens );
var localAccum = [];
@@ -894,7 +888,6 @@
} else {
// SSS FIXME: with individual stage tracing, this
overall generic tracing
// is becoming less and less useful now. Do a cleanup
one of these days.
- this.env.tracer.traceToken(token);
}
var transformer,
@@ -946,7 +939,6 @@
localAccum.rank = this.phaseEndRank;
localAccum.cache = tokens.cache;
this.env.dp( 'SyncTokenTransformManager.onChunk: emitting ', localAccum
);
- this.env.tracer.endPass("onChunk (Sync:" + this.attributeType + ")");
this.emit( 'chunk', localAccum );
};
diff --git a/js/lib/mediawiki.Util.js b/js/lib/mediawiki.Util.js
index a24f4bd..da2204d 100644
--- a/js/lib/mediawiki.Util.js
+++ b/js/lib/mediawiki.Util.js
@@ -533,6 +533,69 @@
}
},
+ /**
+ * A 'clone harder' native clone implementation. Also clones
+ * constructor-based objects (fixes bug 48048), but does not handle
cyclic
+ * structures.
+ */
+ thoroughClone: function(obj, deepClone, seen) {
+ if (deepClone === undefined) {
+ deepClone = true;
+ }
+ if ( obj ) {
+ var copy, i, key;
+ if ( obj.constructor === Array ) {
+ if ( deepClone ) {
+ copy = obj.map(Util.thoroughClone, obj);
+ var keys = Object.keys(obj);
+ if (keys.length > obj.length) {
+ // transfer extra properties too
+ for (i = obj.length; i <
keys.length; i++) {
+ key = keys[i];
+ if
(obj.hasOwnProperty(key)) {
+ copy[key] =
Util.thoroughClone(obj[key]);
+ }
+ }
+ }
+ return copy;
+ } else {
+ return obj.slice();
+ }
+ } else if (obj.constructor === Function) {
+ return obj;
+ } else if ( obj instanceof Object ) {
+ if (obj.cloneNode && obj.cloneNode.constructor
=== Function) {
+ return obj.cloneNode(deepClone);
+ }
+ if (obj.clone && obj.clone.constructor ===
Function) {
+ return obj.clone(deepClone);
+ }
+ copy = {};
+ if (deepClone) {
+ for (key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ copy[key] =
Util.thoroughClone(obj[key]);
+ }
+ }
+ } else {
+ for (key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ copy[key] = obj[key];
+ }
+ }
+ }
+ if (obj.constructor !== Object) {
+ copy.__proto__ = obj.__proto__;
+ }
+ return copy;
+ } else {
+ return obj;
+ }
+ } else {
+ return obj;
+ }
+ },
+
// Deep-freeze an object
// See
//
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/freeze
diff --git a/js/lib/mediawiki.parser.environment.js
b/js/lib/mediawiki.parser.environment.js
index ccfbbdf..f8c3ca2 100644
--- a/js/lib/mediawiki.parser.environment.js
+++ b/js/lib/mediawiki.parser.environment.js
@@ -105,9 +105,6 @@
this.setPageName( this.page.name );
- // Tracing object
- this.tracer = new Tracer(this);
-
// Outstanding page requests (for templates etc)
this.requestQueue = {};
};
diff --git a/js/lib/mediawiki.tokenizer.peg.js
b/js/lib/mediawiki.tokenizer.peg.js
index 6757544..a651b7f 100644
--- a/js/lib/mediawiki.tokenizer.peg.js
+++ b/js/lib/mediawiki.tokenizer.peg.js
@@ -110,9 +110,6 @@
//console.warn( JSON.stringify( maybeCached,
null, 2 ) );
for ( var i = 0, l = maybeCached.length; i < l;
i++ ) {
var cachedChunk = maybeCached[i];
- if (this.env.conf.parsoid.trace) {
-
this.env.tracer.outputChunk(cachedChunk);
- }
// emit a clone of this chunk
this.emit('chunk', cachedChunk );
}
diff --git a/js/lib/pegTokenizer.pegjs.txt b/js/lib/pegTokenizer.pegjs.txt
index a22c629..9b429f3 100644
--- a/js/lib/pegTokenizer.pegjs.txt
+++ b/js/lib/pegTokenizer.pegjs.txt
@@ -523,10 +523,6 @@
tokens = [b];
}
- if (pegArgs.pegTokenizer.env.conf.parsoid.trace) {
- pegArgs.pegTokenizer.env.tracer.outputChunk(tokens);
- }
-
// Emit tokens for this toplevelblock. This feeds a chunk to the parser
pipeline.
emitChunk( tokens );
--
To view, visit https://gerrit.wikimedia.org/r/68114
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iffaf8c6617f8df894ddb45327992a28d59b40fec
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: GWicke <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits