Commit 46f992dd authored by yangguo's avatar yangguo Committed by Commit bot

Reland "Use function wrapper argument to expose internal arrays to native scripts."

Review URL: https://codereview.chromium.org/1138173002

Cr-Commit-Position: refs/heads/master@{#28367}
parent 0bbe7874
...@@ -19,7 +19,12 @@ var $innerArrayEvery; ...@@ -19,7 +19,12 @@ var $innerArrayEvery;
%CheckIsBootstrapping(); %CheckIsBootstrapping();
// -------------------------------------------------------------------
// Imports
var GlobalArray = global.Array; var GlobalArray = global.Array;
var InternalArray = exports.InternalArray;
var InternalPackedArray = exports.InternalPackedArray;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
......
This diff is collapsed.
...@@ -185,7 +185,8 @@ enum BindingFlags { ...@@ -185,7 +185,8 @@ enum BindingFlags {
V(MAP_ITERATOR_MAP_INDEX, Map, map_iterator_map) \ V(MAP_ITERATOR_MAP_INDEX, Map, map_iterator_map) \
V(SET_ITERATOR_MAP_INDEX, Map, set_iterator_map) \ V(SET_ITERATOR_MAP_INDEX, Map, set_iterator_map) \
V(ARRAY_VALUES_ITERATOR_INDEX, JSFunction, array_values_iterator) \ V(ARRAY_VALUES_ITERATOR_INDEX, JSFunction, array_values_iterator) \
V(SCRIPT_CONTEXT_TABLE_INDEX, ScriptContextTable, script_context_table) V(SCRIPT_CONTEXT_TABLE_INDEX, ScriptContextTable, script_context_table) \
V(BUILTIN_EXPORTS_OBJECT_INDEX, Object, builtin_exports_object)
// A table of all script contexts. Every loaded top-level script with top-level // A table of all script contexts. Every loaded top-level script with top-level
...@@ -422,6 +423,7 @@ class Context: public FixedArray { ...@@ -422,6 +423,7 @@ class Context: public FixedArray {
SCRIPT_CONTEXT_TABLE_INDEX, SCRIPT_CONTEXT_TABLE_INDEX,
MAP_CACHE_INDEX, MAP_CACHE_INDEX,
TO_LENGTH_FUN_INDEX, TO_LENGTH_FUN_INDEX,
BUILTIN_EXPORTS_OBJECT_INDEX,
// Properties from here are treated as weak references by the full GC. // Properties from here are treated as weak references by the full GC.
// Scavenge treats them as strong references. // Scavenge treats them as strong references.
......
...@@ -16,7 +16,13 @@ var $createDate; ...@@ -16,7 +16,13 @@ var $createDate;
%CheckIsBootstrapping(); %CheckIsBootstrapping();
// -------------------------------------------------------------------
// Imports
var GlobalDate = global.Date; var GlobalDate = global.Date;
var InternalArray = shared.InternalArray;
// -------------------------------------------------------------------
// This file contains date support implemented in JavaScript. // This file contains date support implemented in JavaScript.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
(function(global, shared, exports) { (function(global, exports) {
'use strict'; 'use strict';
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
(function(global, shared, exports) { (function(global, exports) {
'use strict'; 'use strict';
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
(function(global, shared, exports) { (function(global, exports) {
"use strict"; "use strict";
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
(function(global, shared, exports) { (function(global, exports) {
'use strict'; 'use strict';
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
(function(global, shared, exports) { (function(global, exports) {
'use strict'; 'use strict';
......
...@@ -5,10 +5,16 @@ ...@@ -5,10 +5,16 @@
var $spreadArguments; var $spreadArguments;
var $spreadIterable; var $spreadIterable;
(function(global, shared, exports) { (function(global, exports) {
'use strict'; 'use strict';
// -------------------------------------------------------------------
// Imports
var InternalArray = exports.InternalArray;
// -------------------------------------------------------------------
function SpreadArguments() { function SpreadArguments() {
var count = %_ArgumentsLength(); var count = %_ArgumentsLength();
var args = new InternalArray(); var args = new InternalArray();
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
(function(global, shared, exports) { (function(global, exports) {
"use strict"; "use strict";
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
(function(global, shared, exports) { (function(global, exports) {
"use strict"; "use strict";
......
...@@ -10,7 +10,11 @@ var $jsonSerializeAdapter; ...@@ -10,7 +10,11 @@ var $jsonSerializeAdapter;
%CheckIsBootstrapping(); %CheckIsBootstrapping();
// -------------------------------------------------------------------
// Imports
var GlobalJSON = global.JSON; var GlobalJSON = global.JSON;
var InternalArray = shared.InternalArray;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
......
...@@ -16,7 +16,11 @@ var $min; ...@@ -16,7 +16,11 @@ var $min;
%CheckIsBootstrapping(); %CheckIsBootstrapping();
// -------------------------------------------------------------------
// Imports
var GlobalObject = global.Object; var GlobalObject = global.Object;
var InternalArray = shared.InternalArray;
//------------------------------------------------------------------- //-------------------------------------------------------------------
......
...@@ -35,7 +35,14 @@ var MakeTypeErrorEmbedded; ...@@ -35,7 +35,14 @@ var MakeTypeErrorEmbedded;
%CheckIsBootstrapping(); %CheckIsBootstrapping();
// -------------------------------------------------------------------
// Imports
var GlobalObject = global.Object; var GlobalObject = global.Object;
var InternalArray = shared.InternalArray;
// -------------------------------------------------------------------
var GlobalError; var GlobalError;
var GlobalTypeError; var GlobalTypeError;
var GlobalRangeError; var GlobalRangeError;
...@@ -44,8 +51,6 @@ var GlobalSyntaxError; ...@@ -44,8 +51,6 @@ var GlobalSyntaxError;
var GlobalReferenceError; var GlobalReferenceError;
var GlobalEvalError; var GlobalEvalError;
// -------------------------------------------------------------------
var kMessages = { var kMessages = {
// Error // Error
constructor_is_generator: ["Class constructor may not be a generator"], constructor_is_generator: ["Class constructor may not be a generator"],
......
...@@ -16,8 +16,12 @@ var $observeNativeObjectNotifierPerformChange; ...@@ -16,8 +16,12 @@ var $observeNativeObjectNotifierPerformChange;
%CheckIsBootstrapping(); %CheckIsBootstrapping();
// -------------------------------------------------------------------
// Imports
var GlobalArray = global.Array; var GlobalArray = global.Array;
var GlobalObject = global.Object; var GlobalObject = global.Object;
var InternalArray = shared.InternalArray;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
......
...@@ -1700,9 +1700,6 @@ class JSReceiver: public HeapObject { ...@@ -1700,9 +1700,6 @@ class JSReceiver: public HeapObject {
// Forward declaration for JSObject::GetOrCreateHiddenPropertiesHashTable. // Forward declaration for JSObject::GetOrCreateHiddenPropertiesHashTable.
class ObjectHashTable; class ObjectHashTable;
// Forward declaration for JSObject::Copy.
class AllocationSite;
// The JSObject describes real heap allocated JavaScript objects with // The JSObject describes real heap allocated JavaScript objects with
// properties. // properties.
...@@ -2163,7 +2160,6 @@ class JSObject: public JSReceiver { ...@@ -2163,7 +2160,6 @@ class JSObject: public JSReceiver {
// Copy object. // Copy object.
enum DeepCopyHints { kNoHints = 0, kObjectIsShallow = 1 }; enum DeepCopyHints { kNoHints = 0, kObjectIsShallow = 1 };
static Handle<JSObject> Copy(Handle<JSObject> object);
MUST_USE_RESULT static MaybeHandle<JSObject> DeepCopy( MUST_USE_RESULT static MaybeHandle<JSObject> DeepCopy(
Handle<JSObject> object, Handle<JSObject> object,
AllocationSiteUsageContext* site_context, AllocationSiteUsageContext* site_context,
......
...@@ -18,6 +18,11 @@ var $promiseValue; ...@@ -18,6 +18,11 @@ var $promiseValue;
%CheckIsBootstrapping(); %CheckIsBootstrapping();
// -------------------------------------------------------------------
// Imports
var InternalArray = shared.InternalArray;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Status values: 0 = pending, +1 = resolved, -1 = rejected // Status values: 0 = pending, +1 = resolved, -1 = rejected
......
...@@ -13,7 +13,13 @@ var harmony_unicode_regexps = false; ...@@ -13,7 +13,13 @@ var harmony_unicode_regexps = false;
%CheckIsBootstrapping(); %CheckIsBootstrapping();
// -------------------------------------------------------------------
// Imports
var GlobalRegExp = global.RegExp; var GlobalRegExp = global.RegExp;
var InternalPackedArray = shared.InternalPackedArray;
// -------------------------------------------------------------------
// Property of the builtins object for recording the result of the last // Property of the builtins object for recording the result of the last
// regexp match. The property $regexpLastMatchInfo includes the matchIndices // regexp match. The property $regexpLastMatchInfo includes the matchIndices
......
...@@ -10,8 +10,13 @@ var $stringSubstring; ...@@ -10,8 +10,13 @@ var $stringSubstring;
%CheckIsBootstrapping(); %CheckIsBootstrapping();
// -------------------------------------------------------------------
// Imports
var GlobalRegExp = global.RegExp; var GlobalRegExp = global.RegExp;
var GlobalString = global.String; var GlobalString = global.String;
var InternalArray = shared.InternalArray;
var InternalPackedArray = shared.InternalPackedArray;
//------------------------------------------------------------------- //-------------------------------------------------------------------
......
...@@ -12,9 +12,17 @@ var $getTemplateCallSite; ...@@ -12,9 +12,17 @@ var $getTemplateCallSite;
%CheckIsBootstrapping(); %CheckIsBootstrapping();
var callSiteCache = new global.Map; // -------------------------------------------------------------------
var mapGetFn = global.Map.prototype.get; // Imports
var mapSetFn = global.Map.prototype.set;
var GlobalMap = global.Map;
var InternalArray = shared.InternalArray;
// -------------------------------------------------------------------
var callSiteCache = new GlobalMap;
var mapGetFn = GlobalMap.prototype.get;
var mapSetFn = GlobalMap.prototype.set;
function SameCallSiteElements(rawStrings, other) { function SameCallSiteElements(rawStrings, other) {
......
...@@ -11,8 +11,12 @@ ...@@ -11,8 +11,12 @@
%CheckIsBootstrapping(); %CheckIsBootstrapping();
//- ------------------------------------------------------------------
// Imports
var GlobalObject = global.Object; var GlobalObject = global.Object;
var GlobalArray = global.Array; var GlobalArray = global.Array;
var InternalArray = shared.InternalArray;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Define internal helper functions. // Define internal helper functions.
......
...@@ -36,11 +36,15 @@ var $toNameArray; ...@@ -36,11 +36,15 @@ var $toNameArray;
%CheckIsBootstrapping(); %CheckIsBootstrapping();
// ----------------------------------------------------------------------------
// Imports
var GlobalArray = global.Array; var GlobalArray = global.Array;
var GlobalBoolean = global.Boolean; var GlobalBoolean = global.Boolean;
var GlobalFunction = global.Function; var GlobalFunction = global.Function;
var GlobalNumber = global.Number; var GlobalNumber = global.Number;
var GlobalObject = global.Object; var GlobalObject = global.Object;
var InternalArray = shared.InternalArray;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
......
...@@ -5430,3 +5430,56 @@ TEST(PreprocessStackTrace) { ...@@ -5430,3 +5430,56 @@ TEST(PreprocessStackTrace) {
CHECK(!element->IsCode()); CHECK(!element->IsCode());
} }
} }
static bool shared_has_been_collected = false;
static bool builtin_exports_has_been_collected = false;
static void SharedHasBeenCollected(
const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) {
shared_has_been_collected = true;
data.GetParameter()->Reset();
}
static void BuiltinExportsHasBeenCollected(
const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) {
builtin_exports_has_been_collected = true;
data.GetParameter()->Reset();
}
TEST(BootstrappingExports) {
FLAG_expose_natives_as = "natives";
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
if (Snapshot::HaveASnapshotToStartFrom(CcTest::i_isolate())) return;
shared_has_been_collected = false;
builtin_exports_has_been_collected = false;
v8::Persistent<v8::Object> shared;
v8::Persistent<v8::Object> builtin_exports;
{
v8::HandleScope scope(isolate);
v8::Handle<v8::Object> natives =
CcTest::global()->Get(v8_str("natives"))->ToObject(isolate);
shared.Reset(isolate, natives->Get(v8_str("shared"))->ToObject(isolate));
natives->Delete(v8_str("shared"));
builtin_exports.Reset(
isolate, natives->Get(v8_str("builtin_exports"))->ToObject(isolate));
natives->Delete(v8_str("builtin_exports"));
}
shared.SetWeak(&shared, SharedHasBeenCollected,
v8::WeakCallbackType::kParameter);
builtin_exports.SetWeak(&builtin_exports, BuiltinExportsHasBeenCollected,
v8::WeakCallbackType::kParameter);
CcTest::heap()->CollectAllAvailableGarbage("fire weak callbacks");
CHECK(shared_has_been_collected);
CHECK(builtin_exports_has_been_collected);
}
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-debug-as debug --expose-natives-as=builtins // Flags: --expose-debug-as debug
// Check that the ScopeIterator can properly recreate the scope at // Check that the ScopeIterator can properly recreate the scope at
// every point when stepping through functions. // every point when stepping through functions.
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-debug-as debug --expose-natives-as=builtins // Flags: --expose-debug-as debug
// Check that the ScopeIterator can properly recreate the scope at // Check that the ScopeIterator can properly recreate the scope at
// every point when stepping through functions. // every point when stepping through functions.
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-debug-as debug --expose-natives-as=builtins // Flags: --expose-debug-as debug
// Check that the ScopeIterator can properly recreate the scope at // Check that the ScopeIterator can properly recreate the scope at
// every point when stepping through functions. // every point when stepping through functions.
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-debug-as debug --expose-natives-as=builtins // Flags: --expose-debug-as debug
// Check that the ScopeIterator can properly recreate the scope at // Check that the ScopeIterator can properly recreate the scope at
// every point when stepping through functions. // every point when stepping through functions.
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-debug-as debug --expose-natives-as=builtins // Flags: --expose-debug-as debug
// Check that the ScopeIterator can properly recreate the scope at // Check that the ScopeIterator can properly recreate the scope at
// every point when stepping through functions. // every point when stepping through functions.
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-debug-as debug --expose-natives-as=builtins // Flags: --expose-debug-as debug
// Check that the ScopeIterator can properly recreate the scope at // Check that the ScopeIterator can properly recreate the scope at
// every point when stepping through functions. // every point when stepping through functions.
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-debug-as debug --expose-natives-as=builtins // Flags: --expose-debug-as debug
// Check that the ScopeIterator can properly recreate the scope at // Check that the ScopeIterator can properly recreate the scope at
// every point when stepping through functions. // every point when stepping through functions.
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-debug-as debug --expose-natives-as=builtins // Flags: --expose-debug-as debug
// Check that the ScopeIterator can properly recreate the scope at // Check that the ScopeIterator can properly recreate the scope at
// every point when stepping through functions. // every point when stepping through functions.
......
...@@ -26,9 +26,9 @@ ...@@ -26,9 +26,9 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-natives_as natives // Flags: --expose-natives-as natives
// Test keyed access to deleted property in a global object without access checks. // Test keyed access to deleted property in a global object w/o access checks.
// Regression test that exposed the_hole value from Runtime_KeyedGetPoperty. // Regression test that exposed the_hole value from Runtime_KeyedGetProperty.
var name = "fisk"; var name = "fisk";
natives[name] = name; natives[name] = name;
......
...@@ -27,18 +27,18 @@ ...@@ -27,18 +27,18 @@
// See: http://code.google.com/p/v8/issues/detail?id=1878 // See: http://code.google.com/p/v8/issues/detail?id=1878
// Flags: --allow-natives-syntax --expose_natives_as=natives // Flags: --allow-natives-syntax --expose-natives-as=natives
var a = Array(); var a = Array();
for (var i = 0; i < 1000; i++) { for (var i = 0; i < 1000; i++) {
var ai = natives.InternalArray(10000); var ai = natives.builtin_exports.InternalArray(10000);
assertFalse(%HaveSameMap(ai, a)); assertFalse(%HaveSameMap(ai, a));
assertTrue(%HasFastObjectElements(ai)); assertTrue(%HasFastObjectElements(ai));
} }
for (var i = 0; i < 1000; i++) { for (var i = 0; i < 1000; i++) {
var ai = new natives.InternalArray(10000); var ai = new natives.builtin_exports.InternalArray(10000);
assertFalse(%HaveSameMap(ai, a)); assertFalse(%HaveSameMap(ai, a));
assertTrue(%HasFastObjectElements(ai)); assertTrue(%HasFastObjectElements(ai));
} }
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-natives_as natives // Flags: --expose-natives-as natives
// Test the SameValue internal method. // Test the SameValue internal method.
var obj1 = {x: 10, y: 11, z: "test"}; var obj1 = {x: 10, y: 11, z: "test"};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment