blob: 50232661c1976d67e61fe7855fd19e16d186197f [file] [log] [blame]
yangguo@chromium.org659ceec2012-01-26 07:37:54 +00001// Copyright 2012 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#include "v8.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000029#include "accessors.h"
yangguo@chromium.org659ceec2012-01-26 07:37:54 +000030
31#include "contexts.h"
kasperl@chromium.orga5551262010-12-07 12:49:48 +000032#include "deoptimizer.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000033#include "execution.h"
34#include "factory.h"
yangguo@chromium.org659ceec2012-01-26 07:37:54 +000035#include "frames-inl.h"
36#include "isolate.h"
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +000037#include "list-inl.h"
yangguo@chromium.org659ceec2012-01-26 07:37:54 +000038#include "property-details.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000039
kasperl@chromium.org71affb52009-05-26 05:44:31 +000040namespace v8 {
41namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000042
43
44template <class C>
hpayer@chromium.org8432c912013-02-28 15:55:26 +000045static C* FindInstanceOf(Isolate* isolate, Object* obj) {
46 for (Object* cur = obj; !cur->IsNull(); cur = cur->GetPrototype(isolate)) {
verwaest@chromium.org33e09c82012-10-10 17:07:22 +000047 if (Is<C>(cur)) return C::cast(cur);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000048 }
verwaest@chromium.org33e09c82012-10-10 17:07:22 +000049 return NULL;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000050}
51
52
53// Entry point that never should be called.
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +000054MaybeObject* Accessors::IllegalSetter(Isolate* isolate,
55 JSObject*,
56 Object*,
57 void*) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000058 UNREACHABLE();
59 return NULL;
60}
61
62
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +000063Object* Accessors::IllegalGetAccessor(Isolate* isolate,
64 Object* object,
65 void*) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000066 UNREACHABLE();
67 return object;
68}
69
70
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +000071MaybeObject* Accessors::ReadOnlySetAccessor(Isolate* isolate,
72 JSObject*,
73 Object* value,
74 void*) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000075 // According to ECMA-262, section 8.6.2.2, page 28, setting
76 // read-only properties must be silently ignored.
77 return value;
78}
79
80
machenbach@chromium.org8e36b5b2013-09-26 07:36:30 +000081static V8_INLINE bool CheckForName(Handle<String> name,
82 String* property_name,
83 int offset,
84 int* object_offset) {
85 if (name->Equals(property_name)) {
86 *object_offset = offset;
87 return true;
88 }
89 return false;
90}
91
92
93bool Accessors::IsJSObjectFieldAccessor(
94 Handle<Map> map, Handle<String> name,
95 int* object_offset) {
96 Isolate* isolate = map->GetIsolate();
97 switch (map->instance_type()) {
98 case JS_ARRAY_TYPE:
99 return
100 CheckForName(name, isolate->heap()->length_string(),
101 JSArray::kLengthOffset, object_offset);
102 case JS_TYPED_ARRAY_TYPE:
103 return
104 CheckForName(name, isolate->heap()->length_string(),
105 JSTypedArray::kLengthOffset, object_offset) ||
106 CheckForName(name, isolate->heap()->byte_length_string(),
107 JSTypedArray::kByteLengthOffset, object_offset) ||
108 CheckForName(name, isolate->heap()->byte_offset_string(),
109 JSTypedArray::kByteOffsetOffset, object_offset) ||
110 CheckForName(name, isolate->heap()->buffer_string(),
111 JSTypedArray::kBufferOffset, object_offset);
112 case JS_ARRAY_BUFFER_TYPE:
113 return
114 CheckForName(name, isolate->heap()->byte_length_string(),
115 JSArrayBuffer::kByteLengthOffset, object_offset);
116 case JS_DATA_VIEW_TYPE:
117 return
118 CheckForName(name, isolate->heap()->byte_length_string(),
119 JSDataView::kByteLengthOffset, object_offset) ||
120 CheckForName(name, isolate->heap()->byte_offset_string(),
121 JSDataView::kByteOffsetOffset, object_offset) ||
122 CheckForName(name, isolate->heap()->buffer_string(),
123 JSDataView::kBufferOffset, object_offset);
124 default: {
125 if (map->instance_type() < FIRST_NONSTRING_TYPE) {
126 return
127 CheckForName(name, isolate->heap()->length_string(),
128 String::kLengthOffset, object_offset);
129 }
130 return false;
131 }
132 }
133}
134
135
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000136//
137// Accessors::ArrayLength
138//
139
140
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000141MaybeObject* Accessors::ArrayGetLength(Isolate* isolate,
142 Object* object,
143 void*) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000144 // Traverse the prototype chain until we reach an array.
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000145 JSArray* holder = FindInstanceOf<JSArray>(isolate, object);
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000146 return holder == NULL ? Smi::FromInt(0) : holder->length();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000147}
148
149
150// The helper function will 'flatten' Number objects.
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000151Object* Accessors::FlattenNumber(Isolate* isolate, Object* value) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000152 if (value->IsNumber() || !value->IsJSValue()) return value;
153 JSValue* wrapper = JSValue::cast(value);
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000154 ASSERT(wrapper->GetIsolate()->context()->native_context()->number_function()->
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000155 has_initial_map());
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000156 Map* number_map = isolate->context()->native_context()->
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000157 number_function()->initial_map();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000158 if (wrapper->map() == number_map) return wrapper->value();
159 return value;
160}
161
162
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000163MaybeObject* Accessors::ArraySetLength(Isolate* isolate,
164 JSObject* object,
165 Object* value,
166 void*) {
lrn@chromium.orgac2828d2011-06-23 06:29:21 +0000167 // This means one of the object's prototypes is a JSArray and the
168 // object does not have a 'length' property. Calling SetProperty
169 // causes an infinite loop.
170 if (!object->IsJSArray()) {
dslomov@chromium.org4a35c5a2013-09-13 07:28:52 +0000171 return object->SetLocalPropertyIgnoreAttributesTrampoline(
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +0000172 isolate->heap()->length_string(), value, NONE);
lrn@chromium.orgac2828d2011-06-23 06:29:21 +0000173 }
174
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000175 value = FlattenNumber(isolate, value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000176
177 // Need to call methods that may trigger GC.
lrn@chromium.org7516f052011-03-30 08:52:27 +0000178 HandleScope scope(isolate);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000179
180 // Protect raw pointers.
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +0000181 Handle<JSArray> array_handle(JSArray::cast(object), isolate);
lrn@chromium.org7516f052011-03-30 08:52:27 +0000182 Handle<Object> value_handle(value, isolate);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000183
184 bool has_exception;
mstarzinger@chromium.orge9000182013-09-03 11:25:39 +0000185 Handle<Object> uint32_v =
186 Execution::ToUint32(isolate, value_handle, &has_exception);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000187 if (has_exception) return Failure::Exception();
mstarzinger@chromium.orge9000182013-09-03 11:25:39 +0000188 Handle<Object> number_v =
189 Execution::ToNumber(isolate, value_handle, &has_exception);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000190 if (has_exception) return Failure::Exception();
191
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000192 if (uint32_v->Number() == number_v->Number()) {
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000193 return array_handle->SetElementsLength(*uint32_v);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000194 }
lrn@chromium.org7516f052011-03-30 08:52:27 +0000195 return isolate->Throw(
196 *isolate->factory()->NewRangeError("invalid_array_length",
197 HandleVector<Object>(NULL, 0)));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000198}
199
200
201const AccessorDescriptor Accessors::ArrayLength = {
202 ArrayGetLength,
203 ArraySetLength,
204 0
205};
206
207
208//
209// Accessors::StringLength
210//
211
212
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000213MaybeObject* Accessors::StringGetLength(Isolate* isolate,
214 Object* object,
215 void*) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000216 Object* value = object;
217 if (object->IsJSValue()) value = JSValue::cast(object)->value();
218 if (value->IsString()) return Smi::FromInt(String::cast(value)->length());
219 // If object is not a string we return 0 to be compatible with WebKit.
220 // Note: Firefox returns the length of ToString(object).
221 return Smi::FromInt(0);
222}
223
224
225const AccessorDescriptor Accessors::StringLength = {
226 StringGetLength,
227 IllegalSetter,
228 0
229};
230
231
232//
233// Accessors::ScriptSource
234//
235
236
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000237MaybeObject* Accessors::ScriptGetSource(Isolate* isolate,
238 Object* object,
239 void*) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000240 Object* script = JSValue::cast(object)->value();
241 return Script::cast(script)->source();
242}
243
244
245const AccessorDescriptor Accessors::ScriptSource = {
246 ScriptGetSource,
247 IllegalSetter,
248 0
249};
250
251
252//
253// Accessors::ScriptName
254//
255
256
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000257MaybeObject* Accessors::ScriptGetName(Isolate* isolate,
258 Object* object,
259 void*) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000260 Object* script = JSValue::cast(object)->value();
261 return Script::cast(script)->name();
262}
263
264
265const AccessorDescriptor Accessors::ScriptName = {
266 ScriptGetName,
267 IllegalSetter,
268 0
269};
270
271
272//
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000273// Accessors::ScriptId
274//
275
276
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000277MaybeObject* Accessors::ScriptGetId(Isolate* isolate, Object* object, void*) {
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000278 Object* script = JSValue::cast(object)->value();
279 return Script::cast(script)->id();
280}
281
282
283const AccessorDescriptor Accessors::ScriptId = {
284 ScriptGetId,
285 IllegalSetter,
286 0
287};
288
289
290//
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000291// Accessors::ScriptLineOffset
292//
293
294
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000295MaybeObject* Accessors::ScriptGetLineOffset(Isolate* isolate,
296 Object* object,
297 void*) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000298 Object* script = JSValue::cast(object)->value();
299 return Script::cast(script)->line_offset();
300}
301
302
303const AccessorDescriptor Accessors::ScriptLineOffset = {
304 ScriptGetLineOffset,
305 IllegalSetter,
306 0
307};
308
309
310//
311// Accessors::ScriptColumnOffset
312//
313
314
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000315MaybeObject* Accessors::ScriptGetColumnOffset(Isolate* isolate,
316 Object* object,
317 void*) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000318 Object* script = JSValue::cast(object)->value();
319 return Script::cast(script)->column_offset();
320}
321
322
323const AccessorDescriptor Accessors::ScriptColumnOffset = {
324 ScriptGetColumnOffset,
325 IllegalSetter,
326 0
327};
328
329
330//
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000331// Accessors::ScriptData
332//
333
334
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000335MaybeObject* Accessors::ScriptGetData(Isolate* isolate,
336 Object* object,
337 void*) {
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000338 Object* script = JSValue::cast(object)->value();
339 return Script::cast(script)->data();
340}
341
342
343const AccessorDescriptor Accessors::ScriptData = {
344 ScriptGetData,
345 IllegalSetter,
346 0
347};
348
349
350//
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000351// Accessors::ScriptType
352//
353
354
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000355MaybeObject* Accessors::ScriptGetType(Isolate* isolate,
356 Object* object,
357 void*) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000358 Object* script = JSValue::cast(object)->value();
359 return Script::cast(script)->type();
360}
361
362
363const AccessorDescriptor Accessors::ScriptType = {
364 ScriptGetType,
365 IllegalSetter,
366 0
367};
368
369
370//
ager@chromium.orge2902be2009-06-08 12:21:35 +0000371// Accessors::ScriptCompilationType
372//
373
374
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000375MaybeObject* Accessors::ScriptGetCompilationType(Isolate* isolate,
376 Object* object,
377 void*) {
ager@chromium.orge2902be2009-06-08 12:21:35 +0000378 Object* script = JSValue::cast(object)->value();
danno@chromium.orgd3c42102013-08-01 16:58:23 +0000379 return Smi::FromInt(Script::cast(script)->compilation_type());
ager@chromium.orge2902be2009-06-08 12:21:35 +0000380}
381
382
383const AccessorDescriptor Accessors::ScriptCompilationType = {
384 ScriptGetCompilationType,
385 IllegalSetter,
386 0
387};
388
389
390//
iposva@chromium.org245aa852009-02-10 00:49:54 +0000391// Accessors::ScriptGetLineEnds
392//
393
394
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000395MaybeObject* Accessors::ScriptGetLineEnds(Isolate* isolate,
396 Object* object,
397 void*) {
lrn@chromium.org7516f052011-03-30 08:52:27 +0000398 JSValue* wrapper = JSValue::cast(object);
lrn@chromium.org7516f052011-03-30 08:52:27 +0000399 HandleScope scope(isolate);
400 Handle<Script> script(Script::cast(wrapper->value()), isolate);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000401 InitScriptLineEnds(script);
sgjesse@chromium.org499aaa52009-11-30 08:07:20 +0000402 ASSERT(script->line_ends()->IsFixedArray());
403 Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends()));
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000404 // We do not want anyone to modify this array from JS.
lrn@chromium.org7516f052011-03-30 08:52:27 +0000405 ASSERT(*line_ends == isolate->heap()->empty_fixed_array() ||
406 line_ends->map() == isolate->heap()->fixed_cow_array_map());
407 Handle<JSArray> js_array =
408 isolate->factory()->NewJSArrayWithElements(line_ends);
sgjesse@chromium.org499aaa52009-11-30 08:07:20 +0000409 return *js_array;
iposva@chromium.org245aa852009-02-10 00:49:54 +0000410}
411
412
413const AccessorDescriptor Accessors::ScriptLineEnds = {
414 ScriptGetLineEnds,
415 IllegalSetter,
416 0
417};
418
419
420//
ager@chromium.org9085a012009-05-11 19:22:57 +0000421// Accessors::ScriptGetContextData
422//
423
424
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000425MaybeObject* Accessors::ScriptGetContextData(Isolate* isolate,
426 Object* object,
427 void*) {
ager@chromium.orge2902be2009-06-08 12:21:35 +0000428 Object* script = JSValue::cast(object)->value();
429 return Script::cast(script)->context_data();
ager@chromium.org9085a012009-05-11 19:22:57 +0000430}
431
432
433const AccessorDescriptor Accessors::ScriptContextData = {
434 ScriptGetContextData,
435 IllegalSetter,
436 0
437};
438
439
440//
sgjesse@chromium.org98180592009-12-02 08:17:28 +0000441// Accessors::ScriptGetEvalFromScript
ager@chromium.orge2902be2009-06-08 12:21:35 +0000442//
443
444
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000445MaybeObject* Accessors::ScriptGetEvalFromScript(Isolate* isolate,
446 Object* object,
447 void*) {
ager@chromium.orge2902be2009-06-08 12:21:35 +0000448 Object* script = JSValue::cast(object)->value();
sgjesse@chromium.org98180592009-12-02 08:17:28 +0000449 if (!Script::cast(script)->eval_from_shared()->IsUndefined()) {
450 Handle<SharedFunctionInfo> eval_from_shared(
451 SharedFunctionInfo::cast(Script::cast(script)->eval_from_shared()));
452
453 if (eval_from_shared->script()->IsScript()) {
454 Handle<Script> eval_from_script(Script::cast(eval_from_shared->script()));
455 return *GetScriptWrapper(eval_from_script);
456 }
457 }
hpayer@chromium.orgc5d49712013-09-11 08:25:48 +0000458 return isolate->heap()->undefined_value();
ager@chromium.orge2902be2009-06-08 12:21:35 +0000459}
460
461
sgjesse@chromium.org98180592009-12-02 08:17:28 +0000462const AccessorDescriptor Accessors::ScriptEvalFromScript = {
463 ScriptGetEvalFromScript,
ager@chromium.orge2902be2009-06-08 12:21:35 +0000464 IllegalSetter,
465 0
466};
467
468
469//
sgjesse@chromium.org98180592009-12-02 08:17:28 +0000470// Accessors::ScriptGetEvalFromScriptPosition
ager@chromium.orge2902be2009-06-08 12:21:35 +0000471//
472
473
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000474MaybeObject* Accessors::ScriptGetEvalFromScriptPosition(Isolate* isolate,
475 Object* object,
476 void*) {
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +0000477 Script* raw_script = Script::cast(JSValue::cast(object)->value());
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000478 HandleScope scope(isolate);
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +0000479 Handle<Script> script(raw_script);
ager@chromium.orge2902be2009-06-08 12:21:35 +0000480
481 // If this is not a script compiled through eval there is no eval position.
danno@chromium.orgd3c42102013-08-01 16:58:23 +0000482 if (script->compilation_type() != Script::COMPILATION_TYPE_EVAL) {
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +0000483 return script->GetHeap()->undefined_value();
ager@chromium.orge2902be2009-06-08 12:21:35 +0000484 }
485
486 // Get the function from where eval was called and find the source position
487 // from the instruction offset.
sgjesse@chromium.org98180592009-12-02 08:17:28 +0000488 Handle<Code> code(SharedFunctionInfo::cast(
489 script->eval_from_shared())->code());
ager@chromium.orge2902be2009-06-08 12:21:35 +0000490 return Smi::FromInt(code->SourcePosition(code->instruction_start() +
491 script->eval_from_instructions_offset()->value()));
492}
493
494
sgjesse@chromium.org98180592009-12-02 08:17:28 +0000495const AccessorDescriptor Accessors::ScriptEvalFromScriptPosition = {
496 ScriptGetEvalFromScriptPosition,
497 IllegalSetter,
498 0
499};
500
501
502//
503// Accessors::ScriptGetEvalFromFunctionName
504//
505
506
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000507MaybeObject* Accessors::ScriptGetEvalFromFunctionName(Isolate* isolate,
508 Object* object,
509 void*) {
sgjesse@chromium.org98180592009-12-02 08:17:28 +0000510 Object* script = JSValue::cast(object)->value();
511 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(
512 Script::cast(script)->eval_from_shared()));
513
514
515 // Find the name of the function calling eval.
516 if (!shared->name()->IsUndefined()) {
517 return shared->name();
518 } else {
519 return shared->inferred_name();
520 }
521}
522
523
524const AccessorDescriptor Accessors::ScriptEvalFromFunctionName = {
525 ScriptGetEvalFromFunctionName,
ager@chromium.orge2902be2009-06-08 12:21:35 +0000526 IllegalSetter,
527 0
528};
529
530
531//
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000532// Accessors::FunctionPrototype
533//
534
535
rossberg@chromium.orgebeba022013-08-19 09:36:44 +0000536Handle<Object> Accessors::FunctionGetPrototype(Handle<JSFunction> function) {
537 CALL_HEAP_FUNCTION(function->GetIsolate(),
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000538 Accessors::FunctionGetPrototype(function->GetIsolate(),
539 *function,
540 NULL),
rossberg@chromium.orgebeba022013-08-19 09:36:44 +0000541 Object);
542}
543
544
545Handle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function,
546 Handle<Object> prototype) {
547 ASSERT(function->should_have_prototype());
548 CALL_HEAP_FUNCTION(function->GetIsolate(),
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000549 Accessors::FunctionSetPrototype(function->GetIsolate(),
550 *function,
rossberg@chromium.orgebeba022013-08-19 09:36:44 +0000551 *prototype,
552 NULL),
553 Object);
ulan@chromium.org77ca49a2013-04-22 09:43:56 +0000554}
555
556
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000557MaybeObject* Accessors::FunctionGetPrototype(Isolate* isolate,
558 Object* object,
559 void*) {
jkummerow@chromium.orgba72ec82013-07-22 09:21:20 +0000560 JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, object);
561 if (function_raw == NULL) return isolate->heap()->undefined_value();
562 while (!function_raw->should_have_prototype()) {
563 function_raw = FindInstanceOf<JSFunction>(isolate,
564 function_raw->GetPrototype());
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000565 // There has to be one because we hit the getter.
jkummerow@chromium.orgba72ec82013-07-22 09:21:20 +0000566 ASSERT(function_raw != NULL);
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000567 }
568
jkummerow@chromium.orgba72ec82013-07-22 09:21:20 +0000569 if (!function_raw->has_prototype()) {
570 HandleScope scope(isolate);
571 Handle<JSFunction> function(function_raw);
572 Handle<Object> proto = isolate->factory()->NewFunctionPrototype(function);
573 JSFunction::SetPrototype(function, proto);
574 function_raw = *function;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000575 }
jkummerow@chromium.orgba72ec82013-07-22 09:21:20 +0000576 return function_raw->prototype();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000577}
578
579
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000580MaybeObject* Accessors::FunctionSetPrototype(Isolate* isolate,
581 JSObject* object,
jkummerow@chromium.org5323a9c2012-12-10 19:00:50 +0000582 Object* value_raw,
lrn@chromium.org303ada72010-10-27 09:33:13 +0000583 void*) {
jkummerow@chromium.org5323a9c2012-12-10 19:00:50 +0000584 Heap* heap = isolate->heap();
hpayer@chromium.org8432c912013-02-28 15:55:26 +0000585 JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, object);
jkummerow@chromium.org5323a9c2012-12-10 19:00:50 +0000586 if (function_raw == NULL) return heap->undefined_value();
587 if (!function_raw->should_have_prototype()) {
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000588 // Since we hit this accessor, object will have no prototype property.
dslomov@chromium.org4a35c5a2013-09-13 07:28:52 +0000589 return object->SetLocalPropertyIgnoreAttributesTrampoline(
590 heap->prototype_string(), value_raw, NONE);
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000591 }
592
jkummerow@chromium.org5323a9c2012-12-10 19:00:50 +0000593 HandleScope scope(isolate);
594 Handle<JSFunction> function(function_raw, isolate);
595 Handle<Object> value(value_raw, isolate);
596
597 Handle<Object> old_value;
598 bool is_observed =
599 FLAG_harmony_observation &&
600 *function == object &&
601 function->map()->is_observed();
602 if (is_observed) {
603 if (function->has_prototype())
604 old_value = handle(function->prototype(), isolate);
605 else
606 old_value = isolate->factory()->NewFunctionPrototype(function);
lrn@chromium.org303ada72010-10-27 09:33:13 +0000607 }
jkummerow@chromium.org5323a9c2012-12-10 19:00:50 +0000608
jkummerow@chromium.orgba72ec82013-07-22 09:21:20 +0000609 JSFunction::SetPrototype(function, value);
jkummerow@chromium.org5323a9c2012-12-10 19:00:50 +0000610 ASSERT(function->prototype() == *value);
611
612 if (is_observed && !old_value->SameValue(*value)) {
613 JSObject::EnqueueChangeRecord(
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +0000614 function, "updated", isolate->factory()->prototype_string(), old_value);
jkummerow@chromium.org5323a9c2012-12-10 19:00:50 +0000615 }
616
617 return *function;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000618}
619
620
621const AccessorDescriptor Accessors::FunctionPrototype = {
622 FunctionGetPrototype,
623 FunctionSetPrototype,
624 0
625};
626
627
628//
629// Accessors::FunctionLength
630//
631
632
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000633MaybeObject* Accessors::FunctionGetLength(Isolate* isolate,
634 Object* object,
635 void*) {
hpayer@chromium.org8432c912013-02-28 15:55:26 +0000636 JSFunction* function = FindInstanceOf<JSFunction>(isolate, object);
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000637 if (function == NULL) return Smi::FromInt(0);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000638 // Check if already compiled.
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000639 if (function->shared()->is_compiled()) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000640 return Smi::FromInt(function->shared()->length());
641 }
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000642 // If the function isn't compiled yet, the length is not computed correctly
643 // yet. Compile it now and return the right length.
hpayer@chromium.org8432c912013-02-28 15:55:26 +0000644 HandleScope scope(isolate);
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000645 Handle<JSFunction> handle(function);
646 if (JSFunction::CompileLazy(handle, KEEP_EXCEPTION)) {
647 return Smi::FromInt(handle->shared()->length());
648 }
649 return Failure::Exception();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000650}
651
652
653const AccessorDescriptor Accessors::FunctionLength = {
654 FunctionGetLength,
655 ReadOnlySetAccessor,
656 0
657};
658
659
660//
661// Accessors::FunctionName
662//
663
664
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000665MaybeObject* Accessors::FunctionGetName(Isolate* isolate,
666 Object* object,
667 void*) {
hpayer@chromium.org8432c912013-02-28 15:55:26 +0000668 JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object);
669 return holder == NULL
670 ? isolate->heap()->undefined_value()
671 : holder->shared()->name();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000672}
673
674
675const AccessorDescriptor Accessors::FunctionName = {
676 FunctionGetName,
677 ReadOnlySetAccessor,
678 0
679};
680
681
682//
683// Accessors::FunctionArguments
684//
685
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000686
rossberg@chromium.orgebeba022013-08-19 09:36:44 +0000687Handle<Object> Accessors::FunctionGetArguments(Handle<JSFunction> function) {
688 CALL_HEAP_FUNCTION(function->GetIsolate(),
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000689 Accessors::FunctionGetArguments(function->GetIsolate(),
690 *function,
691 NULL),
rossberg@chromium.orgebeba022013-08-19 09:36:44 +0000692 Object);
jkummerow@chromium.orgba72ec82013-07-22 09:21:20 +0000693}
694
695
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000696static MaybeObject* ConstructArgumentsObjectForInlinedFunction(
697 JavaScriptFrame* frame,
698 Handle<JSFunction> inlined_function,
699 int inlined_frame_index) {
ulan@chromium.org09d7ab52013-02-25 15:50:35 +0000700 Isolate* isolate = inlined_function->GetIsolate();
701 Factory* factory = isolate->factory();
yangguo@chromium.org659ceec2012-01-26 07:37:54 +0000702 Vector<SlotRef> args_slots =
703 SlotRef::ComputeSlotMappingForArguments(
704 frame,
705 inlined_frame_index,
706 inlined_function->shared()->formal_parameter_count());
707 int args_count = args_slots.length();
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000708 Handle<JSObject> arguments =
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000709 factory->NewArgumentsObject(inlined_function, args_count);
710 Handle<FixedArray> array = factory->NewFixedArray(args_count);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000711 for (int i = 0; i < args_count; ++i) {
ulan@chromium.org09d7ab52013-02-25 15:50:35 +0000712 Handle<Object> value = args_slots[i].GetValue(isolate);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000713 array->set(i, *value);
714 }
715 arguments->set_elements(*array);
yangguo@chromium.org659ceec2012-01-26 07:37:54 +0000716 args_slots.Dispose();
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000717
718 // Return the freshly allocated arguments object.
719 return *arguments;
720}
721
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000722
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000723MaybeObject* Accessors::FunctionGetArguments(Isolate* isolate,
724 Object* object,
725 void*) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000726 HandleScope scope(isolate);
hpayer@chromium.org8432c912013-02-28 15:55:26 +0000727 JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object);
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000728 if (holder == NULL) return isolate->heap()->undefined_value();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000729 Handle<JSFunction> function(holder, isolate);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000730
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000731 if (function->shared()->native()) return isolate->heap()->null_value();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000732 // Find the top invocation of the function by traversing frames.
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000733 List<JSFunction*> functions(2);
vegorov@chromium.org74f333b2011-04-06 11:17:46 +0000734 for (JavaScriptFrameIterator it(isolate); !it.done(); it.Advance()) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000735 JavaScriptFrame* frame = it.frame();
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000736 frame->GetFunctions(&functions);
737 for (int i = functions.length() - 1; i >= 0; i--) {
738 // Skip all frames that aren't invocations of the given function.
739 if (functions[i] != *function) continue;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000740
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000741 if (i > 0) {
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000742 // The function in question was inlined. Inlined functions have the
743 // correct number of arguments and no allocated arguments object, so
744 // we can construct a fresh one by interpreting the function's
745 // deoptimization input data.
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000746 return ConstructArgumentsObjectForInlinedFunction(frame, function, i);
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000747 }
748
749 if (!frame->is_optimized()) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000750 // If there is an arguments variable in the stack, we return that.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000751 Handle<ScopeInfo> scope_info(function->shared()->scope_info());
752 int index = scope_info->StackSlotIndex(
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +0000753 isolate->heap()->arguments_string());
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000754 if (index >= 0) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000755 Handle<Object> arguments(frame->GetExpression(index), isolate);
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000756 if (!arguments->IsArgumentsMarker()) return *arguments;
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000757 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000758 }
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000759
760 // If there is no arguments variable in the stack or we have an
761 // optimized frame, we find the frame that holds the actual arguments
762 // passed to the function.
763 it.AdvanceToArgumentsFrame();
764 frame = it.frame();
765
766 // Get the number of arguments and construct an arguments object
767 // mirror for the right frame.
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +0000768 const int length = frame->ComputeParametersCount();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000769 Handle<JSObject> arguments = isolate->factory()->NewArgumentsObject(
770 function, length);
771 Handle<FixedArray> array = isolate->factory()->NewFixedArray(length);
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000772
773 // Copy the parameters to the arguments object.
774 ASSERT(array->length() == length);
775 for (int i = 0; i < length; i++) array->set(i, frame->GetParameter(i));
776 arguments->set_elements(*array);
777
778 // Return the freshly allocated arguments object.
779 return *arguments;
ager@chromium.org3e875802009-06-29 08:26:34 +0000780 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000781 functions.Rewind(0);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000782 }
783
784 // No frame corresponding to the given function found. Return null.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000785 return isolate->heap()->null_value();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000786}
787
788
789const AccessorDescriptor Accessors::FunctionArguments = {
790 FunctionGetArguments,
791 ReadOnlySetAccessor,
792 0
793};
794
795
796//
797// Accessors::FunctionCaller
798//
799
800
ricow@chromium.org4668a2c2011-08-29 10:41:00 +0000801class FrameFunctionIterator {
802 public:
rossberg@chromium.org79e79022013-06-03 15:43:46 +0000803 FrameFunctionIterator(Isolate* isolate, const DisallowHeapAllocation& promise)
ricow@chromium.org4668a2c2011-08-29 10:41:00 +0000804 : frame_iterator_(isolate),
805 functions_(2),
806 index_(0) {
807 GetFunctions();
808 }
809 JSFunction* next() {
810 if (functions_.length() == 0) return NULL;
811 JSFunction* next_function = functions_[index_];
812 index_--;
813 if (index_ < 0) {
814 GetFunctions();
815 }
816 return next_function;
817 }
818
819 // Iterate through functions until the first occurence of 'function'.
820 // Returns true if 'function' is found, and false if the iterator ends
821 // without finding it.
822 bool Find(JSFunction* function) {
823 JSFunction* next_function;
824 do {
825 next_function = next();
826 if (next_function == function) return true;
827 } while (next_function != NULL);
828 return false;
829 }
kmillikin@chromium.org83e16822011-09-13 08:21:47 +0000830
ricow@chromium.org4668a2c2011-08-29 10:41:00 +0000831 private:
832 void GetFunctions() {
833 functions_.Rewind(0);
834 if (frame_iterator_.done()) return;
835 JavaScriptFrame* frame = frame_iterator_.frame();
836 frame->GetFunctions(&functions_);
837 ASSERT(functions_.length() > 0);
838 frame_iterator_.Advance();
839 index_ = functions_.length() - 1;
840 }
841 JavaScriptFrameIterator frame_iterator_;
842 List<JSFunction*> functions_;
843 int index_;
844};
845
846
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000847MaybeObject* Accessors::FunctionGetCaller(Isolate* isolate,
848 Object* object,
849 void*) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000850 HandleScope scope(isolate);
rossberg@chromium.org79e79022013-06-03 15:43:46 +0000851 DisallowHeapAllocation no_allocation;
hpayer@chromium.org8432c912013-02-28 15:55:26 +0000852 JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object);
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000853 if (holder == NULL) return isolate->heap()->undefined_value();
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000854 if (holder->shared()->native()) return isolate->heap()->null_value();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000855 Handle<JSFunction> function(holder, isolate);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000856
rossberg@chromium.org79e79022013-06-03 15:43:46 +0000857 FrameFunctionIterator it(isolate, no_allocation);
ricow@chromium.org4668a2c2011-08-29 10:41:00 +0000858
859 // Find the function from the frames.
860 if (!it.Find(*function)) {
861 // No frame corresponding to the given function found. Return null.
862 return isolate->heap()->null_value();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000863 }
864
ricow@chromium.org4668a2c2011-08-29 10:41:00 +0000865 // Find previously called non-toplevel function.
866 JSFunction* caller;
867 do {
868 caller = it.next();
869 if (caller == NULL) return isolate->heap()->null_value();
870 } while (caller->shared()->is_toplevel());
871
872 // If caller is a built-in function and caller's caller is also built-in,
873 // use that instead.
874 JSFunction* potential_caller = caller;
875 while (potential_caller != NULL && potential_caller->IsBuiltin()) {
876 caller = potential_caller;
877 potential_caller = it.next();
878 }
jkummerow@chromium.org78502a92012-09-06 13:50:42 +0000879 if (!caller->shared()->native() && potential_caller != NULL) {
880 caller = potential_caller;
881 }
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000882 // If caller is bound, return null. This is compatible with JSC, and
883 // allows us to make bound functions use the strict function map
884 // and its associated throwing caller and arguments.
885 if (caller->shared()->bound()) {
886 return isolate->heap()->null_value();
887 }
danno@chromium.org1f34ad32012-11-26 14:53:56 +0000888 // Censor if the caller is not a classic mode function.
889 // Change from ES5, which used to throw, see:
890 // https://bugs.ecmascript.org/show_bug.cgi?id=310
891 if (!caller->shared()->is_classic_mode()) {
892 return isolate->heap()->null_value();
893 }
894
895 return caller;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000896}
897
898
899const AccessorDescriptor Accessors::FunctionCaller = {
900 FunctionGetCaller,
901 ReadOnlySetAccessor,
902 0
903};
904
905
906//
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000907// Accessors::MakeModuleExport
908//
909
verwaest@chromium.orgd4be0f02013-06-05 13:39:03 +0000910static void ModuleGetExport(
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000911 v8::Local<v8::String> property,
verwaest@chromium.orgd4be0f02013-06-05 13:39:03 +0000912 const v8::PropertyCallbackInfo<v8::Value>& info) {
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000913 JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder()));
914 Context* context = Context::cast(instance->context());
915 ASSERT(context->IsModuleContext());
916 int slot = info.Data()->Int32Value();
917 Object* value = context->get(slot);
ulan@chromium.org09d7ab52013-02-25 15:50:35 +0000918 Isolate* isolate = instance->GetIsolate();
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000919 if (value->IsTheHole()) {
920 Handle<String> name = v8::Utils::OpenHandle(*property);
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000921 isolate->ScheduleThrow(
922 *isolate->factory()->NewReferenceError("not_defined",
923 HandleVector(&name, 1)));
verwaest@chromium.orgd4be0f02013-06-05 13:39:03 +0000924 return;
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000925 }
verwaest@chromium.orgd4be0f02013-06-05 13:39:03 +0000926 info.GetReturnValue().Set(v8::Utils::ToLocal(Handle<Object>(value, isolate)));
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000927}
928
929
930static void ModuleSetExport(
931 v8::Local<v8::String> property,
932 v8::Local<v8::Value> value,
verwaest@chromium.orgd4be0f02013-06-05 13:39:03 +0000933 const v8::PropertyCallbackInfo<v8::Value>& info) {
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000934 JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder()));
935 Context* context = Context::cast(instance->context());
936 ASSERT(context->IsModuleContext());
937 int slot = info.Data()->Int32Value();
938 Object* old_value = context->get(slot);
939 if (old_value->IsTheHole()) {
940 Handle<String> name = v8::Utils::OpenHandle(*property);
941 Isolate* isolate = instance->GetIsolate();
942 isolate->ScheduleThrow(
943 *isolate->factory()->NewReferenceError("not_defined",
944 HandleVector(&name, 1)));
945 return;
946 }
947 context->set(slot, *v8::Utils::OpenHandle(*value));
948}
949
950
951Handle<AccessorInfo> Accessors::MakeModuleExport(
952 Handle<String> name,
953 int index,
954 PropertyAttributes attributes) {
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000955 Isolate* isolate = name->GetIsolate();
956 Factory* factory = isolate->factory();
hpayer@chromium.org7c3372b2013-02-13 17:26:04 +0000957 Handle<ExecutableAccessorInfo> info = factory->NewExecutableAccessorInfo();
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000958 info->set_property_attributes(attributes);
959 info->set_all_can_read(true);
960 info->set_all_can_write(true);
961 info->set_name(*name);
962 info->set_data(Smi::FromInt(index));
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000963 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport);
964 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport);
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000965 info->set_getter(*getter);
966 if (!(attributes & ReadOnly)) info->set_setter(*setter);
967 return info;
968}
969
970
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000971} } // namespace v8::internal