OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 static void SetGlobalProperty(const char* name, Object* value) { | 107 static void SetGlobalProperty(const char* name, Object* value) { |
108 Handle<Object> object(value); | 108 Handle<Object> object(value); |
109 Handle<String> symbol = Factory::LookupAsciiSymbol(name); | 109 Handle<String> symbol = Factory::LookupAsciiSymbol(name); |
110 Handle<JSObject> global(Top::context()->global()); | 110 Handle<JSObject> global(Top::context()->global()); |
111 SetProperty(global, symbol, object, NONE); | 111 SetProperty(global, symbol, object, NONE); |
112 } | 112 } |
113 | 113 |
114 | 114 |
115 static Handle<JSFunction> Compile(const char* source) { | 115 static Handle<JSFunction> Compile(const char* source) { |
116 Handle<String> source_code(Factory::NewStringFromUtf8(CStrVector(source))); | 116 Handle<String> source_code(Factory::NewStringFromUtf8(CStrVector(source))); |
117 Handle<JSFunction> boilerplate = | 117 Handle<SharedFunctionInfo> shared_function = |
118 Compiler::Compile(source_code, | 118 Compiler::Compile(source_code, |
119 Handle<String>(), | 119 Handle<String>(), |
120 0, | 120 0, |
121 0, | 121 0, |
122 NULL, | 122 NULL, |
123 NULL, | 123 NULL, |
124 Handle<String>::null(), | 124 Handle<String>::null(), |
125 NOT_NATIVES_CODE); | 125 NOT_NATIVES_CODE); |
126 return Factory::NewFunctionFromBoilerplate(boilerplate, | 126 return Factory::NewFunctionFromSharedFunctionInfo(shared_function, |
127 Top::global_context()); | 127 Top::global_context()); |
128 } | 128 } |
129 | 129 |
130 | 130 |
131 static double Inc(int x) { | 131 static double Inc(int x) { |
132 const char* source = "result = %d + 1;"; | 132 const char* source = "result = %d + 1;"; |
133 EmbeddedVector<char, 512> buffer; | 133 EmbeddedVector<char, 512> buffer; |
134 OS::SNPrintF(buffer, source, x); | 134 OS::SNPrintF(buffer, source, x); |
135 | 135 |
136 Handle<JSFunction> fun = Compile(buffer.start()); | 136 Handle<JSFunction> fun = Compile(buffer.start()); |
137 if (fun.is_null()) return -1; | 137 if (fun.is_null()) return -1; |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 if (i > 0) | 341 if (i > 0) |
342 buffer[i - 1] = '\n'; | 342 buffer[i - 1] = '\n'; |
343 memcpy(&buffer[i], function_f, sizeof(function_f) - 1); | 343 memcpy(&buffer[i], function_f, sizeof(function_f) - 1); |
344 v8::Handle<v8::String> script_body = v8::String::New(buffer.start()); | 344 v8::Handle<v8::String> script_body = v8::String::New(buffer.start()); |
345 v8::Script::Compile(script_body, &origin)->Run(); | 345 v8::Script::Compile(script_body, &origin)->Run(); |
346 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( | 346 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( |
347 env->Global()->Get(v8::String::New("f"))); | 347 env->Global()->Get(v8::String::New("f"))); |
348 CHECK_EQ(i, f->GetScriptLineNumber()); | 348 CHECK_EQ(i, f->GetScriptLineNumber()); |
349 } | 349 } |
350 } | 350 } |
OLD | NEW |