Skip to content

Commit bb84bec

Browse files
hs0225yichoi
authored andcommitted
module: fix circular reference to mod (#1578)
This commit comes from #1410. IoT.js-DCO-1.0-Signed-off-by: Yorkie Liu [email protected]
1 parent 4c62b79 commit bb84bec

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

src/js/module.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ Module.load = function(id, parent) {
213213

214214
module.filename = modPath;
215215
module.dirs = [modPath.substring(0, modPath.lastIndexOf('/') + 1)];
216+
Module.cache[modPath] = module;
217+
216218
var ext = modPath.substr(modPath.lastIndexOf('.') + 1);
217219
var source;
218220

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
// Copyright Joyent, Inc. and other Node contributors.
17+
//
18+
// Permission is hereby granted, free of charge, to any person obtaining a
19+
// copy of this software and associated documentation files (the
20+
// "Software"), to deal in the Software without restriction, including
21+
// without limitation the rights to use, copy, modify, merge, publish,
22+
// distribute, sublicense, and/or sell copies of the Software, and to permit
23+
// persons to whom the Software is furnished to do so, subject to the
24+
// following conditions:
25+
//
26+
// The above copyright notice and this permission notice shall be included
27+
// in all copies or substantial portions of the Software.
28+
//
29+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
30+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
32+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
33+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
34+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
35+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
36+
37+
'use strict';
38+
39+
require('./test-module-circular');
40+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
// Copyright Joyent, Inc. and other Node contributors.
17+
//
18+
// Permission is hereby granted, free of charge, to any person obtaining a
19+
// copy of this software and associated documentation files (the
20+
// "Software"), to deal in the Software without restriction, including
21+
// without limitation the rights to use, copy, modify, merge, publish,
22+
// distribute, sublicense, and/or sell copies of the Software, and to permit
23+
// persons to whom the Software is furnished to do so, subject to the
24+
// following conditions:
25+
//
26+
// The above copyright notice and this permission notice shall be included
27+
// in all copies or substantial portions of the Software.
28+
//
29+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
30+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
32+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
33+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
34+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
35+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
36+
37+
'use strict';
38+
require('node/common');
39+
40+
var assert = require('assert');
41+
require('./test-module-circular-b');
42+
43+
assert.ok(true);

test/testsets.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
],
143143
"node/parallel": [
144144
{ "name": "test-assert.js" },
145+
{ "name": "test-module-circular.js" },
145146
{ "name": "test-http-catch-uncaughtexception.js" },
146147
{ "name": "test-http-status-message.js" },
147148
{ "name": "test-http-write-head.js" },

0 commit comments

Comments
 (0)