webextension-polyfill/test
Rob Wu 67b3780d38 fix: Lazily initialize API via the original target (#71)
Originally, the polyfill created a Proxy with the original API object as
the target. This was changed to `Object.create(chrome)` because not
doing so would prevent the `browser.devtools` API from working because
the devtools API object is assigned as a read-only & non-configurable
property (#57).

However, that action itself caused a new bug: Whenever an API object
is dereferenced via the `browser` namespace, the original API is no
longer available in the `chrome` namespace, and trying to access the
API through `chrome` returns `undefined` plus the "Previous API
instantiation failed" warning (#58).
This is because Chrome lazily initializes fields in the `chrome`
API, but on the object from which the property is accessed, while
the polyfill accessed the property through an object with the
prototype set to `chrome` instead of directly via chrome.

To fix that, `Object.create(chrome)` was replaced with
`Object.assign({}, chrome)`. This fixes both of the previous issues
because
1) It is still a new object.
2) All lazily initialized fields are explicitly initialized.

This fix created a new issue: In Chrome some APIs cannot be used even
though they are visible in the API (e.g. `chrome.clipboard`), so
calling `Object.assign({}, chrome)` causes an error to be printed to
the console (#70).

To solve this, I use `Object.create(chrome)` again as a proxy target,
but dereference the API via the original target (`chrome`) to not
regress on #58.
Besides fixing the bug, this also reduces the performance impact
of the API because all API fields are lazily initialized again,
instead of upon start-up.

This fixes #70.
2018-03-12 19:23:28 +01:00
..
fixtures test: Run a minimal set of tests from a test extension running on Chrome (#66) 2017-10-23 19:42:01 +02:00
integration fix: Pass --no-sandbox chrome CLI option when running the integration tests on travis (#85) 2018-01-09 17:49:56 +01:00
.eslintrc fix: relax max-nested-callback eslint rules for tests. 2016-11-07 16:34:34 +01:00
mocha-babel.js test: Run a minimal set of tests from a test extension running on Chrome (#66) 2017-10-23 19:42:01 +02:00
run-chrome-smoketests.sh test: Run a minimal set of tests from a test extension running on Chrome (#66) 2017-10-23 19:42:01 +02:00
run-module-bundlers-smoketests.sh test: run tests for the webpack and browserify bundled files on travis 2017-04-13 14:30:52 +02:00
setup.js test: run tests for the webpack and browserify bundled files on travis 2017-04-13 14:30:52 +02:00
test-async-functions.js feat: Added devtools.inspectedWindow.eval and devtools.panels.create to wrapped APIs. 2017-09-25 22:20:07 +02:00
test-browser-global.js test: run tests for the webpack and browserify bundled files on travis 2017-04-13 14:30:52 +02:00
test-proxied-properties.js fix: Lazily initialize API via the original target (#71) 2018-03-12 19:23:28 +01:00
test-runtime-onMessage.js fix: indentation missed by eslint 2016-11-07 16:34:34 +01:00