Commit 5fd4fa2a authored by ager@chromium.org's avatar ager@chromium.org

Introduce experimental natives that are enabled by a runtime flag.

Clean up the use of js2c. We generated two identical files.

R=sgjesse@chromium.org,rossberg@chromium.org
BUG=
TEST=

Review URL: http://codereview.chromium.org/6865013

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7630 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 1eaa4d60
...@@ -297,6 +297,11 @@ debug-debugger.js ...@@ -297,6 +297,11 @@ debug-debugger.js
'''.split() '''.split()
EXPERIMENTAL_LIBRARY_FILES = '''
proxy.js
'''.split()
def Abort(message): def Abort(message):
print message print message
sys.exit(1) sys.exit(1)
...@@ -321,9 +326,16 @@ def ConfigureObjectFiles(): ...@@ -321,9 +326,16 @@ def ConfigureObjectFiles():
# compile it. # compile it.
library_files = [s for s in LIBRARY_FILES] library_files = [s for s in LIBRARY_FILES]
library_files.append('macros.py') library_files.append('macros.py')
libraries_src, libraries_empty_src = env.JS2C(['libraries.cc', 'libraries-empty.cc'], library_files, TYPE='CORE') libraries_src = env.JS2C(['libraries.cc'], library_files, TYPE='CORE')
libraries_obj = context.ConfigureObject(env, libraries_src, CPPPATH=['.']) libraries_obj = context.ConfigureObject(env, libraries_src, CPPPATH=['.'])
# Combine the experimental JavaScript library files into a C++ file
# and compile it.
experimental_library_files = [ s for s in EXPERIMENTAL_LIBRARY_FILES ]
experimental_library_files.append('macros.py')
experimental_libraries_src = env.JS2C(['experimental-libraries.cc'], experimental_library_files, TYPE='EXPERIMENTAL')
experimental_libraries_obj = context.ConfigureObject(env, experimental_libraries_src, CPPPATH=['.'])
source_objs = context.ConfigureObject(env, source_files) source_objs = context.ConfigureObject(env, source_files)
non_snapshot_files = [source_objs] non_snapshot_files = [source_objs]
...@@ -340,7 +352,7 @@ def ConfigureObjectFiles(): ...@@ -340,7 +352,7 @@ def ConfigureObjectFiles():
mksnapshot_env = env.Copy() mksnapshot_env = env.Copy()
mksnapshot_env.Replace(**context.flags['mksnapshot']) mksnapshot_env.Replace(**context.flags['mksnapshot'])
mksnapshot_src = 'mksnapshot.cc' mksnapshot_src = 'mksnapshot.cc'
mksnapshot = mksnapshot_env.Program('mksnapshot', [mksnapshot_src, libraries_obj, non_snapshot_files, empty_snapshot_obj], PDB='mksnapshot.exe.pdb') mksnapshot = mksnapshot_env.Program('mksnapshot', [mksnapshot_src, libraries_obj, experimental_libraries_obj, non_snapshot_files, empty_snapshot_obj], PDB='mksnapshot.exe.pdb')
if context.use_snapshot: if context.use_snapshot:
if context.build_snapshot: if context.build_snapshot:
snapshot_cc = env.Snapshot('snapshot.cc', mksnapshot, LOGFILE=File('snapshot.log').abspath) snapshot_cc = env.Snapshot('snapshot.cc', mksnapshot, LOGFILE=File('snapshot.log').abspath)
...@@ -349,7 +361,7 @@ def ConfigureObjectFiles(): ...@@ -349,7 +361,7 @@ def ConfigureObjectFiles():
snapshot_obj = context.ConfigureObject(env, snapshot_cc, CPPPATH=['.']) snapshot_obj = context.ConfigureObject(env, snapshot_cc, CPPPATH=['.'])
else: else:
snapshot_obj = empty_snapshot_obj snapshot_obj = empty_snapshot_obj
library_objs = [non_snapshot_files, libraries_obj, snapshot_obj] library_objs = [non_snapshot_files, libraries_obj, experimental_libraries_obj, snapshot_obj]
return (library_objs, d8_objs, [mksnapshot], preparser_objs) return (library_objs, d8_objs, [mksnapshot], preparser_objs)
......
...@@ -200,6 +200,7 @@ class Genesis BASE_EMBEDDED { ...@@ -200,6 +200,7 @@ class Genesis BASE_EMBEDDED {
// Used for creating a context from scratch. // Used for creating a context from scratch.
void InstallNativeFunctions(); void InstallNativeFunctions();
bool InstallNatives(); bool InstallNatives();
bool InstallExperimentalNatives();
void InstallBuiltinFunctionIds(); void InstallBuiltinFunctionIds();
void InstallJSFunctionResultCaches(); void InstallJSFunctionResultCaches();
void InitializeNormalizedMapCaches(); void InitializeNormalizedMapCaches();
...@@ -246,6 +247,7 @@ class Genesis BASE_EMBEDDED { ...@@ -246,6 +247,7 @@ class Genesis BASE_EMBEDDED {
Handle<FixedArray> caller); Handle<FixedArray> caller);
static bool CompileBuiltin(Isolate* isolate, int index); static bool CompileBuiltin(Isolate* isolate, int index);
static bool CompileExperimentalBuiltin(Isolate* isolate, int index);
static bool CompileNative(Vector<const char> name, Handle<String> source); static bool CompileNative(Vector<const char> name, Handle<String> source);
static bool CompileScriptCached(Vector<const char> name, static bool CompileScriptCached(Vector<const char> name,
Handle<String> source, Handle<String> source,
...@@ -1175,6 +1177,15 @@ bool Genesis::CompileBuiltin(Isolate* isolate, int index) { ...@@ -1175,6 +1177,15 @@ bool Genesis::CompileBuiltin(Isolate* isolate, int index) {
} }
bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) {
Vector<const char> name = ExperimentalNatives::GetScriptName(index);
Factory* factory = isolate->factory();
Handle<String> source_code =
factory->NewStringFromAscii(ExperimentalNatives::GetScriptSource(index));
return CompileNative(name, source_code);
}
bool Genesis::CompileNative(Vector<const char> name, Handle<String> source) { bool Genesis::CompileNative(Vector<const char> name, Handle<String> source) {
HandleScope scope; HandleScope scope;
Isolate* isolate = source->GetIsolate(); Isolate* isolate = source->GetIsolate();
...@@ -1510,7 +1521,6 @@ bool Genesis::InstallNatives() { ...@@ -1510,7 +1521,6 @@ bool Genesis::InstallNatives() {
for (int i = Natives::GetDebuggerCount(); for (int i = Natives::GetDebuggerCount();
i < Natives::GetBuiltinsCount(); i < Natives::GetBuiltinsCount();
i++) { i++) {
Vector<const char> name = Natives::GetScriptName(i);
if (!CompileBuiltin(isolate(), i)) return false; if (!CompileBuiltin(isolate(), i)) return false;
// TODO(ager): We really only need to install the JS builtin // TODO(ager): We really only need to install the JS builtin
// functions on the builtins object after compiling and running // functions on the builtins object after compiling and running
...@@ -1628,6 +1638,18 @@ bool Genesis::InstallNatives() { ...@@ -1628,6 +1638,18 @@ bool Genesis::InstallNatives() {
} }
bool Genesis::InstallExperimentalNatives() {
if (FLAG_harmony_proxies) {
for (int i = ExperimentalNatives::GetDebuggerCount();
i < ExperimentalNatives::GetBuiltinsCount();
i++) {
if (!CompileExperimentalBuiltin(isolate(), i)) return false;
}
}
return true;
}
static Handle<JSObject> ResolveBuiltinIdHolder( static Handle<JSObject> ResolveBuiltinIdHolder(
Handle<Context> global_context, Handle<Context> global_context,
const char* holder_expr) { const char* holder_expr) {
...@@ -2108,6 +2130,9 @@ Genesis::Genesis(Isolate* isolate, ...@@ -2108,6 +2130,9 @@ Genesis::Genesis(Isolate* isolate,
isolate->counters()->contexts_created_from_scratch()->Increment(); isolate->counters()->contexts_created_from_scratch()->Increment();
} }
// Install experimental natives.
if (!InstallExperimentalNatives()) return;
result_ = global_context_; result_ = global_context_;
} }
......
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
'variables': { 'variables': {
'js_files': [ 'js_files': [
'd8.js', 'd8.js',
'macros.py',
], ],
}, },
'actions': [ 'actions': [
...@@ -72,7 +73,6 @@ ...@@ -72,7 +73,6 @@
], ],
'outputs': [ 'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/d8-js.cc', '<(SHARED_INTERMEDIATE_DIR)/d8-js.cc',
'<(SHARED_INTERMEDIATE_DIR)/d8-js-empty.cc',
], ],
'action': [ 'action': [
'python', 'python',
......
...@@ -75,7 +75,6 @@ ...@@ -75,7 +75,6 @@
], ],
'outputs': [ 'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/i18n-js.cc', '<(SHARED_INTERMEDIATE_DIR)/i18n-js.cc',
'<(SHARED_INTERMEDIATE_DIR)/i18n-js-empty.cc'
], ],
'action': [ 'action': [
'python', 'python',
......
...@@ -96,6 +96,9 @@ private: ...@@ -96,6 +96,9 @@ private:
// //
#define FLAG FLAG_FULL #define FLAG FLAG_FULL
// Flags for experimental language features.
DEFINE_bool(harmony_proxies, false, "enable harmony proxies")
// Flags for Crankshaft. // Flags for Crankshaft.
#ifdef V8_TARGET_ARCH_MIPS #ifdef V8_TARGET_ARCH_MIPS
DEFINE_bool(crankshaft, false, "use crankshaft") DEFINE_bool(crankshaft, false, "use crankshaft")
......
// Copyright 2006-2008 the V8 project authors. All rights reserved. // Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
...@@ -36,7 +36,7 @@ typedef bool (*NativeSourceCallback)(Vector<const char> name, ...@@ -36,7 +36,7 @@ typedef bool (*NativeSourceCallback)(Vector<const char> name,
int index); int index);
enum NativeType { enum NativeType {
CORE, D8, I18N CORE, EXPERIMENTAL, D8, I18N
}; };
template <NativeType type> template <NativeType type>
...@@ -57,6 +57,7 @@ class NativesCollection { ...@@ -57,6 +57,7 @@ class NativesCollection {
}; };
typedef NativesCollection<CORE> Natives; typedef NativesCollection<CORE> Natives;
typedef NativesCollection<EXPERIMENTAL> ExperimentalNatives;
} } // namespace v8::internal } } // namespace v8::internal
......
// Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
global.Proxy = new $Object();
...@@ -230,7 +230,8 @@ ...@@ -230,7 +230,8 @@
'../../src', '../../src',
], ],
'sources': [ 'sources': [
'<(SHARED_INTERMEDIATE_DIR)/libraries-empty.cc', '<(SHARED_INTERMEDIATE_DIR)/libraries.cc',
'<(SHARED_INTERMEDIATE_DIR)/experimental-libraries.cc',
'<(INTERMEDIATE_DIR)/snapshot.cc', '<(INTERMEDIATE_DIR)/snapshot.cc',
], ],
'actions': [ 'actions': [
...@@ -259,6 +260,7 @@ ...@@ -259,6 +260,7 @@
], ],
'sources': [ 'sources': [
'<(SHARED_INTERMEDIATE_DIR)/libraries.cc', '<(SHARED_INTERMEDIATE_DIR)/libraries.cc',
'<(SHARED_INTERMEDIATE_DIR)/experimental-libraries.cc',
'../../src/snapshot-empty.cc', '../../src/snapshot-empty.cc',
], ],
'conditions': [ 'conditions': [
...@@ -722,6 +724,10 @@ ...@@ -722,6 +724,10 @@
'../../src/regexp.js', '../../src/regexp.js',
'../../src/macros.py', '../../src/macros.py',
], ],
'experimental_library_files': [
'../../src/proxy.js',
'../../src/macros.py',
],
}, },
'actions': [ 'actions': [
{ {
...@@ -732,7 +738,6 @@ ...@@ -732,7 +738,6 @@
], ],
'outputs': [ 'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/libraries.cc', '<(SHARED_INTERMEDIATE_DIR)/libraries.cc',
'<(SHARED_INTERMEDIATE_DIR)/libraries-empty.cc',
], ],
'action': [ 'action': [
'python', 'python',
...@@ -742,6 +747,23 @@ ...@@ -742,6 +747,23 @@
'<@(library_files)' '<@(library_files)'
], ],
}, },
{
'action_name': 'js2c_experimental',
'inputs': [
'../../tools/js2c.py',
'<@(experimental_library_files)',
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/experimental-libraries.cc',
],
'action': [
'python',
'../../tools/js2c.py',
'<@(_outputs)',
'EXPERIMENTAL',
'<@(experimental_library_files)'
],
},
], ],
}, },
{ {
......
...@@ -204,7 +204,7 @@ def ReadMacros(lines): ...@@ -204,7 +204,7 @@ def ReadMacros(lines):
HEADER_TEMPLATE = """\ HEADER_TEMPLATE = """\
// Copyright 2008 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// This file was generated from .js source files by SCons. If you // This file was generated from .js source files by SCons. If you
// want to make changes to this file you should either change the // want to make changes to this file you should either change the
...@@ -288,7 +288,6 @@ def JS2C(source, target, env): ...@@ -288,7 +288,6 @@ def JS2C(source, target, env):
minifier = jsmin.JavaScriptMinifier() minifier = jsmin.JavaScriptMinifier()
source_lines_empty = []
for module in modules: for module in modules:
filename = str(module) filename = str(module)
debugger = filename.endswith('-debugger.js') debugger = filename.endswith('-debugger.js')
...@@ -305,7 +304,6 @@ def JS2C(source, target, env): ...@@ -305,7 +304,6 @@ def JS2C(source, target, env):
else: else:
ids.append((id, len(lines))) ids.append((id, len(lines)))
source_lines.append(SOURCE_DECLARATION % { 'id': id, 'data': data }) source_lines.append(SOURCE_DECLARATION % { 'id': id, 'data': data })
source_lines_empty.append(SOURCE_DECLARATION % { 'id': id, 'data': data })
# Build debugger support functions # Build debugger support functions
get_index_cases = [ ] get_index_cases = [ ]
...@@ -356,25 +354,11 @@ def JS2C(source, target, env): ...@@ -356,25 +354,11 @@ def JS2C(source, target, env):
}) })
output.close() output.close()
if len(target) > 1:
output = open(str(target[1]), "w")
output.write(HEADER_TEMPLATE % {
'builtin_count': len(ids) + len(debugger_ids),
'debugger_count': len(debugger_ids),
'source_lines': "\n".join(source_lines_empty),
'get_index_cases': "".join(get_index_cases),
'get_script_source_cases': "".join(get_script_source_cases),
'get_script_name_cases': "".join(get_script_name_cases),
'type': env['TYPE']
})
output.close()
def main(): def main():
natives = sys.argv[1] natives = sys.argv[1]
natives_empty = sys.argv[2] type = sys.argv[2]
type = sys.argv[3] source_files = sys.argv[3:]
source_files = sys.argv[4:] JS2C(source_files, [natives], { 'TYPE': type })
JS2C(source_files, [natives, natives_empty], { 'TYPE': type })
if __name__ == "__main__": if __name__ == "__main__":
main() main()
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