Skip to content
This repository was archived by the owner on Jan 3, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
URLSearchParams.prototype.sort():void
As requested in order to fix #22.

The method is patched for native constructors that haven't implemented it yet.
However, even constructoring via records or sequences might be broken.

In those cases there is still no patch or the whole constructor needs to be substituted.

TODO: decide if it's the case to feature detect upfront and globally replace the class if not standard
      also probably return strings like native (quite some work, not sure if worth it)
  • Loading branch information
Andrea Giammarchi committed May 2, 2017
commit a40c18f9dafce4b5d6f1b52a85a65537449067ce
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (C) 2015 by WebReflection
Copyright (C) 2015-2017 Andrea Giammarchi - @WebReflection

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ build:
# build generic version
var:
mkdir -p build
cat template/var.before $(VAR) template/var.after >build/no-copy.$(REPO).max.js
cat template/var.before $(VAR) template/var.after src/$(REPO)-sort.js >build/no-copy.$(REPO).max.js
node node_modules/uglify-js/bin/uglifyjs --verbose build/no-copy.$(REPO).max.js >build/no-copy.$(REPO).js
cat template/license.before LICENSE.txt template/license.after build/no-copy.$(REPO).max.js >build/$(REPO).max.js
cat template/copyright build/no-copy.$(REPO).js >build/$(REPO).js
Expand All @@ -40,12 +40,12 @@ var:
# build node.js version
node:
mkdir -p build
cat template/license.before LICENSE.txt template/license.after template/node.before $(NODE) template/node.after >build/$(REPO).node.js
cat template/license.before LICENSE.txt template/license.after template/node.before $(NODE) template/node.after src/$(REPO)-sort.js >build/$(REPO).node.js

# build AMD version
amd:
mkdir -p build
cat template/amd.before $(AMD) template/amd.after >build/no-copy.$(REPO).max.amd.js
cat template/amd.before $(AMD) src/$(REPO)-sort.js template/amd.after >build/no-copy.$(REPO).max.amd.js
node node_modules/uglify-js/bin/uglifyjs --verbose build/no-copy.$(REPO).max.amd.js >build/no-copy.$(REPO).amd.js
cat template/license.before LICENSE.txt template/license.after build/no-copy.$(REPO).max.amd.js >build/$(REPO).max.amd.js
cat template/copyright build/no-copy.$(REPO).amd.js >build/$(REPO).amd.js
Expand Down
4 changes: 2 additions & 2 deletions build/url-search-params.amd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions build/url-search-params.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 35 additions & 1 deletion build/url-search-params.max.amd.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
Copyright (C) 2015 by WebReflection
Copyright (C) 2015-2017 Andrea Giammarchi - @WebReflection

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -375,5 +375,39 @@ function spUpdate(a) {

*/

if (!('sort' in URLSearchParams.prototype)) {
URLSearchParams.prototype.sort = function sort() {
var
entries = this.entries(),
entry = entries.next(),
done = entry.done,
keys = [],
values = Object.create(null),
i, key, value
;
while (!done) {
value = entry.value;
key = value[0];
keys.push(key);
if (!(key in values)) {
values[key] = [];
}
values[key].push(value[1]);
entry = entries.next();
done = entry.done;
}
// not the champion in efficiency
// but these two bits just do the job
keys.sort();
for (i = 0; i < keys.length; i++) {
this.delete(keys[i]);
}
for (i = 0; i < keys.length; i++) {
key = keys[i];
this.append(key, values[key].shift());
}
};
}

return URLSearchParams;
});
37 changes: 35 additions & 2 deletions build/url-search-params.max.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
Copyright (C) 2015 by WebReflection
Copyright (C) 2015-2017 Andrea Giammarchi - @WebReflection

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -376,4 +376,37 @@ function spUpdate(a) {
*/

return URLSearchParams;
}());
}());
if (!('sort' in URLSearchParams.prototype)) {
URLSearchParams.prototype.sort = function sort() {
var
entries = this.entries(),
entry = entries.next(),
done = entry.done,
keys = [],
values = Object.create(null),
i, key, value
;
while (!done) {
value = entry.value;
key = value[0];
keys.push(key);
if (!(key in values)) {
values[key] = [];
}
values[key].push(value[1]);
entry = entries.next();
done = entry.done;
}
// not the champion in efficiency
// but these two bits just do the job
keys.sort();
for (i = 0; i < keys.length; i++) {
this.delete(keys[i]);
}
for (i = 0; i < keys.length; i++) {
key = keys[i];
this.append(key, values[key].shift());
}
};
}
Loading