Skip to content

Commit

Permalink
[IE8] Fix in 1.1.5 only handles 2 levels of dynamically nested classes
Browse files Browse the repository at this point in the history
  • Loading branch information
MSNev committed May 3, 2022
1 parent 710d25f commit d478c78
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
4 changes: 2 additions & 2 deletions lib/docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3314,7 +3314,7 @@ <h3>Dynamic<wbr>Proto<wbr>Delegate</h3>
<div class="tsd-signature tsd-kind-icon">Dynamic<wbr>Proto<wbr>Delegate&lt;DPType&gt;<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span>theTarget<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">DPType</span>, baseFuncProxy<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">DPType</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> =&gt; </span><span class="tsd-signature-type">void</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/microsoft/DynamicProto-JS/blob/f424da6/lib/src/DynamicProto.ts#L494">DynamicProto.ts:494</a></li>
<li>Defined in <a href="https://github.com/microsoft/DynamicProto-JS/blob/053ad04/lib/src/DynamicProto.ts#L505">DynamicProto.ts:505</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -3379,7 +3379,7 @@ <h3>default</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/microsoft/DynamicProto-JS/blob/f424da6/lib/src/DynamicProto.ts#L548">DynamicProto.ts:548</a></li>
<li>Defined in <a href="https://github.com/microsoft/DynamicProto-JS/blob/053ad04/lib/src/DynamicProto.ts#L559">DynamicProto.ts:559</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down
4 changes: 2 additions & 2 deletions lib/docs/interfaces/idynamicprotoopts.html
Original file line number Diff line number Diff line change
Expand Up @@ -2762,7 +2762,7 @@ <h3>set<wbr>Inst<wbr>Funcs</h3>
<div class="tsd-signature tsd-kind-icon">set<wbr>Inst<wbr>Funcs<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/microsoft/DynamicProto-JS/blob/f424da6/lib/src/DynamicProto.ts#L477">DynamicProto.ts:477</a></li>
<li>Defined in <a href="https://github.com/microsoft/DynamicProto-JS/blob/053ad04/lib/src/DynamicProto.ts#L488">DynamicProto.ts:488</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -2778,7 +2778,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> use<wbr>Base<wbr>Inst
<div class="tsd-signature tsd-kind-icon">use<wbr>Base<wbr>Inst<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/microsoft/DynamicProto-JS/blob/f424da6/lib/src/DynamicProto.ts#L483">DynamicProto.ts:483</a></li>
<li>Defined in <a href="https://github.com/microsoft/DynamicProto-JS/blob/053ad04/lib/src/DynamicProto.ts#L494">DynamicProto.ts:494</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down
4 changes: 2 additions & 2 deletions lib/docs/modules.html
Original file line number Diff line number Diff line change
Expand Up @@ -3313,7 +3313,7 @@ <h3>Dynamic<wbr>Proto<wbr>Delegate</h3>
<div class="tsd-signature tsd-kind-icon">Dynamic<wbr>Proto<wbr>Delegate&lt;DPType&gt;<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span>theTarget<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">DPType</span>, baseFuncProxy<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">DPType</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> =&gt; </span><span class="tsd-signature-type">void</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/microsoft/DynamicProto-JS/blob/f424da6/lib/src/DynamicProto.ts#L494">DynamicProto.ts:494</a></li>
<li>Defined in <a href="https://github.com/microsoft/DynamicProto-JS/blob/053ad04/lib/src/DynamicProto.ts#L505">DynamicProto.ts:505</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -3378,7 +3378,7 @@ <h3>default</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/microsoft/DynamicProto-JS/blob/f424da6/lib/src/DynamicProto.ts#L548">DynamicProto.ts:548</a></li>
<li>Defined in <a href="https://github.com/microsoft/DynamicProto-JS/blob/053ad04/lib/src/DynamicProto.ts#L559">DynamicProto.ts:559</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down
45 changes: 28 additions & 17 deletions lib/src/DynamicProto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ const DynAllowInstChkTag = DynInstChkTag;
*/
const DynProtoDefaultOptions = '_dfOpts';

/**
* The polyfill version of __proto__ so that it doesn't cause issues for anyone not expecting it to exist
*/
const DynProtoPolyProto = "_dynProto";

/**
* Value used as the name of a class when it cannot be determined
* @ignore
Expand All @@ -77,6 +72,16 @@ const UnknownValue = '_unknown_';
*/
const str__Proto = "__proto__";

/**
* The polyfill version of __proto__ so that it doesn't cause issues for anyone not expecting it to exist
*/
const DynProtoBaseProto = "_dyn" + str__Proto;

/**
* Track the current prototype for IE8 as you can't look back to get the prototype
*/
const DynProtoCurrent = "_dynInstProto";

/**
* Constant string defined to support minimization
* @ignore
Expand All @@ -97,6 +102,11 @@ const Obj = Object;
*/
let _objGetPrototypeOf = Obj["getPrototypeOf"];

/**
* Pre-lookup to check for the existence of this function
*/
let _objGetOwnProps = Obj["getOwnPropertyNames"];

/**
* Internal Global used to generate a unique dynamic class name, every new class will increase this value
* @ignore
Expand Down Expand Up @@ -133,25 +143,27 @@ function _isObjectArrayOrFunctionPrototype(target:any)
* @ignore
*/
function _getObjProto(target:any) {
let newProto;

if (target) {
// This method doesn't existing in older browsers (e.g. IE8)
if (_objGetPrototypeOf) {
return _objGetPrototypeOf(target);
}

// target[Constructor] May break if the constructor has been changed or removed
let newProto = target[DynProtoPolyProto] || target[str__Proto] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
if(newProto) {
// Set the _dynProto so the hierarchy can lookup base classes correctly on IE8
if (!target[DynProtoPolyProto]) {
target[DynProtoPolyProto] = newProto;
}
let curProto = target[str__Proto] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);

return newProto;
// Using the pre-calculated value as IE8 doesn't support looking up the prototype of a prototype and thus fails for more than 1 base class
newProto = target[DynProtoBaseProto] || curProto;
if (!_hasOwnProperty(target, DynProtoBaseProto)) {
// As this prototype doesn't have this property then this is from an inherited class so newProto is the base to return so save it
// so we can look it up value (which for a multiple hierarchy dynamicProto will be the base class)
newProto = target[DynProtoBaseProto] = target[DynProtoCurrent] || target[DynProtoBaseProto];
target[DynProtoCurrent] = curProto;
}
}

return null;
return newProto;
}

/**
Expand All @@ -161,9 +173,8 @@ function _getObjProto(target:any) {
*/
function _forEachProp(target: any, func: (name: string) => void) {
let props: string[] = [];
let getOwnProps = Obj["getOwnPropertyNames"];
if (getOwnProps) {
props = getOwnProps(target);
if (_objGetOwnProps) {
props = _objGetOwnProps(target);
} else {
for (let name in target) {
if (typeof name === "string" && _hasOwnProperty(target, name)) {
Expand Down

0 comments on commit d478c78

Please sign in to comment.