Auto merge of #20314 - Xanewok:remove-heap-constructor, r=jdm

Don't use unsafe Heap::new constructor

<!-- Please describe your changes on the following line: -->
Pulls https://github.com/servo/rust-mozjs/pull/398 and aims to close https://github.com/servo/rust-mozjs/issues/343.

We can't convert from `JSVal` to `Heap<JSVal>` safely (due to GC barriers we can't move Heap value after changing its underlying value to something meaningful, e.g. non-null or non-undefined), so I decided to also wrap the Heap values in a Box (and in dictionaries in RootedTraceableBox, see https://github.com/servo/servo/pull/20265#issuecomment-372838379 and the issue for more details) in dictionaries.

Since we allocate more to be safe, I think it'd be good to also do some sort of a JS perf run, if there is any to see if there's any significant overhead.

r? @jdm

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because checking for not moving Heap after setting a value would require encoding a lot more info in type system (Heap) and I'm not sure how to do that and end up with an ergonomic and consistent API

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20314)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-03-18 15:22:23 -04:00 committed by GitHub
commit 23b6f569d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 93 additions and 31 deletions

View file

@ -0,0 +1,44 @@
<!doctype html>
<meta charset="utf-8">
<title>Value and pair iterable bindings</title>
<script>
// Requires passing --pref=dom.testbinding.enabled to Servo binary
function collect(iter) {
var collection = [];
for (element of iter) {
collection.push(element);
}
return collection;
}
function measure_time(func) {
var start = performance.now();
func();
var stop = performance.now();
return (stop - start) / 1000.0;
};
const ENTRY_COUNT = 10000;
const RUN_COUNT = 10;
var benchMe = function() {
var t = new TestBindingPairIterable();
for (var i = 0; i < ENTRY_COUNT; i++) {
t.add(i.toString(), i);
}
var result = collect(t.entries());
};
var avg = 0;
for (var i = 0; i < RUN_COUNT; i++) {
var time = measure_time(benchMe);
avg += time;
}
avg /= RUN_COUNT;
console.log('Average running time across ' + RUN_COUNT + ' runs: ' + avg);
</script>