Revision
5256
Author
watson1978@gmail.com
Date
2011-03-06 03:08:26 -0800 (Sun, 06 Mar 2011)

Log Message

Array#rotate will not raise a SecurityError when $SAFE is 4.

Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions

ary = [ "a", "b", "c" ]
ret = nil
Thread.start {
  $SAFE=4
  ret = ["b", "c", "a"] == ary.rotate

  begin
    ary.rotate!
  rescue SecurityError => err
  else
    raise "error"
  end
}.join

assert_equal(true, ret)
assert_equal(["a", "b", "c"], ary)

puts :ok
}}}

Modified Paths

Diff

Modified: MacRuby/trunk/array.c (5255 => 5256)


--- MacRuby/trunk/array.c	2011-03-06 08:34:38 UTC (rev 5255)
+++ MacRuby/trunk/array.c	2011-03-06 11:08:26 UTC (rev 5256)
@@ -1353,7 +1353,6 @@
 VALUE
 ary_rotate(VALUE ary, long cnt)
 {
-    rb_ary_modify(ary);
     if (cnt != 0) {
 	long len = RARY(ary)->len;
 	if (len > 0 && (cnt = rotate_count(cnt, len)) > 0) {
@@ -1399,6 +1398,7 @@
     if (!NIL_P(n)) {
 	cnt = NUM2LONG(n);
     }
+    rb_ary_modify(ary);
     ary_rotate(ary, cnt);
     return ary;
 }