Skip to content

Commit 08db80f

Browse files
author
Vlad Balin
committed
Applied Type-R fixes
1 parent 06bb172 commit 08db80f

File tree

9 files changed

+13276
-13
lines changed

9 files changed

+13276
-13
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ node_modules
66
npm-debug.log
77
.DS_Store
88

9+
.idea

agent/Bridge.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -429,25 +429,31 @@ class Bridge {
429429
val = iterVal;
430430
}
431431

432-
Object.getOwnPropertyNames(val).forEach(name => {
433-
if (name === '__proto__') {
432+
433+
// Extract inner state of the third-party frameworks data objects...
434+
var source = ( val && val.__inner_state__ ) || val;
435+
436+
Object.getOwnPropertyNames( source ).forEach(name => {
437+
if (name === '__proto__' ) {
434438
protod = true;
435439
}
436440
if (isFn && (name === 'arguments' || name === 'callee' || name === 'caller')) {
437441
return;
438442
}
439-
result[name] = dehydrate(val[name], cleaned, [name]);
443+
result[name] = dehydrate( source[name], cleaned, [name]);
440444
});
441445

442446
/* eslint-disable no-proto */
443447
if (!protod && val.__proto__ && val.constructor.name !== 'Object') {
444448
var newProto = {};
445449
var pIsFn = typeof val.__proto__ === 'function';
446450
Object.getOwnPropertyNames(val.__proto__).forEach(name => {
447-
if (pIsFn && (name === 'arguments' || name === 'callee' || name === 'caller')) {
451+
if ( name === '__inner_state__' || ( pIsFn && (name === 'arguments' || name === 'callee' || name === 'caller') ) ) {
448452
return;
449453
}
450-
newProto[name] = dehydrate(val.__proto__[name], protoclean, [name]);
454+
// Calculated properties should not be evaluated on prototype.
455+
var prop = Object.getOwnPropertyDescriptor( val.__proto__, name );
456+
newProto[name] = dehydrate( prop.get ? prop.get : val.__proto__[name], protoclean, [name]);
451457
});
452458
proto = newProto;
453459
}

agent/dehydrate.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ function createDehydrated(type: string, data: Object, cleaned: Array<Array<strin
8989
* and cleaned = [["some", "attr"], ["other"]]
9090
*/
9191
function dehydrate(data: Object, cleaned: Array<Array<string>>, path?: Array<string> = [], level?: number = 0): string | Object {
92-
92+
// Support third-party frameworks data objects in react component state.
93+
if (data && data.__inner_state__ && path && path[path.length - 1] === 'state') {
94+
data = data.__inner_state__;
95+
}
96+
9397
var type = getPropType(data);
9498

9599
switch (type) {

agent/getIn.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,29 @@
1515
* @return {any} Value at end of path or `mull`
1616
*/
1717
function getIn(base, path) {
18+
let isPrototypeChain = false;
19+
1820
return path.reduce((obj, attr) => {
1921
if (obj) {
20-
if (obj.hasOwnProperty(attr)) {
22+
// Mark the beginning of the prototype chain...
23+
if (attr === '__proto__') {
24+
isPrototypeChain = true;
2125
return obj[attr];
2226
}
27+
2328
if (typeof obj[Symbol.iterator] === 'function') {
2429
// Convert iterable to array and return array[index]
2530
return [...obj][attr];
2631
}
32+
33+
34+
if (isPrototypeChain) {
35+
// Avoid calling calculated properties on prototype.
36+
const property = Object.getOwnPropertyDescriptor( obj, attr );
37+
return property.get || property.value;
38+
}
39+
40+
return ( obj.__inner_state__ || obj )[attr];
2741
}
2842

2943
return null;

0 commit comments

Comments
 (0)