File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,17 @@ function STable(REPR, HOW) {
4
4
this . obj_constructor = function ( ) { } ;
5
5
this . obj_constructor . prototype . _STable = this ;
6
6
7
+ /* HACK - it's a bit hackish - think how correct it is */
8
+ this . obj_constructor . prototype . $$clone = function ( ) {
9
+ var clone = new this . _STable . obj_constructor ( ) ;
10
+ for ( var i in this ) {
11
+ if ( this . hasOwnProperty ( i ) && i != '_SC' ) {
12
+ clone [ i ] = this [ i ] ;
13
+ }
14
+ }
15
+ return clone ;
16
+ } ;
17
+
7
18
/* Default boolification mode 5 */
8
19
this . obj_constructor . prototype . $$to_bool = function ( ctx ) {
9
20
return this . type_object_ ? 0 : 1 ;
Original file line number Diff line number Diff line change 1
- plan (5 );
1
+ plan (7 );
2
2
sub foo () {
3
3
' hello there' ;
4
4
}
@@ -12,3 +12,21 @@ ok($b() eq 'hello there', 'you can call a cloned sub');
12
12
nqp ::setcodename($ b , ' bumblebee' );
13
13
ok (nqp ::getcodename($ a ) eq ' foo' , " changing the name on the cloned sub doesn't affect orginal" );
14
14
ok (nqp ::getcodename($ b ) eq ' bumblebee' , " you can change the name on the cloned sub" );
15
+
16
+ class Foo {
17
+ has $ ! foo ;
18
+ method get_foo () {
19
+ $ ! foo ;
20
+ }
21
+ method set_foo ($ value ) {
22
+ $ ! foo := $ value ;
23
+ }
24
+ }
25
+
26
+ {
27
+ my $ c := Foo. new (foo => 123 );
28
+ my $ d := nqp :: clone ($ c );
29
+ $ c . set_foo(456 );
30
+ ok ($ d . get_foo == 123 , " changing an attr on the cloned object doesn't affect the orginal" );
31
+ ok ($ c . get_foo == 456 , " we can change an attr on the new object" );
32
+ }
You can’t perform that action at this time.
0 commit comments