Skip to content

Commit 87bce81

Browse files
committed
isObjectRegistrable only accepts POJO objects
1 parent 8a67d62 commit 87bce81

File tree

5 files changed

+41
-14
lines changed

5 files changed

+41
-14
lines changed

Gruntfile.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,35 @@ module.exports = function(grunt) {
7272
}
7373
},
7474

75+
replace: {
76+
dist: {
77+
options: {
78+
patterns: [
79+
{
80+
match: /\.core\./g,
81+
replacement: '.c.'
82+
},
83+
{
84+
match: /\.util\./g,
85+
replacement: '.u.'
86+
},
87+
{
88+
match: /\.protocol\./g,
89+
replacement: '.p.'
90+
}
91+
]
92+
},
93+
files: [
94+
{
95+
expand: true,
96+
flatten: true,
97+
src: 'dist/dop.min.js',
98+
dest: 'dist'
99+
}
100+
]
101+
}
102+
},
103+
75104
'optimize-js': {
76105
options: {
77106
sourceMap: false,
@@ -92,10 +121,11 @@ module.exports = function(grunt) {
92121
grunt.loadNpmTasks('grunt-contrib-concat');
93122
grunt.loadNpmTasks('grunt-contrib-uglify');
94123
grunt.loadNpmTasks('grunt-contrib-watch');
124+
grunt.loadNpmTasks('grunt-replace');
95125
grunt.loadNpmTasks('grunt-optimize-js');
96126

97127

98-
var tasks = ['copy', 'concat:nodejs', 'concat:browser', 'uglify'/*, 'optimize-js'*/];
128+
var tasks = ['copy', 'concat:nodejs', 'concat:browser', 'uglify', /*'replace', 'optimize-js'*/];
99129
if (grunt.option('build') === undefined)
100130
tasks.push('watch');
101131
grunt.registerTask('default', tasks);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dop",
3-
"version": "0.22.1",
3+
"version": "0.22.2",
44
"main": "./dist/dop.nodejs.js",
55
"browser": "./dist/dop.js",
66
"unpkg": "./dist/dop.min.js",
@@ -48,6 +48,7 @@
4848
"grunt-contrib-uglify": "^0.6.0",
4949
"grunt-contrib-watch": "^0.6.1",
5050
"grunt-optimize-js": "^0.6.0",
51+
"grunt-replace": "^1.0.1",
5152
"js-combinatorics": "^0.5.2",
5253
"lodash.merge": "^4.6.0",
5354
"tap": "^7.1.2",

src/api/isObjectRegistrable.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11

22
dop.isObjectRegistrable = function(object) {
3-
var tof = dop.util.typeof(object);
4-
return (tof === 'object' || tof == 'array');
3+
if (!object || typeof object !== "object") return false;
4+
var prototype = Object.getPrototypeOf(object);
5+
return prototype === Object.prototype || prototype === Array.prototype;
56
};
67

7-
// dop.isObjectRegistrable = function(object) {
8-
// if (!object)
9-
// return false;
10-
// var prototype = Object.getPrototypeOf(object);
11-
// return (prototype === Object.prototype || prototype === Array.prototype);
8+
//dop.isObjectRegistrable = function(object) {
9+
// var tof = dop.util.typeof(object);
10+
// return (tof === 'object' || tof == 'array');
1211
// };
1312

1413
// function Test(){}

src/api/register.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
dop.register = function(object) {
3-
dop.util.invariant(dop.util.typeof(object) == 'object', 'dop.register needs a regular plain object as first parameter');
3+
dop.util.invariant(dop.isObjectRegistrable(object) && !isArray(object), 'dop.register needs a regular plain object as first parameter');
44
return (dop.isRegistered(object)) ?
55
dop.getObjectProxy(object)
66
:

test/zarrays.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ function gify(obj) {
1010
this.myClassProperty=123;
1111
return JSON.stringify(obj);
1212
}
13-
function isObjectRegistrable(object) {
14-
var tof = dop.util.typeof(object);
15-
return (tof === 'object' || tof == 'array');
16-
}
13+
var isObjectRegistrable = dop.isObjectRegistrable;
1714

1815

1916

0 commit comments

Comments
 (0)