Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Perlito5 - js - reference stringification
  • Loading branch information
fglock committed Sep 11, 2013
1 parent 6332f51 commit 67d865d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
23 changes: 20 additions & 3 deletions html/perlito5.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion perlito5.pl

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src5/lib/Perlito5/Dumper.pm
@@ -1,5 +1,10 @@
package Perlito5::Dumper;

sub _identity {
# returns true if the 2 arguments point to the same reference
"$_[0]" eq "$_[1]"
}

sub Dumper {
my $obj = $_[0];
my $level = $_[1] || 0;
Expand Down
18 changes: 16 additions & 2 deletions src5/lib/Perlito5/Javascript2/Runtime.pm
Expand Up @@ -369,27 +369,33 @@ function p5cleanup_local(idx, value) {
//-------- Reference
var p5id = Math.floor(Math.random() * 1000000000) + 1000000000;
function p5HashRef(o) {
this._hash_ = o;
this._ref_ = "HASH";
this._id_ = p5id++;
this.bool = function() { return 1 };
}
function p5ArrayRef(o) {
this._array_ = o;
this._ref_ = "ARRAY";
this._id_ = p5id++;
this.bool = function() { return 1 };
}
function p5ScalarRef(o) {
this._scalar_ = o;
this._ref_ = "SCALAR";
this._id_ = p5id++;
this.bool = function() { return 1 };
}
function p5GlobRef(o) {
this._scalar_ = o;
this._ref_ = "GLOB";
this._id_ = p5id++;
this.bool = function() { return 1 };
}
Expand Down Expand Up @@ -517,8 +523,16 @@ p5str = function(o) {
if (o == null) {
return "";
}
if (typeof o === "object" && (o instanceof Array)) {
return CORE.join(["", o]);
if (typeof o === "object") {
if (o instanceof Array) {
return CORE.join(["", o]);
}
if ( o.hasOwnProperty("_ref_") ) {
return [o._ref_, '(0x', o._id_.toString( 16 ), ')'].join('');
}
}
// if (typeof o.string === "function") {
// return o.string();
Expand Down

0 comments on commit 67d865d

Please sign in to comment.