blob: 6364ce4b49a6ca70af4561c3162e054d510f397f [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/* eslint-disable */
// https://gist.github.com/WebReflection/5593554
/* istanbul ignore if */
if (!Object.setPrototypeOf) {
Object.setPrototypeOf = (function(Object, magic) {
var set;
function setPrototypeOf(O, proto) {
set.call(O, proto);
return O;
}
try {
// this works already in Firefox and Safari
set = Object.getOwnPropertyDescriptor(Object.prototype, magic).set;
set.call({}, null);
} catch (e) {
if (
// IE < 11 cannot be shimmed
Object.prototype !== {}[magic] ||
// neither can any browser that actually
// implemented __proto__ correctly
// (all but old V8 will return here)
{__proto__: null}.__proto__ === void 0
// this case means null objects cannot be passed
// through setPrototypeOf in a reliable way
// which means here a **Sham** is needed instead
) {
return;
}
// nodejs 0.8 and 0.10 are (buggy and..) fine here
// probably Chrome or some old Mobile stock browser
set = function(proto) {
this[magic] = proto;
};
// please note that this will **not** work
// in those browsers that do not inherit
// __proto__ by mistake from Object.prototype
// in these cases we should probably throw an error
// or at least be informed about the issue
setPrototypeOf.polyfill = setPrototypeOf(
setPrototypeOf({}, null),
Object.prototype
) instanceof Object;
// setPrototypeOf.polyfill === true means it works as meant
// setPrototypeOf.polyfill === false means it's not 100% reliable
// setPrototypeOf.polyfill === undefined
// or
// setPrototypeOf.polyfill == null means it's not a polyfill
// which means it works as expected
// we can even delete Object.prototype.__proto__;
}
return setPrototypeOf;
}(Object, '__proto__'));
}