Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions bench/bench-shell-bindings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
if (typeof load !== "function") {
var fs = require("fs");
var vm = require("vm");
load = function(file) {
var src = fs.readFileSync(file, "utf8");
vm.runInThisContext(src);
};
}

if (typeof print !== "function") {
print = console.log.bind(console);
}

load("./scalajs-runtime-sourcemap.js");
load("./stats.js");
load("../dist/source-map.js");
Expand Down
14 changes: 8 additions & 6 deletions lib/source-map/array-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ define(function (require, exports, module) {
* @param String aStr
*/
ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
var isDuplicate = this.has(aStr);
var sStr = util.toSetString(aStr);
var isDuplicate = this._set.hasOwnProperty(sStr);
var idx = this._array.length;
if (!isDuplicate || aAllowDuplicates) {
this._array.push(aStr);
}
if (!isDuplicate) {
this._set[util.toSetString(aStr)] = idx;
this._set[sStr] = idx;
}
};

Expand All @@ -65,8 +66,8 @@ define(function (require, exports, module) {
* @param String aStr
*/
ArraySet.prototype.has = function ArraySet_has(aStr) {
return Object.prototype.hasOwnProperty.call(this._set,
util.toSetString(aStr));
var sStr = util.toSetString(aStr);
return this._set.hasOwnProperty(sStr);
};

/**
Expand All @@ -75,8 +76,9 @@ define(function (require, exports, module) {
* @param String aStr
*/
ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
if (this.has(aStr)) {
return this._set[util.toSetString(aStr)];
var sStr = util.toSetString(aStr);
if (this._set.hasOwnProperty(sStr)) {
return this._set[sStr];
}
throw new Error('"' + aStr + '" is not in the set.');
};
Expand Down
14 changes: 8 additions & 6 deletions lib/source-map/source-map-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ define(function (require, exports, module) {
var previousSource = 0;
var result = '';
var mapping;
var nameIdx;
var sourceIdx;

var mappings = this._mappings.toArray();
for (var i = 0, len = mappings.length; i < len; i++) {
Expand All @@ -321,9 +323,9 @@ define(function (require, exports, module) {
previousGeneratedColumn = mapping.generatedColumn;

if (mapping.source != null) {
result += base64VLQ.encode(this._sources.indexOf(mapping.source)
- previousSource);
previousSource = this._sources.indexOf(mapping.source);
sourceIdx = this._sources.indexOf(mapping.source);
result += base64VLQ.encode(sourceIdx - previousSource);
previousSource = sourceIdx;

// lines are stored 0-based in SourceMap spec version 3
result += base64VLQ.encode(mapping.originalLine - 1
Expand All @@ -335,9 +337,9 @@ define(function (require, exports, module) {
previousOriginalColumn = mapping.originalColumn;

if (mapping.name != null) {
result += base64VLQ.encode(this._names.indexOf(mapping.name)
- previousName);
previousName = this._names.indexOf(mapping.name);
nameIdx = this._names.indexOf(mapping.name);
result += base64VLQ.encode(nameIdx - previousName);
previousName = nameIdx;
}
}
}
Expand Down